diff --git a/config/default_config.json b/config/default_config.json index 8fa65a6c22..4c1e6488ed 100644 --- a/config/default_config.json +++ b/config/default_config.json @@ -79,6 +79,11 @@ "privacy": "TemporaryValue", "value": true }, + "consensus.consensus_delay": { + "description": "The delay in seconds before starting consensus to prevent 'InsufficientPeers' error.", + "privacy": "Public", + "value": 5 + }, "consensus.num_validators": { "description": "The number of validators in the consensus.", "privacy": "Public", 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 7b76e5e02e..3e1dcf6752 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 @@ -89,6 +89,13 @@ expression: dumped_default_config "value": true, "privacy": "TemporaryValue" }, + "consensus.consensus_delay": { + "description": "The delay in seconds before starting consensus to prevent 'InsufficientPeers' error.", + "value": { + "$serde_json::private::Number": "5" + }, + "privacy": "Public" + }, "consensus.num_validators": { "description": "The number of validators in the consensus.", "value": { diff --git a/crates/papyrus_node/src/main.rs b/crates/papyrus_node/src/main.rs index 71d3e5f350..f7d54f59ed 100644 --- a/crates/papyrus_node/src/main.rs +++ b/crates/papyrus_node/src/main.rs @@ -128,6 +128,7 @@ fn run_consensus( context, start_height, validator_id, + config.consensus_delay, consensus_channels.broadcasted_messages_receiver, ))) } diff --git a/crates/sequencing/papyrus_consensus/src/config.rs b/crates/sequencing/papyrus_consensus/src/config.rs index 1508dd91d7..718621bfb8 100644 --- a/crates/sequencing/papyrus_consensus/src/config.rs +++ b/crates/sequencing/papyrus_consensus/src/config.rs @@ -23,6 +23,8 @@ pub struct ConsensusConfig { /// The number of validators in the consensus. // Used for testing in an early milestones. pub num_validators: u64, + /// The delay in seconds before starting consensus to prevent InsufficientPeers error. + pub consensus_delay: u64, } impl SerializeConfig for ConsensusConfig { @@ -52,6 +54,13 @@ impl SerializeConfig for ConsensusConfig { "The number of validators in the consensus.", ParamPrivacyInput::Public, ), + ser_param( + "consensus_delay", + &self.consensus_delay, + "The delay in seconds before starting consensus to prevent 'InsufficientPeers' \ + error.", + ParamPrivacyInput::Public, + ), ]) } } @@ -63,6 +72,7 @@ impl Default for ConsensusConfig { topic: "consensus".to_string(), start_height: BlockNumber::default(), num_validators: 4, + consensus_delay: 5, } } } diff --git a/crates/sequencing/papyrus_consensus/src/lib.rs b/crates/sequencing/papyrus_consensus/src/lib.rs index 2d076720ce..64fdda6fff 100644 --- a/crates/sequencing/papyrus_consensus/src/lib.rs +++ b/crates/sequencing/papyrus_consensus/src/lib.rs @@ -106,12 +106,15 @@ pub async fn run_consensus, ) -> Result<(), ConsensusError> where ProposalWrapper: Into<(ProposalInit, mpsc::Receiver, oneshot::Receiver)>, { + // Add a short delay to allow peers to connect and avoid "InsufficientPeers" error + tokio::time::sleep(std::time::Duration::from_secs(consensus_delay)).await; let mut current_height = start_height; let mut future_messages = Vec::new(); loop {