Skip to content
Merged
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
417 changes: 296 additions & 121 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contender_bundle_provider = { path = "crates/bundle_provider/" }

# eyre = "0.6.12"
tokio = { version = "1.40.0" }
alloy = { version = "0.11.1" }
alloy = { version = "0.12.5" }
serde = "1.0.209"
rand = "0.8.5"

Expand Down
4 changes: 2 additions & 2 deletions crates/cli/src/commands/report/block_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::sync::Arc;
use crate::commands::report::cache::CacheFile;
use alloy::network::{AnyRpcBlock, AnyTransactionReceipt};
use alloy::providers::ext::DebugApi;
use alloy::rpc::types::BlockTransactionsKind;
use alloy::{
providers::Provider,
rpc::types::trace::geth::{
Expand Down Expand Up @@ -70,7 +69,8 @@ pub async fn get_block_trace_data(
let handle = tokio::task::spawn(async move {
println!("getting block {}...", block_num);
let block = rpc_client
.get_block_by_number(block_num.into(), BlockTransactionsKind::Full)
.get_block_by_number(block_num.into())
.full()
.await
.expect("failed to get block");
if let Some(block) = block {
Expand Down
3 changes: 1 addition & 2 deletions crates/cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use alloy::{
eips::BlockId,
network::AnyNetwork,
providers::{DynProvider, Provider, ProviderBuilder},
rpc::types::BlockTransactionsKind,
transports::http::reqwest::Url,
};
use contender_core::{
Expand Down Expand Up @@ -45,7 +44,7 @@ pub async fn run(
.network::<AnyNetwork>()
.on_http(Url::parse(&args.rpc_url).expect("Invalid RPC URL"));
let block_gas_limit = provider
.get_block(BlockId::latest(), BlockTransactionsKind::Hashes)
.get_block(BlockId::latest())
.await?
.map(|b| b.header.gas_limit)
.ok_or(ContenderError::SetupError(
Expand Down
2 changes: 0 additions & 2 deletions crates/cli/src/commands/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pub async fn setup(
.network::<AnyNetwork>()
.on_http(url.to_owned()),
);
let eth_client = DynProvider::new(ProviderBuilder::new().on_http(url.to_owned()));
let testconfig: TestConfig = TestConfig::from_file(testfile.as_ref())?;
let min_balance = parse_ether(&min_balance)?;

Expand Down Expand Up @@ -114,7 +113,6 @@ pub async fn setup(
&all_signer_addrs,
admin_signer,
&rpc_client,
&eth_client,
min_balance,
tx_type,
)
Expand Down
2 changes: 0 additions & 2 deletions crates/cli/src/commands/spam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ async fn init_scenario<D: DbOps + Clone + Send + Sync + 'static>(
.network::<AnyNetwork>()
.on_http(url.to_owned()),
);
let eth_client = DynProvider::new(ProviderBuilder::new().on_http(url.to_owned()));

let duration = duration.unwrap_or_default();
let min_balance = parse_ether(min_balance)?;
Expand Down Expand Up @@ -179,7 +178,6 @@ async fn init_scenario<D: DbOps + Clone + Send + Sync + 'static>(
&all_signer_addrs,
&user_signers[0],
&rpc_client,
&eth_client,
min_balance,
*tx_type,
)
Expand Down
22 changes: 10 additions & 12 deletions crates/cli/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use alloy::{
consensus::TxType,
hex::ToHexExt,
network::{EthereumWallet, TransactionBuilder},
network::{AnyTxEnvelope, EthereumWallet, TransactionBuilder},
primitives::{utils::format_ether, Address, U256},
providers::{PendingTransactionConfig, Provider},
rpc::types::TransactionRequest,
Expand All @@ -10,7 +10,7 @@ use alloy::{
use contender_core::{
db::RunTx,
generator::{
types::{AnyProvider, EthProvider, FunctionCallDefinition, SpamRequest},
types::{AnyProvider, FunctionCallDefinition, SpamRequest},
util::complete_tx_request,
},
spammer::{LogCallback, NilCallback},
Expand Down Expand Up @@ -138,7 +138,6 @@ pub async fn fund_accounts(
recipient_addresses: &[Address],
fund_with: &PrivateKeySigner,
rpc_client: &AnyProvider,
eth_client: &EthProvider,
min_balance: U256,
tx_type: TxType,
) -> Result<(), Box<dyn std::error::Error>> {
Expand Down Expand Up @@ -171,9 +170,10 @@ pub async fn fund_accounts(
let mut fund_handles: Vec<tokio::task::JoinHandle<()>> = vec![];
let (sender, mut receiver) = tokio::sync::mpsc::channel::<PendingTransactionConfig>(9000);
let sendr = Arc::new(sender.clone());
let rpc_client = Arc::new(rpc_client.to_owned());
for (idx, (address, _)) in insufficient_balances.into_iter().enumerate() {
let (balance_sufficient, balance) =
is_balance_sufficient(&fund_with.address(), min_balance, rpc_client).await?;
is_balance_sufficient(&fund_with.address(), min_balance, &rpc_client).await?;
if !balance_sufficient {
// error early if admin account runs out of funds
return Err(format!(
Expand All @@ -189,16 +189,15 @@ pub async fn fund_accounts(

let fund_amount = min_balance;
let fund_with = fund_with.to_owned();
let eth_client = Arc::new(eth_client.clone());
let sender = sendr.clone();

let rpc = rpc_client.clone();
fund_handles.push(tokio::task::spawn(async move {
let eth_client = eth_client.as_ref();
let res = fund_account(
&fund_with.to_owned(),
address,
fund_amount,
eth_client,
&rpc,
Some(admin_nonce + idx as u64),
tx_type,
)
Expand Down Expand Up @@ -231,7 +230,7 @@ pub async fn fund_account(
sender: &PrivateKeySigner,
recipient: Address,
amount: U256,
rpc_client: &EthProvider,
rpc_client: &AnyProvider,
nonce: Option<u64>,
tx_type: TxType,
) -> Result<PendingTransactionConfig, Box<dyn std::error::Error>> {
Expand All @@ -257,7 +256,9 @@ pub async fn fund_account(
sender.address(),
tx.tx_hash().encode_hex()
);
let res = rpc_client.send_tx_envelope(tx).await?;
let res = rpc_client
.send_tx_envelope(AnyTxEnvelope::Ethereum(tx))
.await?;

Ok(res.into_inner())
}
Expand Down Expand Up @@ -371,7 +372,6 @@ mod test {
.network::<AnyNetwork>()
.on_http(anvil.endpoint_url()),
);
let eth_client = DynProvider::new(ProviderBuilder::new().on_http(anvil.endpoint_url()));
let min_balance = U256::from(ETH_TO_WEI);
let default_signer = PrivateKeySigner::from_str(super::DEFAULT_PRV_KEYS[0]).unwrap();
// address: 0x7E57f00F16dE6A0D6B720E9C0af5C869a1f71c66
Expand All @@ -394,7 +394,6 @@ mod test {
&recipient_addresses,
&default_signer,
&rpc_client,
&eth_client,
min_balance,
tx_type,
)
Expand All @@ -413,7 +412,6 @@ mod test {
.unwrap()],
&new_signer,
&rpc_client,
&eth_client,
min_balance,
tx_type,
)
Expand Down
9 changes: 2 additions & 7 deletions crates/core/src/spammer/tx_actor.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use std::{sync::Arc, time::Duration};

use alloy::{
network::ReceiptResponse, primitives::TxHash, providers::Provider,
rpc::types::BlockTransactionsKind,
};
use alloy::{network::ReceiptResponse, primitives::TxHash, providers::Provider};
use tokio::sync::{mpsc, oneshot};

use crate::{
Expand Down Expand Up @@ -99,9 +96,7 @@ where
println!("unconfirmed txs: {}", cache.len());
let mut maybe_block;
loop {
maybe_block = rpc
.get_block_by_number(target_block_num.into(), BlockTransactionsKind::Hashes)
.await;
maybe_block = rpc.get_block_by_number(target_block_num.into()).await;
if let Ok(maybe_block) = &maybe_block {
if maybe_block.is_some() {
break;
Expand Down
30 changes: 17 additions & 13 deletions crates/core/src/test_scenario.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ where
let client = ClientBuilder::default()
.layer(LoggingLayer)
.http(rpc_url.to_owned());
let rpc_client = Arc::new(DynProvider::new(
let rpc_client = DynProvider::new(
ProviderBuilder::new()
.network::<AnyNetwork>()
.on_client(client),
));
);

let mut wallet_map = HashMap::new();
let wallets = signers.iter().map(|s| {
Expand Down Expand Up @@ -126,13 +126,17 @@ where
.as_ref()
.map(|url| Arc::new(BundleClient::new(url.clone())));

let msg_handle = Arc::new(TxActorHandle::new(12, db.clone(), rpc_client.clone()));
let msg_handle = Arc::new(TxActorHandle::new(
12,
db.clone(),
Arc::new(rpc_client.clone()),
));

Ok(Self {
config,
db: db.clone(),
rpc_url: rpc_url.to_owned(),
rpc_client: rpc_client.clone(),
rpc_client: Arc::new(rpc_client),
eth_client: Arc::new(DynProvider::new(ProviderBuilder::new().on_http(rpc_url))),
bundle_client,
builder_rpc_url,
Expand Down Expand Up @@ -304,7 +308,7 @@ where
let handle = tokio::task::spawn(async move {
// estimate gas limit
let gas_limit = wallet
.estimate_gas(&tx_req.tx)
.estimate_gas(tx_req.tx.to_owned())
.await
.expect("failed to estimate gas");

Expand Down Expand Up @@ -396,9 +400,12 @@ where
let gas_limit = if let Some(gas) = tx_req.tx.gas {
gas
} else {
wallet.estimate_gas(&tx_req.tx).await.unwrap_or_else(|_| {
panic!("failed to estimate gas for setup step '{}'", tx_label)
})
wallet
.estimate_gas(tx_req.tx.to_owned())
.await
.unwrap_or_else(|_| {
panic!("failed to estimate gas for setup step '{}'", tx_label)
})
};
let mut tx = tx_req.tx;
complete_tx_request(
Expand Down Expand Up @@ -469,7 +476,7 @@ where
gas
} else {
self.eth_client
.estimate_gas(tx_req)
.estimate_gas(tx_req.to_owned())
.await
.map_err(|e| ContenderError::with_err(e, "failed to estimate gas for tx"))?
};
Expand Down Expand Up @@ -668,10 +675,7 @@ where
SpamTrigger::BlockNumber(n) => n,
SpamTrigger::BlockHash(h) => {
let block = rpc_client
.get_block_by_hash(
h,
alloy::rpc::types::BlockTransactionsKind::Hashes,
)
.get_block_by_hash(h)
.await
.expect("failed to get block")
.expect("block not found");
Expand Down
Loading