Skip to content

Commit 1a1c35b

Browse files
authored
fix(hubble): arbitrum consensus height tracking (#3337)
2 parents aec3816 + 6c25cad commit 1a1c35b

File tree

5 files changed

+59
-18
lines changed

5 files changed

+59
-18
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
}

hubble/src/indexer/eth/block_handle.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use alloy::rpc::types::Block;
1+
use alloy::network::AnyRpcBlock;
22
use axum::async_trait;
33
use color_eyre::eyre::Report;
44
use futures::{stream::FuturesOrdered, Stream};
@@ -21,7 +21,7 @@ use crate::{
2121

2222
#[derive(Clone)]
2323
pub enum BlockDetails {
24-
Lazy(Block),
24+
Lazy(AnyRpcBlock),
2525
Eager(Option<BlockInsert>),
2626
}
2727

@@ -30,7 +30,7 @@ pub enum BlockDetails {
3030
pub struct BlockInsert {
3131
pub chain_id: ChainId,
3232
pub hash: String,
33-
pub header: Block,
33+
pub header: AnyRpcBlock,
3434
pub height: i32,
3535
pub time: OffsetDateTime,
3636
pub transactions: Vec<TransactionInsert>,

hubble/src/indexer/eth/fetcher_client.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ use std::{collections::HashMap, fmt::Display};
22

33
use alloy::{
44
eips::BlockId,
5+
network::AnyRpcBlock,
56
primitives::{Address, BloomInput, FixedBytes},
6-
rpc::types::{Block, BlockTransactionsKind, Filter, Log},
7+
rpc::types::{BlockTransactionsKind, Filter, Log},
78
};
89
use axum::async_trait;
910
use color_eyre::eyre::Report;
@@ -45,7 +46,7 @@ trait BlockReferenceProvider {
4546
fn block_reference(&self) -> Result<BlockReference, Report>;
4647
}
4748

48-
impl BlockReferenceProvider for Block {
49+
impl BlockReferenceProvider for AnyRpcBlock {
4950
fn block_reference(&self) -> Result<BlockReference, Report> {
5051
Ok(BlockReference {
5152
height: self.header.number,
@@ -110,6 +111,8 @@ impl EthFetcherClient {
110111
)
111112
.await;
112113

114+
info!("block: {block:?}");
115+
113116
match block {
114117
Ok(rpc_result) => match rpc_result {
115118
Some(result) => {
@@ -147,7 +150,7 @@ impl EthFetcherClient {
147150

148151
pub async fn fetch_details(
149152
&self,
150-
block: &Block,
153+
block: &AnyRpcBlock,
151154
provider_id: RpcProviderId,
152155
) -> Result<Option<BlockInsert>, IndexerError> {
153156
let block_reference = block.block_reference()?;

hubble/src/indexer/eth/postgres.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use alloy::rpc::types::Block;
1+
use alloy::network::AnyRpcBlock;
22
use itertools::Itertools;
33
use serde::{Deserialize, Serialize};
44
use sqlx::{PgPool, Postgres, Transaction};
@@ -26,7 +26,7 @@ pub struct PgLog {
2626
#[derive(Serialize, Deserialize)]
2727
pub struct PgLogData {
2828
pub transactions: Vec<TransactionInsert>,
29-
pub header: Block,
29+
pub header: AnyRpcBlock,
3030
}
3131

3232
impl From<BlockInsert> for PgLog {

hubble/src/indexer/eth/provider.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use alloy::{
22
eips::BlockId,
3-
network::{Ethereum, Network},
3+
network::{AnyNetwork, AnyRpcBlock, Network},
44
primitives::TxHash,
55
providers::{Provider as AlloyProvider, ProviderBuilder, RootProvider},
6-
rpc::types::{Block, BlockTransactionsKind, Filter, Log},
6+
rpc::types::{BlockTransactionsKind, Filter, Log},
77
transports::{
88
http::{Client, Http},
99
RpcError, TransportErrorKind,
@@ -15,7 +15,7 @@ use crate::race_client::{RaceClient, RaceClientId, RaceClientResponse};
1515

1616
#[derive(Clone, Debug)]
1717
pub struct Provider {
18-
pub rpc_client: RaceClient<RootProvider<Http<Client>>>,
18+
pub rpc_client: RaceClient<RootProvider<Http<Client>, AnyNetwork>>,
1919
}
2020

2121
#[derive(Clone, Debug, Copy)]
@@ -56,7 +56,7 @@ impl Provider {
5656
rpc_client: RaceClient::new(
5757
rpc_urls
5858
.into_iter()
59-
.map(|url| ProviderBuilder::new().on_http(url))
59+
.map(|url| ProviderBuilder::new().network::<AnyNetwork>().on_http(url))
6060
.collect(),
6161
),
6262
}
@@ -77,7 +77,7 @@ impl Provider {
7777
id: BlockId,
7878
kind: BlockTransactionsKind,
7979
provider_id: Option<RpcProviderId>,
80-
) -> Result<Option<RpcResult<Block>>, RpcError<TransportErrorKind>> {
80+
) -> Result<Option<RpcResult<AnyRpcBlock>>, RpcError<TransportErrorKind>> {
8181
self.rpc_client
8282
.race_some(provider_id.map(Into::into), |c| c.get_block(id, kind))
8383
.await
@@ -100,7 +100,7 @@ impl Provider {
100100
tx_hash: TxHash,
101101
provider_id: Option<RpcProviderId>,
102102
) -> Result<
103-
Option<RpcResult<<Ethereum as Network>::TransactionResponse>>,
103+
Option<RpcResult<<AnyNetwork as Network>::TransactionResponse>>,
104104
RpcError<TransportErrorKind>,
105105
> {
106106
self.rpc_client

0 commit comments

Comments
 (0)