Skip to content

Commit

Permalink
DA mock implementation (Sovereign-Labs#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkolad authored Aug 22, 2023
1 parent 72d7f36 commit d119b47
Show file tree
Hide file tree
Showing 29 changed files with 442 additions and 241 deletions.
11 changes: 10 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@ secp256k1 = { version = "0.27.0", default-features = false, features = ["global-
[patch.crates-io]
# See reth: https://github.com/paradigmxyz/reth/blob/main/Cargo.toml#L79
revm = { git = "https://github.com/bluealloy/revm/", branch = "release/v25" }
revm-primitives = { git = "https://github.com/bluealloy/revm/", branch = "release/v25" }
revm-primitives = { git = "https://github.com/bluealloy/revm/", branch = "release/v25" }
22 changes: 11 additions & 11 deletions adapters/celestia/src/da_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,8 @@ const fn default_request_timeout_seconds() -> u64 {
60
}

#[async_trait]
impl DaService for CelestiaService {
type RuntimeConfig = DaServiceConfig;

type Spec = CelestiaSpec;

type FilteredBlock = FilteredCelestiaBlock;

type Error = BoxError;

async fn new(config: Self::RuntimeConfig, chain_params: RollupParams) -> Self {
impl CelestiaService {
pub async fn new(config: DaServiceConfig, chain_params: RollupParams) -> Self {
let client = {
let mut headers = HeaderMap::new();
headers.insert(
Expand All @@ -146,6 +137,15 @@ impl DaService for CelestiaService {

Self::with_client(client, chain_params.namespace)
}
}

#[async_trait]
impl DaService for CelestiaService {
type Spec = CelestiaSpec;

type FilteredBlock = FilteredCelestiaBlock;

type Error = BoxError;

async fn get_finalized_at(&self, height: u64) -> Result<Self::FilteredBlock, Self::Error> {
let client = self.client.clone();
Expand Down
2 changes: 2 additions & 0 deletions examples/demo-prover/Cargo.lock

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

2 changes: 1 addition & 1 deletion examples/demo-prover/methods/guest/src/bin/rollup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::str::FromStr;

use celestia::types::NamespaceId;
use celestia::verifier::address::CelestiaAddress;
use celestia::verifier::{CelestiaSpec, CelestiaVerifier, ChainValidityCondition};
use celestia::verifier::{CelestiaSpec, CelestiaVerifier};
use celestia::{BlobWithSender, CelestiaHeader};
use const_rollup_config::{ROLLUP_NAMESPACE_RAW, SEQUENCER_DA_ADDRESS};
use demo_stf::app::create_zk_app_template;
Expand Down
3 changes: 2 additions & 1 deletion examples/demo-rollup/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
/demo_data
/path_readme
/path_readme
/tests/test_data/tmp
11 changes: 11 additions & 0 deletions examples/demo-rollup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ prometheus = "0.11.0"
prettytable-rs = "^0.10"
criterion = "0.5.1"

ethereum-types = "0.14.1"
ethers-core = { workspace = true }
ethers-contract = { workspace = true }
ethers-middleware = { workspace = true }
ethers-providers = { workspace = true }
ethers-signers = { workspace = true }
ethers = { workspace = true }
revm = { workspace = true }

sov-demo-rollup = { path = ".", features = ["experimental"] }

[features]
default = []
experimental = ["sov-ethereum/experimental"]
Expand Down
9 changes: 1 addition & 8 deletions examples/demo-rollup/benches/rng_xfers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,10 @@ impl DaSpec for RngDaSpec {

#[async_trait]
impl DaService for RngDaService {
type RuntimeConfig = ();
type Spec = RngDaSpec;
type FilteredBlock = MockBlock;
type Error = anyhow::Error;

async fn new(
_config: Self::RuntimeConfig,
_chain_params: <Self::Spec as DaSpec>::ChainParams,
) -> Self {
RngDaService::new()
}

async fn get_finalized_at(&self, height: u64) -> Result<Self::FilteredBlock, Self::Error> {
let num_bytes = height.to_le_bytes();
let mut barray = [0u8; 32];
Expand All @@ -128,6 +120,7 @@ impl DaService for RngDaService {
},
height,
validity_cond: MockValidityCond { is_valid: true },
blobs: Default::default(),
};

Ok(block)
Expand Down
9 changes: 5 additions & 4 deletions examples/demo-rollup/benches/rollup_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rng_xfers::{RngDaService, RngDaSpec};
use sov_db::ledger_db::{LedgerDB, SlotCommit};
use sov_modules_api::default_signature::private_key::DefaultPrivateKey;
use sov_modules_api::PrivateKey;
use sov_rollup_interface::mocks::{MockBlock, MockBlockHeader, MockHash, MockValidityCond};
use sov_rollup_interface::mocks::{MockBlock, MockBlockHeader, MockHash};
use sov_rollup_interface::services::da::DaService;
use sov_rollup_interface::stf::StateTransitionFunction;
use sov_stf_runner::{from_toml_path, RollupConfig};
Expand Down Expand Up @@ -73,9 +73,10 @@ fn rollup_bench(_bench: &mut Criterion) {
prev_hash: MockHash([0u8; 32]),
},
height,
validity_cond: MockValidityCond::default(),
validity_cond: Default::default(),
blobs: Default::default(),
};
blocks.push(filtered_block);
blocks.push(filtered_block.clone());

let blob_txs = da_service.extract_relevant_txs(&filtered_block);
blobs.push(blob_txs.clone());
Expand All @@ -86,7 +87,7 @@ fn rollup_bench(_bench: &mut Criterion) {
b.iter(|| {
let filtered_block = &blocks[height as usize];

let mut data_to_commit = SlotCommit::new(*filtered_block);
let mut data_to_commit = SlotCommit::new(filtered_block.clone());
let apply_block_result = demo.apply_slot(
Default::default(),
data_to_commit.slot_data(),
Expand Down
9 changes: 5 additions & 4 deletions examples/demo-rollup/benches/rollup_coarse_measure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rng_xfers::{RngDaService, RngDaSpec};
use sov_db::ledger_db::{LedgerDB, SlotCommit};
use sov_modules_api::default_signature::private_key::DefaultPrivateKey;
use sov_modules_api::PrivateKey;
use sov_rollup_interface::mocks::{MockBlock, MockBlockHeader, MockHash, MockValidityCond};
use sov_rollup_interface::mocks::{MockBlock, MockBlockHeader, MockHash};
use sov_rollup_interface::services::da::DaService;
use sov_rollup_interface::stf::StateTransitionFunction;
use sov_stf_runner::{from_toml_path, RollupConfig};
Expand Down Expand Up @@ -122,9 +122,10 @@ async fn main() -> Result<(), anyhow::Error> {
prev_hash: MockHash([0u8; 32]),
},
height,
validity_cond: MockValidityCond::default(),
validity_cond: Default::default(),
blobs: Default::default(),
};
blocks.push(filtered_block);
blocks.push(filtered_block.clone());

let blob_txs = da_service.extract_relevant_txs(&filtered_block);
blobs.push(blob_txs);
Expand All @@ -136,7 +137,7 @@ async fn main() -> Result<(), anyhow::Error> {
for height in start_height..end_height {
let filtered_block = &blocks[height as usize];

let mut data_to_commit = SlotCommit::new(*filtered_block);
let mut data_to_commit = SlotCommit::new(filtered_block.clone());

let now = Instant::now();

Expand Down
11 changes: 6 additions & 5 deletions examples/demo-rollup/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@

pub mod register_rpc;
mod rollup;
use std::str::FromStr;

use celestia::types::NamespaceId;
use celestia::verifier::address::CelestiaAddress;
use const_rollup_config::{ROLLUP_NAMESPACE_RAW, SEQUENCER_DA_ADDRESS};
use const_rollup_config::ROLLUP_NAMESPACE_RAW;
use demo_stf::app::DefaultPrivateKey;
use demo_stf::genesis_config::create_demo_genesis_config;
use demo_stf::runtime::GenesisConfig;
pub use rollup::{new_rollup_with_celestia_da, Rollup};
use sov_db::ledger_db::LedgerDB;
use sov_modules_api::default_context::DefaultContext;
use sov_rollup_interface::AddressTrait;

/// The rollup stores its data in the namespace b"sov-test" on Celestia
/// You can change this constant to point your rollup at a different namespace
Expand Down Expand Up @@ -41,7 +40,9 @@ pub struct HexKey {
/// ```rust,no_run
/// const SEQUENCER_DA_ADDRESS: [u8;47] = *b"celestia1qp09ysygcx6npted5yc0au6k9lner05yvs9208";
/// ```
pub fn get_genesis_config() -> GenesisConfig<DefaultContext> {
pub fn get_genesis_config<D: AddressTrait>(
sequencer_da_address: D,
) -> GenesisConfig<DefaultContext> {
let hex_key: HexKey = serde_json::from_slice(include_bytes!(
"../../test-data/keys/token_deployer_private_key.json"
))
Expand All @@ -52,7 +53,7 @@ pub fn get_genesis_config() -> GenesisConfig<DefaultContext> {
hex_key.address,
"Inconsistent key data",
);
let sequencer_da_address = CelestiaAddress::from_str(SEQUENCER_DA_ADDRESS).unwrap();

create_demo_genesis_config(
100000000,
sequencer_private_key.default_address(),
Expand Down
26 changes: 19 additions & 7 deletions examples/demo-rollup/src/rollup.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use std::str::FromStr;

use anyhow::Context;
use celestia::verifier::address::CelestiaAddress;
use celestia::verifier::RollupParams;
use celestia::CelestiaService;
use const_rollup_config::SEQUENCER_DA_ADDRESS;
use demo_stf::app::{App, DefaultContext};
use demo_stf::runtime::get_rpc_methods;
use demo_stf::runtime::{get_rpc_methods, GenesisConfig};
use risc0_adapter::host::Risc0Verifier;
use sov_db::ledger_db::LedgerDB;
use sov_rollup_interface::services::da::DaService;
Expand All @@ -18,10 +22,16 @@ use crate::{get_genesis_config, initialize_ledger, ROLLUP_NAMESPACE};

/// Dependencies needed to run the rollup.
pub struct Rollup<Vm: Zkvm, DA: DaService + Clone> {
app: App<Vm, DA::Spec>,
da_service: DA,
ledger_db: LedgerDB,
runner_config: RunnerConfig,
/// Implementation of the STF.
pub app: App<Vm, DA::Spec>,
/// Data availability service.
pub da_service: DA,
/// Ledger db.
pub ledger_db: LedgerDB,
/// Runner configuration.
pub runner_config: RunnerConfig,
/// Initial rollup configuration.
pub genesis_config: GenesisConfig<DefaultContext>,
}

/// Creates celestia based rollup.
Expand All @@ -43,12 +53,15 @@ pub async fn new_rollup_with_celestia_da(
.await;

let app = App::new(rollup_config.storage);
let sequencer_da_address = CelestiaAddress::from_str(SEQUENCER_DA_ADDRESS)?;
let genesis_config = get_genesis_config(sequencer_da_address);

Ok(Rollup {
app,
da_service,
ledger_db,
runner_config: rollup_config.runner,
genesis_config,
})
}

Expand All @@ -67,15 +80,14 @@ impl<Vm: Zkvm, DA: DaService<Error = anyhow::Error> + Clone> Rollup<Vm, DA> {
}

let storage = self.app.get_storage();
let genesis_config = get_genesis_config();

let mut runner = StateTransitionRunner::new(
self.runner_config,
self.da_service,
self.ledger_db,
self.app.stf,
storage.is_empty(),
genesis_config,
self.genesis_config,
)?;

runner.start_rpc_server(methods).await;
Expand Down
7 changes: 4 additions & 3 deletions examples/demo-rollup/src/test_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use proptest::{prop_compose, proptest};
use reqwest::header::CONTENT_TYPE;
use serde_json::json;
use sov_db::ledger_db::{LedgerDB, SlotCommit};
use sov_rollup_interface::mocks::MockValidityCond;
#[cfg(test)]
use sov_rollup_interface::mocks::{MockBlock, MockBlockHeader, MockHash};
use sov_rollup_interface::services::da::SlotData;
Expand Down Expand Up @@ -116,7 +115,8 @@ fn regular_test_helper(payload: serde_json::Value, expected: &serde_json::Value)
prev_hash: MockHash(sha2::Sha256::digest(b"prev_header")),
},
height: 0,
validity_cond: MockValidityCond::default(),
validity_cond: Default::default(),
blobs: Default::default(),
})];

let batches = vec![
Expand Down Expand Up @@ -320,7 +320,8 @@ prop_compose! {
prev_hash,
},
height: 0,
validity_cond: MockValidityCond::default()
validity_cond: Default::default(),
blobs: Default::default()
});

total_num_batches += batches.len();
Expand Down
Loading

0 comments on commit d119b47

Please sign in to comment.