Skip to content

Commit

Permalink
node: Broadcast a valid block before get_provisioners call
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 62690a3 commit 637c38d
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions node/src/chain/acceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> Acceptor<N, DB, VM> {
pub(crate) async fn try_accept_block(
&mut self,
blk: &Block,
msg: Option<&Message>,
enable_consensus: bool,
) -> anyhow::Result<Label> {
let mut task = self.task.write().await;
Expand Down Expand Up @@ -342,6 +343,14 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> Acceptor<N, DB, VM> {
Ok(txs)
})?;

// (Re)broadcast a fully valid block before any call to
// get_provisioners to speed up its propagation
if let Some(msg) = msg {
let _ = self.network.read().await.broadcast(msg).await.map_err(
|err| warn!("Unable to broadcast accepted block: {err}"),
);
}

self.log_missing_iterations(
provisioners_list.current(),
header.iteration,
Expand Down Expand Up @@ -456,28 +465,26 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> Acceptor<N, DB, VM> {
// VM was reverted to.

// The blockchain tip (most recent block) after reverting
let mut label: Label = Label::Attested;
let blk = self.db.read().await.update(|t| {
let (blk, label) = self.db.read().await.update(|t| {
let mut height = curr_height;
while height != 0 {
let b = Ledger::fetch_block_by_height(t, height)?
.ok_or_else(|| anyhow::anyhow!("could not fetch block"))?;
let h = b.header();
let label =
t.fetch_block_label_by_height(h.height)?.ok_or_else(
|| anyhow::anyhow!("could not fetch block label"),
)?;

if h.state_hash == target_state_hash {
label =
t.fetch_block_label_by_height(h.height)?.ok_or_else(
|| anyhow::anyhow!("could not fetch block label"),
)?;

return Ok(b);
return Ok((b, label));
}

info!(
event = "block deleted",
height = h.height,
iter = h.iteration,
label = format!("{:?}", label),
label = ?label,
hash = hex::encode(h.hash)
);

Expand Down

0 comments on commit 637c38d

Please sign in to comment.