diff --git a/config/papyrus/default_config.json b/config/papyrus/default_config.json index dc125e5bac2..228e39782c6 100644 --- a/config/papyrus/default_config.json +++ b/config/papyrus/default_config.json @@ -89,81 +89,6 @@ "privacy": "Public", "value": 5 }, - "consensus.network_config.advertised_multiaddr": { - "description": "The external address other peers see this node. If this is set, the node will not try to find out which addresses it has and will write this address as external instead", - "privacy": "Public", - "value": "" - }, - "consensus.network_config.advertised_multiaddr.#is_none": { - "description": "Flag for an optional field.", - "privacy": "TemporaryValue", - "value": true - }, - "consensus.network_config.bootstrap_peer_multiaddr": { - "description": "The multiaddress of the peer node. It should include the peer's id. For more info: https://docs.libp2p.io/concepts/fundamentals/peers/", - "privacy": "Public", - "value": "" - }, - "consensus.network_config.bootstrap_peer_multiaddr.#is_none": { - "description": "Flag for an optional field.", - "privacy": "TemporaryValue", - "value": true - }, - "consensus.network_config.chain_id": { - "description": "The chain to follow. For more details see https://docs.starknet.io/documentation/architecture_and_concepts/Blocks/transactions/#chain-id.", - "pointer_target": "chain_id", - "privacy": "Public" - }, - "consensus.network_config.discovery_config.bootstrap_dial_retry_config.base_delay_millis": { - "description": "The base delay in milliseconds for the exponential backoff strategy.", - "privacy": "Public", - "value": 2 - }, - "consensus.network_config.discovery_config.bootstrap_dial_retry_config.factor": { - "description": "The factor for the exponential backoff strategy.", - "privacy": "Public", - "value": 5 - }, - "consensus.network_config.discovery_config.bootstrap_dial_retry_config.max_delay_seconds": { - "description": "The maximum delay in seconds for the exponential backoff strategy.", - "privacy": "Public", - "value": 5 - }, - "consensus.network_config.discovery_config.heartbeat_interval": { - "description": "The interval between each discovery (Kademlia) query in milliseconds.", - "privacy": "Public", - "value": 100 - }, - "consensus.network_config.idle_connection_timeout": { - "description": "Amount of time in seconds that a connection with no active sessions will stay alive.", - "privacy": "Public", - "value": 120 - }, - "consensus.network_config.peer_manager_config.malicious_timeout_seconds": { - "description": "The duration in seconds a peer is blacklisted after being marked as malicious.", - "privacy": "Public", - "value": 31536000 - }, - "consensus.network_config.peer_manager_config.unstable_timeout_millis": { - "description": "The duration in milliseconds a peer blacklisted after being reported as unstable.", - "privacy": "Public", - "value": 1000 - }, - "consensus.network_config.secret_key": { - "description": "The secret key used for building the peer id. If it's an empty string a random one will be used.", - "privacy": "Private", - "value": "" - }, - "consensus.network_config.session_timeout": { - "description": "Maximal time in seconds that each session can take before failing on timeout.", - "privacy": "Public", - "value": 120 - }, - "consensus.network_config.tcp_port": { - "description": "The port that the node listens on for incoming tcp connections.", - "privacy": "Public", - "value": 10100 - }, "consensus.network_topic": { "description": "The network topic of the consensus.", "privacy": "Public", @@ -364,6 +289,26 @@ "privacy": "Public", "value": 50 }, + "papyrus_consensus.#is_none": { + "description": "Flag for an optional field.", + "privacy": "TemporaryValue", + "value": true + }, + "papyrus_consensus.proposals_topic": { + "description": "The topic for consensus proposals.", + "privacy": "Public", + "value": "consensus_proposals" + }, + "papyrus_consensus.start_height": { + "description": "The height to start the consensus from.", + "privacy": "Public", + "value": 0 + }, + "papyrus_consensus.votes_topic": { + "description": "The topic for consensus votes.", + "privacy": "Public", + "value": "consensus_votes" + }, "rpc.chain_id": { "description": "The chain to follow. For more details see https://docs.starknet.io/documentation/architecture_and_concepts/Blocks/transactions/#chain-id.", "pointer_target": "chain_id", diff --git a/config/sequencer/default_config.json b/config/sequencer/default_config.json index ecc38f5cb01..d569a5cecd7 100644 --- a/config/sequencer/default_config.json +++ b/config/sequencer/default_config.json @@ -689,135 +689,145 @@ "privacy": "Public", "value": 5 }, - "consensus_manager_config.consensus_config.network_config.advertised_multiaddr": { + "consensus_manager_config.consensus_config.network_topic": { + "description": "The network topic of the consensus.", + "privacy": "Public", + "value": "consensus" + }, + "consensus_manager_config.consensus_config.num_validators": { + "description": "The number of validators in the consensus.", + "privacy": "Public", + "value": 1 + }, + "consensus_manager_config.consensus_config.start_height": { + "description": "The height to start the consensus from.", + "privacy": "Public", + "value": 0 + }, + "consensus_manager_config.consensus_config.sync_retry_interval": { + "description": "The duration (seconds) between sync attempts.", + "privacy": "Public", + "value": 1.0 + }, + "consensus_manager_config.consensus_config.timeouts.precommit_timeout": { + "description": "The timeout (seconds) for a precommit.", + "privacy": "Public", + "value": 1.0 + }, + "consensus_manager_config.consensus_config.timeouts.prevote_timeout": { + "description": "The timeout (seconds) for a prevote.", + "privacy": "Public", + "value": 1.0 + }, + "consensus_manager_config.consensus_config.timeouts.proposal_timeout": { + "description": "The timeout (seconds) for a proposal.", + "privacy": "Public", + "value": 3.0 + }, + "consensus_manager_config.consensus_config.validator_id": { + "description": "The validator id of the node.", + "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 + }, + "consensus_manager_config.immediate_active_height": { + "description": "The height at which the consensus manager becomes active.", + "privacy": "Public", + "value": 0 + }, + "consensus_manager_config.network_config.advertised_multiaddr": { "description": "The external address other peers see this node. If this is set, the node will not try to find out which addresses it has and will write this address as external instead", "privacy": "Public", "value": "" }, - "consensus_manager_config.consensus_config.network_config.advertised_multiaddr.#is_none": { + "consensus_manager_config.network_config.advertised_multiaddr.#is_none": { "description": "Flag for an optional field.", "privacy": "TemporaryValue", "value": true }, - "consensus_manager_config.consensus_config.network_config.bootstrap_peer_multiaddr": { + "consensus_manager_config.network_config.bootstrap_peer_multiaddr": { "description": "The multiaddress of the peer node. It should include the peer's id. For more info: https://docs.libp2p.io/concepts/fundamentals/peers/", "privacy": "Public", "value": "" }, - "consensus_manager_config.consensus_config.network_config.bootstrap_peer_multiaddr.#is_none": { + "consensus_manager_config.network_config.bootstrap_peer_multiaddr.#is_none": { "description": "Flag for an optional field.", "privacy": "TemporaryValue", "value": true }, - "consensus_manager_config.consensus_config.network_config.chain_id": { + "consensus_manager_config.network_config.chain_id": { "description": "The chain to follow. For more details see https://docs.starknet.io/documentation/architecture_and_concepts/Blocks/transactions/#chain-id.", "pointer_target": "chain_id", "privacy": "Public" }, - "consensus_manager_config.consensus_config.network_config.discovery_config.bootstrap_dial_retry_config.base_delay_millis": { + "consensus_manager_config.network_config.discovery_config.bootstrap_dial_retry_config.base_delay_millis": { "description": "The base delay in milliseconds for the exponential backoff strategy.", "privacy": "Public", "value": 2 }, - "consensus_manager_config.consensus_config.network_config.discovery_config.bootstrap_dial_retry_config.factor": { + "consensus_manager_config.network_config.discovery_config.bootstrap_dial_retry_config.factor": { "description": "The factor for the exponential backoff strategy.", "privacy": "Public", "value": 5 }, - "consensus_manager_config.consensus_config.network_config.discovery_config.bootstrap_dial_retry_config.max_delay_seconds": { + "consensus_manager_config.network_config.discovery_config.bootstrap_dial_retry_config.max_delay_seconds": { "description": "The maximum delay in seconds for the exponential backoff strategy.", "privacy": "Public", "value": 5 }, - "consensus_manager_config.consensus_config.network_config.discovery_config.heartbeat_interval": { + "consensus_manager_config.network_config.discovery_config.heartbeat_interval": { "description": "The interval between each discovery (Kademlia) query in milliseconds.", "privacy": "Public", "value": 100 }, - "consensus_manager_config.consensus_config.network_config.idle_connection_timeout": { + "consensus_manager_config.network_config.idle_connection_timeout": { "description": "Amount of time in seconds that a connection with no active sessions will stay alive.", "privacy": "Public", "value": 120 }, - "consensus_manager_config.consensus_config.network_config.peer_manager_config.malicious_timeout_seconds": { + "consensus_manager_config.network_config.peer_manager_config.malicious_timeout_seconds": { "description": "The duration in seconds a peer is blacklisted after being marked as malicious.", "privacy": "Public", "value": 31536000 }, - "consensus_manager_config.consensus_config.network_config.peer_manager_config.unstable_timeout_millis": { + "consensus_manager_config.network_config.peer_manager_config.unstable_timeout_millis": { "description": "The duration in milliseconds a peer blacklisted after being reported as unstable.", "privacy": "Public", "value": 1000 }, - "consensus_manager_config.consensus_config.network_config.secret_key": { + "consensus_manager_config.network_config.secret_key": { "description": "The secret key used for building the peer id. If it's an empty string a random one will be used.", "privacy": "Private", "value": "" }, - "consensus_manager_config.consensus_config.network_config.session_timeout": { + "consensus_manager_config.network_config.session_timeout": { "description": "Maximal time in seconds that each session can take before failing on timeout.", "privacy": "Public", "value": 120 }, - "consensus_manager_config.consensus_config.network_config.tcp_port": { + "consensus_manager_config.network_config.tcp_port": { "description": "The port that the node listens on for incoming tcp connections.", "privacy": "Public", - "value": 10100 - }, - "consensus_manager_config.consensus_config.network_topic": { - "description": "The network topic of the consensus.", - "privacy": "Public", - "value": "consensus" - }, - "consensus_manager_config.consensus_config.num_validators": { - "description": "The number of validators in the consensus.", - "privacy": "Public", - "value": 1 - }, - "consensus_manager_config.consensus_config.start_height": { - "description": "The height to start the consensus from.", - "privacy": "Public", - "value": 0 - }, - "consensus_manager_config.consensus_config.sync_retry_interval": { - "description": "The duration (seconds) between sync attempts.", - "privacy": "Public", - "value": 1.0 - }, - "consensus_manager_config.consensus_config.timeouts.precommit_timeout": { - "description": "The timeout (seconds) for a precommit.", - "privacy": "Public", - "value": 1.0 - }, - "consensus_manager_config.consensus_config.timeouts.prevote_timeout": { - "description": "The timeout (seconds) for a prevote.", - "privacy": "Public", - "value": 1.0 - }, - "consensus_manager_config.consensus_config.timeouts.proposal_timeout": { - "description": "The timeout (seconds) for a proposal.", - "privacy": "Public", - "value": 3.0 - }, - "consensus_manager_config.consensus_config.validator_id": { - "description": "The validator id of the node.", - "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" + "value": 10000 }, - "consensus_manager_config.context_config.num_validators": { - "description": "The number of validators.", + "consensus_manager_config.proposals_topic": { + "description": "The topic for consensus proposals.", "privacy": "Public", - "value": 1 + "value": "consensus_proposals" }, "consensus_manager_config.revert_up_to_and_including": { "description": "The batcher will revert blocks up to this block number (including). Use this configurations carefully to prevent significant revert operations and data loss.", @@ -829,6 +839,11 @@ "privacy": "TemporaryValue", "value": true }, + "consensus_manager_config.votes_topic": { + "description": "The topic for consensus votes.", + "privacy": "Public", + "value": "consensus_votes" + }, "eth_fee_token_address": { "description": "A required param! Address of the ETH fee token.", "param_type": "String", diff --git a/crates/papyrus_node/src/config/mod.rs b/crates/papyrus_node/src/config/mod.rs index bdc0f993daf..79db705db99 100644 --- a/crates/papyrus_node/src/config/mod.rs +++ b/crates/papyrus_node/src/config/mod.rs @@ -36,6 +36,7 @@ use papyrus_sync::sources::central::CentralSourceConfig; use papyrus_sync::SyncConfig; use serde::{Deserialize, Serialize}; use serde_json::{Map, Value}; +use starknet_api::block::BlockNumber; use starknet_api::core::ChainId; use starknet_client::RetryConfig; use starknet_consensus::config::ConsensusConfig; @@ -65,6 +66,7 @@ pub struct NodeConfig { // TODO(yair): Change NodeConfig to have an option of enum of SyncConfig or P2pSyncConfig. pub p2p_sync: Option, pub consensus: Option, + pub papyrus_consensus: Option, pub context: Option, // TODO(shahak): Make network non-optional once it's developed enough. pub network: Option, @@ -84,6 +86,7 @@ impl Default for NodeConfig { sync: Some(SyncConfig::default()), p2p_sync: None, consensus: None, + papyrus_consensus: None, context: None, network: None, collect_profiling_metrics: false, @@ -102,6 +105,7 @@ impl SerializeConfig for NodeConfig { ser_optional_sub_config(&self.sync, "sync"), ser_optional_sub_config(&self.p2p_sync, "p2p_sync"), ser_optional_sub_config(&self.consensus, "consensus"), + ser_optional_sub_config(&self.papyrus_consensus, "papyrus_consensus"), ser_optional_sub_config(&self.context, "context"), ser_optional_sub_config(&self.network, "network"), BTreeMap::from_iter([ser_param( @@ -133,3 +137,47 @@ pub fn node_command() -> Command { .version(VERSION_FULL) .about("Papyrus is a StarkNet full node written in Rust.") } + +#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Validate)] +pub struct PapyrusConsensusConfig { + pub start_height: BlockNumber, + pub proposals_topic: String, + pub votes_topic: String, + pub config: ContextConfig, +} + +impl SerializeConfig for PapyrusConsensusConfig { + fn dump(&self) -> BTreeMap { + BTreeMap::from_iter([ + ser_param( + "start_height", + &self.start_height, + "The height to start the consensus from.", + ParamPrivacyInput::Public, + ), + ser_param( + "proposals_topic", + &self.proposals_topic, + "The topic for consensus proposals.", + ParamPrivacyInput::Public, + ), + ser_param( + "votes_topic", + &self.votes_topic, + "The topic for consensus votes.", + ParamPrivacyInput::Public, + ), + ]) + } +} + +impl Default for PapyrusConsensusConfig { + fn default() -> Self { + Self { + start_height: BlockNumber::default(), + proposals_topic: "consensus_proposals".to_string(), + votes_topic: "consensus_votes".to_string(), + config: ContextConfig::default(), + } + } +} diff --git a/crates/papyrus_node/src/config/pointers.rs b/crates/papyrus_node/src/config/pointers.rs index ee8a18d5d45..33c93c204d6 100644 --- a/crates/papyrus_node/src/config/pointers.rs +++ b/crates/papyrus_node/src/config/pointers.rs @@ -60,7 +60,6 @@ pub static CONFIG_POINTERS: LazyLock = LazyLock::new(|| { set_pointing_param_paths(&[ "consensus.chain_id", "context.chain_id", - "consensus.network_config.chain_id", "network.chain_id", "rpc.chain_id", "storage.db_config.chain_id", diff --git a/crates/papyrus_node/src/config/snapshots/papyrus_node__config__config_test__dump_default_config.snap b/crates/papyrus_node/src/config/snapshots/papyrus_node__config__config_test__dump_default_config.snap index 7f1b567abb1..0aa9b1d4fb1 100644 --- a/crates/papyrus_node/src/config/snapshots/papyrus_node__config__config_test__dump_default_config.snap +++ b/crates/papyrus_node/src/config/snapshots/papyrus_node__config__config_test__dump_default_config.snap @@ -101,99 +101,6 @@ expression: dumped_default_config }, "privacy": "Public" }, - "consensus.network_config.advertised_multiaddr": { - "description": "The external address other peers see this node. If this is set, the node will not try to find out which addresses it has and will write this address as external instead", - "value": "", - "privacy": "Public" - }, - "consensus.network_config.advertised_multiaddr.#is_none": { - "description": "Flag for an optional field.", - "value": true, - "privacy": "TemporaryValue" - }, - "consensus.network_config.bootstrap_peer_multiaddr": { - "description": "The multiaddress of the peer node. It should include the peer's id. For more info: https://docs.libp2p.io/concepts/fundamentals/peers/", - "value": "", - "privacy": "Public" - }, - "consensus.network_config.bootstrap_peer_multiaddr.#is_none": { - "description": "Flag for an optional field.", - "value": true, - "privacy": "TemporaryValue" - }, - "consensus.network_config.chain_id": { - "description": "The chain to follow. For more details see https://docs.starknet.io/documentation/architecture_and_concepts/Blocks/transactions/#chain-id.", - "value": "SN_MAIN", - "privacy": "Public" - }, - "consensus.network_config.discovery_config.bootstrap_dial_retry_config.base_delay_millis": { - "description": "The base delay in milliseconds for the exponential backoff strategy.", - "value": { - "$serde_json::private::Number": "2" - }, - "privacy": "Public" - }, - "consensus.network_config.discovery_config.bootstrap_dial_retry_config.factor": { - "description": "The factor for the exponential backoff strategy.", - "value": { - "$serde_json::private::Number": "5" - }, - "privacy": "Public" - }, - "consensus.network_config.discovery_config.bootstrap_dial_retry_config.max_delay_seconds": { - "description": "The maximum delay in seconds for the exponential backoff strategy.", - "value": { - "$serde_json::private::Number": "5" - }, - "privacy": "Public" - }, - "consensus.network_config.discovery_config.heartbeat_interval": { - "description": "The interval between each discovery (Kademlia) query in milliseconds.", - "value": { - "$serde_json::private::Number": "100" - }, - "privacy": "Public" - }, - "consensus.network_config.idle_connection_timeout": { - "description": "Amount of time in seconds that a connection with no active sessions will stay alive.", - "value": { - "$serde_json::private::Number": "120" - }, - "privacy": "Public" - }, - "consensus.network_config.peer_manager_config.malicious_timeout_seconds": { - "description": "The duration in seconds a peer is blacklisted after being marked as malicious.", - "value": { - "$serde_json::private::Number": "31536000" - }, - "privacy": "Public" - }, - "consensus.network_config.peer_manager_config.unstable_timeout_millis": { - "description": "The duration in milliseconds a peer blacklisted after being reported as unstable.", - "value": { - "$serde_json::private::Number": "1000" - }, - "privacy": "Public" - }, - "consensus.network_config.secret_key": { - "description": "The secret key used for building the peer id. If it's an empty string a random one will be used.", - "value": "", - "privacy": "Private" - }, - "consensus.network_config.session_timeout": { - "description": "Maximal time in seconds that each session can take before failing on timeout.", - "value": { - "$serde_json::private::Number": "120" - }, - "privacy": "Public" - }, - "consensus.network_config.tcp_port": { - "description": "The port that the node listens on for incoming tcp connections.", - "value": { - "$serde_json::private::Number": "10100" - }, - "privacy": "Public" - }, "consensus.network_topic": { "description": "The network topic of the consensus.", "value": "consensus", @@ -440,6 +347,28 @@ expression: dumped_default_config }, "privacy": "Public" }, + "papyrus_consensus.#is_none": { + "description": "Flag for an optional field.", + "value": true, + "privacy": "TemporaryValue" + }, + "papyrus_consensus.proposals_topic": { + "description": "The topic for consensus proposals.", + "value": "consensus_proposals", + "privacy": "Public" + }, + "papyrus_consensus.start_height": { + "description": "The height to start the consensus from.", + "value": { + "$serde_json::private::Number": "0" + }, + "privacy": "Public" + }, + "papyrus_consensus.votes_topic": { + "description": "The topic for consensus votes.", + "value": "consensus_votes", + "privacy": "Public" + }, "rpc.chain_id": { "description": "The chain to follow. For more details see https://docs.starknet.io/documentation/architecture_and_concepts/Blocks/transactions/#chain-id.", "value": "SN_MAIN", diff --git a/crates/starknet_consensus/src/config.rs b/crates/starknet_consensus/src/config.rs index 6411db2c6a8..21a1512d3f2 100644 --- a/crates/starknet_consensus/src/config.rs +++ b/crates/starknet_consensus/src/config.rs @@ -11,7 +11,6 @@ use papyrus_config::converters::{ }; use papyrus_config::dumping::{append_sub_config_name, ser_param, SerializeConfig}; use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam}; -use papyrus_network::NetworkConfig; use papyrus_protobuf::consensus::DEFAULT_VALIDATOR_ID; use serde::{Deserialize, Serialize}; use starknet_api::block::BlockNumber; @@ -20,8 +19,6 @@ use validator::Validate; use crate::types::ValidatorId; -const CONSENSUS_TCP_PORT: u16 = 10100; - /// Configuration for consensus. #[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Validate)] pub struct ConsensusConfig { @@ -31,8 +28,10 @@ pub struct ConsensusConfig { pub chain_id: ChainId, /// The validator ID of the node. pub validator_id: ValidatorId, + // TODO(guyn): this will be removed in one of the next PRs. /// The network topic of the consensus. pub network_topic: String, + // TODO(guyn): this will be removed in one of the next PRs?? /// The height to start the consensus from. pub start_height: BlockNumber, /// The number of validators in the consensus. @@ -46,9 +45,6 @@ pub struct ConsensusConfig { /// The duration (seconds) between sync attempts. #[serde(deserialize_with = "deserialize_float_seconds_to_duration")] pub sync_retry_interval: Duration, - /// The network configuration for the consensus. - #[validate] - pub network_config: NetworkConfig, } impl SerializeConfig for ConsensusConfig { @@ -98,14 +94,12 @@ impl SerializeConfig for ConsensusConfig { ), ]); config.extend(append_sub_config_name(self.timeouts.dump(), "timeouts")); - config.extend(append_sub_config_name(self.network_config.dump(), "network_config")); config } } impl Default for ConsensusConfig { fn default() -> Self { - let network_config = NetworkConfig { tcp_port: CONSENSUS_TCP_PORT, ..Default::default() }; Self { chain_id: ChainId::Other("0x0".to_string()), validator_id: ValidatorId::from(DEFAULT_VALIDATOR_ID), @@ -115,7 +109,6 @@ impl Default for ConsensusConfig { consensus_delay: Duration::from_secs(5), timeouts: TimeoutsConfig::default(), sync_retry_interval: Duration::from_secs_f64(1.0), - network_config, } } } diff --git a/crates/starknet_consensus_manager/src/config.rs b/crates/starknet_consensus_manager/src/config.rs index b11be14f0c3..7f43ca3aabc 100644 --- a/crates/starknet_consensus_manager/src/config.rs +++ b/crates/starknet_consensus_manager/src/config.rs @@ -1,7 +1,8 @@ use std::collections::BTreeMap; -use papyrus_config::dumping::{append_sub_config_name, ser_optional_param, SerializeConfig}; +use papyrus_config::dumping::{append_sub_config_name, ser_param,ser_optional_param, SerializeConfig}; use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam}; +use papyrus_network::NetworkConfig; use serde::{Deserialize, Serialize}; use starknet_api::block::BlockNumber; use starknet_consensus::config::ConsensusConfig; @@ -11,24 +12,41 @@ use validator::Validate; /// The consensus manager related configuration. /// TODO(Matan): Remove ConsensusManagerConfig if it's only field remains ConsensusConfig. -#[derive(Clone, Default, Debug, Serialize, Deserialize, Validate, PartialEq)] +#[derive(Clone, Debug, Serialize, Deserialize, Validate, PartialEq)] pub struct ConsensusManagerConfig { pub consensus_config: ConsensusConfig, pub context_config: ContextConfig, + #[validate] + pub network_config: NetworkConfig, pub cende_config: CendeConfig, pub revert_up_to_and_including: Option, + pub votes_topic: String, + pub proposals_topic: String, + pub immediate_active_height: u64, } impl SerializeConfig for ConsensusManagerConfig { fn dump(&self) -> BTreeMap { - let mut config = BTreeMap::new(); - - config.extend(append_sub_config_name(self.consensus_config.dump(), "consensus_config")); - config.extend(append_sub_config_name(self.context_config.dump(), "context_config")); - config.extend(append_sub_config_name(self.cende_config.dump(), "cende_config")); - - // TODO(dvir): when there will be an option to have an optional config value, which is also - // a pointer, use it instead. + let mut config = BTreeMap::from_iter([ + ser_param( + "votes_topic", + &self.votes_topic, + "The topic for consensus votes.", + ParamPrivacyInput::Public, + ), + ser_param( + "proposals_topic", + &self.proposals_topic, + "The topic for consensus proposals.", + ParamPrivacyInput::Public, + ), + ser_param( + "immediate_active_height", + &self.immediate_active_height, + "The height at which the consensus manager becomes active.", + ParamPrivacyInput::Public, + ) + ]); config.extend(ser_optional_param( &self.revert_up_to_and_including, // Use u64::MAX as a placeholder to prevent setting this value to @@ -39,7 +57,25 @@ impl SerializeConfig for ConsensusManagerConfig { configurations carefully to prevent significant revert operations and data loss.", ParamPrivacyInput::Private, )); - + config.extend(append_sub_config_name(self.consensus_config.dump(), "consensus_config")); + config.extend(append_sub_config_name(self.context_config.dump(), "context_config")); + config.extend(append_sub_config_name(self.cende_config.dump(), "cende_config")); + config.extend(append_sub_config_name(self.network_config.dump(), "network_config")); config } } + +impl Default for ConsensusManagerConfig { + fn default() -> Self { + ConsensusManagerConfig { + consensus_config: ConsensusConfig::default(), + context_config: ContextConfig::default(), + cende_config: CendeConfig::default(), + network_config: NetworkConfig::default(), + revert_up_to_and_including: None, + votes_topic: "consensus_votes".to_string(), + proposals_topic: "consensus_proposals".to_string(), + immediate_active_height: 0, + } + } +} diff --git a/crates/starknet_consensus_manager/src/consensus_manager.rs b/crates/starknet_consensus_manager/src/consensus_manager.rs index 0efe81c67eb..2272f0b7cb7 100644 --- a/crates/starknet_consensus_manager/src/consensus_manager.rs +++ b/crates/starknet_consensus_manager/src/consensus_manager.rs @@ -52,8 +52,7 @@ impl ConsensusManager { return std::future::pending().await; } - let mut network_manager = - NetworkManager::new(self.config.consensus_config.network_config.clone(), None); + let mut network_manager = NetworkManager::new(self.config.network_config.clone(), None); let proposals_broadcast_channels = network_manager .register_broadcast_topic::>( diff --git a/crates/starknet_integration_tests/src/utils.rs b/crates/starknet_integration_tests/src/utils.rs index 6fe3327688d..19ed726b8af 100644 --- a/crates/starknet_integration_tests/src/utils.rs +++ b/crates/starknet_integration_tests/src/utils.rs @@ -131,11 +131,11 @@ pub(crate) fn create_consensus_manager_configs_from_network_configs( .into_iter() // TODO(Matan): Get config from default config file. .map(|network_config| ConsensusManagerConfig { + network_config, consensus_config: ConsensusConfig { start_height: BlockNumber(1), // TODO(Matan, Dan): Set the right amount consensus_delay: Duration::from_secs(15), - network_config, num_validators, timeouts: timeouts.clone(), ..Default::default() @@ -149,7 +149,7 @@ pub(crate) fn create_consensus_manager_configs_from_network_configs( skip_write_height: Some(BlockNumber(1)), ..Default::default() }, - revert_up_to_and_including: None, + ..Default::default() }) .collect() } diff --git a/crates/starknet_sequencer_node/src/config/node_config.rs b/crates/starknet_sequencer_node/src/config/node_config.rs index e21160a52c2..bd3fb051fd6 100644 --- a/crates/starknet_sequencer_node/src/config/node_config.rs +++ b/crates/starknet_sequencer_node/src/config/node_config.rs @@ -53,7 +53,7 @@ pub static CONFIG_POINTERS: LazyLock = LazyLock::new(|| { "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", + "consensus_manager_config.network_config.chain_id", "gateway_config.chain_info.chain_id", "l1_scraper_config.chain_id", "mempool_p2p_config.network_config.chain_id",