Skip to content

Commit

Permalink
Store states in the DB before their blocks
Browse files Browse the repository at this point in the history
Partial fix for #692
  • Loading branch information
michaelsproul committed Dec 11, 2019
1 parent 8a62f3f commit 48c3204
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1322,8 +1322,13 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
}

// Store the block and state.
self.store.put(&block_root, &block)?;
// NOTE: we store the block *after* the state to guard against inconsistency in the event of
// a crash, as states are usually looked up from blocks, not the other way around. A better
// solution would be to use a database transaction (once our choice of database and API
// settles down).
// See: https://github.com/sigp/lighthouse/issues/692
self.store.put_state(&state_root, &state)?;
self.store.put(&block_root, &block)?;

metrics::stop_timer(db_write_timer);

Expand Down

0 comments on commit 48c3204

Please sign in to comment.