Skip to content
This repository has been archived by the owner on Dec 26, 2024. It is now read-only.

Commit

Permalink
build(node): separate dump config exe to module
Browse files Browse the repository at this point in the history
  • Loading branch information
ShahakShama committed Feb 14, 2024
1 parent 0801a30 commit 99ace0d
Showing 1 changed file with 42 additions and 40 deletions.
82 changes: 42 additions & 40 deletions crates/papyrus_node/src/bin/dump_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,58 @@
#![cfg_attr(coverage_nightly, feature(coverage_attribute))]

#[cfg(feature = "rpc")]
use lazy_static::lazy_static;
#[cfg(feature = "rpc")]
use papyrus_config::dumping::{ser_pointer_target_param, SerializeConfig};
#[cfg(feature = "rpc")]
use papyrus_config::{ParamPath, SerializedParam};
#[cfg(feature = "rpc")]
use papyrus_node::config::{NodeConfig, DEFAULT_CONFIG_PATH};
#[cfg(feature = "rpc")]
use starknet_api::core::ChainId;
mod with_rpc {

#[cfg(feature = "rpc")]
lazy_static! {
/// Returns vector of (pointer target name, pointer target serialized param, vec<pointer param path>)
/// to be applied on the dumped node config.
/// The config updates will be performed on the shared pointer targets, and finally, the values
/// will be propagated to the pointer params.
static ref CONFIG_POINTERS: Vec<((ParamPath, SerializedParam), Vec<ParamPath>)> = vec![(
ser_pointer_target_param(
"chain_id",
&ChainId("SN_MAIN".to_string()),
"The chain to follow. For more details see https://docs.starknet.io/documentation/architecture_and_concepts/Blocks/transactions/#chain-id.",
),
vec!["storage.db_config.chain_id".to_owned(), "rpc.chain_id".to_owned()],
),
(
ser_pointer_target_param(
"starknet_url",
&"https://alpha-mainnet.starknet.io/".to_string(),
"The URL of a centralized Starknet gateway.",
use lazy_static::lazy_static;
use papyrus_config::dumping::{ser_pointer_target_param, SerializeConfig};
use papyrus_config::{ParamPath, SerializedParam};
use papyrus_node::config::{NodeConfig, DEFAULT_CONFIG_PATH};
use starknet_api::core::ChainId;

lazy_static! {
/// Returns vector of (pointer target name, pointer target serialized param, vec<pointer param path>)
/// to be applied on the dumped node config.
/// The config updates will be performed on the shared pointer targets, and finally, the values
/// will be propagated to the pointer params.
static ref CONFIG_POINTERS: Vec<((ParamPath, SerializedParam), Vec<ParamPath>)> = vec![(
ser_pointer_target_param(
"chain_id",
&ChainId("SN_MAIN".to_string()),
"The chain to follow. For more details see https://docs.starknet.io/documentation/architecture_and_concepts/Blocks/transactions/#chain-id.",
),
vec!["storage.db_config.chain_id".to_owned(), "rpc.chain_id".to_owned()],
),
vec!["rpc.starknet_url".to_owned(), "central.url".to_owned(), "monitoring_gateway.starknet_url".to_owned()],
),
(
ser_pointer_target_param(
"collect_metrics",
&false,
"If true, collect metrics for the node.",
(
ser_pointer_target_param(
"starknet_url",
&"https://alpha-mainnet.starknet.io/".to_string(),
"The URL of a centralized Starknet gateway.",
),
vec!["rpc.starknet_url".to_owned(), "central.url".to_owned(), "monitoring_gateway.starknet_url".to_owned()],
),
vec!["rpc.collect_metrics".to_owned(), "monitoring_gateway.collect_metrics".to_owned()],
)];
(
ser_pointer_target_param(
"collect_metrics",
&false,
"If true, collect metrics for the node.",
),
vec!["rpc.collect_metrics".to_owned(), "monitoring_gateway.collect_metrics".to_owned()],
)];
}

pub fn dump_config() {
NodeConfig::default()
.dump_to_file(&CONFIG_POINTERS, DEFAULT_CONFIG_PATH)
.expect("dump to file error");
}
}

/// Updates the default config file by:
/// cargo run --bin dump_config -q
#[cfg_attr(coverage_nightly, coverage_attribute)]
fn main() {
#[cfg(feature = "rpc")]
NodeConfig::default()
.dump_to_file(&CONFIG_POINTERS, DEFAULT_CONFIG_PATH)
.expect("dump to file error");
with_rpc::dump_config();
// TODO(shahak): Try to find a way to remove this binary altogether when the feature rpc is
// turned off.
#[cfg(not(feature = "rpc"))]
Expand Down

0 comments on commit 99ace0d

Please sign in to comment.