Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More succint GenesisPaths initialization #1012

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions examples/demo-rollup/benches/node/rollup_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,6 @@ use sov_rollup_interface::stf::StateTransitionFunction;
use sov_stf_runner::{from_toml_path, RollupConfig};
use tempfile::TempDir;

const TEST_GENESIS_PATHS: GenesisPaths<&str> = GenesisPaths {
bank_genesis_path: "../test-data/genesis/integration-tests/bank.json",
sequencer_genesis_path: "../test-data/genesis/integration-tests/sequencer_registry.json",
value_setter_genesis_path: "../test-data/genesis/integration-tests/value_setter.json",
accounts_genesis_path: "../test-data/genesis/integration-tests/accounts.json",
chain_state_genesis_path: "../test-data/genesis/integration-tests/chain_state.json",
nft_path: "../test-data/genesis/integration-tests/nft.json",
#[cfg(feature = "experimental")]
evm_genesis_path: "../test-data/genesis/integration-tests/evm.json",
};

fn rollup_bench(_bench: &mut Criterion) {
let start_height: u64 = 0u64;
let mut end_height: u64 = 100u64;
Expand Down Expand Up @@ -63,7 +52,7 @@ fn rollup_bench(_bench: &mut Criterion) {

let demo_genesis_config = get_genesis_config(
sequencer_da_address,
&TEST_GENESIS_PATHS,
&GenesisPaths::from_dir("../test-data/genesis/integration-tests"),
#[cfg(feature = "experimental")]
Default::default(),
);
Expand Down
13 changes: 1 addition & 12 deletions examples/demo-rollup/benches/node/rollup_coarse_measure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,6 @@ extern crate prettytable;
use prettytable::Table;
use sov_modules_stf_template::TxEffect;

const TEST_GENESIS_PATHS: GenesisPaths<&str> = GenesisPaths {
bank_genesis_path: "../test-data/genesis/integration-tests/bank.json",
sequencer_genesis_path: "../test-data/genesis/integration-tests/sequencer_registry.json",
value_setter_genesis_path: "../test-data/genesis/integration-tests/value_setter.json",
accounts_genesis_path: "../test-data/genesis/integration-tests/accounts.json",
chain_state_genesis_path: "../test-data/genesis/integration-tests/chain_state.json",
nft_path: "../test-data/genesis/integration-tests/nft.json",
#[cfg(feature = "experimental")]
evm_genesis_path: "../test-data/genesis/integration-tests/evm.json",
};

fn print_times(
total: Duration,
apply_block_time: Duration,
Expand Down Expand Up @@ -120,7 +109,7 @@ async fn main() -> Result<(), anyhow::Error> {

let demo_genesis_config = get_genesis_config(
sequencer_da_address,
&TEST_GENESIS_PATHS,
&GenesisPaths::from_dir("../test-data/genesis/integration-tests"),
#[cfg(feature = "experimental")]
Default::default(),
);
Expand Down
13 changes: 1 addition & 12 deletions examples/demo-rollup/benches/prover/prover_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,6 @@ use sov_rollup_interface::zk::ZkvmHost;
use sov_stf_runner::{from_toml_path, RollupConfig};
use tempfile::TempDir;

const GENESIS_PATHS: GenesisPaths<&str> = GenesisPaths {
bank_genesis_path: "../test-data/genesis/demo-tests/bank.json",
sequencer_genesis_path: "../test-data/genesis/demo-tests/sequencer_registry.json",
value_setter_genesis_path: "../test-data/genesis/demo-tests/value_setter.json",
accounts_genesis_path: "../test-data/genesis/demo-tests/accounts.json",
chain_state_genesis_path: "../test-data/genesis/demo-tests/chain_state.json",
nft_path: "../test-data/genesis/demo-tests/nft.json",
#[cfg(feature = "experimental")]
evm_genesis_path: "../test-data/genesis/demo-tests/evm.json",
};

#[derive(Debug)]
struct RegexAppender {
regex: Regex,
Expand Down Expand Up @@ -184,7 +173,7 @@ async fn main() -> Result<(), anyhow::Error> {

let genesis_config = get_genesis_config(
sequencer_da_address,
&GENESIS_PATHS,
&GenesisPaths::from_dir("../test-data/genesis/demo-tests"),
#[cfg(feature = "experimental")]
Default::default(),
);
Expand Down
13 changes: 1 addition & 12 deletions examples/demo-rollup/provers/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@ use tracing::info;
use tracing_subscriber::filter::LevelFilter;
use tracing_subscriber::EnvFilter;

const GENESIS_PATHS: GenesisPaths<&str> = GenesisPaths {
bank_genesis_path: "../../test-data/genesis/demo-tests/bank.json",
sequencer_genesis_path: "../../test-data/genesis/demo-tests/sequencer_registry.json",
value_setter_genesis_path: "../../test-data/genesis/demo-tests/value_setter.json",
accounts_genesis_path: "../../test-data/genesis/demo-tests/accounts.json",
chain_state_genesis_path: "../../test-data/genesis/demo-tests/chain_state.json",
nft_path: "../../test-data/genesis/demo-tests/nft.json",
#[cfg(feature = "experimental")]
evm_genesis_path: "../../test-data/genesis/demo-tests/evm.json",
};

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
// If SKIP_PROVER is set, We still compile and run the zkVM code inside of an emulator without generating
Expand Down Expand Up @@ -51,7 +40,7 @@ async fn main() -> Result<(), anyhow::Error> {
let rollup = new_rollup_with_celestia_da(
&rollup_config_path,
Some((prover, prover_config)),
&GENESIS_PATHS,
&GenesisPaths::from_dir("../test-data/genesis/demo-tests"),
)
.await?;
rollup.run().await?;
Expand Down
26 changes: 2 additions & 24 deletions examples/demo-rollup/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,6 @@ use sov_risc0_adapter::host::Risc0Host;
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter};

const DEMO_GENESIS_PATHS: GenesisPaths<&str> = GenesisPaths {
bank_genesis_path: "../test-data/genesis/demo-tests/bank.json",
sequencer_genesis_path: "../test-data/genesis/demo-tests/sequencer_registry.json",
value_setter_genesis_path: "../test-data/genesis/demo-tests/value_setter.json",
accounts_genesis_path: "../test-data/genesis/demo-tests/accounts.json",
chain_state_genesis_path: "../test-data/genesis/demo-tests/chain_state.json",
nft_path: "../test-data/genesis/demo-tests/nft.json",
#[cfg(feature = "experimental")]
evm_genesis_path: "../test-data/genesis/demo-tests/evm.json",
};

const TEST_GENESIS_PATHS: GenesisPaths<&str> = GenesisPaths {
bank_genesis_path: "../test-data/genesis/integration-tests/bank.json",
sequencer_genesis_path: "../test-data/genesis/integration-tests/sequencer_registry.json",
value_setter_genesis_path: "../test-data/genesis/integration-tests/value_setter.json",
accounts_genesis_path: "../test-data/genesis/integration-tests/accounts.json",
chain_state_genesis_path: "../test-data/genesis/integration-tests/chain_state.json",
nft_path: "../test-data/genesis/integration-tests/nft.json",
#[cfg(feature = "experimental")]
evm_genesis_path: "../test-data/genesis/integration-tests/evm.json",
};

#[cfg(test)]
mod test_rpc;

Expand Down Expand Up @@ -69,7 +47,7 @@ async fn main() -> Result<(), anyhow::Error> {
rollup_config_path,
//Some((prover, config)),
None,
&TEST_GENESIS_PATHS,
&GenesisPaths::from_dir("../test-data/genesis/integration-tests"),
)?;
rollup.run().await
}
Expand All @@ -81,7 +59,7 @@ async fn main() -> Result<(), anyhow::Error> {
rollup_config_path,
//Some((prover, config)),
None,
&DEMO_GENESIS_PATHS,
&GenesisPaths::from_dir("../test-data/genesis/demo-tests"),
)
.await?;
rollup.run().await
Expand Down
18 changes: 6 additions & 12 deletions examples/demo-rollup/tests/bank/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,6 @@ use super::test_helpers::start_rollup;
const TOKEN_SALT: u64 = 0;
const TOKEN_NAME: &str = "test_token";

const TEST_GENESIS_PATHS: GenesisPaths<&str> = GenesisPaths {
bank_genesis_path: "../test-data/genesis/integration-tests/bank.json",
sequencer_genesis_path: "../test-data/genesis/integration-tests/sequencer_registry.json",
value_setter_genesis_path: "../test-data/genesis/integration-tests/value_setter.json",
accounts_genesis_path: "../test-data/genesis/integration-tests/accounts.json",
chain_state_genesis_path: "../test-data/genesis/integration-tests/chain_state.json",
nft_path: "../test-data/genesis/integration-tests/nft.json",
#[cfg(feature = "experimental")]
evm_genesis_path: "../test-data/genesis/integration-tests/evm.json",
};

async fn send_test_create_token_tx(rpc_address: SocketAddr) -> Result<(), anyhow::Error> {
let key = DefaultPrivateKey::generate();
let user_address: <DefaultContext as Spec>::Address = key.to_address();
Expand Down Expand Up @@ -86,7 +75,12 @@ async fn bank_tx_tests() -> Result<(), anyhow::Error> {
let config = DemoProverConfig::Execute;

let rollup_task = tokio::spawn(async {
start_rollup(port_tx, Some((prover, config)), &TEST_GENESIS_PATHS).await;
start_rollup(
port_tx,
Some((prover, config)),
&GenesisPaths::from_dir("../test-data/genesis/integration-tests"),
)
.await;
});

// Wait for rollup task to start:
Expand Down
18 changes: 6 additions & 12 deletions examples/demo-rollup/tests/evm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,19 @@ use test_client::TestClient;

use super::test_helpers::start_rollup;

const TEST_GENESIS_PATHS: GenesisPaths<&str> = GenesisPaths {
bank_genesis_path: "../test-data/genesis/integration-tests/bank.json",
sequencer_genesis_path: "../test-data/genesis/integration-tests/sequencer_registry.json",
value_setter_genesis_path: "../test-data/genesis/integration-tests/value_setter.json",
accounts_genesis_path: "../test-data/genesis/integration-tests/accounts.json",
chain_state_genesis_path: "../test-data/genesis/integration-tests/chain_state.json",
nft_path: "../test-data/genesis/integration-tests/nft.json",
#[cfg(feature = "experimental")]
evm_genesis_path: "../test-data/genesis/integration-tests/evm.json",
};

#[cfg(feature = "experimental")]
#[tokio::test]
async fn evm_tx_tests() -> Result<(), anyhow::Error> {
let (port_tx, port_rx) = tokio::sync::oneshot::channel();

let rollup_task = tokio::spawn(async {
// Don't provide a prover since the EVM is not currently provable
start_rollup::<Risc0Host<'static>, _>(port_tx, None, &TEST_GENESIS_PATHS).await;
start_rollup::<Risc0Host<'static>, _>(
port_tx,
None,
&GenesisPaths::from_dir("../test-data/genesis/integration-tests"),
)
.await;
});

// Wait for rollup task to start:
Expand Down
26 changes: 23 additions & 3 deletions examples/demo-stf/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! that transforms module genesis data into Rollup genesis data.

use std::convert::AsRef;
use std::path::Path;
use std::path::{Path, PathBuf};

use anyhow::{bail, Context as AnyhowContext};
use serde::de::DeserializeOwned;
Expand Down Expand Up @@ -35,21 +35,41 @@ pub struct GenesisPaths<P: AsRef<Path>> {
pub accounts_genesis_path: P,
/// Chain State genesis path.
pub chain_state_genesis_path: P,
/// Nft genesis path.
/// NFT genesis path.
pub nft_path: P,
#[cfg(feature = "experimental")]
/// EVM genesis path.
pub evm_genesis_path: P,
}

impl GenesisPaths<PathBuf> {
/// Creates a new [`GenesisPaths`] from the files contained in the given
/// directory.
///
/// Take a look at the contents of the `test_data` directory to see the
/// expected files.
pub fn from_dir(dir: impl AsRef<Path>) -> Self {
Self {
bank_genesis_path: dir.as_ref().join("bank.json"),
sequencer_genesis_path: dir.as_ref().join("sequencer_registry.json"),
value_setter_genesis_path: dir.as_ref().join("value_setter.json"),
accounts_genesis_path: dir.as_ref().join("accounts.json"),
chain_state_genesis_path: dir.as_ref().join("chain_state.json"),
nft_path: dir.as_ref().join("nft.json"),
#[cfg(feature = "experimental")]
evm_genesis_path: dir.as_ref().join("evm.json"),
}
}
}

/// Configure our rollup with a centralized sequencer using the SEQUENCER_DA_ADDRESS
/// address constant. Since the centralize sequencer's address is consensus critical,
/// it has to be hardcoded as a constant, rather than read from the config at runtime.
///
/// If you want to customize the rollup to accept transactions from your own celestia
/// address, simply change the value of the SEQUENCER_DA_ADDRESS to your own address.
/// For example:
/// ```rust,no_run
/// ```
/// const SEQUENCER_DA_ADDRESS: &str = "celestia1qp09ysygcx6npted5yc0au6k9lner05yvs9208";
/// ```
pub fn get_genesis_config<C: Context, Da: DaSpec, P: AsRef<Path>>(
Expand Down
13 changes: 1 addition & 12 deletions examples/demo-stf/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@ mod tx_revert_tests;
pub(crate) type C = DefaultContext;
pub(crate) type Da = MockDaSpec;

const TEST_GENESIS_PATHS: GenesisPaths<&str> = GenesisPaths {
bank_genesis_path: "../test-data/genesis/integration-tests/bank.json",
sequencer_genesis_path: "../test-data/genesis/integration-tests/sequencer_registry.json",
value_setter_genesis_path: "../test-data/genesis/integration-tests/value_setter.json",
accounts_genesis_path: "../test-data/genesis/integration-tests/accounts.json",
chain_state_genesis_path: "../test-data/genesis/integration-tests/chain_state.json",
nft_path: "../test-data/genesis/integration-tests/nft.json",
#[cfg(feature = "experimental")]
evm_genesis_path: "../test-data/genesis/integration-tests/evm.json",
};

pub(crate) fn create_new_app_template_for_tests(
path: impl AsRef<Path>,
) -> AppTemplate<
Expand All @@ -42,7 +31,7 @@ pub(crate) fn create_new_app_template_for_tests(
pub(crate) fn get_genesis_config_for_tests<Da: DaSpec>() -> GenesisConfig<DefaultContext, Da> {
get_genesis_config::<DefaultContext, Da, _>(
Da::Address::try_from(&MOCK_SEQUENCER_DA_ADDRESS).unwrap(),
&TEST_GENESIS_PATHS,
&GenesisPaths::from_dir("../test-data/genesis/integration-tests"),
#[cfg(feature = "experimental")]
Vec::default(),
)
Expand Down