From 77162eee0f71e9520b59e30f7fa14b680a7b0a40 Mon Sep 17 00:00:00 2001 From: Joonmo Yang Date: Fri, 22 Nov 2019 09:31:52 +0900 Subject: [PATCH] Detect bootstrap header in tendermint worker Tendermint worker skips some process for the genesis block since it doesn't have a parent, and this should be applied to the bootstrap header too. --- core/src/consensus/tendermint/worker.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/core/src/consensus/tendermint/worker.rs b/core/src/consensus/tendermint/worker.rs index da3c9d407c..3b49bb9014 100644 --- a/core/src/consensus/tendermint/worker.rs +++ b/core/src/consensus/tendermint/worker.rs @@ -52,6 +52,7 @@ use crate::encoded; use crate::error::{BlockError, Error}; use crate::snapshot_notify::NotifySender as SnapshotNotifySender; use crate::transaction::{SignedTransaction, UnverifiedTransaction}; +use crate::types::BlockStatus; use crate::views::BlockView; use crate::BlockId; use std::cell::Cell; @@ -958,7 +959,8 @@ impl Worker { } pub fn on_imported_proposal(&mut self, proposal: &Header) { - if proposal.number() < 1 { + // NOTE: Only the genesis block and the snapshot target don't have the parent in the blockchain + if self.client().block_status(&BlockId::Hash(*proposal.parent_hash())) == BlockStatus::Unknown { return } @@ -1660,11 +1662,11 @@ impl Worker { let mut last_term_end = None; for block_hash in &enacted { let header = c.block_header(&BlockId::Hash(*block_hash)).expect("Block is enacted").decode(); - if header.number() == 0 { - continue - } - let parent_header = - c.block_header(&BlockId::Hash(*header.parent_hash())).expect("Parent block should be enacted").decode(); + let parent_header = match c.block_header(&BlockId::Hash(*header.parent_hash())) { + Some(h) => h.decode(), + // NOTE: Only the genesis block and the snapshot target don't have the parent in the blockchain + None => continue, + }; let term_common_params = if let Some(p) = c.term_common_params(parent_header.hash().into()) { p } else {