Skip to content

Commit

Permalink
node: exec_api_address setting (#2366)
Browse files Browse the repository at this point in the history
  • Loading branch information
battlmonstr authored Sep 20, 2024
1 parent cf1073e commit 2654468
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
3 changes: 3 additions & 0 deletions cmd/common/node_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ void add_node_options(CLI::App& cli, NodeSettings& settings) {

add_option_remote_sentry_addresses(cli, settings.remote_sentry_addresses, /*is_required=*/false);

cli.add_option("--exec.api.addr", settings.exec_api_address)
->description("Execution API GRPC server bind address (IP:port) for connecting an external chain sync client");

// Chain options
add_option_chain(cli, settings.network_id);
}
Expand Down
1 change: 1 addition & 0 deletions silkworm/node/common/node_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct NodeSettings {
uint32_t sync_loop_log_interval_seconds{30}; // Interval for sync loop to emit logs
bool parallel_fork_tracking_enabled{false}; // Whether to track multiple parallel forks at head
bool keep_db_txn_open{true}; // Whether to keep db transaction open between requests
std::optional<std::string> exec_api_address; // Execution API GRPC server bind address (IP:port)

db::etl::CollectorSettings etl() const {
return {data_directory->temp().path(), etl_buffer_size};
Expand Down
28 changes: 20 additions & 8 deletions silkworm/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ class NodeImpl final {
BlockNum last_pre_validated_block() const { return chain_sync_.last_pre_validated_block(); }

private:
Task<void> run_execution_service();
Task<void> run_execution_server();
Task<void> run_backend_kv_grpc_server();
Task<void> embedded_sentry_run_if_needed();
Task<void> run_chain_sync();

Settings& settings_;
ChainConfig& chain_config_;
Expand Down Expand Up @@ -94,9 +96,9 @@ class NodeImpl final {
std::unique_ptr<snapshots::bittorrent::BitTorrentClient> bittorrent_client_;
};

static rpc::ServerSettings make_execution_server_settings() {
static rpc::ServerSettings make_execution_server_settings(std::optional<std::string> exec_api_address) {
return rpc::ServerSettings{
.address_uri = "localhost:9092",
.address_uri = exec_api_address.value_or("localhost:9092"),
.context_pool_settings = {.num_contexts = 1}, // just one execution context
};
}
Expand Down Expand Up @@ -161,7 +163,7 @@ NodeImpl::NodeImpl(
db::RWAccess{chaindata_env_},
},
execution_service_{std::make_shared<execution::api::ActiveDirectService>(execution_engine_, execution_context_)},
execution_server_{make_execution_server_settings(), execution_service_},
execution_server_{make_execution_server_settings(settings_.node_settings.exec_api_address), execution_service_},
execution_direct_client_{execution_service_},
snapshot_sync_{settings.snapshot_settings, chain_config_.chain_id, chaindata_env_, settings_.node_settings.data_directory->temp().path(), execution_engine_.stage_scheduler()},
sentry_{
Expand Down Expand Up @@ -206,18 +208,22 @@ Task<void> NodeImpl::run_tasks() {
co_await wait_for_setup();

co_await (
run_execution_service() &&
run_execution_server() &&
resource_usage_log_.run() &&
chain_sync_.async_run() &&
run_chain_sync() &&
run_backend_kv_grpc_server());
}

Task<void> NodeImpl::run_execution_service() {
// Thread running block execution requires custom stack size because of deep EVM call stacks
return execution_service_->async_run("exec-engine", /* stack_size = */ kExecutionThreadStackSize);
}

Task<void> NodeImpl::run_execution_server() {
// Thread running block execution requires custom stack size because of deep EVM call stacks
if (settings_.execution_server_enabled) {
co_await execution_server_.async_run(/*stack_size=*/kExecutionThreadStackSize);
} else {
co_await execution_service_->async_run("exec-engine", /*stack_size=*/kExecutionThreadStackSize);
if (settings_.node_settings.exec_api_address) {
co_await execution_server_.async_run(/* stack_size = */ kExecutionThreadStackSize);
}
}

Expand All @@ -239,6 +245,12 @@ Task<void> NodeImpl::embedded_sentry_run_if_needed() {
}
}

Task<void> NodeImpl::run_chain_sync() {
if (!settings_.node_settings.exec_api_address) {
co_await chain_sync_.async_run();
}
}

Node::Node(
rpc::ClientContextPool& context_pool,
Settings& settings,
Expand Down
1 change: 0 additions & 1 deletion silkworm/node/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ struct Settings {
sentry::Settings sentry_settings; // Configuration for Sentry client + embedded server
rpc::ServerSettings server_settings; // Configuration for the gRPC server
snapshots::SnapshotSettings snapshot_settings; // Configuration for the database snapshots
bool execution_server_enabled{false};
};

} // namespace silkworm::node

0 comments on commit 2654468

Please sign in to comment.