1
- use std:: time:: Duration ;
1
+ use std:: { str :: FromStr , time:: Duration } ;
2
2
3
3
use alloy:: {
4
4
network:: { Ethereum , TransactionBuilder } ,
5
5
primitives:: { Address , U256 , address} ,
6
6
providers:: { Provider , RootProvider } ,
7
7
rpc:: types:: TransactionRequest ,
8
+ signers:: local:: PrivateKeySigner ,
8
9
} ;
9
10
use anyhow:: { Context , Result } ;
10
11
use futures:: future:: join_all;
11
12
use reqwest:: { Client , Url } ;
12
13
use timeboost:: types:: BundleVariant ;
13
- use timeboost_utils:: load_generation:: { make_bundle, make_dev_acct_bundle, tps_to_millis} ;
14
+ use timeboost_utils:: load_generation:: { TxInfo , make_bundle, make_dev_acct_bundle, tps_to_millis} ;
14
15
use tokio:: time:: interval;
15
16
use tracing:: warn;
16
17
@@ -20,6 +21,10 @@ use crate::{config::YapperConfig, enc_key::ThresholdEncKeyCellAccumulator};
20
21
/// https://docs.arbitrum.io/run-arbitrum-node/run-local-full-chain-simulation#default-endpoints-and-addresses
21
22
const DEV_ACCT_ADDRESS : Address = address ! ( "0x3f1Eae7D46d88F08fc2F8ed27FCb2AB183EB2d0E" ) ;
22
23
24
+ /// Private key from pre funded dev account on test node
25
+ /// https://docs.arbitrum.io/run-arbitrum-node/run-local-full-chain-simulation#default-endpoints-and-addresses
26
+ const DEV_ACCT_PRIV_KEY : & str = "b6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659" ;
27
+
23
28
/// This is the address of validator for the chain
24
29
/// https://docs.arbitrum.io/run-arbitrum-node/run-local-full-chain-simulation#default-endpoints-and-addresses
25
30
const VALIDATOR_ADDRESS : Address = address ! ( "0x6A568afe0f82d34759347bb36F14A6bB171d2CBe" ) ;
@@ -34,15 +39,16 @@ pub(crate) struct Yapper {
34
39
urls : Vec < ApiUrls > ,
35
40
client : Client ,
36
41
interval : Duration ,
42
+ chain_id : u64 ,
37
43
provider : Option < RootProvider > ,
38
44
txn_limit : Option < u64 > ,
39
45
}
40
46
41
47
impl Yapper {
42
- pub ( crate ) async fn new ( config : YapperConfig ) -> Result < Self > {
48
+ pub ( crate ) async fn new ( cfg : YapperConfig ) -> Result < Self > {
43
49
let mut urls = Vec :: new ( ) ;
44
50
45
- for addr in config . addresses {
51
+ for addr in cfg . addresses {
46
52
let regular_url = Url :: parse ( & format ! ( "http://{addr}/v0/submit-regular" ) )
47
53
. with_context ( || format ! ( "parsing {addr} into a url" ) ) ?;
48
54
let priority_url = Url :: parse ( & format ! ( "http://{addr}/v0/submit-priority" ) )
@@ -57,23 +63,24 @@ impl Yapper {
57
63
} ) ;
58
64
}
59
65
let client = Client :: builder ( ) . timeout ( Duration :: from_secs ( 1 ) ) . build ( ) ?;
60
- let ( provider, interval, txn_limit) = if config . nitro_integration {
66
+ let ( provider, interval, txn_limit) = if cfg . nitro_integration {
61
67
(
62
- Some ( RootProvider :: < Ethereum > :: connect ( & config . nitro_url ) . await ?) ,
68
+ Some ( RootProvider :: < Ethereum > :: connect ( & cfg . nitro_url ) . await ?) ,
63
69
Duration :: from_secs ( 1 ) ,
64
70
// For nitro running in ci, avoid race conditions with block height by setting txn
65
71
// limit
66
- Some ( config . txn_limit ) ,
72
+ Some ( cfg . txn_limit ) ,
67
73
)
68
74
} else {
69
- ( None , Duration :: from_millis ( tps_to_millis ( config . tps ) ) , None )
75
+ ( None , Duration :: from_millis ( tps_to_millis ( cfg . tps ) ) , None )
70
76
} ;
71
77
Ok ( Self {
72
78
urls,
73
79
interval,
74
80
client,
75
81
provider,
76
82
txn_limit,
83
+ chain_id : cfg. chain_id ,
77
84
} )
78
85
}
79
86
@@ -89,40 +96,17 @@ impl Yapper {
89
96
let mut txn_sent = 0 ;
90
97
loop {
91
98
let b = if let Some ( ref p) = self . provider {
92
- 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" ) ;
99
+ // For testing just send from the dev account to the validator address
100
+ let Ok ( txn) = Self :: prepare_txn ( p, self . chain_id ) . await else {
101
+ warn ! ( "failed to prepare txn" ) ;
109
102
continue ;
110
103
} ;
111
- // For testing just send from the dev account to the validator address
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 {
104
+ let Ok ( b) = make_dev_acct_bundle ( acc. enc_key ( ) . await , txn) else {
120
105
warn ! ( "failed to generate dev account bundle" ) ;
121
106
continue ;
122
107
} ;
123
108
b
124
109
} else {
125
- // create a bundle for next `interval.tick()`, then send this bundle to each node
126
110
let Ok ( b) = make_bundle ( acc. enc_key ( ) . await ) else {
127
111
warn ! ( "failed to generate bundle" ) ;
128
112
continue ;
@@ -145,6 +129,36 @@ impl Yapper {
145
129
}
146
130
}
147
131
132
+ async fn prepare_txn ( p : & RootProvider , chain_id : u64 ) -> Result < TxInfo > {
133
+ let nonce = p. get_transaction_count ( DEV_ACCT_ADDRESS ) . await ?;
134
+ let tx = TransactionRequest :: default ( )
135
+ . with_chain_id ( chain_id)
136
+ . with_nonce ( nonce)
137
+ . with_from ( DEV_ACCT_ADDRESS )
138
+ // Just choosing an address that already exists on the chain
139
+ . with_to ( VALIDATOR_ADDRESS )
140
+ . with_value ( U256 :: from ( 1 ) ) ;
141
+
142
+ let gas_limit = p
143
+ . estimate_gas ( tx)
144
+ . await
145
+ . with_context ( || "failed to estimate gas" ) ?;
146
+
147
+ let base_fee = p
148
+ . get_gas_price ( )
149
+ . await
150
+ . with_context ( || "failed to get gas price" ) ?;
151
+
152
+ Ok ( TxInfo {
153
+ chain_id,
154
+ nonce,
155
+ to : VALIDATOR_ADDRESS ,
156
+ gas_limit,
157
+ base_fee,
158
+ signer : PrivateKeySigner :: from_str ( DEV_ACCT_PRIV_KEY ) ?,
159
+ } )
160
+ }
161
+
148
162
async fn send_bundle_to_node (
149
163
& self ,
150
164
bundle : & BundleVariant ,
0 commit comments