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>
where
F: FountainCode + Send + Sync + 'static,
A: NetworkAdapter + Send + Sync + 'static,
P: MemPool + Send + Sync + 'static,
P::Settings: Clone + Send + Sync + 'static,
P::Tx: Debug + Send + Sync + 'static,
P::Id: Debug + Send + Sync + 'static,
M: MempoolAdapter<Tx = P::Tx> + Send + Sync + 'static,
F: FountainCode,
A: NetworkAdapter,
M: MempoolAdapter<Tx = P::Tx>,
P: MemPool,
P::Tx: Debug + 'static,
P::Id: Debug + 'static,
A::Backend: 'static,
{
service_state: ServiceStateHandle<Self>,
// 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>
where
F: FountainCode + Send + Sync + 'static,
A: NetworkAdapter + Send + Sync + 'static,
P: MemPool + Send + Sync + 'static,
P::Settings: Clone + Send + Sync + 'static,
P::Tx: Debug + Send + Sync + 'static,
P::Id: Debug + Send + Sync + 'static,
M: MempoolAdapter<Tx = P::Tx> + Send + Sync + 'static,
F: FountainCode,
A: NetworkAdapter,
P: MemPool,
P::Tx: Debug,
P::Id: Debug,
M: MempoolAdapter<Tx = P::Tx>,
{
const SERVICE_ID: ServiceId = "Carnot";
type Settings = CarnotSettings<F>;
@ -94,7 +93,7 @@ where
F: FountainCode + Send + Sync + 'static,
A: NetworkAdapter + 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::Id: Debug + 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]
pub trait NetworkAdapter {
type Backend: NetworkBackend + Send + Sync + 'static;
type Backend: NetworkBackend + 'static;
async fn new(
network_relay: OutboundRelay<<NetworkService<Self::Backend> as ServiceData>::Message>,
) -> Self;

View File

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

View File

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

View File

@ -20,13 +20,13 @@ use overwatch_rs::services::{
ServiceCore, ServiceData, ServiceId,
};
pub struct MempoolService<
N: NetworkAdapter<Tx = P::Tx> + Send + Sync + 'static,
P: MemPool + Send + Sync + 'static,
> where
P::Settings: Clone + Send + Sync + 'static,
P::Tx: Debug + Send + Sync + 'static,
P::Id: Debug + Send + Sync + 'static,
pub struct MempoolService<N, P>
where
N: NetworkAdapter<Tx = P::Tx>,
P: MemPool,
P::Settings: Clone,
P::Tx: Debug + 'static,
P::Id: Debug + 'static,
{
service_state: ServiceStateHandle<Self>,
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>
where
N: NetworkAdapter<Tx = P::Tx> + Send + Sync + 'static,
P: MemPool + Send + Sync + 'static,
P::Settings: Clone + Send + Sync + 'static,
P::Id: Debug + Send + Sync + 'static,
P::Tx: Debug + Send + Sync + 'static,
N: NetworkAdapter<Tx = P::Tx>,
P: MemPool,
P::Settings: Clone,
P::Tx: Debug + 'static,
P::Id: Debug + 'static,
{
const SERVICE_ID: ServiceId = "Mempool";
type Settings = P::Settings;
@ -93,10 +93,10 @@ where
#[async_trait::async_trait]
impl<N, P> ServiceCore for MempoolService<N, P>
where
P: MemPool + Send + Sync + 'static,
P: MemPool + Send + 'static,
P::Settings: Clone + Send + Sync + 'static,
P::Id: Debug + Send + Sync + 'static,
P::Tx: Debug + Send + Sync + 'static,
P::Id: Debug + Send + 'static,
P::Tx: Debug + Send + 'static,
N: NetworkAdapter<Tx = P::Tx> + Send + Sync + 'static,
{
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]
pub trait NetworkAdapter {
type Backend: NetworkBackend + Send + Sync + 'static;
type Backend: NetworkBackend + 'static;
type Tx: Send + Sync + 'static;
async fn new(
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,
service_state: ServiceStateHandle<Self>,
}
@ -59,7 +59,7 @@ pub struct NetworkState<B: NetworkBackend> {
_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";
type Settings = NetworkConfig<B>;
type State = NetworkState<B>;
@ -68,7 +68,11 @@ impl<B: NetworkBackend + Send + 'static> ServiceData for NetworkService<B> {
}
#[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> {
Ok(Self {
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 Error = <B::State as ServiceState>::Error;