state: fix bug in SledState::commit_finalized

The previous code filled in block height 0 for a missing coinbase height
in `SledState::commit_finalized`, since the genesis block is the only
block without a coinbase height (because of a mistake when it was
created).

However, @teor2345 noticed that this is incorrect, because we already
parse the genesis block specially and fill in its coinbase height
correctly.  So instead, we can .expect it to be present, because we can
assume that all finalized blocks are valid.
This commit is contained in:
Henry de Valence 2020-09-11 12:56:32 -07:00
parent 2e7f33a958
commit bbd8a069bb
1 changed files with 3 additions and 4 deletions

View File

@ -89,10 +89,9 @@ impl SledState {
fn commit_finalized(&mut self, queued_block: QueuedBlock) { fn commit_finalized(&mut self, queued_block: QueuedBlock) {
let QueuedBlock { block, rsp_tx } = queued_block; let QueuedBlock { block, rsp_tx } = queued_block;
// The only valid block without a coinbase height is the genesis let height = block
// block. By this point the block has been validated, so if .coinbase_height()
// there's no coinbase height, it must be the genesis block. .expect("finalized blocks are valid and have a coinbase height");
let height = block.coinbase_height().unwrap_or(block::Height(0));
let height_bytes = height.0.to_be_bytes(); let height_bytes = height.0.to_be_bytes();
let hash = block.hash(); let hash = block.hash();