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

Commit

Permalink
build(node): add option to compile the node without rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
ShahakShama committed Feb 11, 2024
1 parent 62ec8d4 commit ae611b1
Show file tree
Hide file tree
Showing 10 changed files with 354 additions and 17 deletions.
32 changes: 32 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 @@ -88,6 +107,19 @@ 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

- 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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
187 changes: 187 additions & 0 deletions config/default_config_no_rpc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
{
"base_layer.node_url": {
"description": "A required param! Ethereum node URL. A schema to match to Infura node: https://mainnet.infura.io/v3/<your_api_key>, but any other node can be used.",
"param_type": "String",
"privacy": "Private"
},
"base_layer.starknet_contract_address": {
"description": "Starknet contract address in ethereum.",
"privacy": "Public",
"value": "0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4"
},
"central.class_cache_size": {
"description": "Size of class cache, must be a positive integer.",
"privacy": "Public",
"value": 100
},
"central.concurrent_requests": {
"description": "Maximum number of concurrent requests to Starknet feeder-gateway for getting a type of data (for example, blocks).",
"privacy": "Public",
"value": 10
},
"central.http_headers": {
"description": "'k1:v1 k2:v2 ...' headers for SN-client.",
"privacy": "Private",
"value": ""
},
"central.max_classes_to_download": {
"description": "Maximum number of classes to download at a given time.",
"privacy": "Public",
"value": 20
},
"central.max_state_updates_to_download": {
"description": "Maximum number of state updates to download at a given time.",
"privacy": "Public",
"value": 20
},
"central.max_state_updates_to_store_in_memory": {
"description": "Maximum number of state updates to store in memory at a given time.",
"privacy": "Public",
"value": 20
},
"central.retry_config.max_retries": {
"description": "Maximum number of retries before the node stops retrying.",
"privacy": "Public",
"value": 10
},
"central.retry_config.retry_base_millis": {
"description": "Base waiting time after a failed request. After that, the time increases exponentially.",
"privacy": "Public",
"value": 30
},
"central.retry_config.retry_max_delay_millis": {
"description": "Max waiting time after a failed request.",
"privacy": "Public",
"value": 30000
},
"central.url": {
"description": "Starknet feeder-gateway URL. It should match chain_id.",
"pointer_target": "starknet_url",
"privacy": "Public"
},
"chain_id": {
"description": "The chain to follow. For more details see https://docs.starknet.io/documentation/architecture_and_concepts/Blocks/transactions/#chain-id.",
"privacy": "TemporaryValue",
"value": "SN_MAIN"
},
"collect_metrics": {
"description": "If true, collect metrics for the node.",
"privacy": "TemporaryValue",
"value": false
},
"monitoring_gateway.collect_metrics": {
"description": "If true, collect and return metrics in the monitoring gateway.",
"pointer_target": "collect_metrics",
"privacy": "Public"
},
"monitoring_gateway.metric_labels": {
"description": "'label1:value1 label2:value2 ...' additional labels for metrics.",
"privacy": "Public",
"value": ""
},
"monitoring_gateway.present_full_config_secret": {
"description": "A secret for presenting the full general config. If no value is provided, the system will generate one.",
"param_type": "String",
"privacy": "Private"
},
"monitoring_gateway.server_address": {
"description": "node's monitoring server.",
"privacy": "Public",
"value": "0.0.0.0:8081"
},
"monitoring_gateway.starknet_url": {
"description": "The URL of a centralized Starknet gateway.",
"pointer_target": "starknet_url",
"privacy": "Public"
},
"rpc.dummy_value": {
"description": "Dummy value because an empty config doesn't work.",
"privacy": "Public",
"value": false
},
"starknet_url": {
"description": "The URL of a centralized Starknet gateway.",
"privacy": "TemporaryValue",
"value": "https://alpha-mainnet.starknet.io/"
},
"storage.db_config.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",
"privacy": "Public"
},
"storage.db_config.enforce_file_exists": {
"description": "Whether to enforce that the path exists. If true, `open_env` fails when the mdbx.dat file does not exist.",
"privacy": "Public",
"value": false
},
"storage.db_config.growth_step": {
"description": "The growth step in bytes, must be greater than zero to allow the database to grow.",
"privacy": "Public",
"value": 4294967296
},
"storage.db_config.max_size": {
"description": "The maximum size of the node's storage in bytes.",
"privacy": "Public",
"value": 1099511627776
},
"storage.db_config.min_size": {
"description": "The minimum size of the node's storage in bytes.",
"privacy": "Public",
"value": 1048576
},
"storage.db_config.path_prefix": {
"description": "Prefix of the path of the node's storage directory, the storage file path will be <path_prefix>/<chain_id>. The path is not created automatically.",
"privacy": "Public",
"value": "./data"
},
"storage.mmap_file_config.growth_step": {
"description": "The growth step in bytes, must be greater than max_object_size.",
"privacy": "Public",
"value": 1073741824
},
"storage.mmap_file_config.max_object_size": {
"description": "The maximum size of a single object in the file in bytes",
"privacy": "Public",
"value": 1048576
},
"storage.mmap_file_config.max_size": {
"description": "The maximum size of a memory mapped file in bytes. Must be greater than growth_step.",
"privacy": "Public",
"value": 1099511627776
},
"storage.scope": {
"description": "The categories of data saved in storage.",
"privacy": "Public",
"value": "FullArchive"
},
"sync.#is_none": {
"description": "Flag for an optional field",
"privacy": "TemporaryValue",
"value": false
},
"sync.base_layer_propagation_sleep_duration": {
"description": "Time in seconds to poll the base layer to get the latest proved block.",
"privacy": "Public",
"value": 10
},
"sync.block_propagation_sleep_duration": {
"description": "Time in seconds before checking for a new block after the node is synchronized.",
"privacy": "Public",
"value": 2
},
"sync.blocks_max_stream_size": {
"description": "Max amount of blocks to download in a stream.",
"privacy": "Public",
"value": 1000
},
"sync.recoverable_error_sleep_duration": {
"description": "Waiting time in seconds before restarting synchronization after a recoverable error.",
"privacy": "Public",
"value": 3
},
"sync.state_updates_max_stream_size": {
"description": "Max amount of state updates to download in a stream.",
"privacy": "Public",
"value": 1000
}
}
9 changes: 8 additions & 1 deletion 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 @@ -22,7 +26,7 @@ papyrus_base_layer = { path = "../papyrus_base_layer" }
papyrus_config = { path = "../papyrus_config", version = "0.3.0-dev.1" }
papyrus_common = { path = "../papyrus_common", version = "0.3.0-dev.1" }
papyrus_monitoring_gateway = { path = "../papyrus_monitoring_gateway" }
papyrus_rpc = { path = "../papyrus_rpc" }
papyrus_rpc = { path = "../papyrus_rpc", optional = true }
papyrus_storage = { path = "../papyrus_storage", version = "0.3.0-dev.1" }
papyrus_sync = { path = "../papyrus_sync" }
reqwest = { workspace = true, features = ["json", "blocking"] }
Expand All @@ -38,6 +42,9 @@ tracing.workspace = true
url.workspace = true
validator = { workspace = true, features = ["derive"] }

