Skip to content

Commit

Permalink
node: Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
goshawk-3 authored and goshawk-3 committed Jan 18, 2024
1 parent d7bf54b commit d45091d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
15 changes: 7 additions & 8 deletions node/src/chain/acceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> Acceptor<N, DB, VM> {
}

/// 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()
}

Expand Down Expand Up @@ -547,15 +547,14 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> Acceptor<N, DB, VM> {
}
}

/// 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: database::DB>(
db: Arc<RwLock<DB>>,
mrb: &ledger::Header,
prev_block: &ledger::Header,
provisioners: &ContextProvisioners,
candidate_header: &ledger::Header,
header: &ledger::Header,
) -> anyhow::Result<bool> {
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
}
6 changes: 3 additions & 3 deletions node/src/chain/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(()),
}?;

Expand Down
20 changes: 10 additions & 10 deletions node/src/chain/fsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> InSyncImpl<DB, VM, N> {
msg: &Message,
) -> anyhow::Result<Option<(Block, SocketAddr)>> {
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 {
Expand All @@ -293,18 +293,18 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> InSyncImpl<DB, VM, N> {
}

// 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
{
Expand All @@ -316,10 +316,10 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> InSyncImpl<DB, VM, N> {
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,
)
Expand Down Expand Up @@ -356,7 +356,7 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> InSyncImpl<DB, VM, N> {
info!(
event = "entering fallback",
height = local_header.height,
iter = local_header.height,
iter = local_header.iteration,
new_iter = remote_blk.header().iteration,
);

Expand Down

0 comments on commit d45091d

Please sign in to comment.