From d45091de71c5063c7e5b76a885efb8a47cdbbf8e Mon Sep 17 00:00:00 2001 From: goshawk-3 Date: Thu, 18 Jan 2024 13:45:07 +0200 Subject: [PATCH] node: Address PR comments --- node/src/chain/acceptor.rs | 15 +++++++-------- node/src/chain/fallback.rs | 6 +++--- node/src/chain/fsm.rs | 20 ++++++++++---------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/node/src/chain/acceptor.rs b/node/src/chain/acceptor.rs index 180b90e745..a3e1eb2a4c 100644 --- a/node/src/chain/acceptor.rs +++ b/node/src/chain/acceptor.rs @@ -494,7 +494,7 @@ impl Acceptor { } /// Returns chain tip header - pub(crate) async fn header(&self) -> ledger::Header { + pub(crate) async fn tip_header(&self) -> ledger::Header { self.mrb.read().await.inner().header().clone() } @@ -547,15 +547,14 @@ impl Acceptor { } } -/// Performs full verification of block header (blk_header) against -/// local/current state. +/// Performs full verification of block header against prev_block header where +/// prev_block is usually the blockchain tip pub(crate) async fn verify_block_header( db: Arc>, - mrb: &ledger::Header, + prev_block: &ledger::Header, provisioners: &ContextProvisioners, - candidate_header: &ledger::Header, + header: &ledger::Header, ) -> anyhow::Result { - let validator = Validator::new(db, mrb, provisioners); - - validator.execute_checks(candidate_header, false).await + let validator = Validator::new(db, prev_block, provisioners); + validator.execute_checks(header, false).await } diff --git a/node/src/chain/fallback.rs b/node/src/chain/fallback.rs index 0da001c45a..b4b3484924 100644 --- a/node/src/chain/fallback.rs +++ b/node/src/chain/fallback.rs @@ -48,8 +48,8 @@ impl<'a, N: Network, DB: database::DB, VM: vm::VMExecution> self.acc.try_revert(revert_target).await } - /// Verifies if a block of header `local` can be replaced with a block with - /// header `remote` + /// Verifies if a block with header `local` can be replaced with a block + /// with header `remote` async fn verify_header( &self, local: &Header, @@ -65,7 +65,7 @@ impl<'a, N: Network, DB: database::DB, VM: vm::VMExecution> (_, Ordering::Equal) => Err(anyhow!( "iteration is equal to the current {:?}", local.iteration - )), + )), // TODO: This may be a slashing condition _ => Ok(()), }?; diff --git a/node/src/chain/fsm.rs b/node/src/chain/fsm.rs index 8867f0c9f1..d566a3ba7c 100644 --- a/node/src/chain/fsm.rs +++ b/node/src/chain/fsm.rs @@ -268,7 +268,7 @@ impl InSyncImpl { msg: &Message, ) -> anyhow::Result> { let mut acc = self.acc.write().await; - let local_header = acc.header().await; + let local_header = acc.tip_header().await; let remote_height = remote_blk.header().height; if remote_height < local_header.height { @@ -293,18 +293,18 @@ impl InSyncImpl { } // If our local chain has a block L_B with ConsensusState not Final, - // and we receive a block N_B such that: + // and we receive a block R_B such that: // - // N_B.PrevBlock == L_B.PrevBlock - // N_B.Iteration < L_B.Iteration + // R_B.PrevBlock == L_B.PrevBlock + // R_B.Iteration < L_B.Iteration // // Then we fallback to N_B.PrevBlock and accept N_B - let header = acc.db.read().await.view(|t| { + let local_header = acc.db.read().await.view(|t| { if let Some((prev_header, _)) = t.fetch_block_header(&remote_blk.header().prev_block_hash)? { - let l_b_height = prev_header.height + 1; - if let Some(l_b) = t.fetch_block_by_height(l_b_height)? { + let local_height = prev_header.height + 1; + if let Some(l_b) = t.fetch_block_by_height(local_height)? { if remote_blk.header().iteration < l_b.header().iteration { @@ -316,10 +316,10 @@ impl InSyncImpl { anyhow::Ok(None) })?; - if let Some(header) = header { + if let Some(local_header) = local_header { match fallback::WithContext::new(acc.deref()) .try_revert( - &header, + &local_header, remote_blk.header(), RevertTarget::LastFinalizedState, ) @@ -356,7 +356,7 @@ impl InSyncImpl { info!( event = "entering fallback", height = local_header.height, - iter = local_header.height, + iter = local_header.iteration, new_iter = remote_blk.header().iteration, );