Skip to content

Commit

Permalink
feat(kona-derive): Towards Derivation (#243)
Browse files Browse the repository at this point in the history
* feat: small fixes and kona deriver

* fixes

* fixes

* start derivation fixes

* first valid payload

* cleanup

* fixes

* fix: lints

* updates

* fix: lints

* fix: bin cleanup

* fix: lints

* fix: ignore tests for now

* fix: blob decoding

* fix: tests and logs

* fix: validation

* fix: update deps

* feat: superchain registry types

* fix: make sync less verbose by default

* fix: print l2 attributes timestamp

* fix: pipeline interface and cursor updates

* fixes

* cleanup

* fix: broken tests from scr

* fix: ecotone batches working

* attempt cov fix

* fix: move kona-sync to example

* fix: move validation to trusted-sync example

* fix(examples): validation hardcoded canyon timestamp

* fix: exclude examples in cannon and asterisc builds

* fix(primitives): make types impl hash

* chore: clean kona-derive examples

* fix(kona-derive): remove async bound on online pipeline constructor

* fix: batch encoding/decoding tests

* fix: batch reader test

* fix(derive): last batch queue test

* chore: remove execution validation log match

* fix: nit

* nit fix

---------

Co-authored-by: clabby <ben@clab.by>
  • Loading branch information
refcell and clabby authored Jun 15, 2024
1 parent b24f145 commit 2b667ea
Show file tree
Hide file tree
Showing 68 changed files with 761 additions and 1,161 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
with:
submodules: true
- name: Install stable
uses: dtolnay/rust-toolchain@stable
uses: dtolnay/rust-toolchain@1.78.0
with:
components: llvm-tools-preview
- name: Rust cache
Expand Down
66 changes: 56 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = ["crates/*", "bin/host", "bin/programs/*"]
members = ["crates/*", "bin/host", "bin/programs/*", "examples/*"]
default-members = ["bin/host", "bin/programs/*"]
exclude = ["fpvm-tests/cannon-rs-tests"]
resolver = "2"

Expand Down
25 changes: 22 additions & 3 deletions bin/programs/client/src/l2/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,15 @@ where
.next_block_excess_blob_gas()
.or_else(|| spec_id.is_enabled_in(SpecId::ECOTONE).then_some(0))
.map(|x| BlobExcessGasAndPrice::new(x as u64));
let next_block_base_fee = parent_header
.next_block_base_fee(config.base_fee_params_at_timestamp(payload_attrs.timestamp))
.unwrap_or_default();
// If the payload attribute timestamp is past canyon activation,
// use the canyon base fee params from the rollup config.
let base_fee_params = if config.is_canyon_active(payload_attrs.timestamp) {
config.canyon_base_fee_params.expect("Canyon base fee params not provided")
} else {
config.base_fee_params
};
let next_block_base_fee =
parent_header.next_block_base_fee(base_fee_params).unwrap_or_default();

BlockEnv {
number: U256::from(parent_header.number + 1),
Expand Down Expand Up @@ -581,6 +587,7 @@ mod test {
use super::*;
use alloy_primitives::{address, b256, hex};
use alloy_rlp::Decodable;
use kona_derive::types::{OP_BASE_FEE_PARAMS, OP_CANYON_BASE_FEE_PARAMS};
use kona_mpt::NoopTrieDBHinter;
use serde::Deserialize;
use std::{collections::HashMap, format};
Expand Down Expand Up @@ -640,6 +647,8 @@ mod test {
canyon_time: Some(0),
delta_time: Some(0),
ecotone_time: Some(0),
base_fee_params: OP_BASE_FEE_PARAMS,
canyon_base_fee_params: Some(OP_CANYON_BASE_FEE_PARAMS),
..Default::default()
};

Expand Down Expand Up @@ -691,6 +700,8 @@ mod test {
canyon_time: Some(0),
delta_time: Some(0),
ecotone_time: Some(0),
base_fee_params: OP_BASE_FEE_PARAMS,
canyon_base_fee_params: Some(OP_CANYON_BASE_FEE_PARAMS),
..Default::default()
};

Expand Down Expand Up @@ -746,6 +757,8 @@ mod test {
canyon_time: Some(0),
delta_time: Some(0),
ecotone_time: Some(0),
base_fee_params: OP_BASE_FEE_PARAMS,
canyon_base_fee_params: Some(OP_CANYON_BASE_FEE_PARAMS),
..Default::default()
};

Expand Down Expand Up @@ -808,6 +821,8 @@ mod test {
canyon_time: Some(0),
delta_time: Some(0),
ecotone_time: Some(0),
base_fee_params: OP_BASE_FEE_PARAMS,
canyon_base_fee_params: Some(OP_CANYON_BASE_FEE_PARAMS),
..Default::default()
};

Expand Down Expand Up @@ -864,6 +879,8 @@ mod test {
canyon_time: Some(0),
delta_time: Some(0),
ecotone_time: Some(0),
base_fee_params: OP_BASE_FEE_PARAMS,
canyon_base_fee_params: Some(OP_CANYON_BASE_FEE_PARAMS),
..Default::default()
};

Expand Down Expand Up @@ -929,6 +946,8 @@ mod test {
canyon_time: Some(0),
delta_time: Some(0),
ecotone_time: Some(0),
base_fee_params: OP_BASE_FEE_PARAMS,
canyon_base_fee_params: Some(OP_CANYON_BASE_FEE_PARAMS),
..Default::default()
};

Expand Down
45 changes: 2 additions & 43 deletions crates/derive/USAGE.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,5 @@
## Usage

```rust
use alloc::sync::Arc;
use kona_derive::online::*;
use kona_derive::pipeline::*;
use kona_primitives::{BlockInfo, L2BlockInfo, RollupConfig};
See the [examples][examples] for example usage of the derivation pipeline.

// Creates a new chain provider using the `L1_RPC_URL` environment variable.
let l1_rpc_url = std::env::var("L1_RPC_URL").expect("L1_RPC_URL must be set");
let chain_provider = AlloyChainProvider::new_http(l1_rpc_url.parse().unwrap());

// Creates a new l2 chain provider using the `L2_RPC_URL` environment variable.
let l2_rpc_url = std::env::var("L2_RPC_URL").expect("L2_RPC_URL must be set");
let l2_chain_provider = AlloyL2ChainProvider::new_http(l2_rpc_url.parse().unwrap());

// TODO(refcell): replace this will a rollup config
// fetched from the superchain-registry via network id.
let rollup_config = Arc::new(RollupConfig::default());

// Create the beacon client used to fetch blob data.
let beacon_url = std::env::var("BEACON_URL").expect("BEACON_URL must be set");
let beacon_client = OnlineBeaconClient::new_http(beacon_url.parse().unwrap());

// Build the online blob provider.
let blob_provider = OnlineBlobProvider::<_, SimpleSlotDerivation>::new(true, beacon_client, None, None);

// Build the ethereum data source
let dap_source = EthereumDataSource::new(chain_provider.clone(), blob_provider, &rollup_config);

// The payload attributes builder that is stateful.
let attributes_builder = StatefulAttributesBuilder::new(rollup_config.clone(), l2_chain_provider.clone(), chain_provider.clone());

// Build the pipeline.
let pipeline = PipelineBuilder::new()
.rollup_config(rollup_config)
.dap_source(dap_source)
.l2_chain_provider(l2_chain_provider)
.chain_provider(chain_provider)
.builder(attributes_builder)
.build();

// The pipeline should be at the default state.
assert_eq!(pipeline.tip, BlockInfo::default());
assert_eq!(pipeline.cursor, L2BlockInfo::default());
```
[examples]: ../../examples/
2 changes: 1 addition & 1 deletion crates/derive/src/online/alloy_providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl L2ChainProvider for AlloyL2ChainProvider {
rollup_config: Arc<RollupConfig>,
) -> Result<SystemConfig> {
if let Some(system_config) = self.system_config_by_number_cache.get(&number) {
return Ok(*system_config);
return Ok(system_config.clone());
}

let envelope = self.payload_by_number(number).await?;
Expand Down
Loading

0 comments on commit 2b667ea

Please sign in to comment.