Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
FM-255: Skip broadcasting checkpoint signature if syncing
Browse files Browse the repository at this point in the history
  • Loading branch information
aakoshh committed Sep 29, 2023
1 parent ee00e29 commit a82cc62
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 23 deletions.
49 changes: 26 additions & 23 deletions fendermint/vm/interpreter/src/fvm/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,29 +142,32 @@ where
.find(|v| v.public_key.0 == ctx.public_key)
.cloned()
{
let secret_key = ctx.secret_key.clone();
let broadcaster = ctx.broadcaster.clone();
let gateway = self.gateway.clone();
let chain_id = state.chain_id();

tokio::spawn(async move {
let height = checkpoint.block_height;

let res = checkpoint::broadcast_signature(
&broadcaster,
&gateway,
checkpoint,
&power_table,
&validator,
&secret_key,
chain_id,
)
.await;

if let Err(e) = res {
tracing::error!(error =? e, height, "error broadcasting checkpoint signature");
}
});
// Do not resend past signatures.
if !self.syncing().await? {
let secret_key = ctx.secret_key.clone();
let broadcaster = ctx.broadcaster.clone();
let gateway = self.gateway.clone();
let chain_id = state.chain_id();

tokio::spawn(async move {
let height = checkpoint.block_height;

let res = checkpoint::broadcast_signature(
&broadcaster,
&gateway,
checkpoint,
&power_table,
&validator,
&secret_key,
chain_id,
)
.await;

if let Err(e) = res {
tracing::error!(error =? e, height, "error broadcasting checkpoint signature");
}
});
}
}
}

Expand Down
18 changes: 18 additions & 0 deletions fendermint/vm/interpreter/src/fvm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod store;
#[cfg(any(test, feature = "bundle"))]
pub mod bundle;

use anyhow::Context;
pub use check::FvmCheckRet;
pub use checkpoint::PowerUpdates;
pub use exec::FvmApplyRet;
Expand All @@ -23,6 +24,7 @@ use fendermint_eth_hardhat::Hardhat;
pub use fendermint_vm_message::query::FvmQuery;
pub use genesis::FvmGenesisOutput;
pub use query::FvmQueryRet;
use tendermint_rpc::Client;

pub use self::broadcast::Broadcaster;
use self::state::ipc::GatewayCaller;
Expand Down Expand Up @@ -92,3 +94,19 @@ impl<DB, C> FvmMessageInterpreter<DB, C> {
}
}
}

impl<DB, C> FvmMessageInterpreter<DB, C>
where
C: Client + Sync,
{
/// Indicate that the node is syncing with the rest of the network and hasn't caught up with the tip yet.
async fn syncing(&self) -> anyhow::Result<bool> {
let status: tendermint_rpc::endpoint::status::Response = self
.client
.status()
.await
.context("failed to get Tendermint status")?;

Ok(status.sync_info.catching_up)
}
}

0 comments on commit a82cc62

Please sign in to comment.