From 2f57a69cb6e96eb1c152fa65a2fdedcc53555fa1 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Wed, 30 Aug 2023 22:56:59 -0400 Subject: [PATCH] Define BLOCK_PROCESSING_TIME, LATENCY_TIME in ms Updates Tributary values to allow 999ms for block processing (from 2s) and 1667ms for latency (up from 1s). The intent is to resolve #365. I don't know if this will, but it increases the chances of success and these values should be fine in prod since Tributary is a post-execution chain (making block procesisng time minimal). Does embed the dagger of N::block_time() panicking if the block time in ms doesn't cleanly divide by 1000. --- coordinator/tributary/src/tendermint/mod.rs | 9 +++++---- coordinator/tributary/tendermint/src/ext.rs | 15 +++++++++++---- coordinator/tributary/tendermint/src/round.rs | 2 +- coordinator/tributary/tendermint/tests/ext.rs | 4 ++-- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/coordinator/tributary/src/tendermint/mod.rs b/coordinator/tributary/src/tendermint/mod.rs index edfcb48e..9a4baca5 100644 --- a/coordinator/tributary/src/tendermint/mod.rs +++ b/coordinator/tributary/src/tendermint/mod.rs @@ -281,11 +281,12 @@ impl Network for TendermintNetwork type Weights = Arc; type Block = TendermintBlock; - // These are in seconds and create a six-second block time. + // These are in milliseconds and create a six-second block time. // The block time is the latency on message delivery (where a message is some piece of data - // embedded in a transaction), hence why it should be kept low. - const BLOCK_PROCESSING_TIME: u32 = 3; - const LATENCY_TIME: u32 = 1; + // 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; fn signer(&self) -> Arc { self.signer.clone() diff --git a/coordinator/tributary/tendermint/src/ext.rs b/coordinator/tributary/tendermint/src/ext.rs index 787ab1d8..02c6dd28 100644 --- a/coordinator/tributary/tendermint/src/ext.rs +++ b/coordinator/tributary/tendermint/src/ext.rs @@ -221,16 +221,23 @@ pub trait Network: Sized + Send + Sync { /// Type used for ordered blocks of information. type Block: Block; - /// Maximum block processing time in seconds. + /// Maximum block processing time in milliseconds. /// /// This should include both the time to download the block and the actual processing time. + /// + /// BLOCK_PROCESSING_TIME + (3 * LATENCY_TIME) must be divisible by 1000. const BLOCK_PROCESSING_TIME: u32; - /// Network latency time in seconds. + /// Network latency time in milliseconds. + /// + /// BLOCK_PROCESSING_TIME + (3 * LATENCY_TIME) must be divisible by 1000. const LATENCY_TIME: u32; - /// The block time is defined as the processing time plus three times the latency. + /// The block time, in seconds. Defined as the processing time plus three times the latency. fn block_time() -> u32 { - Self::BLOCK_PROCESSING_TIME + (3 * Self::LATENCY_TIME) + let raw = Self::BLOCK_PROCESSING_TIME + (3 * Self::LATENCY_TIME); + let res = raw / 1000; + assert_eq!(res * 1000, raw); + res } /// Return a handle on the signer in use, usable for the entire lifetime of the machine. diff --git a/coordinator/tributary/tendermint/src/round.rs b/coordinator/tributary/tendermint/src/round.rs index c55e0702..d685c713 100644 --- a/coordinator/tributary/tendermint/src/round.rs +++ b/coordinator/tributary/tendermint/src/round.rs @@ -35,7 +35,7 @@ impl RoundData { fn timeout(&self, step: Step) -> CanonicalInstant { let adjusted_block = N::BLOCK_PROCESSING_TIME * (self.number.0 + 1); let adjusted_latency = N::LATENCY_TIME * (self.number.0 + 1); - let offset = Duration::from_secs( + let offset = Duration::from_millis( (match step { Step::Propose => adjusted_block + adjusted_latency, Step::Prevote => adjusted_block + (2 * adjusted_latency), diff --git a/coordinator/tributary/tendermint/tests/ext.rs b/coordinator/tributary/tendermint/tests/ext.rs index 59da2940..aa87ee29 100644 --- a/coordinator/tributary/tendermint/tests/ext.rs +++ b/coordinator/tributary/tendermint/tests/ext.rs @@ -116,8 +116,8 @@ impl Network for TestNetwork { type Weights = TestWeights; type Block = TestBlock; - const BLOCK_PROCESSING_TIME: u32 = 2; - const LATENCY_TIME: u32 = 1; + const BLOCK_PROCESSING_TIME: u32 = 2000; + const LATENCY_TIME: u32 = 1000; fn signer(&self) -> TestSigner { TestSigner(self.0)