From ba860d5419c5a8fb9584434a3e0d27cb42fb731a Mon Sep 17 00:00:00 2001 From: Matan Markind Date: Mon, 16 Dec 2024 13:29:51 +0200 Subject: [PATCH] fix(consensus): add a safety margin so the batcher stops building early enough This should become configurable as part of a refactor Guy will do to the consensus configs. --- .../src/sequencer_consensus_context.rs | 7 +++++-- .../src/sequencer_consensus_context_test.rs | 2 +- crates/starknet_batcher/src/utils.rs | 3 +-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context.rs b/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context.rs index 92e45cd85d..aa9f7d4493 100644 --- a/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context.rs +++ b/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context.rs @@ -79,6 +79,8 @@ type HeightToIdToContent = type ValidationParams = (BlockNumber, ValidatorId, Duration, mpsc::Receiver); const CHANNEL_SIZE: usize = 100; +// TODO(Guy): Move this to the context config. +const BUILD_PROPOSAL_MARGIN: Duration = Duration::from_millis(100); pub struct SequencerConsensusContext { batcher: Arc, @@ -153,8 +155,9 @@ impl ConsensusContext for SequencerConsensusContext { let proposal_id = ProposalId(self.proposal_id); self.proposal_id += 1; - let timeout = - chrono::Duration::from_std(timeout).expect("Can't convert timeout to chrono::Duration"); + assert!(timeout > BUILD_PROPOSAL_MARGIN); + let timeout = chrono::Duration::from_std(timeout - BUILD_PROPOSAL_MARGIN) + .expect("Can't convert timeout to chrono::Duration"); let now = chrono::Utc::now(); let build_proposal_input = ProposeBlockInput { proposal_id, diff --git a/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context_test.rs b/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context_test.rs index 085cfed39d..6b21f7dde9 100644 --- a/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context_test.rs +++ b/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context_test.rs @@ -44,7 +44,7 @@ use starknet_types_core::felt::Felt; use crate::sequencer_consensus_context::SequencerConsensusContext; -const TIMEOUT: Duration = Duration::from_millis(100); +const TIMEOUT: Duration = Duration::from_millis(200); const CHANNEL_SIZE: usize = 5000; const NUM_VALIDATORS: u64 = 4; const STATE_DIFF_COMMITMENT: StateDiffCommitment = StateDiffCommitment(PoseidonHash(Felt::ZERO)); diff --git a/crates/starknet_batcher/src/utils.rs b/crates/starknet_batcher/src/utils.rs index 1d656d8eda..4ea923a4db 100644 --- a/crates/starknet_batcher/src/utils.rs +++ b/crates/starknet_batcher/src/utils.rs @@ -67,8 +67,7 @@ pub(crate) fn deadline_as_instant( let time_to_deadline = deadline - chrono::Utc::now(); let as_duration = time_to_deadline.to_std().map_err(|_| BatcherError::TimeToDeadlineError { deadline })?; - // TODO(Matan): this is a temporary solution to the timeout issue. - Ok((std::time::Instant::now() + (as_duration / 2)).into()) + Ok((std::time::Instant::now() + as_duration).into()) } pub(crate) fn verify_block_input(