[target.'cfg(not(feature = "rpc"))'.dependencies]
futures.workspace = true

[dev-dependencies]
metrics-exporter-prometheus.workspace = true
pretty_assertions.workspace = true
Expand Down
33 changes: 33 additions & 0 deletions crates/papyrus_node/src/bin/dump_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use papyrus_config::{ParamPath, SerializedParam};
use papyrus_node::config::{NodeConfig, DEFAULT_CONFIG_PATH};
use starknet_api::core::ChainId;

#[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.
Expand Down Expand Up @@ -39,6 +40,38 @@ lazy_static! {
)];
}

#[cfg(not(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()],
),
(
ser_pointer_target_param(
"starknet_url",
&"https://alpha-mainnet.starknet.io/".to_string(),
"The URL of a centralized Starknet gateway.",
),
vec!["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!["monitoring_gateway.collect_metrics".to_owned()],
)];
}

/// Updates the default config file by:
/// cargo run --bin dump_config -q
#[cfg_attr(coverage_nightly, coverage_attribute)]
Expand Down
12 changes: 9 additions & 3 deletions crates/papyrus_node/src/config/config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ fn load_http_headers() {
assert_eq!(config.central.http_headers.unwrap(), target_http_headers);
}

// insta doesn't work well with features, so we can either test rpc or 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 @@ -95,11 +97,15 @@ 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"));
}
Loading

0 comments on commit ae611b1

Please sign in to comment.