Skip to content

Commit 4f1bf1e

Browse files
committed
fix(hubble): arbitrum consensus height tracking
1 parent 77a7924 commit 4f1bf1e

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

hubble/src/arb.rs

+42-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use alloy::{
1111
};
1212
use backon::{ConstantBuilder, ExponentialBuilder, Retryable};
1313
use color_eyre::eyre::{eyre, ContextCompat, Result, WrapErr};
14-
use tracing::{debug, info};
14+
use tracing::{debug, info, trace};
1515
use unionlabs::{bounded::BoundedU32, hash::H160, uint::U256};
1616

1717
use crate::{
@@ -86,6 +86,8 @@ impl Config {
8686
.retry(&ExponentialBuilder::default())
8787
.await?;
8888

89+
info!("fetched db chain_id for chain {l2_chain_id} => {chain_id:?}");
90+
8991
let querier = Arb {
9092
l1_client: ProviderBuilder::new().on_http(self.l1_url),
9193
l2_client,
@@ -102,8 +104,13 @@ impl Config {
102104
impl Arb {
103105
// NOTE: Copied from chain_utils
104106
async fn execution_height_of_beacon_slot(&self, slot: u64) -> Result<u64> {
107+
trace!("find execution height of beacon slot {slot}");
108+
105109
// read the next_node_num at l1.execution_height(beacon_slot), then from there filter for `NodeCreated`
106110
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+
107114
let [event] = self
108115
.l1_client
109116
.get_logs(
@@ -123,24 +130,38 @@ impl Arb {
123130
.await
124131
.wrap_err("error fetching `NodeCreated` log from l1")?
125132
.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+
128137
let event = NodeCreated::decode_log(&event.inner, true).unwrap();
138+
139+
trace!("find execution height of beacon slot {slot}. event(decoded): {event:?}");
129140
let block_id = BlockId::Hash(RpcBlockHash {
130141
block_hash: FixedBytes::from_slice(event.assertion.0 .0 .0[0].as_ref()),
131142
require_canonical: None,
132143
});
144+
145+
trace!("find execution height of beacon slot {slot}. block-id: {block_id}");
146+
133147
let block = self
134148
.l2_client
135-
.get_block(block_id, BlockTransactionsKind::Full)
149+
.get_block(block_id, BlockTransactionsKind::Hashes)
136150
.await
137151
.wrap_err("error fetching l2 block")?
138152
.expect("block should exist if it is finalized on the l1");
139153

154+
trace!(
155+
"find execution height of beacon slot {slot}. block-number: {}",
156+
block.header.number
157+
);
158+
140159
Ok(block.header.number)
141160
}
142161

143162
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+
144165
let l1_height = self
145166
.beacon
146167
.get_height_at_skip_missing(slot.try_into().expect("negative slot?"))
@@ -151,12 +172,15 @@ impl Arb {
151172
.execution_payload
152173
.block_number;
153174

175+
trace!("find next node num at beacon slot {slot}: l1-height: {l1_height}");
176+
154177
let slot_offset_bytes = self
155178
.rollup_finalization_config
156179
.l1_next_node_num_slot_offset_bytes
157180
.inner()
158181
.try_into()
159182
.unwrap();
183+
160184
let raw_slot = self
161185
.l1_client
162186
.get_storage_at(
@@ -171,27 +195,41 @@ impl Arb {
171195
)
172196
.await?;
173197

198+
trace!("find next node num at beacon slot {slot}: l1-height: {l1_height}: raw_slow: {raw_slot}");
199+
174200
let raw_slot: B256 = raw_slot.into();
175201
let latest_confirmed = u64::from_be_bytes(
176202
raw_slot.0[slot_offset_bytes..slot_offset_bytes + 8]
177203
.try_into()
178204
.expect("size is correct; qed;"),
179205
);
180206

207+
trace!("find next node num at beacon slot {slot}: l1-height: {l1_height}: latest_confirmed: {latest_confirmed}");
208+
181209
debug!("l1_height {l1_height} is next node num {latest_confirmed}",);
182210
Ok(latest_confirmed)
183211
}
184212
}
185213

186214
impl Querier for Arb {
187215
async fn get_execution_height(&self, slot: i64) -> Result<(i64, i64)> {
216+
trace!("get execution height of beacon slot {slot}");
217+
188218
let height = (|| self.execution_height_of_beacon_slot(slot.try_into().unwrap()))
189219
.retry(
190220
&ConstantBuilder::default()
191221
.with_delay(Duration::from_millis(500))
192222
.with_max_times(60),
193223
)
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+
})
194230
.await?;
231+
232+
trace!("get execution height of beacon slot {slot}, found: {height}");
195233
Ok((slot, height.try_into().unwrap()))
196234
}
197235
}

0 commit comments

Comments
 (0)