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

build: add option to compile the node without rpc #1689

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@ jobs:
target/release/papyrus_node --base_layer.node_url ${{ secrets.CI_BASE_LAYER_NODE_URL }}
& sleep 30 ; kill $!
executable-run-no-rpc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- uses: Noelware/[email protected]
with:
version: ${{env.PROTOC_VERSION}}
- run: mkdir data

- name: Build node
run: cargo build -r --no-default-features

- name: Run executable
run: >
target/release/papyrus_node --base_layer.node_url ${{ secrets.CI_BASE_LAYER_NODE_URL }}
& sleep 30 ; kill $!
test:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -91,6 +110,20 @@ jobs:
cargo test -r --test '*' -- --include-ignored --skip test_gw_integration_testnet;
cargo run -r -p papyrus_node --bin central_source_integration_test
test-no-rpc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- uses: Noelware/[email protected]

- run: |
cargo test -p papyrus_node --no-default-features
env:
SEED: 0
rustfmt:
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const Configuration = {
'load_test',
'monitoring',
'network',
'node',
'release',
'starknet_client',
'storage',
Expand Down
8 changes: 6 additions & 2 deletions crates/papyrus_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ license-file.workspace = true
[package.metadata.cargo-udeps.ignore]
normal = ["papyrus_base_layer"]

[features]
default = ["rpc"]
rpc = ["papyrus_rpc"]

[dependencies]
anyhow.workspace = true
async-stream.workspace = true
Expand All @@ -25,13 +29,13 @@ papyrus_common = { path = "../papyrus_common", version = "0.3.0" }
papyrus_monitoring_gateway = { path = "../papyrus_monitoring_gateway", version = "0.3.0" }
papyrus_network = { path = "../papyrus_network", version = "0.3.0" }
papyrus_p2p_sync = { path = "../papyrus_p2p_sync", version = "0.3.0" }
papyrus_rpc = { path = "../papyrus_rpc", version = "0.3.0" }
papyrus_rpc = { path = "../papyrus_rpc", version = "0.3.0", optional = true }
papyrus_storage = { path = "../papyrus_storage", version = "0.3.0" }
papyrus_sync = { path = "../papyrus_sync", version = "0.3.0" }
reqwest = { workspace = true, features = ["json", "blocking"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, features = ["arbitrary_precision"] }
starknet_api.workspace = true
starknet_api = { workspace = true, features = ["testing"] }
starknet_client = { path = "../starknet_client" }
thiserror.workspace = true
tokio = { workspace = true, features = ["full", "sync"] }
Expand Down
11 changes: 10 additions & 1 deletion crates/papyrus_node/src/bin/dump_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@
// within this crate
#![cfg_attr(coverage_nightly, feature(coverage_attribute))]

#[cfg(feature = "rpc")]
use papyrus_config::dumping::SerializeConfig;
use papyrus_node::config::{NodeConfig, CONFIG_POINTERS, DEFAULT_CONFIG_PATH};
#[cfg(feature = "rpc")]
use papyrus_node::config::pointers::CONFIG_POINTERS;
#[cfg(feature = "rpc")]
use papyrus_node::config::{NodeConfig, DEFAULT_CONFIG_PATH};

/// 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");
// TODO(shahak): Try to find a way to remove this binary altogether when the feature rpc is
// turned off.
#[cfg(not(feature = "rpc"))]
panic!("Can't dump config when the rpc feature is deactivated");
}
18 changes: 14 additions & 4 deletions crates/papyrus_node/src/config/config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ use tempfile::NamedTempFile;
use test_utils::get_absolute_path;
use validator::Validate;

use crate::config::{node_command, NodeConfig, CONFIG_POINTERS, DEFAULT_CONFIG_PATH};
#[cfg(feature = "rpc")]
use crate::config::pointers::CONFIG_POINTERS;
use crate::config::{node_command, NodeConfig, DEFAULT_CONFIG_PATH};

// Returns the required and generated params in default_config.json with the default value from the
// config presentation.
Expand Down Expand Up @@ -76,6 +78,9 @@ fn load_http_headers() {
assert_eq!(config.central.http_headers.unwrap(), target_http_headers);
}

// insta doesn't work well with features, so if the output between two features are different we
// can only test one of them. We chose to test rpc over testing not(rpc).
#[cfg(feature = "rpc")]
#[test]
// Regression test which checks that the default config dumping hasn't changed.
fn test_dump_default_config() {
Expand All @@ -98,15 +103,20 @@ fn test_default_config_process() {

#[test]
fn test_update_dumped_config_by_command() {
let args =
get_args(vec!["--rpc.max_events_keys", "1234", "--storage.db_config.path_prefix", "/abc"]);
let args = get_args(vec![
"--central.retry_config.retry_max_delay_millis",
"1234",
"--storage.db_config.path_prefix",
"/abc",
]);
env::set_current_dir(get_absolute_path("")).expect("Couldn't set working dir.");
let config = NodeConfig::load_and_process(args).unwrap();

assert_eq!(config.rpc.max_events_keys, 1234);
assert_eq!(config.central.retry_config.retry_max_delay_millis, 1234);
assert_eq!(config.storage.db_config.path_prefix.to_str(), Some("/abc"));
}

#[cfg(feature = "rpc")]
#[test]
fn default_config_file_is_up_to_date() {
env::set_current_dir(get_absolute_path("")).expect("Couldn't set working dir.");
Expand Down
52 changes: 17 additions & 35 deletions crates/papyrus_node/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#[cfg(test)]
mod config_test;
#[cfg(feature = "rpc")]
pub mod pointers;

use std::collections::{BTreeMap, HashMap};
use std::fs::File;
Expand All @@ -14,17 +16,22 @@ use clap::{arg, value_parser, Arg, ArgMatches, Command};
use itertools::{chain, Itertools};
use lazy_static::lazy_static;
use papyrus_base_layer::ethereum_base_layer_contract::EthereumBaseLayerConfig;
#[cfg(not(feature = "rpc"))]
use papyrus_config::dumping::ser_param;
use papyrus_config::dumping::{
append_sub_config_name,
ser_optional_sub_config,
ser_pointer_target_param,
SerializeConfig,
};
use papyrus_config::loading::load_and_process_config;
#[cfg(not(feature = "rpc"))]
use papyrus_config::ParamPrivacyInput;
use papyrus_config::{ConfigError, ParamPath, SerializedParam};
use papyrus_monitoring_gateway::MonitoringGatewayConfig;
use papyrus_network::NetworkConfig;
use papyrus_p2p_sync::{P2PSync, P2PSyncConfig};
#[cfg(feature = "rpc")]
use papyrus_rpc::RpcConfig;
use papyrus_storage::db::DbConfig;
use papyrus_storage::StorageConfig;
Expand All @@ -41,40 +48,10 @@ use crate::version::VERSION_FULL;
// The path of the default configuration file, provided as part of the crate.
pub const DEFAULT_CONFIG_PATH: &str = "config/default_config.json";

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.
pub 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.",
),
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.",
),
vec!["rpc.collect_metrics".to_owned(), "monitoring_gateway.collect_metrics".to_owned()],
)];
}

/// The configurations of the various components of the node.
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Validate)]
pub struct NodeConfig {
#[cfg(feature = "rpc")]
#[validate]
pub rpc: RpcConfig,
pub central: CentralSourceConfig,
Expand All @@ -98,6 +75,7 @@ impl Default for NodeConfig {
NodeConfig {
central: CentralSourceConfig::default(),
base_layer: EthereumBaseLayerConfig::default(),
#[cfg(feature = "rpc")]
rpc: RpcConfig::default(),
monitoring_gateway: MonitoringGatewayConfig::default(),
storage: StorageConfig::default(),
Expand All @@ -110,17 +88,21 @@ impl Default for NodeConfig {

impl SerializeConfig for NodeConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
chain!(
#[allow(unused_mut)]
let mut sub_configs = vec![
append_sub_config_name(self.central.dump(), "central"),
append_sub_config_name(self.central.dump(), "central"),
append_sub_config_name(self.base_layer.dump(), "base_layer"),
append_sub_config_name(self.rpc.dump(), "rpc"),
append_sub_config_name(self.monitoring_gateway.dump(), "monitoring_gateway"),
append_sub_config_name(self.storage.dump(), "storage"),
ser_optional_sub_config(&self.sync, "sync"),
ser_optional_sub_config(&self.p2p_sync, "p2p_sync"),
ser_optional_sub_config(&self.network, "network"),
)
.collect()
];
#[cfg(feature = "rpc")]
sub_configs.push(append_sub_config_name(self.rpc.dump(), "rpc"));

sub_configs.into_iter().flatten().collect()
}
}

Expand Down
72 changes: 72 additions & 0 deletions crates/papyrus_node/src/config/pointers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use std::collections::{BTreeMap, HashMap};
use std::fs::File;
use std::io::{BufWriter, Write};
use std::mem::discriminant;
use std::ops::IndexMut;
use std::path::{Path, PathBuf};
use std::time::Duration;
use std::{env, fs, io};

use clap::{arg, value_parser, Arg, ArgMatches, Command};
use itertools::{chain, Itertools};
use lazy_static::lazy_static;
use papyrus_base_layer::ethereum_base_layer_contract::EthereumBaseLayerConfig;
#[cfg(not(feature = "rpc"))]
use papyrus_config::dumping::ser_param;
use papyrus_config::dumping::{
append_sub_config_name,
ser_optional_sub_config,
ser_pointer_target_param,
SerializeConfig,
};
use papyrus_config::loading::load_and_process_config;
#[cfg(not(feature = "rpc"))]
use papyrus_config::ParamPrivacyInput;
use papyrus_config::{ConfigError, ParamPath, SerializedParam};
use papyrus_monitoring_gateway::MonitoringGatewayConfig;
use papyrus_network::NetworkConfig;
use papyrus_p2p_sync::{P2PSync, P2PSyncConfig};
#[cfg(feature = "rpc")]
use papyrus_rpc::RpcConfig;
use papyrus_storage::db::DbConfig;
use papyrus_storage::StorageConfig;
use papyrus_sync::sources::central::CentralSourceConfig;
use papyrus_sync::SyncConfig;
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
use starknet_api::core::ChainId;
use starknet_client::RetryConfig;
use validator::Validate;

use crate::version::VERSION_FULL;

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.
pub 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.",
),
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.",
),
vec!["rpc.collect_metrics".to_owned(), "monitoring_gateway.collect_metrics".to_owned()],
)];
}
Loading
Loading