Skip to content

Commit

Permalink
chore(config): add short consensus delay to prevent InsufficientPeers…
Browse files Browse the repository at this point in the history
… error
  • Loading branch information
asmaastarkware committed Jul 23, 2024
1 parent 5e540b9 commit b97d984
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions crates/papyrus_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ fn run_consensus(
context,
start_height,
validator_id,
config.consensus_delay,
consensus_channels.broadcasted_messages_receiver,
)))
}
Expand Down
10 changes: 10 additions & 0 deletions crates/sequencing/papyrus_consensus/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
),
])
}
}
Expand All @@ -63,6 +72,7 @@ impl Default for ConsensusConfig {
topic: "consensus".to_string(),
start_height: BlockNumber::default(),
num_validators: 4,
consensus_delay: 5,
}
}
}
3 changes: 3 additions & 0 deletions crates/sequencing/papyrus_consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,15 @@ pub async fn run_consensus<BlockT: ConsensusBlock, ContextT: ConsensusContext<Bl
context: ContextT,
start_height: BlockNumber,
validator_id: ValidatorId,
consensus_delay: u64,
mut network_receiver: BroadcastSubscriberReceiver<ConsensusMessage>,
) -> Result<(), ConsensusError>
where
ProposalWrapper:
Into<(ProposalInit, mpsc::Receiver<BlockT::ProposalChunk>, oneshot::Receiver<BlockHash>)>,
{
// 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 {
Expand Down

0 comments on commit b97d984

Please sign in to comment.