Skip to content

Commit d6d67ec

Browse files
authored
chore(taiko-client-rs): several improvments for preconfirmation-driver (#21330)
1 parent e531244 commit d6d67ec

File tree

11 files changed

+66
-21
lines changed

11 files changed

+66
-21
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
**/target

packages/taiko-client-rs/Dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ COPY packages/preconfirmation-p2p packages/preconfirmation-p2p
1212

1313
WORKDIR /app/packages/taiko-client-rs
1414

15-
RUN cargo build --release
15+
RUN --mount=type=cache,target=/usr/local/cargo/registry \
16+
--mount=type=cache,target=/usr/local/cargo/git \
17+
--mount=type=cache,target=/app/packages/taiko-client-rs/target \
18+
cargo build --release && \
19+
cp /app/packages/taiko-client-rs/target/release/taiko-client /tmp/taiko-client
1620

1721
FROM ubuntu:22.04
1822

@@ -22,6 +26,6 @@ RUN apt-get update && \
2226

2327
WORKDIR /app
2428

25-
COPY --from=build /app/packages/taiko-client-rs/target/release/taiko-client ./
29+
COPY --from=build /tmp/taiko-client ./taiko-client
2630

2731
ENTRYPOINT ["./taiko-client"]

packages/taiko-client-rs/crates/preconfirmation-driver/src/rpc/server.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ fn api_error_to_rpc(err: PreconfirmationClientError) -> ErrorObjectOwned {
201201
LookaheadError::SystemTime(_) |
202202
LookaheadError::UnknownChain(_) |
203203
LookaheadError::MissingLookahead(_) |
204-
LookaheadError::CorruptLookaheadCache { .. } => {
204+
LookaheadError::CorruptLookaheadCache { .. } |
205+
LookaheadError::GetLookaheadStoreConfig(_) |
206+
LookaheadError::GetPreconfWhitelistAddress(_) => {
205207
PreconfRpcErrorCode::LookaheadUnavailable.code()
206208
}
207209
},

packages/taiko-client-rs/crates/preconfirmation-driver/src/runner/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::{
2121
},
2222
};
2323
use protocol::preconfirmation::LookaheadResolver;
24+
use rpc::beacon::BeaconClient;
2425

2526
use preconf_ingress_sync::PreconfIngressSync;
2627

@@ -76,6 +77,9 @@ pub enum RunnerError {
7677
/// Preconfirmation client error.
7778
#[error(transparent)]
7879
Preconfirmation(#[from] PreconfirmationClientError),
80+
/// Failed to fetch beacon genesis for lookahead resolver.
81+
#[error("beacon genesis fetch failed: {0}")]
82+
BeaconGenesis(String),
7983
}
8084

8185
/// Configuration for the preconfirmation driver runner.
@@ -139,8 +143,13 @@ impl PreconfirmationDriverRunner {
139143

140144
// Build the lookahead resolver and start its background event scanner
141145
let l1_source = self.config.driver_config.client.l1_provider_source.clone();
146+
let beacon_client = BeaconClient::new(self.config.driver_config.l1_beacon_endpoint.clone())
147+
.await
148+
.map_err(|e| RunnerError::BeaconGenesis(e.to_string()))?;
149+
let genesis_timestamp = beacon_client.genesis_time();
150+
142151
let (lookahead_resolver, _scanner_handle) =
143-
LookaheadResolver::new(inbox_address, l1_source)
152+
LookaheadResolver::new_with_genesis(inbox_address, l1_source, genesis_timestamp)
144153
.await
145154
.map_err(PreconfirmationClientError::from)?;
146155

packages/taiko-client-rs/crates/protocol/src/preconfirmation/lookahead/client.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use bindings::{
55
};
66

77
use super::{LookaheadData, LookaheadError, ProposerContext, Result};
8+
use tracing::debug;
89

910
/// Thin wrapper around on-chain lookahead contracts resolved via the Inbox configuration.
1011
#[derive(Clone)]
@@ -19,6 +20,7 @@ impl<P: Provider + Clone> LookaheadClient<P> {
1920
pub async fn new(inbox_address: Address, provider: P) -> Result<Self> {
2021
let inbox = InboxInstance::new(inbox_address, provider.clone());
2122
let config = inbox.getConfig().call().await.map_err(LookaheadError::InboxConfig)?;
23+
debug!("Inbox config: {:?}", config);
2224

2325
let lookahead_store = LookaheadStoreInstance::new(config.proposerChecker, provider);
2426

packages/taiko-client-rs/crates/protocol/src/preconfirmation/lookahead/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ pub enum LookaheadError {
3737
/// Failure when querying the LookaheadStore.
3838
#[error("failed to call lookahead store: {0}")]
3939
Lookahead(alloy_contract::Error),
40+
/// Failed to fetch lookahead store config from the LookaheadStore.
41+
#[error("failed to get lookahead store config: {0}")]
42+
GetLookaheadStoreConfig(alloy_contract::Error),
43+
/// Failed to fetch preconf whitelist address from the LookaheadStore.
44+
#[error("failed to get preconf whitelist address: {0}")]
45+
GetPreconfWhitelistAddress(alloy_contract::Error),
4046
/// Failure when querying the preconfirmation whitelist.
4147
#[error("failed to call preconf whitelist: {0}")]
4248
PreconfWhitelist(alloy_contract::Error),

packages/taiko-client-rs/crates/protocol/src/preconfirmation/lookahead/resolver/core.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ impl LookaheadResolver {
9999
.getLookaheadStoreConfig()
100100
.call()
101101
.await
102-
.map_err(LookaheadError::Lookahead)?;
102+
.map_err(LookaheadError::GetLookaheadStoreConfig)?;
103103

104104
let preconf_whitelist = PreconfWhitelistInstance::new(
105105
client
106106
.lookahead_store()
107107
.preconfWhitelist()
108108
.call()
109109
.await
110-
.map_err(LookaheadError::Lookahead)?,
110+
.map_err(LookaheadError::GetPreconfWhitelistAddress)?,
111111
provider.clone(),
112112
);
113113

packages/taiko-client-rs/crates/rpc/src/beacon.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,13 @@ impl BeaconClient {
335335
pub const fn slots_per_epoch(&self) -> u64 {
336336
self.slots_per_epoch
337337
}
338+
339+
/// Return the beacon genesis timestamp (seconds since UNIX epoch).
340+
///
341+
/// Fetched from `/eth/v1/beacon/genesis` during client construction.
342+
pub const fn genesis_time(&self) -> u64 {
343+
self.genesis_time
344+
}
338345
}
339346

340347
fn parse_blob(value: &str) -> Result<Blob, BlobDataError> {

packages/taiko-client-rs/crates/rpc/src/client.rs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,36 +85,49 @@ pub struct ClientConfig {
8585
impl Client<FillProvider<JoinedRecommendedFillers, RootProvider>> {
8686
/// Create a new `Client` without a wallet from the given configuration.
8787
pub async fn new(config: ClientConfig) -> Result<Self> {
88-
Self::new_with_l1_provider(config.l1_provider_source.to_provider().await?, config).await
88+
let l1_provider = config.l1_provider_source.to_provider().await.map_err(|e| {
89+
RpcClientError::Connection(format!("L1 WebSocket (l1.ws) connection failed: {}", e))
90+
})?;
91+
Self::new_with_l1_provider(l1_provider, config).await
8992
}
9093
}
9194

9295
impl Client<FillProvider<JoinedRecommendedFillersWithWallet, RootProvider>> {
9396
/// Create a new `Client` with a wallet from the given configuration.
9497
pub async fn new_with_wallet(config: ClientConfig, private_key: B256) -> Result<Self> {
95-
Self::new_with_l1_provider(
96-
config.l1_provider_source.to_provider_with_wallet(private_key).await?,
97-
config,
98-
)
99-
.await
98+
let l1_provider =
99+
config.l1_provider_source.to_provider_with_wallet(private_key).await.map_err(|e| {
100+
RpcClientError::Connection(format!("L1 WebSocket (l1.ws) connection failed: {}", e))
101+
})?;
102+
Self::new_with_l1_provider(l1_provider, config).await
100103
}
101104
}
102105

103106
impl<P: Provider + Clone> Client<P> {
104107
/// Create a new `Client` from the given L1 provider and configuration.
105108
async fn new_with_l1_provider(l1_provider: P, config: ClientConfig) -> Result<Self> {
106-
let l2_provider = connect_provider_with_timeout(config.l2_provider_url).await?;
109+
let l2_provider =
110+
connect_provider_with_timeout(config.l2_provider_url.clone()).await.map_err(|e| {
111+
RpcClientError::Connection(format!(
112+
"L2 HTTP RPC (l2.http) connection failed for {}: {}",
113+
config.l2_provider_url, e
114+
))
115+
})?;
107116
let jwt_secret = read_jwt_secret(config.jwt_secret.as_path()).ok_or_else(|| {
108117
RpcClientError::JwtSecretReadFailed(config.jwt_secret.display().to_string())
109118
})?;
110119
let l2_auth_provider =
111120
build_jwt_http_provider(config.l2_auth_provider_url.clone(), jwt_secret);
112121

122+
let chain_id = l2_provider.get_chain_id().await.map_err(|e| {
123+
RpcClientError::Rpc(format!(
124+
"L2 HTTP RPC (l2.http) failed to get chain id from {}: {}",
125+
config.l2_provider_url, e
126+
))
127+
})?;
128+
113129
let inbox = InboxInstance::new(config.inbox_address, l1_provider.clone());
114-
let anchor = AnchorInstance::new(
115-
get_treasury_address(l2_provider.get_chain_id().await?),
116-
l2_auth_provider.clone(),
117-
);
130+
let anchor = AnchorInstance::new(get_treasury_address(chain_id), l2_auth_provider.clone());
118131

119132
info!(
120133
inbox_address = ?config.inbox_address,

packages/taiko-client-rs/crates/test-harness/src/driver/proposal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub async fn wait_for_proposal_id(
5959
return Err(anyhow!(
6060
"timed out waiting for proposal {expected_proposal_id}, current: {}",
6161
*rx.borrow()
62-
))
62+
));
6363
}
6464
}
6565
}

0 commit comments

Comments
 (0)