Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(consensus): add StateSyncClient to sequencer context #2938

Merged
merged 1 commit into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ serde.workspace = true
starknet-types-core.workspace = true
starknet_api.workspace = true
starknet_batcher_types = { workspace = true, features = ["testing"] }
starknet_state_sync_types = { workspace = true, features = ["testing"] }
tokio = { workspace = true, features = ["full"] }
tokio-util.workspace = true
tracing.workspace = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ use starknet_batcher_types::batcher_types::{
ValidateBlockInput,
};
use starknet_batcher_types::communication::BatcherClient;
use starknet_state_sync_types::communication::SharedStateSyncClient;
use tokio::task::JoinHandle;
use tokio_util::sync::CancellationToken;
use tracing::{debug, debug_span, info, instrument, trace, warn, Instrument};
Expand Down Expand Up @@ -96,6 +97,8 @@ enum HandledProposalPart {
const BUILD_PROPOSAL_MARGIN: Duration = Duration::from_millis(1000);

pub struct SequencerConsensusContext {
#[allow(dead_code)]
state_sync_client: SharedStateSyncClient,
batcher: Arc<dyn BatcherClient>,
validators: Vec<ValidatorId>,
// Proposal building/validating returns immediately, leaving the actual processing to a spawned
Expand Down Expand Up @@ -126,6 +129,7 @@ pub struct SequencerConsensusContext {

impl SequencerConsensusContext {
pub fn new(
state_sync_client: SharedStateSyncClient,
batcher: Arc<dyn BatcherClient>,
outbound_proposal_sender: mpsc::Sender<(u64, mpsc::Receiver<ProposalPart>)>,
vote_broadcast_client: BroadcastTopicClient<Vote>,
Expand All @@ -134,6 +138,7 @@ impl SequencerConsensusContext {
cende_ambassador: Arc<dyn CendeContext>,
) -> Self {
Self {
state_sync_client,
batcher,
outbound_proposal_sender,
vote_broadcast_client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use starknet_batcher_types::batcher_types::{
ValidateBlockInput,
};
use starknet_batcher_types::communication::MockBatcherClient;
use starknet_state_sync_types::communication::MockStateSyncClient;
use starknet_types_core::felt::Felt;

use crate::cende::MockCendeContext;
Expand Down Expand Up @@ -88,8 +89,10 @@ fn setup(
mock_register_broadcast_topic().expect("Failed to create mock network");
let BroadcastTopicChannels { broadcast_topic_client: votes_topic_client, .. } =
subscriber_channels;
let state_sync_client = MockStateSyncClient::new();

let context = SequencerConsensusContext::new(
Arc::new(state_sync_client),
Arc::new(batcher),
outbound_proposal_stream_sender,
votes_topic_client,
Expand Down
1 change: 1 addition & 0 deletions crates/starknet_consensus_manager/src/consensus_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ impl ConsensusManager {
};

let context = SequencerConsensusContext::new(
Arc::clone(&self.state_sync_client),
Arc::clone(&self.batcher_client),
outbound_internal_sender,
votes_broadcast_channels.broadcast_topic_client.clone(),
Expand Down
8 changes: 8 additions & 0 deletions crates/starknet_state_sync_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,24 @@ edition.workspace = true
license.workspace = true
repository.workspace = true

[features]
testing = ["mockall"]

[lints]
workspace = true

[dependencies]
async-trait.workspace = true
futures.workspace = true
mockall = { workspace = true, optional = true }
papyrus_proc_macros.workspace = true
papyrus_storage.workspace = true
serde = { workspace = true, features = ["derive"] }
starknet-types-core.workspace = true
starknet_api.workspace = true
starknet_sequencer_infra.workspace = true
thiserror.workspace = true

[dev-dependencies]
# Enable self with "testing" feature in tests.
starknet_state_sync_types = { workspace = true, features = ["testing"] }
3 changes: 3 additions & 0 deletions crates/starknet_state_sync_types/src/communication.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::sync::Arc;

use async_trait::async_trait;
#[cfg(any(feature = "testing", test))]
use mockall::automock;
use papyrus_proc_macros::handle_response_variants;
use serde::{Deserialize, Serialize};
use starknet_api::block::BlockNumber;
Expand All @@ -22,6 +24,7 @@ use thiserror::Error;
use crate::errors::StateSyncError;
use crate::state_sync_types::{StateSyncResult, SyncBlock};

#[cfg_attr(any(test, feature = "testing"), automock)]
#[async_trait]
pub trait StateSyncClient: Send + Sync {
/// Request for a block at a specific height.
Expand Down
Loading