@@ -8,6 +8,7 @@ use alloy::{
8
8
signers:: local:: PrivateKeySigner ,
9
9
} ;
10
10
use anyhow:: { Result , anyhow} ;
11
+ use tracing:: { debug, info} ;
11
12
12
13
use crate :: Config ;
13
14
@@ -23,12 +24,12 @@ pub async fn send_payload(cfg: Config, b: Vec<u8>) -> Result<TxHash> {
23
24
. connect ( & cfg. rpc_url )
24
25
. await ?;
25
26
let latest_block = provider. get_block_number ( ) . await ?;
26
- println ! ( "Latest block number: {latest_block}" ) ;
27
+ info ! ( "Latest block number: {latest_block}" ) ;
27
28
28
29
let sender = signer. address ( ) ;
29
30
let receiver = Address :: from ( [ 0x42 ; 20 ] ) ;
30
- dbg ! ( & sender) ;
31
- dbg ! ( & receiver) ;
31
+ debug ! ( "{}" , sender) ;
32
+ debug ! ( "{}" , receiver) ;
32
33
33
34
let sidecar: SidecarBuilder < SimpleCoder > = SidecarBuilder :: from_slice ( & b) ;
34
35
let sidecar = sidecar. build ( ) ?;
@@ -39,18 +40,10 @@ pub async fn send_payload(cfg: Config, b: Vec<u8>) -> Result<TxHash> {
39
40
// for a new tx, increase gas price by 10% to reduce the chances of the
40
41
// nodes rejecting it (in practice increase it by 11% to ensure it passes
41
42
// the miner filter)
42
- let ( receipt, tx_hash) = send_tx (
43
- cfg,
44
- provider,
45
- receiver,
46
- sidecar,
47
- fees,
48
- blob_base_fee,
49
- 111 / 100 ,
50
- )
51
- . await ?;
52
-
53
- println ! (
43
+ let ( receipt, tx_hash) =
44
+ send_tx ( cfg, provider, receiver, sidecar, fees, blob_base_fee, 11 ) . await ?;
45
+
46
+ info ! (
54
47
"Transaction included in block {}" ,
55
48
receipt. block_number. expect( "Failed to get block number" )
56
49
) ;
@@ -93,18 +86,20 @@ async fn send_tx<'async_recursion>(
93
86
sidecar : alloy:: eips:: eip4844:: BlobTransactionSidecar ,
94
87
fees : Eip1559Estimation ,
95
88
blob_base_fee : u128 ,
96
- increase_ratio : u128 ,
89
+ increase_percentage : u128 ,
97
90
) -> Result < ( TransactionReceipt , TxHash ) > {
98
91
let tx = TransactionRequest :: default ( )
99
- . with_max_fee_per_gas ( fees. max_fee_per_gas * increase_ratio)
100
- . with_max_priority_fee_per_gas ( fees. max_priority_fee_per_gas * increase_ratio)
101
- . with_max_fee_per_blob_gas ( blob_base_fee * increase_ratio)
92
+ . with_max_fee_per_gas ( fees. max_fee_per_gas * ( 100 + increase_percentage) / 100 )
93
+ . with_max_priority_fee_per_gas (
94
+ fees. max_priority_fee_per_gas * ( 100 + increase_percentage) / 100 ,
95
+ )
96
+ . with_max_fee_per_blob_gas ( blob_base_fee * ( 100 + increase_percentage) / 100 )
102
97
. with_to ( receiver)
103
98
. with_blob_sidecar ( sidecar. clone ( ) ) ;
104
99
105
- dbg ! ( & tx. max_fee_per_gas. unwrap( ) ) ;
106
- dbg ! ( & tx. max_priority_fee_per_gas. unwrap( ) ) ;
107
- dbg ! ( & tx. max_fee_per_blob_gas. unwrap( ) ) ;
100
+ debug ! ( "{}" , tx. max_fee_per_gas. unwrap( ) ) ;
101
+ debug ! ( "{}" , tx. max_priority_fee_per_gas. unwrap( ) ) ;
102
+ debug ! ( "{}" , tx. max_fee_per_blob_gas. unwrap( ) ) ;
108
103
109
104
let send_tx_result = provider. send_transaction ( tx) . await ;
110
105
let pending_tx_result = match send_tx_result {
@@ -115,62 +110,62 @@ async fn send_tx<'async_recursion>(
115
110
return Err ( anyhow ! ( "rpc-error: {}" , e) ) ;
116
111
}
117
112
118
- println ! ( "tx err: {}" , e) ;
119
- println ! ( "sending tx again with 2x gas price" ) ;
113
+ info ! ( "tx err: {}" , e) ;
114
+ info ! ( "sending tx again with 2x gas price" ) ;
120
115
return send_tx (
121
116
cfg,
122
117
provider,
123
118
receiver,
124
119
sidecar,
125
120
fees,
126
121
blob_base_fee,
127
- increase_ratio * 2 ,
122
+ increase_percentage + 100 ,
128
123
)
129
124
. await ;
130
125
}
131
126
} ;
132
- println ! ( "watching pending tx, timeout of {}" , cfg. tx_watch_timeout) ;
127
+ info ! ( "watching pending tx, timeout of {}" , cfg. tx_watch_timeout) ;
133
128
let pending_tx_result = pending_tx_result
134
129
. with_timeout ( Some ( std:: time:: Duration :: from_secs ( cfg. tx_watch_timeout ) ) )
135
130
. watch ( )
136
131
. await ;
137
132
138
- dbg ! ( "sent" ) ;
133
+ debug ! ( "sent" ) ;
139
134
let tx_hash = match pending_tx_result {
140
135
Ok ( pending_tx) => pending_tx,
141
136
Err ( e) => {
142
137
if e. to_string ( ) . contains ( "Too Many Requests" ) {
143
138
panic ! ( "error: {}" , e) ;
144
139
}
145
140
146
- println ! ( "tx err: {}" , e) ;
147
- println ! ( "sending tx again with 2x gas price" ) ;
141
+ info ! ( "tx err: {}" , e) ;
142
+ info ! ( "sending tx again with 2x gas price" ) ;
148
143
return send_tx (
149
144
cfg,
150
145
provider,
151
146
receiver,
152
147
sidecar,
153
148
fees,
154
149
blob_base_fee,
155
- increase_ratio * 2 ,
150
+ increase_percentage + 100 ,
156
151
)
157
152
. await ;
158
153
}
159
154
} ;
160
- println ! ( "Pending transaction... tx hash: {}" , tx_hash) ;
155
+ info ! ( "Pending transaction... tx hash: {}" , tx_hash) ;
161
156
162
157
let receipt = match provider. get_transaction_receipt ( tx_hash) . await ? {
163
158
Some ( receipt) => receipt,
164
159
None => {
165
- println ! ( "get_transaction_receipt failed, resending tx" ) ;
160
+ info ! ( "get_transaction_receipt failed, resending tx" ) ;
166
161
return send_tx (
167
162
cfg,
168
163
provider,
169
164
receiver,
170
165
sidecar,
171
166
fees,
172
167
blob_base_fee,
173
- increase_ratio * 2 ,
168
+ increase_percentage + 100 ,
174
169
)
175
170
. await ;
176
171
}
@@ -181,17 +176,16 @@ async fn send_tx<'async_recursion>(
181
176
182
177
#[ cfg( test) ]
183
178
mod tests {
184
- use tracing:: info;
185
-
186
179
use super :: * ;
187
180
188
181
// this test is mostly to check the send_payload method isolated from the
189
182
// rest of the AD server logic
190
183
#[ tokio:: test]
191
184
async fn test_tx ( ) -> anyhow:: Result < ( ) > {
185
+ crate :: log_init ( ) ;
192
186
common:: load_dotenv ( ) ?;
193
187
let cfg = Config :: from_env ( ) ?;
194
- info ! ( ?cfg , "Loaded config" ) ;
188
+ println ! ( "Loaded config: {:?}" , cfg ) ;
195
189
196
190
let tx_hash = send_payload ( cfg, b"test" . to_vec ( ) ) . await ?;
197
191
dbg ! ( tx_hash) ;
0 commit comments