diff --git a/crates/sequencing/papyrus_consensus/src/test_utils.rs b/crates/sequencing/papyrus_consensus/src/test_utils.rs index ae5a840cb7..32ea37b75f 100644 --- a/crates/sequencing/papyrus_consensus/src/test_utils.rs +++ b/crates/sequencing/papyrus_consensus/src/test_utils.rs @@ -8,7 +8,14 @@ use papyrus_protobuf::converters::ProtobufConversionError; use starknet_api::block::{BlockHash, BlockNumber}; use starknet_types_core::felt::Felt; -use crate::types::{ConsensusContext, ConsensusError, ProposalContentId, Round, ValidatorId}; +use crate::types::{ + ConsensusContext, + ConsensusError, + ProposalContentId, + Round, + ValidatorId, + DEFAULT_VALIDATOR_ID, +}; /// Define a consensus block which can be used to enable auto mocking Context. #[derive(Debug, PartialEq, Clone)] @@ -31,9 +38,8 @@ impl TryFrom for ProposalInit { fn try_from(part: MockProposalPart) -> Result { Ok(ProposalInit { height: BlockNumber(part.0), - round: 0, - proposer: ValidatorId::default(), - valid_round: None, + proposer: DEFAULT_VALIDATOR_ID.into(), + ..Default::default() }) } } diff --git a/crates/sequencing/papyrus_consensus_orchestrator/src/papyrus_consensus_context.rs b/crates/sequencing/papyrus_consensus_orchestrator/src/papyrus_consensus_context.rs index ed3acb19b7..9a34d1af07 100644 --- a/crates/sequencing/papyrus_consensus_orchestrator/src/papyrus_consensus_context.rs +++ b/crates/sequencing/papyrus_consensus_orchestrator/src/papyrus_consensus_context.rs @@ -21,6 +21,7 @@ use papyrus_consensus::types::{ ProposalContentId, Round, ValidatorId, + DEFAULT_VALIDATOR_ID, }; use papyrus_network::network_manager::{BroadcastTopicClient, BroadcastTopicClientTrait}; use papyrus_protobuf::consensus::{ @@ -70,7 +71,9 @@ impl PapyrusConsensusContext { network_broadcast_client, network_proposal_sender, // TODO(Matan): Set the actual validator IDs (contract addresses). - validators: (100..100 + num_validators).map(ValidatorId::from).collect(), + validators: (0..num_validators) + .map(|i| ValidatorId::from(DEFAULT_VALIDATOR_ID + i)) + .collect(), sync_broadcast_sender, valid_proposals: Arc::new(Mutex::new(BTreeMap::new())), } diff --git a/crates/sequencing/papyrus_consensus_orchestrator/src/papyrus_consensus_context_test.rs b/crates/sequencing/papyrus_consensus_orchestrator/src/papyrus_consensus_context_test.rs index e5818fc9f3..dc83ee01c7 100644 --- a/crates/sequencing/papyrus_consensus_orchestrator/src/papyrus_consensus_context_test.rs +++ b/crates/sequencing/papyrus_consensus_orchestrator/src/papyrus_consensus_context_test.rs @@ -70,7 +70,7 @@ async fn validate_proposal_success() { .validate_proposal( block_number, 0, - ValidatorId::default(), + ValidatorId::from(DEFAULT_VALIDATOR_ID), Duration::MAX, validate_receiver, ) @@ -101,7 +101,7 @@ async fn validate_proposal_fail() { .validate_proposal( block_number, 0, - ValidatorId::default(), + ValidatorId::from(DEFAULT_VALIDATOR_ID), Duration::MAX, validate_receiver, ) diff --git a/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context.rs b/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context.rs index dfe48a31c8..293d53414e 100644 --- a/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context.rs +++ b/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context.rs @@ -18,6 +18,7 @@ use papyrus_consensus::types::{ ProposalContentId, Round, ValidatorId, + DEFAULT_VALIDATOR_ID, }; use papyrus_network::network_manager::{BroadcastTopicClient, BroadcastTopicClientTrait}; use papyrus_protobuf::consensus::{ @@ -118,7 +119,9 @@ impl SequencerConsensusContext { outbound_proposal_sender, vote_broadcast_client, // TODO(Matan): Set the actual validator IDs (contract addresses). - validators: (100..100 + num_validators).map(ValidatorId::from).collect(), + validators: (0..num_validators) + .map(|i| ValidatorId::from(DEFAULT_VALIDATOR_ID + i)) + .collect(), valid_proposals: Arc::new(Mutex::new(HeightToIdToContent::new())), proposal_id: 0, current_height: None, diff --git a/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context_test.rs b/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context_test.rs index 8ac80c7aaf..085cfed39d 100644 --- a/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context_test.rs +++ b/crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context_test.rs @@ -6,7 +6,7 @@ use futures::channel::mpsc; use futures::{FutureExt, SinkExt}; use lazy_static::lazy_static; use papyrus_consensus::stream_handler::StreamHandler; -use papyrus_consensus::types::{ConsensusContext, ValidatorId}; +use papyrus_consensus::types::{ConsensusContext, ValidatorId, DEFAULT_VALIDATOR_ID}; use papyrus_network::network_manager::test_utils::{ mock_register_broadcast_topic, BroadcastNetworkMock, @@ -130,12 +130,8 @@ async fn build_proposal() { }); let (mut context, _network) = setup(batcher); - let init = ProposalInit { - height: BlockNumber(0), - round: 0, - proposer: ValidatorId::default(), - valid_round: None, - }; + let init = + ProposalInit { proposer: ValidatorId::from(DEFAULT_VALIDATOR_ID), ..Default::default() }; // TODO(Asmaa): Test proposal content. let fin_receiver = context.build_proposal(init, TIMEOUT).await; assert_eq!(fin_receiver.await.unwrap().0, STATE_DIFF_COMMITMENT.0.0); @@ -200,7 +196,13 @@ async fn validate_proposal_success() { .await .unwrap(); let fin_receiver = context - .validate_proposal(BlockNumber(0), 0, ValidatorId::default(), TIMEOUT, content_receiver) + .validate_proposal( + BlockNumber(0), + 0, + ValidatorId::from(DEFAULT_VALIDATOR_ID), + TIMEOUT, + content_receiver, + ) .await; content_sender.close_channel(); assert_eq!(fin_receiver.await.unwrap().0.0, STATE_DIFF_COMMITMENT.0.0); @@ -252,7 +254,13 @@ async fn repropose() { .await .unwrap(); let fin_receiver = context - .validate_proposal(BlockNumber(0), 0, ValidatorId::default(), TIMEOUT, content_receiver) + .validate_proposal( + BlockNumber(0), + 0, + ValidatorId::from(DEFAULT_VALIDATOR_ID), + TIMEOUT, + content_receiver, + ) .await; content_sender.close_channel(); assert_eq!(fin_receiver.await.unwrap().0.0, STATE_DIFF_COMMITMENT.0.0); @@ -321,7 +329,13 @@ async fn proposals_from_different_rounds() { content_sender.send(prop_part_txs.clone()).await.unwrap(); let fin_receiver_past_round = context - .validate_proposal(BlockNumber(0), 0, ValidatorId::default(), TIMEOUT, content_receiver) + .validate_proposal( + BlockNumber(0), + 0, + ValidatorId::from(DEFAULT_VALIDATOR_ID), + TIMEOUT, + content_receiver, + ) .await; // No fin was sent, channel remains open. assert!(fin_receiver_past_round.await.is_err()); @@ -331,7 +345,13 @@ async fn proposals_from_different_rounds() { content_sender.send(prop_part_txs.clone()).await.unwrap(); content_sender.send(prop_part_fin.clone()).await.unwrap(); let fin_receiver_curr_round = context - .validate_proposal(BlockNumber(0), 1, ValidatorId::default(), TIMEOUT, content_receiver) + .validate_proposal( + BlockNumber(0), + 1, + ValidatorId::from(DEFAULT_VALIDATOR_ID), + TIMEOUT, + content_receiver, + ) .await; assert_eq!(fin_receiver_curr_round.await.unwrap().0.0, STATE_DIFF_COMMITMENT.0.0); @@ -340,7 +360,13 @@ async fn proposals_from_different_rounds() { content_sender.send(prop_part_txs.clone()).await.unwrap(); content_sender.send(prop_part_fin.clone()).await.unwrap(); let fin_receiver_future_round = context - .validate_proposal(BlockNumber(0), 2, ValidatorId::default(), TIMEOUT, content_receiver) + .validate_proposal( + BlockNumber(0), + 2, + ValidatorId::from(DEFAULT_VALIDATOR_ID), + TIMEOUT, + content_receiver, + ) .await; content_sender.close_channel(); // Even with sending fin and closing the channel. @@ -396,7 +422,13 @@ async fn interrupt_active_proposal() { // without needing interrupt. let (mut _content_sender_0, content_receiver) = mpsc::channel(CHANNEL_SIZE); let fin_receiver_0 = context - .validate_proposal(BlockNumber(0), 0, ValidatorId::default(), TIMEOUT, content_receiver) + .validate_proposal( + BlockNumber(0), + 0, + ValidatorId::from(DEFAULT_VALIDATOR_ID), + TIMEOUT, + content_receiver, + ) .await; let (mut content_sender_1, content_receiver) = mpsc::channel(CHANNEL_SIZE); @@ -414,7 +446,13 @@ async fn interrupt_active_proposal() { .await .unwrap(); let fin_receiver_1 = context - .validate_proposal(BlockNumber(0), 1, ValidatorId::default(), TIMEOUT, content_receiver) + .validate_proposal( + BlockNumber(0), + 1, + ValidatorId::from(DEFAULT_VALIDATOR_ID), + TIMEOUT, + content_receiver, + ) .await; // Move the context to the next round. context.set_height_and_round(BlockNumber(0), 1).await;