2019-03-01 01:45:01 +00:00
|
|
|
extern crate slog;
|
|
|
|
|
2019-05-25 10:51:15 +00:00
|
|
|
mod beacon_chain_types;
|
2019-06-25 04:51:45 +00:00
|
|
|
mod config;
|
First RESTful HTTP API (#399)
* Added generated code for REST API.
- Created a new crate rest_api, which will adapt the openapi generated code to Lighthouse
- Committed automatically generated code from openapi-generator-cli (via docker). Should hopfully not have to modify this at all, and do all changes in the rest_api crate.
* Removed openapi generated code, because it was the rust client, not the rust server.
* Added the correct rust-server code, automatically generated from openapi.
* Added generated code for REST API.
- Created a new crate rest_api, which will adapt the openapi generated code to Lighthouse
- Committed automatically generated code from openapi-generator-cli (via docker). Should hopfully not have to modify this at all, and do all changes in the rest_api crate.
* Removed openapi generated code, because it was the rust client, not the rust server.
* Added the correct rust-server code, automatically generated from openapi.
* Included REST API in configuratuion.
- Started adding the rest_api into the beacon node's dependencies.
- Set up configuration file for rest_api and integrated into main client config
- Added CLI flags for REST API.
* Futher work on REST API.
- Adding the dependencies to rest_api crate
- Created a skeleton BeaconNodeService, which will handle /node requests.
- Started the rest_api server definition, with the high level request handling logic.
* Added generated code for REST API.
- Created a new crate rest_api, which will adapt the openapi generated code to Lighthouse
- Committed automatically generated code from openapi-generator-cli (via docker). Should hopfully not have to modify this at all, and do all changes in the rest_api crate.
* Removed openapi generated code, because it was the rust client, not the rust server.
* Added the correct rust-server code, automatically generated from openapi.
* Included REST API in configuratuion.
- Started adding the rest_api into the beacon node's dependencies.
- Set up configuration file for rest_api and integrated into main client config
- Added CLI flags for REST API.
* Futher work on REST API.
- Adding the dependencies to rest_api crate
- Created a skeleton BeaconNodeService, which will handle /node requests.
- Started the rest_api server definition, with the high level request handling logic.
* WIP: Restructured REST API to use hyper_router and separate services.
* WIP: Fixing rust for REST API
* WIP: Fixed up many bugs in trying to get router to compile.
* WIP: Got the beacon_node to compile with the REST changes
* Basic API works!
- Changed CLI flags from rest-api* to api*
- Fixed port cli flag
- Tested, works over HTTP
* WIP: Moved things around so that we can get state inside the handlers.
* WIP: Significant API updates.
- Started writing a macro for getting the handler functions.
- Added the BeaconChain into the type map, gives stateful access to the beacon state.
- Created new generic error types (haven't figured out yet), to reduce code duplication.
- Moved common stuff into lib.rs
* WIP: Factored macros, defined API result and error.
- did more logging when creating HTTP responses
- Tried moving stuff into macros, but can't get macros in macros to compile.
- Pulled out a lot of placeholder code.
* Fixed macros so that things compile.
* Cleaned up code.
- Removed unused imports
- Removed comments
- Addressed all compiler warnings.
- Ran cargo fmt.
* Removed auto-generated OpenAPI code.
* Addressed Paul's suggestions.
- Fixed spelling mistake
- Moved the simple macros into functions, since it doesn't make sense for them to be macros.
- Removed redundant code & inclusions.
* Removed redundant validate_request function.
* Included graceful shutdown in Hyper server.
* Fixing the dropped exit_signal, which prevented the API from starting.
* Wrapped the exit signal, to get an API shutdown log line.
2019-07-31 08:29:41 +00:00
|
|
|
|
2019-03-01 01:45:01 +00:00
|
|
|
pub mod error;
|
|
|
|
pub mod notifier;
|
|
|
|
|
2019-03-19 12:47:58 +00:00
|
|
|
use beacon_chain::BeaconChain;
|
2019-03-19 11:53:51 +00:00
|
|
|
use exit_future::Signal;
|
2019-03-26 23:36:20 +00:00
|
|
|
use futures::{future::Future, Stream};
|
2019-03-04 07:31:01 +00:00
|
|
|
use network::Service as NetworkService;
|
2019-05-28 07:30:09 +00:00
|
|
|
use prometheus::Registry;
|
2019-03-26 23:36:20 +00:00
|
|
|
use slog::{error, info, o};
|
|
|
|
use slot_clock::SlotClock;
|
2019-03-01 01:45:01 +00:00
|
|
|
use std::marker::PhantomData;
|
2019-03-04 07:31:01 +00:00
|
|
|
use std::sync::Arc;
|
2019-03-26 23:36:20 +00:00
|
|
|
use std::time::{Duration, Instant};
|
2019-03-01 01:45:01 +00:00
|
|
|
use tokio::runtime::TaskExecutor;
|
2019-03-26 23:36:20 +00:00
|
|
|
use tokio::timer::Interval;
|
2019-03-01 01:45:01 +00:00
|
|
|
|
2019-05-25 10:51:15 +00:00
|
|
|
pub use beacon_chain::BeaconChainTypes;
|
2019-06-08 13:46:04 +00:00
|
|
|
pub use beacon_chain_types::ClientType;
|
2019-06-07 23:44:27 +00:00
|
|
|
pub use beacon_chain_types::InitialiseBeaconChain;
|
2019-06-25 04:51:45 +00:00
|
|
|
pub use config::Config as ClientConfig;
|
2019-06-08 17:17:03 +00:00
|
|
|
pub use eth2_config::Eth2Config;
|
2019-05-09 03:35:00 +00:00
|
|
|
|
2019-03-04 05:39:37 +00:00
|
|
|
/// Main beacon node client service. This provides the connection and initialisation of the clients
|
|
|
|
/// sub-services in multiple threads.
|
2019-05-25 10:51:15 +00:00
|
|
|
pub struct Client<T: BeaconChainTypes> {
|
2019-03-18 06:38:23 +00:00
|
|
|
/// Configuration for the lighthouse client.
|
2019-06-08 17:17:03 +00:00
|
|
|
_client_config: ClientConfig,
|
2019-03-18 06:38:23 +00:00
|
|
|
/// The beacon chain for the running client.
|
2019-05-27 06:32:46 +00:00
|
|
|
beacon_chain: Arc<BeaconChain<T>>,
|
2019-03-18 06:38:23 +00:00
|
|
|
/// Reference to the network service.
|
2019-05-25 10:51:15 +00:00
|
|
|
pub network: Arc<NetworkService<T>>,
|
2019-03-22 05:46:52 +00:00
|
|
|
/// Signal to terminate the RPC server.
|
|
|
|
pub rpc_exit_signal: Option<Signal>,
|
2019-05-25 07:25:21 +00:00
|
|
|
/// Signal to terminate the HTTP server.
|
|
|
|
pub http_exit_signal: Option<Signal>,
|
2019-03-26 23:36:20 +00:00
|
|
|
/// Signal to terminate the slot timer.
|
|
|
|
pub slot_timer_exit_signal: Option<Signal>,
|
First RESTful HTTP API (#399)
* Added generated code for REST API.
- Created a new crate rest_api, which will adapt the openapi generated code to Lighthouse
- Committed automatically generated code from openapi-generator-cli (via docker). Should hopfully not have to modify this at all, and do all changes in the rest_api crate.
* Removed openapi generated code, because it was the rust client, not the rust server.
* Added the correct rust-server code, automatically generated from openapi.
* Added generated code for REST API.
- Created a new crate rest_api, which will adapt the openapi generated code to Lighthouse
- Committed automatically generated code from openapi-generator-cli (via docker). Should hopfully not have to modify this at all, and do all changes in the rest_api crate.
* Removed openapi generated code, because it was the rust client, not the rust server.
* Added the correct rust-server code, automatically generated from openapi.
* Included REST API in configuratuion.
- Started adding the rest_api into the beacon node's dependencies.
- Set up configuration file for rest_api and integrated into main client config
- Added CLI flags for REST API.
* Futher work on REST API.
- Adding the dependencies to rest_api crate
- Created a skeleton BeaconNodeService, which will handle /node requests.
- Started the rest_api server definition, with the high level request handling logic.
* Added generated code for REST API.
- Created a new crate rest_api, which will adapt the openapi generated code to Lighthouse
- Committed automatically generated code from openapi-generator-cli (via docker). Should hopfully not have to modify this at all, and do all changes in the rest_api crate.
* Removed openapi generated code, because it was the rust client, not the rust server.
* Added the correct rust-server code, automatically generated from openapi.
* Included REST API in configuratuion.
- Started adding the rest_api into the beacon node's dependencies.
- Set up configuration file for rest_api and integrated into main client config
- Added CLI flags for REST API.
* Futher work on REST API.
- Adding the dependencies to rest_api crate
- Created a skeleton BeaconNodeService, which will handle /node requests.
- Started the rest_api server definition, with the high level request handling logic.
* WIP: Restructured REST API to use hyper_router and separate services.
* WIP: Fixing rust for REST API
* WIP: Fixed up many bugs in trying to get router to compile.
* WIP: Got the beacon_node to compile with the REST changes
* Basic API works!
- Changed CLI flags from rest-api* to api*
- Fixed port cli flag
- Tested, works over HTTP
* WIP: Moved things around so that we can get state inside the handlers.
* WIP: Significant API updates.
- Started writing a macro for getting the handler functions.
- Added the BeaconChain into the type map, gives stateful access to the beacon state.
- Created new generic error types (haven't figured out yet), to reduce code duplication.
- Moved common stuff into lib.rs
* WIP: Factored macros, defined API result and error.
- did more logging when creating HTTP responses
- Tried moving stuff into macros, but can't get macros in macros to compile.
- Pulled out a lot of placeholder code.
* Fixed macros so that things compile.
* Cleaned up code.
- Removed unused imports
- Removed comments
- Addressed all compiler warnings.
- Ran cargo fmt.
* Removed auto-generated OpenAPI code.
* Addressed Paul's suggestions.
- Fixed spelling mistake
- Moved the simple macros into functions, since it doesn't make sense for them to be macros.
- Removed redundant code & inclusions.
* Removed redundant validate_request function.
* Included graceful shutdown in Hyper server.
* Fixing the dropped exit_signal, which prevented the API from starting.
* Wrapped the exit signal, to get an API shutdown log line.
2019-07-31 08:29:41 +00:00
|
|
|
/// Signal to terminate the API
|
|
|
|
pub api_exit_signal: Option<Signal>,
|
2019-03-18 06:38:23 +00:00
|
|
|
/// The clients logger.
|
2019-03-01 01:45:01 +00:00
|
|
|
log: slog::Logger,
|
2019-03-18 06:38:23 +00:00
|
|
|
/// Marker to pin the beacon chain generics.
|
|
|
|
phantom: PhantomData<T>,
|
2019-03-01 01:45:01 +00:00
|
|
|
}
|
|
|
|
|
2019-05-25 10:51:15 +00:00
|
|
|
impl<T> Client<T>
|
|
|
|
where
|
|
|
|
T: BeaconChainTypes + InitialiseBeaconChain<T> + Clone + 'static,
|
|
|
|
{
|
2019-03-18 06:38:23 +00:00
|
|
|
/// Generate an instance of the client. Spawn and link all internal sub-processes.
|
2019-03-01 01:45:01 +00:00
|
|
|
pub fn new(
|
2019-06-08 17:17:03 +00:00
|
|
|
client_config: ClientConfig,
|
|
|
|
eth2_config: Eth2Config,
|
2019-05-27 06:13:32 +00:00
|
|
|
store: T::Store,
|
2019-03-01 01:45:01 +00:00
|
|
|
log: slog::Logger,
|
2019-03-17 10:49:56 +00:00
|
|
|
executor: &TaskExecutor,
|
2019-03-01 01:45:01 +00:00
|
|
|
) -> error::Result<Self> {
|
2019-05-28 07:30:09 +00:00
|
|
|
let metrics_registry = Registry::new();
|
2019-05-27 06:13:32 +00:00
|
|
|
let store = Arc::new(store);
|
2019-06-08 17:17:03 +00:00
|
|
|
let seconds_per_slot = eth2_config.spec.seconds_per_slot;
|
2019-05-27 06:13:32 +00:00
|
|
|
|
|
|
|
// Load a `BeaconChain` from the store, or create a new one if it does not exist.
|
2019-06-08 11:57:25 +00:00
|
|
|
let beacon_chain = Arc::new(T::initialise_beacon_chain(
|
|
|
|
store,
|
2019-08-06 03:29:27 +00:00
|
|
|
&client_config,
|
2019-06-08 17:17:03 +00:00
|
|
|
eth2_config.spec.clone(),
|
2019-06-08 11:57:25 +00:00
|
|
|
log.clone(),
|
2019-08-06 03:29:27 +00:00
|
|
|
)?);
|
2019-05-28 07:30:09 +00:00
|
|
|
// Registry all beacon chain metrics with the global registry.
|
|
|
|
beacon_chain
|
|
|
|
.metrics
|
|
|
|
.register(&metrics_registry)
|
|
|
|
.expect("Failed to registry metrics");
|
2019-03-04 05:39:37 +00:00
|
|
|
|
2019-03-27 00:25:15 +00:00
|
|
|
if beacon_chain.read_slot_clock().is_none() {
|
|
|
|
panic!("Cannot start client before genesis!")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Block starting the client until we have caught the state up to the current slot.
|
|
|
|
//
|
|
|
|
// If we don't block here we create an initial scenario where we're unable to process any
|
|
|
|
// blocks and we're basically useless.
|
2019-03-26 23:36:20 +00:00
|
|
|
{
|
2019-05-30 08:38:41 +00:00
|
|
|
let state_slot = beacon_chain.head().beacon_state.slot;
|
2019-03-27 00:25:15 +00:00
|
|
|
let wall_clock_slot = beacon_chain.read_slot_clock().unwrap();
|
|
|
|
let slots_since_genesis = beacon_chain.slots_since_genesis().unwrap();
|
2019-03-26 23:36:20 +00:00
|
|
|
info!(
|
|
|
|
log,
|
2019-08-06 03:29:27 +00:00
|
|
|
"BeaconState cache init";
|
2019-03-27 00:25:15 +00:00
|
|
|
"state_slot" => state_slot,
|
|
|
|
"wall_clock_slot" => wall_clock_slot,
|
|
|
|
"slots_since_genesis" => slots_since_genesis,
|
|
|
|
"catchup_distance" => wall_clock_slot - state_slot,
|
2019-03-26 23:36:20 +00:00
|
|
|
);
|
|
|
|
}
|
2019-03-27 00:25:15 +00:00
|
|
|
do_state_catchup(&beacon_chain, &log);
|
2019-03-26 23:36:20 +00:00
|
|
|
|
2019-03-04 07:31:01 +00:00
|
|
|
// Start the network service, libp2p and syncing threads
|
2019-03-04 05:39:37 +00:00
|
|
|
// TODO: Add beacon_chain reference to network parameters
|
2019-06-08 17:17:03 +00:00
|
|
|
let network_config = &client_config.network;
|
2019-03-04 07:31:01 +00:00
|
|
|
let network_logger = log.new(o!("Service" => "Network"));
|
2019-03-25 11:00:11 +00:00
|
|
|
let (network, network_send) = NetworkService::new(
|
2019-03-18 05:16:54 +00:00
|
|
|
beacon_chain.clone(),
|
|
|
|
network_config,
|
|
|
|
executor,
|
|
|
|
network_logger,
|
|
|
|
)?;
|
2019-03-04 05:39:37 +00:00
|
|
|
|
2019-03-19 12:47:58 +00:00
|
|
|
// spawn the RPC server
|
2019-06-08 17:17:03 +00:00
|
|
|
let rpc_exit_signal = if client_config.rpc.enabled {
|
2019-04-03 05:23:09 +00:00
|
|
|
Some(rpc::start_server(
|
2019-06-08 17:17:03 +00:00
|
|
|
&client_config.rpc,
|
2019-03-22 05:46:52 +00:00
|
|
|
executor,
|
2019-05-25 04:31:13 +00:00
|
|
|
network_send.clone(),
|
2019-03-22 05:46:52 +00:00
|
|
|
beacon_chain.clone(),
|
|
|
|
&log,
|
2019-04-03 05:23:09 +00:00
|
|
|
))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
2019-03-19 12:47:58 +00:00
|
|
|
|
2019-05-25 04:31:13 +00:00
|
|
|
// Start the `http_server` service.
|
|
|
|
//
|
|
|
|
// Note: presently we are ignoring the config and _always_ starting a HTTP server.
|
2019-06-08 17:17:03 +00:00
|
|
|
let http_exit_signal = if client_config.http.enabled {
|
2019-05-28 03:50:51 +00:00
|
|
|
Some(http_server::start_service(
|
2019-06-08 17:17:03 +00:00
|
|
|
&client_config.http,
|
2019-05-28 03:50:51 +00:00
|
|
|
executor,
|
|
|
|
network_send,
|
|
|
|
beacon_chain.clone(),
|
2019-06-08 17:17:03 +00:00
|
|
|
client_config.db_path().expect("unable to read datadir"),
|
2019-05-28 07:30:09 +00:00
|
|
|
metrics_registry,
|
2019-05-28 03:50:51 +00:00
|
|
|
&log,
|
|
|
|
))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
2019-05-25 04:31:13 +00:00
|
|
|
|
First RESTful HTTP API (#399)
* Added generated code for REST API.
- Created a new crate rest_api, which will adapt the openapi generated code to Lighthouse
- Committed automatically generated code from openapi-generator-cli (via docker). Should hopfully not have to modify this at all, and do all changes in the rest_api crate.
* Removed openapi generated code, because it was the rust client, not the rust server.
* Added the correct rust-server code, automatically generated from openapi.
* Added generated code for REST API.
- Created a new crate rest_api, which will adapt the openapi generated code to Lighthouse
- Committed automatically generated code from openapi-generator-cli (via docker). Should hopfully not have to modify this at all, and do all changes in the rest_api crate.
* Removed openapi generated code, because it was the rust client, not the rust server.
* Added the correct rust-server code, automatically generated from openapi.
* Included REST API in configuratuion.
- Started adding the rest_api into the beacon node's dependencies.
- Set up configuration file for rest_api and integrated into main client config
- Added CLI flags for REST API.
* Futher work on REST API.
- Adding the dependencies to rest_api crate
- Created a skeleton BeaconNodeService, which will handle /node requests.
- Started the rest_api server definition, with the high level request handling logic.
* Added generated code for REST API.
- Created a new crate rest_api, which will adapt the openapi generated code to Lighthouse
- Committed automatically generated code from openapi-generator-cli (via docker). Should hopfully not have to modify this at all, and do all changes in the rest_api crate.
* Removed openapi generated code, because it was the rust client, not the rust server.
* Added the correct rust-server code, automatically generated from openapi.
* Included REST API in configuratuion.
- Started adding the rest_api into the beacon node's dependencies.
- Set up configuration file for rest_api and integrated into main client config
- Added CLI flags for REST API.
* Futher work on REST API.
- Adding the dependencies to rest_api crate
- Created a skeleton BeaconNodeService, which will handle /node requests.
- Started the rest_api server definition, with the high level request handling logic.
* WIP: Restructured REST API to use hyper_router and separate services.
* WIP: Fixing rust for REST API
* WIP: Fixed up many bugs in trying to get router to compile.
* WIP: Got the beacon_node to compile with the REST changes
* Basic API works!
- Changed CLI flags from rest-api* to api*
- Fixed port cli flag
- Tested, works over HTTP
* WIP: Moved things around so that we can get state inside the handlers.
* WIP: Significant API updates.
- Started writing a macro for getting the handler functions.
- Added the BeaconChain into the type map, gives stateful access to the beacon state.
- Created new generic error types (haven't figured out yet), to reduce code duplication.
- Moved common stuff into lib.rs
* WIP: Factored macros, defined API result and error.
- did more logging when creating HTTP responses
- Tried moving stuff into macros, but can't get macros in macros to compile.
- Pulled out a lot of placeholder code.
* Fixed macros so that things compile.
* Cleaned up code.
- Removed unused imports
- Removed comments
- Addressed all compiler warnings.
- Ran cargo fmt.
* Removed auto-generated OpenAPI code.
* Addressed Paul's suggestions.
- Fixed spelling mistake
- Moved the simple macros into functions, since it doesn't make sense for them to be macros.
- Removed redundant code & inclusions.
* Removed redundant validate_request function.
* Included graceful shutdown in Hyper server.
* Fixing the dropped exit_signal, which prevented the API from starting.
* Wrapped the exit signal, to get an API shutdown log line.
2019-07-31 08:29:41 +00:00
|
|
|
// Start the `rest_api` service
|
|
|
|
let api_exit_signal = if client_config.rest_api.enabled {
|
|
|
|
match rest_api::start_server(
|
|
|
|
&client_config.rest_api,
|
|
|
|
executor,
|
|
|
|
beacon_chain.clone(),
|
|
|
|
&log,
|
|
|
|
) {
|
|
|
|
Ok(s) => Some(s),
|
|
|
|
Err(e) => {
|
|
|
|
error!(log, "API service failed to start."; "error" => format!("{:?}",e));
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2019-03-26 23:36:20 +00:00
|
|
|
let (slot_timer_exit_signal, exit) = exit_future::signal();
|
|
|
|
if let Ok(Some(duration_to_next_slot)) = beacon_chain.slot_clock.duration_to_next_slot() {
|
|
|
|
// set up the validator work interval - start at next slot and proceed every slot
|
|
|
|
let interval = {
|
|
|
|
// Set the interval to start at the next slot, and every slot after
|
2019-06-08 11:57:25 +00:00
|
|
|
let slot_duration = Duration::from_secs(seconds_per_slot);
|
2019-03-26 23:36:20 +00:00
|
|
|
//TODO: Handle checked add correctly
|
|
|
|
Interval::new(Instant::now() + duration_to_next_slot, slot_duration)
|
|
|
|
};
|
|
|
|
|
|
|
|
let chain = beacon_chain.clone();
|
|
|
|
let log = log.new(o!("Service" => "SlotTimer"));
|
|
|
|
executor.spawn(
|
|
|
|
exit.until(
|
|
|
|
interval
|
|
|
|
.for_each(move |_| {
|
2019-03-27 00:25:15 +00:00
|
|
|
do_state_catchup(&chain, &log);
|
2019-03-26 23:36:20 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
.map_err(|_| ()),
|
|
|
|
)
|
|
|
|
.map(|_| ()),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-03-01 01:45:01 +00:00
|
|
|
Ok(Client {
|
2019-06-08 17:17:03 +00:00
|
|
|
_client_config: client_config,
|
2019-05-27 06:32:46 +00:00
|
|
|
beacon_chain,
|
2019-05-25 07:25:21 +00:00
|
|
|
http_exit_signal,
|
2019-03-22 05:46:52 +00:00
|
|
|
rpc_exit_signal,
|
2019-03-26 23:36:20 +00:00
|
|
|
slot_timer_exit_signal: Some(slot_timer_exit_signal),
|
First RESTful HTTP API (#399)
* Added generated code for REST API.
- Created a new crate rest_api, which will adapt the openapi generated code to Lighthouse
- Committed automatically generated code from openapi-generator-cli (via docker). Should hopfully not have to modify this at all, and do all changes in the rest_api crate.
* Removed openapi generated code, because it was the rust client, not the rust server.
* Added the correct rust-server code, automatically generated from openapi.
* Added generated code for REST API.
- Created a new crate rest_api, which will adapt the openapi generated code to Lighthouse
- Committed automatically generated code from openapi-generator-cli (via docker). Should hopfully not have to modify this at all, and do all changes in the rest_api crate.
* Removed openapi generated code, because it was the rust client, not the rust server.
* Added the correct rust-server code, automatically generated from openapi.
* Included REST API in configuratuion.
- Started adding the rest_api into the beacon node's dependencies.
- Set up configuration file for rest_api and integrated into main client config
- Added CLI flags for REST API.
* Futher work on REST API.
- Adding the dependencies to rest_api crate
- Created a skeleton BeaconNodeService, which will handle /node requests.
- Started the rest_api server definition, with the high level request handling logic.
* Added generated code for REST API.
- Created a new crate rest_api, which will adapt the openapi generated code to Lighthouse
- Committed automatically generated code from openapi-generator-cli (via docker). Should hopfully not have to modify this at all, and do all changes in the rest_api crate.
* Removed openapi generated code, because it was the rust client, not the rust server.
* Added the correct rust-server code, automatically generated from openapi.
* Included REST API in configuratuion.
- Started adding the rest_api into the beacon node's dependencies.
- Set up configuration file for rest_api and integrated into main client config
- Added CLI flags for REST API.
* Futher work on REST API.
- Adding the dependencies to rest_api crate
- Created a skeleton BeaconNodeService, which will handle /node requests.
- Started the rest_api server definition, with the high level request handling logic.
* WIP: Restructured REST API to use hyper_router and separate services.
* WIP: Fixing rust for REST API
* WIP: Fixed up many bugs in trying to get router to compile.
* WIP: Got the beacon_node to compile with the REST changes
* Basic API works!
- Changed CLI flags from rest-api* to api*
- Fixed port cli flag
- Tested, works over HTTP
* WIP: Moved things around so that we can get state inside the handlers.
* WIP: Significant API updates.
- Started writing a macro for getting the handler functions.
- Added the BeaconChain into the type map, gives stateful access to the beacon state.
- Created new generic error types (haven't figured out yet), to reduce code duplication.
- Moved common stuff into lib.rs
* WIP: Factored macros, defined API result and error.
- did more logging when creating HTTP responses
- Tried moving stuff into macros, but can't get macros in macros to compile.
- Pulled out a lot of placeholder code.
* Fixed macros so that things compile.
* Cleaned up code.
- Removed unused imports
- Removed comments
- Addressed all compiler warnings.
- Ran cargo fmt.
* Removed auto-generated OpenAPI code.
* Addressed Paul's suggestions.
- Fixed spelling mistake
- Moved the simple macros into functions, since it doesn't make sense for them to be macros.
- Removed redundant code & inclusions.
* Removed redundant validate_request function.
* Included graceful shutdown in Hyper server.
* Fixing the dropped exit_signal, which prevented the API from starting.
* Wrapped the exit signal, to get an API shutdown log line.
2019-07-31 08:29:41 +00:00
|
|
|
api_exit_signal,
|
2019-03-01 01:45:01 +00:00
|
|
|
log,
|
2019-03-19 12:20:39 +00:00
|
|
|
network,
|
2019-03-01 01:45:01 +00:00
|
|
|
phantom: PhantomData,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2019-03-27 00:25:15 +00:00
|
|
|
|
2019-05-27 06:32:46 +00:00
|
|
|
impl<T: BeaconChainTypes> Drop for Client<T> {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
// Save the beacon chain to it's store before dropping.
|
|
|
|
let _result = self.beacon_chain.persist();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-25 10:51:15 +00:00
|
|
|
fn do_state_catchup<T: BeaconChainTypes>(chain: &Arc<BeaconChain<T>>, log: &slog::Logger) {
|
2019-07-29 03:45:45 +00:00
|
|
|
// Only attempt to `catchup_state` if we can read the slot clock.
|
|
|
|
if let Some(current_slot) = chain.read_slot_clock() {
|
|
|
|
let state_catchup_result = chain.catchup_state();
|
|
|
|
|
|
|
|
let best_slot = chain.head().beacon_block.slot;
|
|
|
|
let latest_block_root = chain.head().beacon_block_root;
|
2019-03-27 00:25:15 +00:00
|
|
|
|
|
|
|
let common = o!(
|
2019-07-29 03:45:45 +00:00
|
|
|
"skip_slots" => current_slot.saturating_sub(best_slot),
|
|
|
|
"best_block_root" => format!("{}", latest_block_root),
|
|
|
|
"best_block_slot" => best_slot,
|
|
|
|
"slot" => current_slot,
|
2019-03-27 00:25:15 +00:00
|
|
|
);
|
|
|
|
|
2019-07-29 03:45:45 +00:00
|
|
|
if let Err(e) = state_catchup_result {
|
|
|
|
error!(
|
2019-03-27 00:25:15 +00:00
|
|
|
log,
|
2019-07-29 03:45:45 +00:00
|
|
|
"State catchup failed";
|
|
|
|
"error" => format!("{:?}", e),
|
2019-03-27 00:25:15 +00:00
|
|
|
common
|
2019-07-29 03:45:45 +00:00
|
|
|
)
|
|
|
|
} else {
|
|
|
|
info!(
|
2019-03-27 00:25:15 +00:00
|
|
|
log,
|
2019-07-29 03:45:45 +00:00
|
|
|
"Slot start";
|
2019-03-27 00:25:15 +00:00
|
|
|
common
|
2019-07-29 03:45:45 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error!(
|
|
|
|
log,
|
|
|
|
"Beacon chain running whilst slot clock is unavailable."
|
|
|
|
);
|
|
|
|
};
|
2019-03-27 00:25:15 +00:00
|
|
|
}
|