-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## 📝 Summary This PR adds a benchmark for the txfetcher service. It only benches normal Ethereum transactions. ## 💡 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: * [x] Run `make lint` * [x] Run `make test` * [x] Added tests (if applicable)
- Loading branch information
Showing
8 changed files
with
101 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ mod benchmarks; | |
|
||
criterion_main! { | ||
benchmarks::mev_boost::serialization, | ||
benchmarks::txpool_fetcher::txpool, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod mev_boost; | ||
pub mod txpool_fetcher; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use alloy_network::{EthereumWallet, TransactionBuilder}; | ||
use alloy_node_bindings::Anvil; | ||
use alloy_primitives::U256; | ||
use alloy_provider::{Provider, ProviderBuilder}; | ||
use alloy_rpc_types::TransactionRequest; | ||
use alloy_signer_local::PrivateKeySigner; | ||
use criterion::{criterion_group, Criterion}; | ||
use rbuilder::live_builder::order_input::{ | ||
txpool_fetcher::subscribe_to_txpool_with_blobs, OrderInputConfig, | ||
}; | ||
use std::time::Duration; | ||
use tokio::sync::mpsc; | ||
use tokio_util::sync::CancellationToken; | ||
|
||
async fn txpool_receive_util(count: u32) { | ||
let anvil = Anvil::new() | ||
.args(["--ipc", "/tmp/anvil.ipc"]) | ||
.try_spawn() | ||
.unwrap(); | ||
|
||
let (sender, mut receiver) = mpsc::channel(10); | ||
subscribe_to_txpool_with_blobs( | ||
OrderInputConfig::default_e2e(), | ||
sender, | ||
CancellationToken::new(), | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
let signer: PrivateKeySigner = anvil.keys()[0].clone().into(); | ||
let wallet = EthereumWallet::from(signer); | ||
|
||
let provider = ProviderBuilder::new() | ||
.with_recommended_fillers() | ||
.wallet(wallet) | ||
.on_http(anvil.endpoint().parse().unwrap()); | ||
|
||
let alice = anvil.addresses()[0]; | ||
let eip1559_est = provider.estimate_eip1559_fees(None).await.unwrap(); | ||
|
||
let tx = TransactionRequest::default() | ||
.with_to(alice) | ||
.with_value(U256::from(1)) | ||
.with_max_fee_per_gas(eip1559_est.max_fee_per_gas) | ||
.with_max_priority_fee_per_gas(eip1559_est.max_priority_fee_per_gas); | ||
|
||
tokio::spawn(async move { | ||
for _ in 0..count { | ||
let _ = provider.send_transaction(tx.clone()).await.unwrap(); | ||
} | ||
}); | ||
|
||
for _ in 0..count { | ||
let _ = receiver.recv().await.unwrap(); | ||
} | ||
} | ||
|
||
fn bench_txpool_receive(c: &mut Criterion) { | ||
let rt = tokio::runtime::Runtime::new().unwrap(); | ||
let mut group = c.benchmark_group("Txpool fetcher"); | ||
|
||
group.measurement_time(Duration::from_secs(20)); | ||
group.bench_function("txn_fetcher_normal_10", |b| { | ||
b.to_async(&rt).iter(|| txpool_receive_util(10)); | ||
}); | ||
group.bench_function("txn_fetcher_normal_100", |b| { | ||
b.to_async(&rt).iter(|| txpool_receive_util(100)); | ||
}); | ||
} | ||
|
||
criterion_group!(txpool, bench_txpool_receive,); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters