Skip to content

Commit

Permalink
chore(consensus): add network config
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-starkware committed Nov 5, 2024
1 parent 135c179 commit 133dc43
Show file tree
Hide file tree
Showing 4 changed files with 273 additions and 0 deletions.
80 changes: 80 additions & 0 deletions config/mempool/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
"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": {
"description": "The duration 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": {
"description": "The duration a peer blacklisted after being reported as unstable.",
"privacy": "Public",
"value": 1
},
"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",
Expand Down
80 changes: 80 additions & 0 deletions config/papyrus/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
"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": {
"description": "The duration a peer is blacklisted after being marked as malicious.",
"privacy": "Public",
"value": 31536000
},
"consensus.network_config.peer_manager_config.unstable_timeout": {
"description": "The duration a peer blacklisted after being reported as unstable.",
"privacy": "Public",
"value": 1
},
"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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
"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": {
"description": "The duration 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": {
"description": "The duration a peer blacklisted after being reported as unstable.",
"value": {
"$serde_json::private::Number": "1"
},
"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",
Expand Down
13 changes: 13 additions & 0 deletions crates/sequencing/papyrus_consensus/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -70,19 +77,25 @@ 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(),
start_height: BlockNumber::default(),
num_validators: 1,
consensus_delay: Duration::from_secs(5),
timeouts: TimeoutsConfig::default(),
network_config,
}
}
}
Expand Down

0 comments on commit 133dc43

Please sign in to comment.