From 8e6331ca9aa16eaecd4eb3657321286eb481fd75 Mon Sep 17 00:00:00 2001 From: Dan Brownstein Date: Mon, 4 Nov 2024 21:57:18 +0200 Subject: [PATCH] chore(consensus): add network config --- config/mempool/default_config.json | 80 ++++++++++++++ config/papyrus/default_config.json | 80 ++++++++++++++ crates/papyrus_node/src/config/pointers.rs | 5 +- ...fig__config_test__dump_default_config.snap | 100 ++++++++++++++++++ .../sequencer_node/src/config/node_config.rs | 1 + .../papyrus_consensus/src/config.rs | 13 +++ 6 files changed, 277 insertions(+), 2 deletions(-) diff --git a/config/mempool/default_config.json b/config/mempool/default_config.json index 46668937bc..9b05cc32c2 100644 --- a/config/mempool/default_config.json +++ b/config/mempool/default_config.json @@ -559,6 +559,86 @@ "privacy": "Public", "value": 5 }, + "consensus_manager_config.consensus_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": { + "description": "Flag for an optional field.", + "privacy": "TemporaryValue", + "value": true + }, + "consensus_manager_config.consensus_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": { + "description": "Flag for an optional field.", + "privacy": "TemporaryValue", + "value": true + }, + "consensus_manager_config.consensus_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": { + "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": { + "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": { + "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": { + "description": "The interval between each discovery (Kademlia) query in milliseconds.", + "privacy": "Public", + "value": 100 + }, + "consensus_manager_config.consensus_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": { + "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": { + "description": "The duration in milliseconds a peer blacklisted after being reported as unstable.", + "privacy": "Public", + "value": 1000 + }, + "consensus_manager_config.consensus_config.network_config.quic_port": { + "description": "The port that the node listens on for incoming quic connections.", + "privacy": "Public", + "value": 10101 + }, + "consensus_manager_config.consensus_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": { + "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": { + "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", diff --git a/config/papyrus/default_config.json b/config/papyrus/default_config.json index 0031274076..66e376593b 100644 --- a/config/papyrus/default_config.json +++ b/config/papyrus/default_config.json @@ -84,6 +84,86 @@ "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.quic_port": { + "description": "The port that the node listens on for incoming quic connections.", + "privacy": "Public", + "value": 10101 + }, + "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", diff --git a/crates/papyrus_node/src/config/pointers.rs b/crates/papyrus_node/src/config/pointers.rs index 4e05e022b0..dcc8e6e491 100644 --- a/crates/papyrus_node/src/config/pointers.rs +++ b/crates/papyrus_node/src/config/pointers.rs @@ -56,9 +56,10 @@ pub static CONFIG_POINTERS: LazyLock = LazyLock::new(|| { "The chain to follow. For more details see https://docs.starknet.io/documentation/architecture_and_concepts/Blocks/transactions/#chain-id.", ), set_pointing_param_paths(&[ - "storage.db_config.chain_id", - "rpc.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 4064650ca0..b13bbcd9cf 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 @@ -96,6 +96,106 @@ 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.quic_port": { + "description": "The port that the node listens on for incoming quic connections.", + "value": { + "$serde_json::private::Number": "10101" + }, + "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", diff --git a/crates/sequencer_node/src/config/node_config.rs b/crates/sequencer_node/src/config/node_config.rs index 05216f9618..72329be7cf 100644 --- a/crates/sequencer_node/src/config/node_config.rs +++ b/crates/sequencer_node/src/config/node_config.rs @@ -45,6 +45,7 @@ pub static REQUIRED_PARAM_CONFIG_POINTERS: LazyLock = LazyLock:: set_pointing_param_paths(&[ "batcher_config.block_builder_config.chain_info.chain_id", "batcher_config.storage.db_config.chain_id", + "consensus_manager_config.consensus_config.network_config.chain_id", "gateway_config.chain_info.chain_id", "mempool_p2p_config.network_config.chain_id", ]), diff --git a/crates/sequencing/papyrus_consensus/src/config.rs b/crates/sequencing/papyrus_consensus/src/config.rs index e748891d17..d64f9514b3 100644 --- a/crates/sequencing/papyrus_consensus/src/config.rs +++ b/crates/sequencing/papyrus_consensus/src/config.rs @@ -11,11 +11,15 @@ 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 serde::{Deserialize, Serialize}; use starknet_api::block::BlockNumber; use super::types::ValidatorId; +const CONSENSUS_TCP_PORT: u16 = 10100; +const CONSENSUS_QUIC_PORT: u16 = 10101; + /// Configuration for consensus. #[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] pub struct ConsensusConfig { @@ -33,6 +37,9 @@ pub struct ConsensusConfig { pub consensus_delay: Duration, /// Timeouts configuration for consensus. pub timeouts: TimeoutsConfig, + // TODO(Dan/Matan): validate configs (#[validate]). + /// The network configuration for the consensus. + pub network_config: NetworkConfig, } impl SerializeConfig for ConsensusConfig { @@ -70,12 +77,17 @@ 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 mut network_config = NetworkConfig::default(); + // TODO(Dan/Shahak): consider something nicer, maybe a builder? + network_config.tcp_port = CONSENSUS_TCP_PORT; + network_config.quic_port = CONSENSUS_QUIC_PORT; Self { validator_id: ValidatorId::default(), network_topic: "consensus".to_string(), @@ -83,6 +95,7 @@ impl Default for ConsensusConfig { num_validators: 1, consensus_delay: Duration::from_secs(5), timeouts: TimeoutsConfig::default(), + network_config, } } }