Skip to content

Commit

Permalink
Merge pull request #1564 from eqlabs/sm/feature/rpc-sync-flags
Browse files Browse the repository at this point in the history
feat(config): add `{rpc, sync}.enable` configuration properties
  • Loading branch information
sergey-melnychuk authored Nov 24, 2023
2 parents 4569b58 + 28f4953 commit 531877e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Support for RPC v0.6.0-rc1 via the `/rpc/v0_6` endpoint. Note that this does not include the `/rpc/v0.6` endpoint as the underscore is now the standard across node implementations.
- Configuration options to selectively enable/disable parts of the node. This can be useful to run tests or benchmarks with isolated components e.g. test RPC methods without the sync process updating the database.
- `rpc.enable` configuration option to enable/disable the RPC server. Defaults to enabled.
- `sync.enable` configuration option to enable/disable the sync process. Defaults to enabled.

### Changed

Expand Down
20 changes: 20 additions & 0 deletions crates/pathfinder/src/bin/pathfinder/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,22 @@ This should only be enabled for debugging purposes as it adds substantial proces
default_value = "1"
)]
rpc_batch_concurrency_limit: NonZeroUsize,

#[arg(
long = "sync.enable",
long_help = "Enable syncing the chain",
env = "PATHFINDER_SYNC_ENABLED",
default_value = "true"
)]
is_sync_enabled: bool,

#[arg(
long = "rcp.enable",
long_help = "Enable serving RPC API",
env = "PATHFINDER_RPC_ENABLED",
default_value = "true"
)]
is_rpc_enabled: bool,
}

#[derive(clap::ValueEnum, Debug, Clone, Copy, PartialEq)]
Expand Down Expand Up @@ -433,6 +449,8 @@ pub struct Config {
pub debug: DebugConfig,
pub verify_tree_hashes: bool,
pub rpc_batch_concurrency_limit: NonZeroUsize,
pub is_sync_enabled: bool,
pub is_rpc_enabled: bool,
}

pub struct Ethereum {
Expand Down Expand Up @@ -606,6 +624,8 @@ impl Config {
debug: DebugConfig::parse(cli.debug),
verify_tree_hashes: cli.verify_tree_node_data,
rpc_batch_concurrency_limit: cli.rpc_batch_concurrency_limit,
is_sync_enabled: cli.is_sync_enabled,
is_rpc_enabled: cli.is_rpc_enabled,
}
}
}
Expand Down
22 changes: 15 additions & 7 deletions crates/pathfinder/src/bin/pathfinder/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,22 @@ Hint: This is usually caused by exceeding the file descriptor limit of your syst
verify_tree_hashes: config.verify_tree_hashes,
};

let sync_handle = tokio::spawn(state::sync(sync_context, state::l1::sync, state::l2::sync));

let (rpc_handle, local_addr) = rpc_server
.with_max_connections(config.max_rpc_connections.get())
.spawn()
.context("Starting the RPC server")?;
let sync_handle = if config.is_sync_enabled {
tokio::spawn(state::sync(sync_context, state::l1::sync, state::l2::sync))
} else {
tokio::spawn(std::future::pending())
};

info!("📡 HTTP-RPC server started on: {}", local_addr);
let rpc_handle = if config.is_rpc_enabled {
let (rpc_handle, local_addr) = rpc_server
.with_max_connections(config.max_rpc_connections.get())
.spawn()
.context("Starting the RPC server")?;
info!("📡 HTTP-RPC server started on: {}", local_addr);
rpc_handle
} else {
tokio::spawn(std::future::pending())
};

let update_handle = tokio::spawn(update::poll_github_for_releases());

Expand Down

0 comments on commit 531877e

Please sign in to comment.