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

chore(consensus): add ContextConfig to SequencerConcensusContext #3338

Open
wants to merge 1 commit into
base: guyn/config/add_context_config
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions config/sequencer/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,21 @@
"pointer_target": "validator_id",
"privacy": "Public"
},
"consensus_manager_config.context_config.batcher_build_buffer": {
"description": "The buffer size for the batcher when building proposals.",
"privacy": "Public",
"value": 100
},
"consensus_manager_config.context_config.chain_id": {
"description": "The chain id of the Starknet chain.",
"pointer_target": "chain_id",
"privacy": "Public"
},
"consensus_manager_config.context_config.num_validators": {
"description": "The number of validators.",
"privacy": "Public",
"value": 1
},
"eth_fee_token_address": {
"description": "A required param! Address of the ETH fee token.",
"param_type": "String",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use futures::{FutureExt, SinkExt, StreamExt};
use papyrus_consensus::types::{
ConsensusContext,
ConsensusError,
ContextConfig,
ProposalContentId,
Round,
ValidatorId,
Expand Down Expand Up @@ -110,6 +111,7 @@ const BUILD_PROPOSAL_MARGIN: Duration = Duration::from_millis(1000);
const VALIDATE_PROPOSAL_MARGIN: Duration = Duration::from_secs(10);

pub struct SequencerConsensusContext {
config: ContextConfig,
state_sync_client: SharedStateSyncClient,
batcher: Arc<dyn BatcherClient>,
validators: Vec<ValidatorId>,
Expand All @@ -134,8 +136,6 @@ pub struct SequencerConsensusContext {
outbound_proposal_sender: mpsc::Sender<(HeightAndRound, mpsc::Receiver<ProposalPart>)>,
// Used to broadcast votes to other consensus nodes.
vote_broadcast_client: BroadcastTopicClient<Vote>,
// Used to convert Transaction to ExecutableTransaction.
chain_id: ChainId,
cende_ambassador: Arc<dyn CendeContext>,
// The next block's l2 gas price, calculated based on EIP-1559, used for building and
// validating proposals.
Expand All @@ -144,15 +144,16 @@ pub struct SequencerConsensusContext {

impl SequencerConsensusContext {
pub fn new(
config: ContextConfig,
state_sync_client: SharedStateSyncClient,
batcher: Arc<dyn BatcherClient>,
outbound_proposal_sender: mpsc::Sender<(HeightAndRound, mpsc::Receiver<ProposalPart>)>,
vote_broadcast_client: BroadcastTopicClient<Vote>,
num_validators: u64,
chain_id: ChainId,
cende_ambassador: Arc<dyn CendeContext>,
) -> Self {
let num_validators = config.num_validators;
Self {
config,
state_sync_client,
batcher,
outbound_proposal_sender,
Expand All @@ -167,7 +168,6 @@ impl SequencerConsensusContext {
current_round: 0,
active_proposal: None,
queued_proposals: BTreeMap::new(),
chain_id,
cende_ambassador,
l2_gas_price: MIN_GAS_PRICE,
}
Expand Down Expand Up @@ -457,7 +457,7 @@ impl SequencerConsensusContext {
let cancel_token_clone = cancel_token.clone();
let batcher = Arc::clone(&self.batcher);
let valid_proposals = Arc::clone(&self.valid_proposals);
let chain_id = self.chain_id.clone();
let chain_id = self.config.chain_id.clone();
let proposal_id = ProposalId(self.proposal_id);
self.proposal_id += 1;
let gas_prices = self.gas_prices();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use futures::future::pending;
use futures::{FutureExt, SinkExt};
use lazy_static::lazy_static;
use papyrus_consensus::stream_handler::StreamHandler;
use papyrus_consensus::types::ConsensusContext;
use papyrus_consensus::types::{ConsensusContext, ContextConfig};
use papyrus_network::network_manager::test_utils::{
mock_register_broadcast_topic,
BroadcastNetworkMock,
Expand Down Expand Up @@ -95,12 +95,11 @@ fn setup(
let state_sync_client = MockStateSyncClient::new();

let context = SequencerConsensusContext::new(
ContextConfig { num_validators: NUM_VALIDATORS, chain_id: CHAIN_ID, ..Default::default() },
Arc::new(state_sync_client),
Arc::new(batcher),
outbound_proposal_stream_sender,
votes_topic_client,
NUM_VALIDATORS,
CHAIN_ID,
Arc::new(cende_ambassador),
);

Expand Down
3 changes: 3 additions & 0 deletions crates/starknet_consensus_manager/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::collections::BTreeMap;
use papyrus_config::dumping::{append_sub_config_name, SerializeConfig};
use papyrus_config::{ParamPath, SerializedParam};
use papyrus_consensus::config::ConsensusConfig;
use papyrus_consensus::types::ContextConfig;
use papyrus_consensus_orchestrator::cende::CendeConfig;
use serde::{Deserialize, Serialize};
use validator::Validate;
Expand All @@ -12,13 +13,15 @@ use validator::Validate;
#[derive(Clone, Default, Debug, Serialize, Deserialize, Validate, PartialEq)]
pub struct ConsensusManagerConfig {
pub consensus_config: ConsensusConfig,
pub context_config: ContextConfig,
pub cende_config: CendeConfig,
}

impl SerializeConfig for ConsensusManagerConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
let sub_configs = vec![
append_sub_config_name(self.consensus_config.dump(), "consensus_config"),
append_sub_config_name(self.context_config.dump(), "context_config"),
append_sub_config_name(self.cende_config.dump(), "cende_config"),
];

Expand Down
3 changes: 1 addition & 2 deletions crates/starknet_consensus_manager/src/consensus_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,11 @@ impl ConsensusManager {
};

let context = SequencerConsensusContext::new(
self.config.context_config.clone(),
Arc::clone(&self.state_sync_client),
Arc::clone(&self.batcher_client),
outbound_internal_sender,
votes_broadcast_channels.broadcast_topic_client.clone(),
self.config.consensus_config.num_validators,
self.config.consensus_config.chain_id.clone(),
Arc::new(CendeAmbassador::new(self.config.cende_config.clone())),
);

Expand Down
7 changes: 6 additions & 1 deletion crates/starknet_integration_tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use mempool_test_utils::starknet_api_test_utils::{
MultiAccountTransactionGenerator,
};
use papyrus_consensus::config::{ConsensusConfig, TimeoutsConfig};
use papyrus_consensus::types::ValidatorId;
use papyrus_consensus::types::{ContextConfig, ValidatorId};
use papyrus_consensus_orchestrator::cende::RECORDER_WRITE_BLOB_PATH;
use papyrus_network::network_manager::test_utils::create_connected_network_configs;
use papyrus_network::NetworkConfig;
Expand Down Expand Up @@ -142,6 +142,11 @@ pub(crate) fn create_consensus_manager_configs_from_network_configs(
timeouts: timeouts.clone(),
..Default::default()
},
context_config: ContextConfig {
num_validators,
chain_id: papyrus_storage::test_utils::CHAIN_ID_FOR_TESTS.clone(),
..Default::default()
},
..Default::default()
})
.collect()
Expand Down
1 change: 1 addition & 0 deletions crates/starknet_sequencer_node/src/config/node_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub static CONFIG_POINTERS: LazyLock<ConfigPointers> = LazyLock::new(|| {
"batcher_config.block_builder_config.chain_info.chain_id",
"batcher_config.storage.db_config.chain_id",
"consensus_manager_config.consensus_config.chain_id",
"consensus_manager_config.context_config.chain_id",
"consensus_manager_config.consensus_config.network_config.chain_id",
"gateway_config.chain_info.chain_id",
"l1_scraper_config.chain_id",
Expand Down
Loading