Implement saving BeaconChain on client drop

This commit is contained in:
Paul Hauner
2019-05-27 16:32:46 +10:00
parent 9ed8a4d380
commit faa682a9b5
3 changed files with 34 additions and 9 deletions

View File

@@ -28,7 +28,7 @@ pub struct Client<T: BeaconChainTypes> {
/// Configuration for the lighthouse client.
_config: ClientConfig,
/// The beacon chain for the running client.
_beacon_chain: Arc<BeaconChain<T>>,
beacon_chain: Arc<BeaconChain<T>>,
/// Reference to the network service.
pub network: Arc<NetworkService<T>>,
/// Signal to terminate the RPC server.
@@ -57,7 +57,7 @@ where
let store = Arc::new(store);
// Load a `BeaconChain` from the store, or create a new one if it does not exist.
let beacon_chain = Arc::new(T::initialise_beacon_chain(store));
let beacon_chain = Arc::new(T::initialise_beacon_chain(store, log.clone()));
if beacon_chain.read_slot_clock().is_none() {
panic!("Cannot start client before genesis!")
@@ -151,7 +151,7 @@ where
Ok(Client {
_config: config,
_beacon_chain: beacon_chain,
beacon_chain,
http_exit_signal,
rpc_exit_signal,
slot_timer_exit_signal: Some(slot_timer_exit_signal),
@@ -162,6 +162,14 @@ where
}
}
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();
dbg!("Saved BeaconChain to store");
}
}
fn do_state_catchup<T: BeaconChainTypes>(chain: &Arc<BeaconChain<T>>, log: &slog::Logger) {
if let Some(genesis_height) = chain.slots_since_genesis() {
let result = chain.catchup_state();