diff --git a/beacon_node/client/Cargo.toml b/beacon_node/client/Cargo.toml index 11453e4b8..12c1b5c80 100644 --- a/beacon_node/client/Cargo.toml +++ b/beacon_node/client/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" beacon_chain = { path = "../beacon_chain" } network = { path = "../network" } db = { path = "../db" } +rpc = { path = "../rpc" } fork_choice = { path = "../../eth2/fork_choice" } types = { path = "../../eth2/types" } slot_clock = { path = "../../eth2/utils/slot_clock" } diff --git a/beacon_node/client/src/client_config.rs b/beacon_node/client/src/client_config.rs index 4fe390cb1..570bd30e4 100644 --- a/beacon_node/client/src/client_config.rs +++ b/beacon_node/client/src/client_config.rs @@ -20,7 +20,7 @@ pub struct ClientConfig { pub fork_choice: ForkChoiceAlgorithm, pub db_type: DBType, pub db_name: PathBuf, - //pub rpc_conf: + pub rpc_conf: rpc::RPCConfig, //pub ipc_conf: } @@ -48,6 +48,7 @@ impl Default for ClientConfig { db_type: DBType::Memory, // default db name for disk-based dbs db_name: data_dir.join("chain.db"), + rpc_conf: rpc::RPCConfig::default(), } } } diff --git a/beacon_node/client/src/lib.rs b/beacon_node/client/src/lib.rs index beba6f4de..e6d08ac54 100644 --- a/beacon_node/client/src/lib.rs +++ b/beacon_node/client/src/lib.rs @@ -6,11 +6,9 @@ pub mod client_types; pub mod error; pub mod notifier; +use beacon_chain::BeaconChain; pub use client_config::ClientConfig; pub use client_types::ClientTypes; - -//use beacon_chain::BeaconChain; -use beacon_chain::BeaconChain; use exit_future::Signal; use network::Service as NetworkService; use slog::o; @@ -62,6 +60,9 @@ impl Client { network_logger, )?; + // spawn the RPC server + rpc::start_server(&config.rpc_conf, &log); + Ok(Client { config, beacon_chain, diff --git a/beacon_node/rpc/src/lib.rs b/beacon_node/rpc/src/lib.rs index 6a18a4aa8..7f776d7d8 100644 --- a/beacon_node/rpc/src/lib.rs +++ b/beacon_node/rpc/src/lib.rs @@ -1,16 +1,18 @@ mod beacon_block; +pub mod config; mod validator; use self::beacon_block::BeaconBlockServiceInstance; use self::validator::ValidatorServiceInstance; +pub use config::Config as RPCConfig; use grpcio::{Environment, Server, ServerBuilder}; use protos::services_grpc::{create_beacon_block_service, create_validator_service}; use std::sync::Arc; -use slog::{info, Logger}; +use slog::{info, o}; -pub fn start_server(log: Logger) -> Server { - let log_clone = log.clone(); +pub fn start_server(config: &RPCConfig, log: &slog::Logger) -> Server { + let log = log.new(o!("Service"=>"RPC")); let env = Arc::new(Environment::new(1)); let beacon_block_service = { @@ -25,12 +27,12 @@ pub fn start_server(log: Logger) -> Server { let mut server = ServerBuilder::new(env) .register_service(beacon_block_service) .register_service(validator_service) - .bind("127.0.0.1", 50_051) + .bind(config.listen_address.to_string(), config.port) .build() .unwrap(); server.start(); for &(ref host, port) in server.bind_addrs() { - info!(log_clone, "gRPC listening on {}:{}", host, port); + info!(log, "gRPC listening on {}:{}", host, port); } server }