mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2025-01-01 00:41:20 +00:00
Add standard RPC service
This commit is contained in:
parent
4b57d32b60
commit
d2f12b7c18
@ -8,6 +8,7 @@ edition = "2018"
|
|||||||
beacon_chain = { path = "../beacon_chain" }
|
beacon_chain = { path = "../beacon_chain" }
|
||||||
network = { path = "../network" }
|
network = { path = "../network" }
|
||||||
db = { path = "../db" }
|
db = { path = "../db" }
|
||||||
|
rpc = { path = "../rpc" }
|
||||||
fork_choice = { path = "../../eth2/fork_choice" }
|
fork_choice = { path = "../../eth2/fork_choice" }
|
||||||
types = { path = "../../eth2/types" }
|
types = { path = "../../eth2/types" }
|
||||||
slot_clock = { path = "../../eth2/utils/slot_clock" }
|
slot_clock = { path = "../../eth2/utils/slot_clock" }
|
||||||
|
@ -20,7 +20,7 @@ pub struct ClientConfig {
|
|||||||
pub fork_choice: ForkChoiceAlgorithm,
|
pub fork_choice: ForkChoiceAlgorithm,
|
||||||
pub db_type: DBType,
|
pub db_type: DBType,
|
||||||
pub db_name: PathBuf,
|
pub db_name: PathBuf,
|
||||||
//pub rpc_conf:
|
pub rpc_conf: rpc::RPCConfig,
|
||||||
//pub ipc_conf:
|
//pub ipc_conf:
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,6 +48,7 @@ impl Default for ClientConfig {
|
|||||||
db_type: DBType::Memory,
|
db_type: DBType::Memory,
|
||||||
// default db name for disk-based dbs
|
// default db name for disk-based dbs
|
||||||
db_name: data_dir.join("chain.db"),
|
db_name: data_dir.join("chain.db"),
|
||||||
|
rpc_conf: rpc::RPCConfig::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,9 @@ pub mod client_types;
|
|||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod notifier;
|
pub mod notifier;
|
||||||
|
|
||||||
|
use beacon_chain::BeaconChain;
|
||||||
pub use client_config::ClientConfig;
|
pub use client_config::ClientConfig;
|
||||||
pub use client_types::ClientTypes;
|
pub use client_types::ClientTypes;
|
||||||
|
|
||||||
//use beacon_chain::BeaconChain;
|
|
||||||
use beacon_chain::BeaconChain;
|
|
||||||
use exit_future::Signal;
|
use exit_future::Signal;
|
||||||
use network::Service as NetworkService;
|
use network::Service as NetworkService;
|
||||||
use slog::o;
|
use slog::o;
|
||||||
@ -62,6 +60,9 @@ impl<TClientType: ClientTypes> Client<TClientType> {
|
|||||||
network_logger,
|
network_logger,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
// spawn the RPC server
|
||||||
|
rpc::start_server(&config.rpc_conf, &log);
|
||||||
|
|
||||||
Ok(Client {
|
Ok(Client {
|
||||||
config,
|
config,
|
||||||
beacon_chain,
|
beacon_chain,
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
mod beacon_block;
|
mod beacon_block;
|
||||||
|
pub mod config;
|
||||||
mod validator;
|
mod validator;
|
||||||
|
|
||||||
use self::beacon_block::BeaconBlockServiceInstance;
|
use self::beacon_block::BeaconBlockServiceInstance;
|
||||||
use self::validator::ValidatorServiceInstance;
|
use self::validator::ValidatorServiceInstance;
|
||||||
|
pub use config::Config as RPCConfig;
|
||||||
use grpcio::{Environment, Server, ServerBuilder};
|
use grpcio::{Environment, Server, ServerBuilder};
|
||||||
use protos::services_grpc::{create_beacon_block_service, create_validator_service};
|
use protos::services_grpc::{create_beacon_block_service, create_validator_service};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use slog::{info, Logger};
|
use slog::{info, o};
|
||||||
|
|
||||||
pub fn start_server(log: Logger) -> Server {
|
pub fn start_server(config: &RPCConfig, log: &slog::Logger) -> Server {
|
||||||
let log_clone = log.clone();
|
let log = log.new(o!("Service"=>"RPC"));
|
||||||
let env = Arc::new(Environment::new(1));
|
let env = Arc::new(Environment::new(1));
|
||||||
|
|
||||||
let beacon_block_service = {
|
let beacon_block_service = {
|
||||||
@ -25,12 +27,12 @@ pub fn start_server(log: Logger) -> Server {
|
|||||||
let mut server = ServerBuilder::new(env)
|
let mut server = ServerBuilder::new(env)
|
||||||
.register_service(beacon_block_service)
|
.register_service(beacon_block_service)
|
||||||
.register_service(validator_service)
|
.register_service(validator_service)
|
||||||
.bind("127.0.0.1", 50_051)
|
.bind(config.listen_address.to_string(), config.port)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
server.start();
|
server.start();
|
||||||
for &(ref host, port) in server.bind_addrs() {
|
for &(ref host, port) in server.bind_addrs() {
|
||||||
info!(log_clone, "gRPC listening on {}:{}", host, port);
|
info!(log, "gRPC listening on {}:{}", host, port);
|
||||||
}
|
}
|
||||||
server
|
server
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user