From 853344af8a6127a70df2207402a317fc7282b8cd Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Thu, 22 Aug 2019 16:34:21 +1000 Subject: [PATCH] Make BeaconChainTypes Send + Sync + 'static --- beacon_node/beacon_chain/src/beacon_chain.rs | 2 +- beacon_node/beacon_chain/src/test_utils.rs | 8 ++++---- beacon_node/client/src/beacon_chain_types.rs | 6 +++++- beacon_node/client/src/lib.rs | 2 +- beacon_node/client/src/notifier.rs | 6 +----- beacon_node/rest_api/src/lib.rs | 2 +- beacon_node/rest_api/src/network.rs | 14 +++++--------- beacon_node/src/run.rs | 2 +- 8 files changed, 19 insertions(+), 23 deletions(-) diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index bd7f37fba..5feefd841 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -77,7 +77,7 @@ pub enum AttestationProcessingOutcome { Invalid(AttestationValidationError), } -pub trait BeaconChainTypes { +pub trait BeaconChainTypes: Send + Sync + 'static { type Store: store::Store; type SlotClock: slot_clock::SlotClock; type LmdGhost: LmdGhost; diff --git a/beacon_node/beacon_chain/src/test_utils.rs b/beacon_node/beacon_chain/src/test_utils.rs index 298c637db..bd51f8620 100644 --- a/beacon_node/beacon_chain/src/test_utils.rs +++ b/beacon_node/beacon_chain/src/test_utils.rs @@ -54,8 +54,8 @@ where impl BeaconChainTypes for CommonTypes where - L: LmdGhost, - E: EthSpec, + L: LmdGhost + 'static, + E: EthSpec + 'static, { type Store = MemoryStore; type SlotClock = TestingSlotClock; @@ -69,8 +69,8 @@ where /// Used for testing. pub struct BeaconChainHarness where - L: LmdGhost, - E: EthSpec, + L: LmdGhost + 'static, + E: EthSpec + 'static, { pub chain: BeaconChain>, pub keypairs: Vec, diff --git a/beacon_node/client/src/beacon_chain_types.rs b/beacon_node/client/src/beacon_chain_types.rs index f2f95226a..adea8c7b5 100644 --- a/beacon_node/client/src/beacon_chain_types.rs +++ b/beacon_node/client/src/beacon_chain_types.rs @@ -36,7 +36,11 @@ pub struct ClientType { _phantom_u: PhantomData, } -impl BeaconChainTypes for ClientType { +impl BeaconChainTypes for ClientType +where + S: Store + 'static, + E: EthSpec + 'static + Clone, +{ type Store = S; type SlotClock = SystemTimeSlotClock; type LmdGhost = ThreadSafeReducedTree; diff --git a/beacon_node/client/src/lib.rs b/beacon_node/client/src/lib.rs index 798aedec9..6405e05e7 100644 --- a/beacon_node/client/src/lib.rs +++ b/beacon_node/client/src/lib.rs @@ -49,7 +49,7 @@ pub struct Client { impl Client where - T: BeaconChainTypes + InitialiseBeaconChain + Clone + Send + Sync + 'static, + T: BeaconChainTypes + InitialiseBeaconChain + Clone, { /// Generate an instance of the client. Spawn and link all internal sub-processes. pub fn new( diff --git a/beacon_node/client/src/notifier.rs b/beacon_node/client/src/notifier.rs index 1c7cf3867..78e50ac79 100644 --- a/beacon_node/client/src/notifier.rs +++ b/beacon_node/client/src/notifier.rs @@ -17,11 +17,7 @@ pub const WARN_PEER_COUNT: usize = 1; /// durations. /// /// Presently unused, but remains for future use. -pub fn run( - client: &Client, - executor: TaskExecutor, - exit: Exit, -) { +pub fn run(client: &Client, executor: TaskExecutor, exit: Exit) { // notification heartbeat let interval = Interval::new( Instant::now(), diff --git a/beacon_node/rest_api/src/lib.rs b/beacon_node/rest_api/src/lib.rs index 839aa7abc..354b23403 100644 --- a/beacon_node/rest_api/src/lib.rs +++ b/beacon_node/rest_api/src/lib.rs @@ -71,7 +71,7 @@ impl From for ApiError { } } -pub fn start_server( +pub fn start_server( config: &ApiConfig, executor: &TaskExecutor, beacon_chain: Arc>, diff --git a/beacon_node/rest_api/src/network.rs b/beacon_node/rest_api/src/network.rs index 154cd142d..daded9d3d 100644 --- a/beacon_node/rest_api/src/network.rs +++ b/beacon_node/rest_api/src/network.rs @@ -7,9 +7,7 @@ use std::sync::Arc; /// HTTP handle to return the list of libp2p multiaddr the client is listening on. /// /// Returns a list of `Multiaddr`, serialized according to their `serde` impl. -pub fn get_listen_addresses( - req: Request, -) -> ApiResult { +pub fn get_listen_addresses(req: Request) -> ApiResult { let network = req .extensions() .get::>>() @@ -26,7 +24,7 @@ pub fn get_listen_addresses( /// HTTP handle to return the Discv5 ENR from the client's libp2p service. /// /// ENR is encoded as base64 string. -pub fn get_enr(req: Request) -> ApiResult { +pub fn get_enr(req: Request) -> ApiResult { let network = req .extensions() .get::>>() @@ -43,7 +41,7 @@ pub fn get_enr(req: Request) /// HTTP handle to return the `PeerId` from the client's libp2p service. /// /// PeerId is encoded as base58 string. -pub fn get_peer_id(req: Request) -> ApiResult { +pub fn get_peer_id(req: Request) -> ApiResult { let network = req .extensions() .get::>>() @@ -58,9 +56,7 @@ pub fn get_peer_id(req: Request( - req: Request, -) -> ApiResult { +pub fn get_peer_count(req: Request) -> ApiResult { let network = req .extensions() .get::>>() @@ -77,7 +73,7 @@ pub fn get_peer_count( /// HTTP handle to return the list of peers connected to the client's libp2p service. /// /// Peers are presented as a list of `PeerId::to_string()`. -pub fn get_peer_list(req: Request) -> ApiResult { +pub fn get_peer_list(req: Request) -> ApiResult { let network = req .extensions() .get::>>() diff --git a/beacon_node/src/run.rs b/beacon_node/src/run.rs index 5066231d5..f88cb7460 100644 --- a/beacon_node/src/run.rs +++ b/beacon_node/src/run.rs @@ -118,7 +118,7 @@ fn run( log: &slog::Logger, ) -> error::Result<()> where - T: BeaconChainTypes + InitialiseBeaconChain + Clone + Send + Sync + 'static, + T: BeaconChainTypes + InitialiseBeaconChain + Clone, T::Store: OpenDatabase, { let store = T::Store::open_database(&db_path)?;