Relax type bounds (#49)

This commit is contained in:
Giacomo Pasini 2023-01-18 11:30:37 +01:00 committed by GitHub
parent f1412b112e
commit f5a1dd5513
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 42 additions and 43 deletions

View File

@ -55,13 +55,13 @@ impl<Fountain: FountainCode> Clone for CarnotSettings<Fountain> {
pub struct CarnotConsensus<A, P, M, F> pub struct CarnotConsensus<A, P, M, F>
where where
F: FountainCode + Send + Sync + 'static, F: FountainCode,
A: NetworkAdapter + Send + Sync + 'static, A: NetworkAdapter,
P: MemPool + Send + Sync + 'static, M: MempoolAdapter<Tx = P::Tx>,
P::Settings: Clone + Send + Sync + 'static, P: MemPool,
P::Tx: Debug + Send + Sync + 'static, P::Tx: Debug + 'static,
P::Id: Debug + Send + Sync + 'static, P::Id: Debug + 'static,
M: MempoolAdapter<Tx = P::Tx> + Send + Sync + 'static, A::Backend: 'static,
{ {
service_state: ServiceStateHandle<Self>, service_state: ServiceStateHandle<Self>,
// underlying networking backend. We need this so we can relay and check the types properly // underlying networking backend. We need this so we can relay and check the types properly
@ -73,13 +73,12 @@ where
impl<A, P, M, F> ServiceData for CarnotConsensus<A, P, M, F> impl<A, P, M, F> ServiceData for CarnotConsensus<A, P, M, F>
where where
F: FountainCode + Send + Sync + 'static, F: FountainCode,
A: NetworkAdapter + Send + Sync + 'static, A: NetworkAdapter,
P: MemPool + Send + Sync + 'static, P: MemPool,
P::Settings: Clone + Send + Sync + 'static, P::Tx: Debug,
P::Tx: Debug + Send + Sync + 'static, P::Id: Debug,
P::Id: Debug + Send + Sync + 'static, M: MempoolAdapter<Tx = P::Tx>,
M: MempoolAdapter<Tx = P::Tx> + Send + Sync + 'static,
{ {
const SERVICE_ID: ServiceId = "Carnot"; const SERVICE_ID: ServiceId = "Carnot";
type Settings = CarnotSettings<F>; type Settings = CarnotSettings<F>;
@ -94,7 +93,7 @@ where
F: FountainCode + Send + Sync + 'static, F: FountainCode + Send + Sync + 'static,
A: NetworkAdapter + Send + Sync + 'static, A: NetworkAdapter + Send + Sync + 'static,
P: MemPool + Send + Sync + 'static, P: MemPool + Send + Sync + 'static,
P::Settings: Clone + Send + Sync + 'static, P::Settings: Send + Sync + 'static,
P::Tx: Debug + Send + Sync + 'static, P::Tx: Debug + Send + Sync + 'static,
P::Id: Debug + Send + Sync + 'static, P::Id: Debug + Send + Sync + 'static,
M: MempoolAdapter<Tx = P::Tx> + Send + Sync + 'static, M: MempoolAdapter<Tx = P::Tx> + Send + Sync + 'static,

View File

@ -15,7 +15,7 @@ use overwatch_rs::services::ServiceData;
#[async_trait::async_trait] #[async_trait::async_trait]
pub trait NetworkAdapter { pub trait NetworkAdapter {
type Backend: NetworkBackend + Send + Sync + 'static; type Backend: NetworkBackend + 'static;
async fn new( async fn new(
network_relay: OutboundRelay<<NetworkService<Self::Backend> as ServiceData>::Message>, network_relay: OutboundRelay<<NetworkService<Self::Backend> as ServiceData>::Message>,
) -> Self; ) -> Self;

View File

@ -95,12 +95,8 @@ impl<'view, const C: usize> Member<'view, C> {
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl< impl<'view, Network: NetworkAdapter + Sync, Fountain: FountainCode + Sync, const C: usize>
'view, Overlay<'view, Network, Fountain> for Member<'view, C>
Network: NetworkAdapter + Send + Sync,
Fountain: FountainCode + Send + Sync,
const C: usize,
> Overlay<'view, Network, Fountain> for Member<'view, C>
{ {
fn new(view: &'view View, node: NodeId) -> Self { fn new(view: &'view View, node: NodeId) -> Self {
let committees = Committees::new(view); let committees = Committees::new(view);

View File

@ -1,7 +1,7 @@
use nomos_core::block::{BlockHeader, BlockId}; use nomos_core::block::{BlockHeader, BlockId};
pub trait MemPool { pub trait MemPool {
type Settings; type Settings: Clone;
type Tx; type Tx;
type Id; type Id;

View File

@ -20,13 +20,13 @@ use overwatch_rs::services::{
ServiceCore, ServiceData, ServiceId, ServiceCore, ServiceData, ServiceId,
}; };
pub struct MempoolService< pub struct MempoolService<N, P>
N: NetworkAdapter<Tx = P::Tx> + Send + Sync + 'static, where
P: MemPool + Send + Sync + 'static, N: NetworkAdapter<Tx = P::Tx>,
> where P: MemPool,
P::Settings: Clone + Send + Sync + 'static, P::Settings: Clone,
P::Tx: Debug + Send + Sync + 'static, P::Tx: Debug + 'static,
P::Id: Debug + Send + Sync + 'static, P::Id: Debug + 'static,
{ {
service_state: ServiceStateHandle<Self>, service_state: ServiceStateHandle<Self>,
network_relay: Relay<NetworkService<N::Backend>>, network_relay: Relay<NetworkService<N::Backend>>,
@ -77,11 +77,11 @@ impl<Tx: 'static, Id: 'static> RelayMessage for MempoolMsg<Tx, Id> {}
impl<N, P> ServiceData for MempoolService<N, P> impl<N, P> ServiceData for MempoolService<N, P>
where where
N: NetworkAdapter<Tx = P::Tx> + Send + Sync + 'static, N: NetworkAdapter<Tx = P::Tx>,
P: MemPool + Send + Sync + 'static, P: MemPool,
P::Settings: Clone + Send + Sync + 'static, P::Settings: Clone,
P::Id: Debug + Send + Sync + 'static, P::Tx: Debug + 'static,
P::Tx: Debug + Send + Sync + 'static, P::Id: Debug + 'static,
{ {
const SERVICE_ID: ServiceId = "Mempool"; const SERVICE_ID: ServiceId = "Mempool";
type Settings = P::Settings; type Settings = P::Settings;
@ -93,10 +93,10 @@ where
#[async_trait::async_trait] #[async_trait::async_trait]
impl<N, P> ServiceCore for MempoolService<N, P> impl<N, P> ServiceCore for MempoolService<N, P>
where where
P: MemPool + Send + Sync + 'static, P: MemPool + Send + 'static,
P::Settings: Clone + Send + Sync + 'static, P::Settings: Clone + Send + Sync + 'static,
P::Id: Debug + Send + Sync + 'static, P::Id: Debug + Send + 'static,
P::Tx: Debug + Send + Sync + 'static, P::Tx: Debug + Send + 'static,
N: NetworkAdapter<Tx = P::Tx> + Send + Sync + 'static, N: NetworkAdapter<Tx = P::Tx> + Send + Sync + 'static,
{ {
fn init(service_state: ServiceStateHandle<Self>) -> Result<Self, overwatch_rs::DynError> { fn init(service_state: ServiceStateHandle<Self>) -> Result<Self, overwatch_rs::DynError> {

View File

@ -13,7 +13,7 @@ use overwatch_rs::services::ServiceData;
#[async_trait::async_trait] #[async_trait::async_trait]
pub trait NetworkAdapter { pub trait NetworkAdapter {
type Backend: NetworkBackend + Send + Sync + 'static; type Backend: NetworkBackend + 'static;
type Tx: Send + Sync + 'static; type Tx: Send + Sync + 'static;
async fn new( async fn new(
network_relay: OutboundRelay<<NetworkService<Self::Backend> as ServiceData>::Message>, network_relay: OutboundRelay<<NetworkService<Self::Backend> as ServiceData>::Message>,

View File

@ -50,7 +50,7 @@ impl<B: NetworkBackend> Debug for NetworkConfig<B> {
} }
} }
pub struct NetworkService<B: NetworkBackend + Send + 'static> { pub struct NetworkService<B: NetworkBackend + 'static> {
backend: B, backend: B,
service_state: ServiceStateHandle<Self>, service_state: ServiceStateHandle<Self>,
} }
@ -59,7 +59,7 @@ pub struct NetworkState<B: NetworkBackend> {
_backend: B::State, _backend: B::State,
} }
impl<B: NetworkBackend + Send + 'static> ServiceData for NetworkService<B> { impl<B: NetworkBackend + 'static> ServiceData for NetworkService<B> {
const SERVICE_ID: ServiceId = "Network"; const SERVICE_ID: ServiceId = "Network";
type Settings = NetworkConfig<B>; type Settings = NetworkConfig<B>;
type State = NetworkState<B>; type State = NetworkState<B>;
@ -68,7 +68,11 @@ impl<B: NetworkBackend + Send + 'static> ServiceData for NetworkService<B> {
} }
#[async_trait] #[async_trait]
impl<B: NetworkBackend + Send + 'static> ServiceCore for NetworkService<B> { impl<B> ServiceCore for NetworkService<B>
where
B: NetworkBackend + Send + 'static,
B::State: Send + Sync,
{
fn init(service_state: ServiceStateHandle<Self>) -> Result<Self, overwatch_rs::DynError> { fn init(service_state: ServiceStateHandle<Self>) -> Result<Self, overwatch_rs::DynError> {
Ok(Self { Ok(Self {
backend: <B as NetworkBackend>::new( backend: <B as NetworkBackend>::new(
@ -123,7 +127,7 @@ impl<B: NetworkBackend> Clone for NetworkState<B> {
} }
} }
impl<B: NetworkBackend + Send + 'static> ServiceState for NetworkState<B> { impl<B: NetworkBackend> ServiceState for NetworkState<B> {
type Settings = NetworkConfig<B>; type Settings = NetworkConfig<B>;
type Error = <B::State as ServiceState>::Error; type Error = <B::State as ServiceState>::Error;