Skip to content

Commit

Permalink
node: Pass Block message to try_accept_block in in_sync mode
Browse files Browse the repository at this point in the history
  • Loading branch information
goshawk-3 authored and goshawk-3 committed Feb 20, 2024
1 parent 637c38d commit 2c9dffe
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions node/src/chain/fsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> InSyncImpl<DB, VM, N> {
let curr_h = acc.get_curr_height().await;

if blk.header().height == curr_h + 1 {
acc.try_accept_block(blk, true).await?;
acc.try_accept_block(blk, None, true).await?;
}

info!(event = "entering in-sync", height = curr_h);
Expand Down Expand Up @@ -330,8 +330,8 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> InSyncImpl<DB, VM, N> {
{
Ok(_) => {
if remote_height == acc.get_curr_height().await + 1 {
acc.try_accept_block(remote_blk, true).await?;
self.broadcast(msg).await;
acc.try_accept_block(remote_blk, Some(msg), true)
.await?;
return Ok(None);
}
}
Expand Down Expand Up @@ -412,9 +412,8 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> InSyncImpl<DB, VM, N> {
// in in_Sync mode instead of switching to Out-Of-Sync
// mode.

acc.try_accept_block(remote_blk, true).await?;
self.broadcast(msg).await;

acc.try_accept_block(remote_blk, Some(msg), true)
.await?;
return Ok(None);
}

Expand All @@ -433,7 +432,8 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> InSyncImpl<DB, VM, N> {

// Try accepting consecutive block
if remote_height == local_header.height + 1 {
let label = acc.try_accept_block(remote_blk, true).await?;
let label =
acc.try_accept_block(remote_blk, Some(msg), true).await?;

// On first final block accepted while we're inSync, clear
// blacklisted blocks
Expand All @@ -456,10 +456,6 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> InSyncImpl<DB, VM, N> {
}
}

// When accepting block from the wire in inSync state, we
// rebroadcast it
self.broadcast(msg).await;

return Ok(None);
}

Expand Down Expand Up @@ -513,12 +509,6 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> InSyncImpl<DB, VM, N> {

Ok(false)
}

async fn broadcast(&self, msg: &Message) {
if let Err(e) = self.network.write().await.broadcast(msg).await {
warn!("Unable to broadcast accepted block: {e}");
}
}
}

struct OutOfSyncImpl<DB: database::DB, VM: vm::VMExecution, N: Network> {
Expand Down Expand Up @@ -623,7 +613,7 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network>

// Try accepting consecutive block
if h == acc.get_curr_height().await + 1 {
acc.try_accept_block(blk, false).await?;
acc.try_accept_block(blk, None, false).await?;

if let Some(metadata) = &msg.metadata {
if metadata.src_addr == self.peer_addr {
Expand All @@ -637,7 +627,7 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network>
// available
for height in (h + 1)..(self.range.1 + 1) {
if let Some(blk) = self.pool.get(&height) {
acc.try_accept_block(blk, false).await?;
acc.try_accept_block(blk, None, false).await?;
} else {
break;
}
Expand Down

0 comments on commit 2c9dffe

Please sign in to comment.