Skip to content

Commit 14931d4

Browse files
authored
Add txn monitoring in op-rbuilder pool (flashbots#500)
## 📝 Summary This PR introduces a monitoring service that prints all the transactions that arrive to the transaction pool in op-rbuilder. ## 💡 Motivation and Context <!--- (Optional) Why is this change required? What problem does it solve? Remove this section if not applicable. --> --- ## ✅ I have completed the following steps: * [ ] Run `make lint` * [ ] Run `make test` * [ ] Added tests (if applicable)
1 parent ebabead commit 14931d4

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

crates/op-rbuilder/src/args.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@ pub struct OpRbuilderArgs {
3838
env = "FLASHBLOCK_BLOCK_TIME"
3939
)]
4040
pub flashblock_block_time: u64,
41+
42+
/// Signals whether to log pool transactions events
43+
#[arg(long = "builder.log-pool-transactions", default_value = "false")]
44+
pub log_pool_transactions: bool,
4145
}

crates/op-rbuilder/src/main.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ use reth_optimism_node::OpNode;
99
use payload_builder::CustomOpPayloadBuilder;
1010
#[cfg(not(feature = "flashblocks"))]
1111
use payload_builder_vanilla::CustomOpPayloadBuilder;
12+
use reth_transaction_pool::TransactionPool;
1213

1314
/// CLI argument parsing.
1415
pub mod args;
1516
pub mod generator;
1617
#[cfg(test)]
1718
mod integration;
1819
mod metrics;
20+
mod monitor_tx_pool;
1921
mod monitoring;
2022
#[cfg(feature = "flashblocks")]
2123
pub mod payload_builder;
@@ -25,6 +27,7 @@ mod primitives;
2527
#[cfg(test)]
2628
mod tester;
2729
mod tx_signer;
30+
use monitor_tx_pool::monitor_tx_pool;
2831

2932
fn main() {
3033
Cli::<OpChainSpecParser, args::OpRbuilderArgs>::parse()
@@ -50,6 +53,16 @@ fn main() {
5053
let new_canonical_blocks = ctx.provider().canonical_state_stream();
5154
let builder_signer = builder_args.builder_signer;
5255

56+
if builder_args.log_pool_transactions {
57+
tracing::info!("Logging pool transactions");
58+
ctx.task_executor.spawn_critical(
59+
"txlogging",
60+
Box::pin(async move {
61+
monitor_tx_pool(ctx.pool.all_transactions_event_listener()).await;
62+
}),
63+
);
64+
}
65+
5366
ctx.task_executor.spawn_critical(
5467
"monitoring",
5568
Box::pin(async move {
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
use futures_util::StreamExt;
2+
use reth_optimism_node::txpool::OpPooledTransaction;
3+
use reth_transaction_pool::{AllTransactionsEvents, FullTransactionEvent};
4+
use tracing::debug;
5+
6+
pub async fn monitor_tx_pool(mut new_transactions: AllTransactionsEvents<OpPooledTransaction>) {
7+
while let Some(event) = new_transactions.next().await {
8+
transaction_event_log(event);
9+
}
10+
}
11+
12+
fn transaction_event_log(event: FullTransactionEvent<OpPooledTransaction>) {
13+
match event {
14+
FullTransactionEvent::Pending(hash) => {
15+
debug!(
16+
tx_hash = hash.to_string(),
17+
kind = "pending",
18+
"Transaction event received"
19+
)
20+
}
21+
FullTransactionEvent::Queued(hash) => {
22+
debug!(
23+
tx_hash = hash.to_string(),
24+
kind = "queued",
25+
"Transaction event received"
26+
)
27+
}
28+
FullTransactionEvent::Mined {
29+
tx_hash,
30+
block_hash,
31+
} => debug!(
32+
tx_hash = tx_hash.to_string(),
33+
kind = "mined",
34+
block_hash = block_hash.to_string(),
35+
"Transaction event received"
36+
),
37+
FullTransactionEvent::Replaced {
38+
transaction,
39+
replaced_by,
40+
} => debug!(
41+
tx_hash = transaction.hash().to_string(),
42+
kind = "replaced",
43+
replaced_by = replaced_by.to_string(),
44+
"Transaction event received"
45+
),
46+
FullTransactionEvent::Discarded(hash) => {
47+
debug!(
48+
tx_hash = hash.to_string(),
49+
kind = "discarded",
50+
"Transaction event received"
51+
)
52+
}
53+
FullTransactionEvent::Invalid(hash) => {
54+
debug!(
55+
tx_hash = hash.to_string(),
56+
kind = "invalid",
57+
"Transaction event received"
58+
)
59+
}
60+
FullTransactionEvent::Propagated(_propagated) => {}
61+
}
62+
}

0 commit comments

Comments
 (0)