@@ -11,7 +11,7 @@ use alloy::{
11
11
} ;
12
12
use backon:: { ConstantBuilder , ExponentialBuilder , Retryable } ;
13
13
use color_eyre:: eyre:: { eyre, ContextCompat , Result , WrapErr } ;
14
- use tracing:: { debug, info} ;
14
+ use tracing:: { debug, info, trace } ;
15
15
use unionlabs:: { bounded:: BoundedU32 , hash:: H160 , uint:: U256 } ;
16
16
17
17
use crate :: {
@@ -86,6 +86,8 @@ impl Config {
86
86
. retry ( & ExponentialBuilder :: default ( ) )
87
87
. await ?;
88
88
89
+ info ! ( "fetched db chain_id for chain {l2_chain_id} => {chain_id:?}" ) ;
90
+
89
91
let querier = Arb {
90
92
l1_client : ProviderBuilder :: new ( ) . on_http ( self . l1_url ) ,
91
93
l2_client,
@@ -102,8 +104,13 @@ impl Config {
102
104
impl Arb {
103
105
// NOTE: Copied from chain_utils
104
106
async fn execution_height_of_beacon_slot ( & self , slot : u64 ) -> Result < u64 > {
107
+ trace ! ( "find execution height of beacon slot {slot}" ) ;
108
+
105
109
// read the next_node_num at l1.execution_height(beacon_slot), then from there filter for `NodeCreated`
106
110
let next_node_num = self . next_node_num_at_beacon_slot ( slot) . await ?;
111
+
112
+ trace ! ( "find execution height of beacon slot {slot}. next node num: {next_node_num}" ) ;
113
+
107
114
let [ event] = self
108
115
. l1_client
109
116
. get_logs (
@@ -123,24 +130,38 @@ impl Arb {
123
130
. await
124
131
. wrap_err ( "error fetching `NodeCreated` log from l1" ) ?
125
132
. try_into ( )
126
- . map_err ( |e| eyre ! ( "too many logs found? there should only be one `NodeCreated event`, but found: {e:?}" ) ) ?;
127
- debug ! ( "next node num: {next_node_num}: {event:?}" ) ;
133
+ . map_err ( |e| eyre ! ( "too many logs or no found? there should only be one `NodeCreated event`, but found: {e:?}" ) ) ?;
134
+
135
+ trace ! ( "find execution height of beacon slot {slot}. event: {event:?}" ) ;
136
+
128
137
let event = NodeCreated :: decode_log ( & event. inner , true ) . unwrap ( ) ;
138
+
139
+ trace ! ( "find execution height of beacon slot {slot}. event(decoded): {event:?}" ) ;
129
140
let block_id = BlockId :: Hash ( RpcBlockHash {
130
141
block_hash : FixedBytes :: from_slice ( event. assertion . 0 . 0 . 0 [ 0 ] . as_ref ( ) ) ,
131
142
require_canonical : None ,
132
143
} ) ;
144
+
145
+ trace ! ( "find execution height of beacon slot {slot}. block-id: {block_id}" ) ;
146
+
133
147
let block = self
134
148
. l2_client
135
- . get_block ( block_id, BlockTransactionsKind :: Full )
149
+ . get_block ( block_id, BlockTransactionsKind :: Hashes )
136
150
. await
137
151
. wrap_err ( "error fetching l2 block" ) ?
138
152
. expect ( "block should exist if it is finalized on the l1" ) ;
139
153
154
+ trace ! (
155
+ "find execution height of beacon slot {slot}. block-number: {}" ,
156
+ block. header. number
157
+ ) ;
158
+
140
159
Ok ( block. header . number )
141
160
}
142
161
143
162
pub async fn next_node_num_at_beacon_slot ( & self , slot : u64 ) -> Result < u64 > {
163
+ trace ! ( "find next node num at beacon slot {slot}" ) ;
164
+
144
165
let l1_height = self
145
166
. beacon
146
167
. get_height_at_skip_missing ( slot. try_into ( ) . expect ( "negative slot?" ) )
@@ -151,12 +172,15 @@ impl Arb {
151
172
. execution_payload
152
173
. block_number ;
153
174
175
+ trace ! ( "find next node num at beacon slot {slot}: l1-height: {l1_height}" ) ;
176
+
154
177
let slot_offset_bytes = self
155
178
. rollup_finalization_config
156
179
. l1_next_node_num_slot_offset_bytes
157
180
. inner ( )
158
181
. try_into ( )
159
182
. unwrap ( ) ;
183
+
160
184
let raw_slot = self
161
185
. l1_client
162
186
. get_storage_at (
@@ -171,27 +195,41 @@ impl Arb {
171
195
)
172
196
. await ?;
173
197
198
+ trace ! ( "find next node num at beacon slot {slot}: l1-height: {l1_height}: raw_slow: {raw_slot}" ) ;
199
+
174
200
let raw_slot: B256 = raw_slot. into ( ) ;
175
201
let latest_confirmed = u64:: from_be_bytes (
176
202
raw_slot. 0 [ slot_offset_bytes..slot_offset_bytes + 8 ]
177
203
. try_into ( )
178
204
. expect ( "size is correct; qed;" ) ,
179
205
) ;
180
206
207
+ trace ! ( "find next node num at beacon slot {slot}: l1-height: {l1_height}: latest_confirmed: {latest_confirmed}" ) ;
208
+
181
209
debug ! ( "l1_height {l1_height} is next node num {latest_confirmed}" , ) ;
182
210
Ok ( latest_confirmed)
183
211
}
184
212
}
185
213
186
214
impl Querier for Arb {
187
215
async fn get_execution_height ( & self , slot : i64 ) -> Result < ( i64 , i64 ) > {
216
+ trace ! ( "get execution height of beacon slot {slot}" ) ;
217
+
188
218
let height = ( || self . execution_height_of_beacon_slot ( slot. try_into ( ) . unwrap ( ) ) )
189
219
. retry (
190
220
& ConstantBuilder :: default ( )
191
221
. with_delay ( Duration :: from_millis ( 500 ) )
192
222
. with_max_times ( 60 ) ,
193
223
)
224
+ . notify ( |err, duration| {
225
+ trace ! (
226
+ "get execution height of beacon slot {slot} => error: {err:?}. retry after {}s" ,
227
+ duration. as_secs( )
228
+ ) ;
229
+ } )
194
230
. await ?;
231
+
232
+ trace ! ( "get execution height of beacon slot {slot}, found: {height}" ) ;
195
233
Ok ( ( slot, height. try_into ( ) . unwrap ( ) ) )
196
234
}
197
235
}
0 commit comments