Skip to content

Commit

Permalink
chore(consensus): use non zero validator id in consensus config
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Dec 9, 2024
1 parent cbd8129 commit 5f9e909
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 11 deletions.
3 changes: 2 additions & 1 deletion crates/sequencing/papyrus_consensus/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 9 additions & 2 deletions crates/sequencing/papyrus_consensus/src/manager_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions crates/sequencing/papyrus_consensus/src/state_machine_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
4 changes: 4 additions & 0 deletions crates/sequencing/papyrus_consensus/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) };

Expand Down

0 comments on commit 5f9e909

Please sign in to comment.