Skip to content

Commit 9fd1bb0

Browse files
feat(taiko-client-rs): check Shasta fork activation based on timestamp (#20621)
1 parent e259627 commit 9fd1bb0

File tree

9 files changed

+85
-209
lines changed

9 files changed

+85
-209
lines changed

packages/taiko-client-rs/Cargo.lock

Lines changed: 14 additions & 115 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/taiko-client-rs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ clap = { version = "4", features = ["derive", "env"] }
3131

3232
# observability
3333
metrics = "0.24"
34-
metrics-exporter-prometheus = "0.15"
34+
metrics-exporter-prometheus = { version = "0.15", default-features = false, features = ["http-listener"] }
3535
tracing = "0.1"
3636
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
3737

packages/taiko-client-rs/crates/driver/src/derivation/pipeline/error.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ pub enum DerivationError {
7979
/// Execution engine returned an unexpected block number.
8080
#[error("engine returned block {actual} but derivation expected {expected}")]
8181
UnexpectedBlockNumber { expected: u64, actual: u64 },
82+
/// Attempted to derive blocks before the Shasta fork is active.
83+
#[error(
84+
"shasta fork inactive: activation timestamp {activation_timestamp}, parent timestamp {parent_timestamp}"
85+
)]
86+
ShastaForkInactive { activation_timestamp: u64, parent_timestamp: u64 },
8287
/// Generic error bucket.
8388
#[error(transparent)]
8489
Other(#[from] AnyhowError),

packages/taiko-client-rs/crates/driver/src/derivation/pipeline/shasta/pipeline/mod.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ use bindings::{
1616
};
1717
use event_indexer::indexer::ShastaEventIndexer;
1818
use protocol::shasta::{
19-
constants::shasta_fork_height_for_chain, manifest::DerivationSourceManifest,
19+
constants::shasta_fork_timestamp_for_chain, manifest::DerivationSourceManifest,
2020
};
21-
use rpc::{blob::BlobDataSource, client::Client, error::RpcClientError};
21+
use rpc::{blob::BlobDataSource, client::Client};
2222

2323
use crate::{
2424
derivation::{
@@ -54,7 +54,7 @@ where
5454
anchor_constructor: AnchorTxConstructor<P>,
5555
derivation_source_manifest_fetcher:
5656
Arc<dyn ManifestFetcher<Manifest = DerivationSourceManifest>>,
57-
shasta_fork_height: u64,
57+
shasta_fork_timestamp: u64,
5858
}
5959

6060
impl<P> ShastaDerivationPipeline<P>
@@ -73,20 +73,15 @@ where
7373
let source_manifest_fetcher: Arc<dyn ManifestFetcher<Manifest = DerivationSourceManifest>> =
7474
Arc::new(ShastaSourceManifestFetcher::new(blob_source.clone()));
7575
let anchor_constructor = AnchorTxConstructor::new(rpc.clone()).await?;
76-
let chain_id = rpc
77-
.l2_provider
78-
.get_chain_id()
79-
.await
80-
.map_err(|err| DerivationError::Rpc(RpcClientError::Provider(err.to_string())))?;
81-
let shasta_fork_height = shasta_fork_height_for_chain(chain_id)
76+
let chain_id = rpc.l2_provider.get_chain_id().await?;
77+
let shasta_fork_timestamp = shasta_fork_timestamp_for_chain(chain_id)
8278
.map_err(|err| DerivationError::Other(err.into()))?;
83-
8479
Ok(Self {
8580
rpc,
8681
indexer,
8782
anchor_constructor,
8883
derivation_source_manifest_fetcher: source_manifest_fetcher,
89-
shasta_fork_height,
84+
shasta_fork_timestamp,
9085
})
9186
}
9287

@@ -162,7 +157,7 @@ where
162157
async fn initialize_parent_state(
163158
&self,
164159
parent_block: &RpcBlock<TxEnvelope>,
165-
) -> Result<(ParentState, u64), DerivationError> {
160+
) -> Result<ParentState, DerivationError> {
166161
let anchor_state = self.rpc.shasta_anchor_state_by_hash(parent_block.hash()).await?;
167162
let parent_header = parent_block.header.inner.clone();
168163

@@ -186,9 +181,10 @@ where
186181
header: parent_header,
187182
bond_instructions_hash: anchor_state.bond_instructions_hash,
188183
anchor_block_number: anchor_state.anchor_block_number,
184+
shasta_fork_timestamp: self.shasta_fork_timestamp,
189185
};
190186

191-
Ok((state, self.shasta_fork_height))
187+
Ok(state)
192188
}
193189
}
194190

@@ -269,14 +265,12 @@ where
269265
},
270266
)?;
271267

272-
let (mut parent_state, shasta_fork_height) =
273-
self.initialize_parent_state(&parent_block).await?;
268+
let mut parent_state = self.initialize_parent_state(&parent_block).await?;
274269

275270
self.build_payloads_from_sources(
276271
sources,
277272
&meta,
278273
proposal_origin_block_hash,
279-
shasta_fork_height,
280274
&mut parent_state,
281275
applier,
282276
)

0 commit comments

Comments
 (0)