Skip to content

Commit

Permalink
chore(consensus): add PapyrusConsensusConfig struct
Browse files Browse the repository at this point in the history
  • Loading branch information
guy-starkware committed Jan 30, 2025
1 parent 06d06b3 commit c533198
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
20 changes: 20 additions & 0 deletions config/papyrus/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,26 @@
"privacy": "Public",
"value": 50
},
"papyrus_consensus.#is_none": {
"description": "Flag for an optional field.",
"privacy": "TemporaryValue",
"value": true
},
"papyrus_consensus.proposals_topic": {
"description": "The topic for consensus proposals.",
"privacy": "Public",
"value": "consensus_proposals"
},
"papyrus_consensus.start_height": {
"description": "The height to start the consensus from.",
"privacy": "Public",
"value": 0
},
"papyrus_consensus.votes_topic": {
"description": "The topic for consensus votes.",
"privacy": "Public",
"value": "consensus_votes"
},
"rpc.chain_id": {
"description": "The chain to follow. For more details see https://docs.starknet.io/documentation/architecture_and_concepts/Blocks/transactions/#chain-id.",
"pointer_target": "chain_id",
Expand Down
48 changes: 48 additions & 0 deletions crates/papyrus_node/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use papyrus_sync::sources::central::CentralSourceConfig;
use papyrus_sync::SyncConfig;
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
use starknet_api::block::BlockNumber;
use starknet_api::core::ChainId;
use starknet_client::RetryConfig;
use starknet_consensus::config::ConsensusConfig;
Expand Down Expand Up @@ -65,6 +66,7 @@ pub struct NodeConfig {
// TODO(yair): Change NodeConfig to have an option of enum of SyncConfig or P2pSyncConfig.
pub p2p_sync: Option<P2pSyncClientConfig>,
pub consensus: Option<ConsensusConfig>,
pub papyrus_consensus: Option<PapyrusConsensusConfig>,
pub context: Option<ContextConfig>,
// TODO(shahak): Make network non-optional once it's developed enough.
pub network: Option<NetworkConfig>,
Expand All @@ -84,6 +86,7 @@ impl Default for NodeConfig {
sync: Some(SyncConfig::default()),
p2p_sync: None,
consensus: None,
papyrus_consensus: None,
context: None,
network: None,
collect_profiling_metrics: false,
Expand All @@ -102,6 +105,7 @@ impl SerializeConfig for NodeConfig {
ser_optional_sub_config(&self.sync, "sync"),
ser_optional_sub_config(&self.p2p_sync, "p2p_sync"),
ser_optional_sub_config(&self.consensus, "consensus"),
ser_optional_sub_config(&self.papyrus_consensus, "papyrus_consensus"),
ser_optional_sub_config(&self.context, "context"),
ser_optional_sub_config(&self.network, "network"),
BTreeMap::from_iter([ser_param(
Expand Down Expand Up @@ -133,3 +137,47 @@ pub fn node_command() -> Command {
.version(VERSION_FULL)
.about("Papyrus is a StarkNet full node written in Rust.")
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Validate)]
pub struct PapyrusConsensusConfig {
pub start_height: BlockNumber,
pub proposals_topic: String,
pub votes_topic: String,
pub config: ContextConfig,
}

impl SerializeConfig for PapyrusConsensusConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
BTreeMap::from_iter([
ser_param(
"start_height",
&self.start_height,
"The height to start the consensus from.",
ParamPrivacyInput::Public,
),
ser_param(
"proposals_topic",
&self.proposals_topic,
"The topic for consensus proposals.",
ParamPrivacyInput::Public,
),
ser_param(
"votes_topic",
&self.votes_topic,
"The topic for consensus votes.",
ParamPrivacyInput::Public,
),
])
}
}

impl Default for PapyrusConsensusConfig {
fn default() -> Self {
Self {
start_height: BlockNumber::default(),
proposals_topic: "consensus_proposals".to_string(),
votes_topic: "consensus_votes".to_string(),
config: ContextConfig::default(),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,28 @@ expression: dumped_default_config
},
"privacy": "Public"
},
"papyrus_consensus.#is_none": {
"description": "Flag for an optional field.",
"value": true,
"privacy": "TemporaryValue"
},
"papyrus_consensus.proposals_topic": {
"description": "The topic for consensus proposals.",
"value": "consensus_proposals",
"privacy": "Public"
},
"papyrus_consensus.start_height": {
"description": "The height to start the consensus from.",
"value": {
"$serde_json::private::Number": "0"
},
"privacy": "Public"
},
"papyrus_consensus.votes_topic": {
"description": "The topic for consensus votes.",
"value": "consensus_votes",
"privacy": "Public"
},
"rpc.chain_id": {
"description": "The chain to follow. For more details see https://docs.starknet.io/documentation/architecture_and_concepts/Blocks/transactions/#chain-id.",
"value": "SN_MAIN",
Expand Down

0 comments on commit c533198

Please sign in to comment.