Make BeaconChainTypes Send + Sync + 'static

This commit is contained in:
Paul Hauner 2019-08-22 16:34:21 +10:00
parent 5a34f86e77
commit 853344af8a
No known key found for this signature in database
GPG Key ID: 5E2CFF9B75FA63DF
8 changed files with 19 additions and 23 deletions

View File

@ -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<Self::Store, Self::EthSpec>;

View File

@ -54,8 +54,8 @@ where
impl<L, E> BeaconChainTypes for CommonTypes<L, E>
where
L: LmdGhost<MemoryStore, E>,
E: EthSpec,
L: LmdGhost<MemoryStore, E> + 'static,
E: EthSpec + 'static,
{
type Store = MemoryStore;
type SlotClock = TestingSlotClock;
@ -69,8 +69,8 @@ where
/// Used for testing.
pub struct BeaconChainHarness<L, E>
where
L: LmdGhost<MemoryStore, E>,
E: EthSpec,
L: LmdGhost<MemoryStore, E> + 'static,
E: EthSpec + 'static,
{
pub chain: BeaconChain<CommonTypes<L, E>>,
pub keypairs: Vec<Keypair>,

View File

@ -36,7 +36,11 @@ pub struct ClientType<S: Store, E: EthSpec> {
_phantom_u: PhantomData<E>,
}
impl<S: Store, E: EthSpec + Clone> BeaconChainTypes for ClientType<S, E> {
impl<S, E> BeaconChainTypes for ClientType<S, E>
where
S: Store + 'static,
E: EthSpec + 'static + Clone,
{
type Store = S;
type SlotClock = SystemTimeSlotClock;
type LmdGhost = ThreadSafeReducedTree<S, E>;

View File

@ -49,7 +49,7 @@ pub struct Client<T: BeaconChainTypes> {
impl<T> Client<T>
where
T: BeaconChainTypes + InitialiseBeaconChain<T> + Clone + Send + Sync + 'static,
T: BeaconChainTypes + InitialiseBeaconChain<T> + Clone,
{
/// Generate an instance of the client. Spawn and link all internal sub-processes.
pub fn new(

View File

@ -17,11 +17,7 @@ pub const WARN_PEER_COUNT: usize = 1;
/// durations.
///
/// Presently unused, but remains for future use.
pub fn run<T: BeaconChainTypes + Send + Sync + 'static>(
client: &Client<T>,
executor: TaskExecutor,
exit: Exit,
) {
pub fn run<T: BeaconChainTypes>(client: &Client<T>, executor: TaskExecutor, exit: Exit) {
// notification heartbeat
let interval = Interval::new(
Instant::now(),

View File

@ -71,7 +71,7 @@ impl From<state_processing::per_slot_processing::Error> for ApiError {
}
}
pub fn start_server<T: BeaconChainTypes + Clone + Send + Sync + 'static>(
pub fn start_server<T: BeaconChainTypes>(
config: &ApiConfig,
executor: &TaskExecutor,
beacon_chain: Arc<BeaconChain<T>>,

View File

@ -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<T: BeaconChainTypes + Send + Sync + 'static>(
req: Request<Body>,
) -> ApiResult {
pub fn get_listen_addresses<T: BeaconChainTypes>(req: Request<Body>) -> ApiResult {
let network = req
.extensions()
.get::<Arc<NetworkService<T>>>()
@ -26,7 +24,7 @@ pub fn get_listen_addresses<T: BeaconChainTypes + Send + Sync + 'static>(
/// HTTP handle to return the Discv5 ENR from the client's libp2p service.
///
/// ENR is encoded as base64 string.
pub fn get_enr<T: BeaconChainTypes + Send + Sync + 'static>(req: Request<Body>) -> ApiResult {
pub fn get_enr<T: BeaconChainTypes>(req: Request<Body>) -> ApiResult {
let network = req
.extensions()
.get::<Arc<NetworkService<T>>>()
@ -43,7 +41,7 @@ pub fn get_enr<T: BeaconChainTypes + Send + Sync + 'static>(req: Request<Body>)
/// HTTP handle to return the `PeerId` from the client's libp2p service.
///
/// PeerId is encoded as base58 string.
pub fn get_peer_id<T: BeaconChainTypes + Send + Sync + 'static>(req: Request<Body>) -> ApiResult {
pub fn get_peer_id<T: BeaconChainTypes>(req: Request<Body>) -> ApiResult {
let network = req
.extensions()
.get::<Arc<NetworkService<T>>>()
@ -58,9 +56,7 @@ pub fn get_peer_id<T: BeaconChainTypes + Send + Sync + 'static>(req: Request<Bod
}
/// HTTP handle to return the number of peers connected in the client's libp2p service.
pub fn get_peer_count<T: BeaconChainTypes + Send + Sync + 'static>(
req: Request<Body>,
) -> ApiResult {
pub fn get_peer_count<T: BeaconChainTypes>(req: Request<Body>) -> ApiResult {
let network = req
.extensions()
.get::<Arc<NetworkService<T>>>()
@ -77,7 +73,7 @@ pub fn get_peer_count<T: BeaconChainTypes + Send + Sync + 'static>(
/// 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<T: BeaconChainTypes + Send + Sync + 'static>(req: Request<Body>) -> ApiResult {
pub fn get_peer_list<T: BeaconChainTypes>(req: Request<Body>) -> ApiResult {
let network = req
.extensions()
.get::<Arc<NetworkService<T>>>()

View File

@ -118,7 +118,7 @@ fn run<T>(
log: &slog::Logger,
) -> error::Result<()>
where
T: BeaconChainTypes + InitialiseBeaconChain<T> + Clone + Send + Sync + 'static,
T: BeaconChainTypes + InitialiseBeaconChain<T> + Clone,
T::Store: OpenDatabase,
{
let store = T::Store::open_database(&db_path)?;