From 5f9e909e699d7bb60bbbf2d8e4575cf544de496f Mon Sep 17 00:00:00 2001 From: Arni Hod Date: Thu, 5 Dec 2024 10:21:21 +0200 Subject: [PATCH] chore(consensus): use non zero validator id in consensus config --- crates/sequencing/papyrus_consensus/src/config.rs | 3 ++- .../sequencing/papyrus_consensus/src/manager_test.rs | 11 +++++++++-- .../src/single_height_consensus_test.rs | 4 ++-- .../papyrus_consensus/src/state_machine_test.rs | 4 ++-- crates/sequencing/papyrus_consensus/src/types.rs | 4 ++++ .../src/papyrus_consensus_context_test.rs | 4 ++-- .../tests/end_to_end_flow_test.rs | 4 ++-- 7 files changed, 23 insertions(+), 11 deletions(-) diff --git a/crates/sequencing/papyrus_consensus/src/config.rs b/crates/sequencing/papyrus_consensus/src/config.rs index 843cc206bf..e6016cea60 100644 --- a/crates/sequencing/papyrus_consensus/src/config.rs +++ b/crates/sequencing/papyrus_consensus/src/config.rs @@ -17,6 +17,7 @@ use starknet_api::block::BlockNumber; use starknet_api::core::ChainId; use super::types::ValidatorId; +use crate::types::DEFAULT_VALIDATOR_ID; const CONSENSUS_TCP_PORT: u16 = 10100; const CONSENSUS_QUIC_PORT: u16 = 10101; @@ -100,7 +101,7 @@ impl Default for ConsensusConfig { }; Self { chain_id: ChainId::Other("0x0".to_string()), - validator_id: ValidatorId::from(100_u32), + validator_id: ValidatorId::from(DEFAULT_VALIDATOR_ID), network_topic: "consensus".to_string(), start_height: BlockNumber::default(), num_validators: 1, diff --git a/crates/sequencing/papyrus_consensus/src/manager_test.rs b/crates/sequencing/papyrus_consensus/src/manager_test.rs index d393627ac9..0b748d5207 100644 --- a/crates/sequencing/papyrus_consensus/src/manager_test.rs +++ b/crates/sequencing/papyrus_consensus/src/manager_test.rs @@ -28,10 +28,17 @@ use starknet_types_core::felt::Felt; use super::{run_consensus, MultiHeightManager}; use crate::config::TimeoutsConfig; use crate::test_utils::{precommit, prevote, proposal_init}; -use crate::types::{ConsensusContext, ConsensusError, ProposalContentId, Round, ValidatorId}; +use crate::types::{ + ConsensusContext, + ConsensusError, + ProposalContentId, + Round, + ValidatorId, + DEFAULT_VALIDATOR_ID, +}; lazy_static! { - static ref PROPOSER_ID: ValidatorId = 100_u32.into(); + static ref PROPOSER_ID: ValidatorId = DEFAULT_VALIDATOR_ID.into(); static ref VALIDATOR_ID: ValidatorId = 101_u32.into(); static ref VALIDATOR_ID_2: ValidatorId = 102_u32.into(); static ref VALIDATOR_ID_3: ValidatorId = 103_u32.into(); diff --git a/crates/sequencing/papyrus_consensus/src/single_height_consensus_test.rs b/crates/sequencing/papyrus_consensus/src/single_height_consensus_test.rs index 60a9251f1a..32093e4501 100644 --- a/crates/sequencing/papyrus_consensus/src/single_height_consensus_test.rs +++ b/crates/sequencing/papyrus_consensus/src/single_height_consensus_test.rs @@ -12,10 +12,10 @@ use crate::config::TimeoutsConfig; use crate::single_height_consensus::{ShcEvent, ShcReturn, ShcTask}; use crate::state_machine::StateMachineEvent; use crate::test_utils::{precommit, prevote, MockProposalPart, MockTestContext, TestBlock}; -use crate::types::{ConsensusError, ValidatorId}; +use crate::types::{ConsensusError, ValidatorId, DEFAULT_VALIDATOR_ID}; lazy_static! { - static ref PROPOSER_ID: ValidatorId = 100_u32.into(); + static ref PROPOSER_ID: ValidatorId = DEFAULT_VALIDATOR_ID.into(); static ref VALIDATOR_ID_1: ValidatorId = 101_u32.into(); static ref VALIDATOR_ID_2: ValidatorId = 102_u32.into(); static ref VALIDATOR_ID_3: ValidatorId = 103_u32.into(); diff --git a/crates/sequencing/papyrus_consensus/src/state_machine_test.rs b/crates/sequencing/papyrus_consensus/src/state_machine_test.rs index 680a4224f0..56e75c6adc 100644 --- a/crates/sequencing/papyrus_consensus/src/state_machine_test.rs +++ b/crates/sequencing/papyrus_consensus/src/state_machine_test.rs @@ -7,10 +7,10 @@ use test_case::test_case; use super::Round; use crate::state_machine::{StateMachine, StateMachineEvent}; -use crate::types::{ProposalContentId, ValidatorId}; +use crate::types::{ProposalContentId, ValidatorId, DEFAULT_VALIDATOR_ID}; lazy_static! { - static ref PROPOSER_ID: ValidatorId = 100_u32.into(); + static ref PROPOSER_ID: ValidatorId = DEFAULT_VALIDATOR_ID.into(); static ref VALIDATOR_ID: ValidatorId = 101_u32.into(); } diff --git a/crates/sequencing/papyrus_consensus/src/types.rs b/crates/sequencing/papyrus_consensus/src/types.rs index becc800fd9..797100b6f4 100644 --- a/crates/sequencing/papyrus_consensus/src/types.rs +++ b/crates/sequencing/papyrus_consensus/src/types.rs @@ -23,6 +23,10 @@ pub type ValidatorId = ContractAddress; pub type Round = u32; pub type ProposalContentId = BlockHash; +/// A temporary constant to use as a validator ID. Zero is not a valid contract address. +// TODO(Matan): Remove this once we have a proper validator set. +pub const DEFAULT_VALIDATOR_ID: u64 = 100; + /// Interface for consensus to call out to the node. #[async_trait] pub trait ConsensusContext { 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 d5cc473555..e5818fc9f3 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 @@ -3,7 +3,7 @@ use std::time::Duration; use futures::channel::{mpsc, oneshot}; use futures::StreamExt; 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, @@ -39,7 +39,7 @@ async fn build_proposal() { let proposal_init = ProposalInit { height: block_number, round: 0, - proposer: ValidatorId::from(100_u32), + proposer: ValidatorId::from(DEFAULT_VALIDATOR_ID), valid_round: None, }; // TODO(Asmaa): Test proposal content. diff --git a/crates/starknet_integration_tests/tests/end_to_end_flow_test.rs b/crates/starknet_integration_tests/tests/end_to_end_flow_test.rs index e648c437ba..9a1bd9de53 100644 --- a/crates/starknet_integration_tests/tests/end_to_end_flow_test.rs +++ b/crates/starknet_integration_tests/tests/end_to_end_flow_test.rs @@ -2,7 +2,7 @@ use std::collections::HashSet; use futures::StreamExt; use mempool_test_utils::starknet_api_test_utils::MultiAccountTransactionGenerator; -use papyrus_consensus::types::ValidatorId; +use papyrus_consensus::types::{ValidatorId, DEFAULT_VALIDATOR_ID}; use papyrus_network::network_manager::BroadcastTopicChannels; use papyrus_protobuf::consensus::{ ProposalFin, @@ -89,7 +89,7 @@ async fn listen_to_broadcasted_messages( height: expected_height, round: 0, valid_round: None, - proposer: ValidatorId::from(100_u32), + proposer: ValidatorId::from(DEFAULT_VALIDATOR_ID), }; let expected_proposal_fin = ProposalFin { proposal_content_id: BlockHash(expected_content_id) };