8000 feat(mempool): Mempool payload processing by bacv · Pull Request #1367 · logos-co/nomos · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(mempool): Mempool payload processing #1367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions dependencies_graph.dot
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ digraph {
28 [ label = "nomos-da-verifier" shape = box]
29 [ label = "nomos-storage" shape = box]
30 [ label = "nomos-mempool" shape = box]
31 [ label = "nomos-tracing-service" shape = box]
32 [ label = "nomos-time" shape = box]
33 [ label = "nomos-da-dispersal" shape = box]
34 [ label = "nomos-da-indexer" shape = box]
35 [ label = "nomos-mantle-core" shape = box]
31 [ label = "nomos-mantle-core" shape = box]
32 [ label = "nomos-tracing-service" shape = box]
33 [ label = "nomos-time" shape = box]
34 [ label = "nomos-da-dispersal" shape = box]
35 [ label = "nomos-da-indexer" shape = box]
36 [ label = "nomos-node" shape = box]
37 [ label = "nomos-system-sig" shape = box]
38 [ label = "executor-http-client" shape = box]
Expand All @@ -50,11 +50,11 @@ digraph {
6 -> 36 [ ]
7 -> 8 [ ]
7 -> 3 [ ]
9 -> 33 [ ]
9 -> 34 [ ]
9 -> 35 [ ]
10 -> 11 [ ]
10 -> 30 [ ]
10 -> 32 [ ]
10 -> 33 [ ]
11 -> 14 [ ]
11 -> 16 [ ]
11 -> 17 [ ]
Expand Down Expand Up @@ -83,16 +83,16 @@ digraph {
28 -> 29 [ ]
29 -> 3 [ ]
30 -> 18 [ ]
30 -> 31 [ ]
30 -> 30 [ color = blue]
30 -> 16 [ ]
30 -> 31 [ color = blue]
31 -> 27 [ ]
32 -> 0 [ ]
33 -> 30 [ ]
34 -> 10 [ ]
35 -> 26 [ ]
30 -> 32 [ color = blue]
31 -> 26 [ ]
32 -> 27 [ ]
33 -> 0 [ ]
34 -> 30 [ ]
35 -> 10 [ ]
36 -> 9 [ ]
36 -> 35 [ ]
36 -> 37 [ ]
38 -> 19 [ ]
40 -> 38 [ ]
Expand Down
1 change: 1 addition & 0 deletions nodes/nomos-executor/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ nomos-network = { workspace = true, features = ["libp2p"] }
nomos-node = { workspace = true }
nomos-storage = { workspace = true, features = ["rocksdb-backend"] }
nomos-time = { workspace = true }
nomos-utils = { workspace = true }
overwatch = { workspace = true }
rand = "0.8"
rand_chacha = "0.3"
Expand Down
2 changes: 2 additions & 0 deletions nodes/nomos-executor/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use nomos_node::{
NomosDaMembership, RocksBackend, SystemSig, Wire, MB16,
};
use nomos_time::backends::NtpTimeBackend;
use nomos_utils::noop_service::NoService;
use overwatch::derive_services;
use rand_chacha::ChaCha20Rng;

Expand Down Expand Up @@ -266,4 +267,5 @@ pub struct NomosExecutor {
http: ApiService,
storage: StorageService,
system_sig: SystemSigService,
no_service: NoService,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? why is this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If PR looks good, I won't merge it, but remove Noop stuff and add all the stuff required to SignedTxProcessor, would be great @zeegomo to take a look before this.

}
2 changes: 2 additions & 0 deletions nodes/nomos-executor/executor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ async fn main() -> Result<()> {
topic: String::from(CL_TOPIC),
id: <SignedMantleTx as Transaction>::hash,
},
processor: (),
recovery_path: config.mempool.cl_pool_recovery_path,
},
da_mempool: DaMempoolSettings {
Expand Down Expand Up @@ -109,6 +110,7 @@ async fn main() -> Result<()> {
initial_locators_mapping: HashMap::default(),
},
},
no_service: (),
},
None,
)
Expand Down
1 change: 1 addition & 0 deletions nodes/nomos-node/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ nomos-system-sig = { workspace = true }
nomos-time = { workspace = true, features = ["ntp", "serde"] }
nomos-tracing = { workspace = true }
nomos-tracing-service = { workspace = true }
nomos-utils = { workspace = true }
overwatch = { workspace = true }
rand_chacha = "0.3"
serde = "1"
Expand Down
2 changes: 2 additions & 0 deletions nodes/nomos-node/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub use nomos_system_sig::SystemSig;
use nomos_time::backends::NtpTimeBackend;
#[cfg(feature = "tracing")]
pub use nomos_tracing_service::Tracing;
use nomos_utils::noop_service::NoService;
use overwatch::derive_services;
use rand_chacha::ChaCha20Rng;
use serde::{de::DeserializeOwned, Serialize};
Expand Down Expand Up @@ -241,4 +242,5 @@ pub struct Nomos {
http: ApiService,
storage: StorageService,
system_sig: SystemSigService,
no_service: NoService,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftovers?

Copy link
Member Author
@bacv bacv Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, added this to have fully working PoC without propagating types everywhere in mempool related services - when plugging in the SignedTxProcessor we'll need to propagate the <Processor> type. At the moment it's hardcoded here https://github.com/logos-co/nomos/pull/1367/files#diff-ca797e6e2c0f5ada3af86c41728f417cb7b1fd3428b65780ab51ade0e4dac0b7R36-R58

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

man these generics are coming after us

}
2 changes: 2 additions & 0 deletions nodes/nomos-node/node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ async fn main() -> Result<()> {
topic: String::from(nomos_node::CL_TOPIC),
id: <SignedMantleTx as Transaction>::hash,
},
processor: (),
recovery_path: config.mempool.cl_pool_recovery_path,
},
da_mempool: nomos_mempool::DaMempoolSettings {
Expand All @@ -108,6 +109,7 @@ async fn main() -> Result<()> {
initial_locators_mapping: HashMap::default(),
},
},
no_service: (),
},
None,
)
Expand Down
2 changes: 1 addition & 1 deletion nomos-mantle/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mod gas;
mod ops;
pub mod ops;
pub mod tx;
2 changes: 2 additions & 0 deletions nomos-services/mempool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ linked-hash-map = { version = "0.5.6", optional = true, features = ["serde
nomos-core = { workspace = true }
nomos-da-network-core = { workspace = true }
nomos-da-sampling = { workspace = true }
nomos-mantle-core = { workspace = true }
nomos-network = { workspace = true }
nomos-utils = { workspace = true }
overwatch = { workspace = true }
rand = { version = "0.8" }
serde = { version = "1.0", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion nomos-services/mempool/src/backend/mockpool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ where
BlockId: Ord + Copy,
{
type Error = Infallible;
type Settings = TxMempoolSettings<(), ()>;
type Settings = TxMempoolSettings<(), (), ()>;

fn from_settings(_settings: &Self::Settings) -> Result<Self, Self::Error> {
Ok(<Self as MemPool>::new(()))
Expand Down
2 changes: 1 addition & 1 deletion nomos-services/mempool/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pub mod backend;
pub mod da;
pub mod network;
pub mod processor;
pub mod tx;
pub mod verify;

use std::fmt::{Debug, Error, Formatter};

Expand Down
23 changes: 23 additions & 0 deletions nomos-services/mempool/src/processor/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pub mod noop;
pub mod tx;

use std::error::Error;

use overwatch::services::{relay::OutboundRelay, ServiceData};

#[async_trait::async_trait]
pub trait PayloadProcessor {
type Payload;
type Settings;
type Error: Error;

type DaSamplingService: ServiceData;

fn new(
settings: Self::Settings,
outbound_relay: OutboundRelay<<Self::DaSamplingService as ServiceData>::Message>,
) -> Self;

/// Executes required procedures before adding payload to the pool.
async fn process(&self, payload: &Self::Payload) -> Result<(), Vec<Self::Error>>;
}
31 changes: 31 additions & 0 deletions nomos-services/mempool/src/processor/noop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use std::{convert::Infallible, marker::PhantomData};

use overwatch::services::{relay::OutboundRelay, ServiceData};

use super::PayloadProcessor;

pub type NoOpPayloadProcessor<Service, Payload> = PhantomData<(Service, Payload)>;

#[async_trait::async_trait]
impl<Service, Payload> PayloadProcessor for NoOpPayloadProcessor<Service, Payload>
where
Payload: Send + Sync,
Service: ServiceData + Send + Sync,
{
type Payload = Payload;
type Settings = ();
type Error = Infallible;

type DaSamplingService = Service;

fn new(
(): Self::Settings,
_: OutboundRelay<<Self::DaSamplingService as ServiceData>::Message>,
) -> Self {
Self
}

async fn process(&self, _: &Self::Payload) -> Result<(), Vec<Self::Error>> {
Ok(())
}
}
81 changes: 81 additions & 0 deletions nomos-services/mempool/src/processor/tx.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use std::error::Error;

use futures::{stream::FuturesUnordered, StreamExt};
use nomos_core::da::BlobId;
use nomos_da_sampling::DaSamplingServiceMsg;
use nomos_mantle_core::{ops::Op, tx::SignedMantleTx};
use overwatch::services::{relay::OutboundRelay, ServiceData};

use super::PayloadProcessor;

#[derive(thiserror::Error, Debug)]
pub enum SignedTxProcessorError {
#[error("Error from sampling relay {0}")]
Sampling(Box<dyn Error + Send>),
}

impl SignedTxProcessorError {
fn sampling_error(err: impl Error + Send + 'static) -> Self {
Self::Sampling(Box::new(err))
}
}

pub struct SignedTxProcessor<SamplingService>
where
SamplingService: ServiceData,
{
sampling_relay: OutboundRelay<<SamplingService as ServiceData>::Message>,
}

#[async_trait::async_trait]
impl<SamplingService> PayloadProcessor for SignedTxProcessor<SamplingService>
where
SamplingService: ServiceData<Message = DaSamplingServiceMsg<BlobId>> + Send + Sync,
{
type Payload = SignedMantleTx;
type Settings = ();
type Error = SignedTxProcessorError;

type DaSamplingService = SamplingService;

fn new(
(): Self::Settings,
sampling_relay: OutboundRelay<<Self::DaSamplingService as ServiceData>::Message>,
) -> Self {
Self { sampling_relay }
}

async fn process(&self, payload: &Self::Payload) -> Result<(), Vec<Self::Error>> {
let all_futures: FuturesUnordered<_> = payload
.mantle_tx
.ops
.iter()
.filter_map(|op| {
if let Op::Blob(blob_op) = op {
Some(async {
self.sampling_relay
.send(DaSamplingServiceMsg::TriggerSampling {
blob_id: blob_op.blob,
})
.await
.map_err(|(e, _)| SignedTxProcessorError::sampling_error(e))
})
} else {
None
}
})
.collect();

let errors: Vec<SignedTxProcessorError> = StreamExt::collect::<Vec<_>>(all_futures)
.await
.into_iter()
.filter_map(Result::err)
.collect();

if errors.is_empty() {
Ok(())
} else {
Err(errors)
}
}
}
Loading
Loading
0