Skip to content

Commit

Permalink
fix(consensus): add a safety margin so the batcher stops building ear…
Browse files Browse the repository at this point in the history
…ly enough

This should become configurable as part of a refactor Guy will do to the consensus configs.
  • Loading branch information
matan-starkware committed Dec 16, 2024
1 parent 3f75d13 commit 5f96c4b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use starknet_batcher_types::batcher_types::{
use starknet_batcher_types::communication::BatcherClient;
use tokio::sync::Notify;
use tokio::task::JoinHandle;
use tracing::{debug, debug_span, error, info, trace, warn, Instrument};
use tracing::{debug, debug_span, error, info, instrument, trace, warn, Instrument};

// TODO(Dan, Matan): Remove this once and replace with real gas prices.
const TEMPORARY_GAS_PRICES: GasPrices = GasPrices {
Expand All @@ -79,6 +79,8 @@ type HeightToIdToContent =
type ValidationParams = (BlockNumber, ValidatorId, Duration, mpsc::Receiver<ProposalPart>);

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<dyn BatcherClient>,
Expand Down Expand Up @@ -135,26 +137,29 @@ impl SequencerConsensusContext {
impl ConsensusContext for SequencerConsensusContext {
type ProposalPart = ProposalPart;

#[instrument(
level = "info",
skip_all,
fields(height=?proposal_init.height, round=?proposal_init.round)
)]
async fn build_proposal(
&mut self,
proposal_init: ProposalInit,
timeout: Duration,
) -> oneshot::Receiver<ProposalContentId> {
info!("Building proposal: {timeout:?} {proposal_init:?}");
// Handles interrupting an active proposal from a previous height/round
self.set_height_and_round(proposal_init.height, proposal_init.round).await;
debug!(
"Building proposal for height: {} with timeout: {:?}",
proposal_init.height, timeout
);
let (fin_sender, fin_receiver) = oneshot::channel();

let batcher = Arc::clone(&self.batcher);
let valid_proposals = Arc::clone(&self.valid_proposals);

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 1 addition & 2 deletions crates/starknet_batcher/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet_sequencer_infra/src/trace_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use tracing::metadata::LevelFilter;
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter};

const DEFAULT_LEVEL: LevelFilter = LevelFilter::INFO;
const DEFAULT_LEVEL: LevelFilter = LevelFilter::DEBUG;
// Define a OnceCell to ensure the configuration is initialized only once
static TRACING_INITIALIZED: OnceCell<()> = OnceCell::const_new();

Expand Down

0 comments on commit 5f96c4b

Please sign in to comment.