diff --git a/coordinator/src/p2p.rs b/coordinator/src/p2p.rs index 67cb2005..81c20cd9 100644 --- a/coordinator/src/p2p.rs +++ b/coordinator/src/p2p.rs @@ -187,8 +187,15 @@ impl LibP2p { // Block size limit + 1 KB of space for signatures/metadata const MAX_LIBP2P_MESSAGE_SIZE: usize = tributary::BLOCK_SIZE_LIMIT + 1024; + let heartbeat_interval = tributary::tendermint::LATENCY_TIME / 2; + let heartbeats_per_block = + usize::try_from(tributary::tendermint::TARGET_BLOCK_TIME / heartbeat_interval).unwrap(); + use blake2::{Digest, Blake2s256}; let config = ConfigBuilder::default() + .heartbeat_interval(Duration::from_millis(heartbeat_interval.into())) + .history_length(heartbeats_per_block * 2) + .history_gossip(heartbeats_per_block) .max_transmit_size(MAX_LIBP2P_MESSAGE_SIZE) // We send KeepAlive after 80s .idle_timeout(Duration::from_secs(85)) @@ -340,6 +347,8 @@ impl P2p for LibP2p { self.0.lock().await.send(msg).expect("broadcast_send closed. are we shutting down?"); } + // TODO: We only have a single handle call this. Differentiate Send/Recv to remove this constant + // lock acquisition? async fn receive_raw(&self) -> (Self::Id, Vec) { self.1.lock().await.recv().await.expect("receive_recv closed. are we shutting down?") } diff --git a/coordinator/tributary/src/tendermint/mod.rs b/coordinator/tributary/src/tendermint/mod.rs index 9a4baca5..ae3966e4 100644 --- a/coordinator/tributary/src/tendermint/mod.rs +++ b/coordinator/tributary/src/tendermint/mod.rs @@ -274,6 +274,11 @@ pub struct TendermintNetwork { pub(crate) p2p: P, } +pub const BLOCK_PROCESSING_TIME: u32 = 999; +pub const LATENCY_TIME: u32 = 1667; +// TODO: Add test asserting this +pub const TARGET_BLOCK_TIME: u32 = BLOCK_PROCESSING_TIME + (3 * LATENCY_TIME); + #[async_trait] impl Network for TendermintNetwork { type ValidatorId = [u8; 32]; @@ -285,8 +290,8 @@ impl Network for TendermintNetwork // The block time is the latency on message delivery (where a message is some piece of data // embedded in a transaction) times three plus the block processing time, hence why it should be // kept low. - const BLOCK_PROCESSING_TIME: u32 = 999; - const LATENCY_TIME: u32 = 1667; + const BLOCK_PROCESSING_TIME: u32 = BLOCK_PROCESSING_TIME; + const LATENCY_TIME: u32 = LATENCY_TIME; fn signer(&self) -> Arc { self.signer.clone() diff --git a/coordinator/tributary/tendermint/src/lib.rs b/coordinator/tributary/tendermint/src/lib.rs index cd123fee..be9d5e5d 100644 --- a/coordinator/tributary/tendermint/src/lib.rs +++ b/coordinator/tributary/tendermint/src/lib.rs @@ -189,7 +189,8 @@ impl TendermintMachine { // Push it on to the queue. This is done so we only handle one message at a time, and so we // can handle our own message before broadcasting it. That way, we fail before before // becoming malicious - self.queue.push_back(msg); + // push_front to prioritize our own messages + self.queue.push_front(msg); } }