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:
parent
2e7f33a958
commit
bbd8a069bb
|
|
@ -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();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue