From bbd8a069bb50d1b1776dff1794e913361168afa3 Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Fri, 11 Sep 2020 12:56:32 -0700 Subject: [PATCH] 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. --- zebra-state/src/sled_state.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/zebra-state/src/sled_state.rs b/zebra-state/src/sled_state.rs index 0d2ff586..a095b5a2 100644 --- a/zebra-state/src/sled_state.rs +++ b/zebra-state/src/sled_state.rs @@ -89,10 +89,9 @@ impl SledState { fn commit_finalized(&mut self, queued_block: QueuedBlock) { let QueuedBlock { block, rsp_tx } = queued_block; - // The only valid block without a coinbase height is the genesis - // block. By this point the block has been validated, so if - // there's no coinbase height, it must be the genesis block. - let height = block.coinbase_height().unwrap_or(block::Height(0)); + let height = block + .coinbase_height() + .expect("finalized blocks are valid and have a coinbase height"); let height_bytes = height.0.to_be_bytes(); let hash = block.hash();