Skip to content

Commit 62dc253

Browse files
committed
properly fetch gas limit and gas base fee
1 parent 11e47ad commit 62dc253

File tree

2 files changed

+45
-18
lines changed

2 files changed

+45
-18
lines changed

timeboost-utils/src/load_generation.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use alloy::{
55
network::TxSignerSync,
66
primitives::{TxKind, U256},
77
rlp::Encodable,
8-
rpc::types::AccessList,
98
signers::local::PrivateKeySigner,
109
};
1110
use arbitrary::Unstructured;
@@ -19,6 +18,10 @@ use timeboost_crypto::{
1918
};
2019
use timeboost_types::{Address, Bundle, BundleVariant, Epoch, PriorityBundle, SeqNo, Signer};
2120

21+
// Private key from pre funded dev account on test node
22+
// https://docs.arbitrum.io/run-arbitrum-node/run-local-full-chain-simulation#default-endpoints-and-addresses
23+
const DEV_ACCT_PRIV_KEY: &str = "b6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659";
24+
2225
pub fn make_bundle(pubkey: &ThresholdEncKeyCell) -> anyhow::Result<BundleVariant> {
2326
let mut rng = rand::thread_rng();
2427
let mut v = [0; 256];
@@ -55,16 +58,19 @@ pub fn make_bundle(pubkey: &ThresholdEncKeyCell) -> anyhow::Result<BundleVariant
5558

5659
pub fn make_dev_acct_bundle(
5760
pubkey: &ThresholdEncKeyCell,
61+
chain_id: u64,
5862
nonce: u64,
5963
to: alloy::primitives::Address,
64+
gas_limit: u64,
65+
max_base_fee: u128,
6066
) -> anyhow::Result<BundleVariant> {
6167
let mut rng = rand::thread_rng();
6268
let mut v = [0; 256];
6369
rng.fill(&mut v);
6470
let mut u = Unstructured::new(&v);
6571

6672
let max_seqno = 10;
67-
let mut bundle = create_dev_acct_txn_bundle(nonce, to)?;
73+
let mut bundle = create_dev_acct_txn_bundle(chain_id, nonce, to, gas_limit, max_base_fee)?;
6874

6975
if let Some(pubkey) = &*pubkey.get_ref()
7076
&& rng.gen_bool(0.5)
@@ -92,29 +98,25 @@ pub fn make_dev_acct_bundle(
9298
}
9399

94100
pub fn create_dev_acct_txn_bundle(
101+
chain_id: u64,
95102
nonce: u64,
96103
to: alloy::primitives::Address,
104+
gas_limit: u64,
105+
max_fee_per_gas: u128,
97106
) -> anyhow::Result<Bundle> {
98-
// Chain id from l2 chain
99-
// https://docs.arbitrum.io/run-arbitrum-node/run-local-full-chain-simulation#default-endpoints-and-addresses
100-
let chain_id = 412346;
101107
let mut tx = TxEip1559 {
102108
chain_id,
103109
nonce,
104-
max_priority_fee_per_gas: 1000000000,
105-
max_fee_per_gas: 1000000000,
106-
gas_limit: 21000,
110+
max_fee_per_gas,
111+
gas_limit,
107112
to: TxKind::Call(to),
108113
value: U256::from(1),
109-
input: alloy::primitives::Bytes::new(),
110-
access_list: AccessList::default(),
114+
..Default::default()
111115
};
112116

113117
// Private key from pre funded dev account on test node
114118
// https://docs.arbitrum.io/run-arbitrum-node/run-local-full-chain-simulation#default-endpoints-and-addresses
115-
let signer = PrivateKeySigner::from_str(
116-
"b6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659",
117-
)?;
119+
let signer = PrivateKeySigner::from_str(DEV_ACCT_PRIV_KEY)?;
118120
let sig = signer.sign_transaction_sync(&mut tx)?;
119121
let signed_tx = tx.into_signed(sig);
120122
let env = TxEnvelope::Eip1559(signed_tx);

yapper/src/yapper.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use std::time::Duration;
22

33
use alloy::{
4-
network::Ethereum,
5-
primitives::{Address, address},
4+
network::{Ethereum, TransactionBuilder},
5+
primitives::{Address, U256, address},
66
providers::{Provider, RootProvider},
7+
rpc::types::TransactionRequest,
78
};
89
use anyhow::{Context, Result};
910
use futures::future::join_all;
@@ -89,10 +90,34 @@ impl Yapper {
8990
loop {
9091
let b = if let Some(ref p) = self.provider {
9192
let nonce = p.get_transaction_count(DEV_ACCT_ADDRESS).await?;
93+
// Chain id from l2 chain
94+
// https://docs.arbitrum.io/run-arbitrum-node/run-local-full-chain-simulation#default-endpoints-and-addresses
95+
let chain_id = 412346;
96+
let tx = TransactionRequest::default()
97+
.with_chain_id(chain_id)
98+
.with_nonce(nonce)
99+
.with_from(DEV_ACCT_ADDRESS)
100+
.with_to(VALIDATOR_ADDRESS)
101+
.with_value(U256::from(1));
102+
103+
let Ok(estimate) = p.estimate_gas(tx).await else {
104+
warn!("failed to get estimate");
105+
continue;
106+
};
107+
let Ok(price) = p.get_gas_price().await else {
108+
warn!("failed to get gas price");
109+
continue;
110+
};
92111
// For testing just send from the dev account to the validator address
93-
let Ok(b) = make_dev_acct_bundle(acc.enc_key().await, nonce, VALIDATOR_ADDRESS)
94-
else {
95-
warn!("failed to dev account generate bundle");
112+
let Ok(b) = make_dev_acct_bundle(
113+
acc.enc_key().await,
114+
chain_id,
115+
nonce,
116+
VALIDATOR_ADDRESS,
117+
estimate,
118+
price,
119+
) else {
120+
warn!("failed to generate dev account bundle");
96121
continue;
97122
};
98123
b

0 commit comments

Comments
 (0)