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

Create rollup template #979

Merged
merged 30 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0e42fb2
WIP: make rollup template
preston-evans98 Sep 28, 2023
5243f6f
Make genesis config serializable
preston-evans98 Sep 28, 2023
eac220c
Merge branch 'nightly' into preston/rollup-template
preston-evans98 Oct 2, 2023
0d0288d
WIP: adding cli
preston-evans98 Oct 2, 2023
afe56a1
Merge remote-tracking branch 'origin/nightly' into preston/rollup-tem…
preston-evans98 Oct 3, 2023
7f2b0e8
Implement working template
preston-evans98 Oct 3, 2023
df65790
Add integ tests
preston-evans98 Oct 3, 2023
3b8894a
lint
preston-evans98 Oct 3, 2023
e7d2e97
lint again
preston-evans98 Oct 4, 2023
ef82cda
fix feature gating
preston-evans98 Oct 4, 2023
85e9795
Merge remote-tracking branch 'origin/nightly' into preston/rollup-tem…
preston-evans98 Oct 4, 2023
2a5858e
add missing docs
preston-evans98 Oct 4, 2023
b39064b
Merge remote-tracking branch 'origin/nightly' into preston/rollup-tem…
preston-evans98 Oct 4, 2023
7f35522
Switch to mockda
preston-evans98 Oct 5, 2023
46f245d
fmt
preston-evans98 Oct 5, 2023
e244dbe
clippy
preston-evans98 Oct 5, 2023
5a75ff4
Fix demo-rollup test
preston-evans98 Oct 5, 2023
fe30159
fix clippy again
preston-evans98 Oct 5, 2023
b8a4c25
Merge branch 'nightly' into preston/rollup-template
bkolad Oct 10, 2023
3d206ef
Merge branch 'nightly' into preston/rollup-template
bkolad Oct 11, 2023
2f4ee9f
cleanup
bkolad Oct 11, 2023
923f3ce
Add runtime module
bkolad Oct 11, 2023
e9a82c4
Add rollup module
bkolad Oct 11, 2023
09a66e3
Add genesis config
bkolad Oct 11, 2023
7c717e0
Read genesis file
bkolad Oct 11, 2023
25043d8
Update path
bkolad Oct 11, 2023
ebbccb1
fix lint
bkolad Oct 11, 2023
a703fcd
fix ci
bkolad Oct 11, 2023
e834a2d
upgrade cargo hack
bkolad Oct 11, 2023
d5dbc42
Merge branch 'nightly' into preston/rollup-template
bkolad Oct 11, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
# building dependencies, only chceking them, so we can share caches
# effectively.
needs: check
runs-on: buildjet-4vcpu-ubuntu-2204
runs-on: buildjet-8vcpu-ubuntu-2204
timeout-minutes: 60
env:
CI_SKIP_GUEST_BUILD: "1"
Expand Down
28 changes: 28 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ members = [
"full-node/sov-ethereum",
"full-node/sov-stf-runner",

"templates/rollup-template",

"utils/zk-cycle-macros",
"utils/zk-cycle-utils",
"utils/bashtestmd",
Expand Down

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

1 change: 1 addition & 0 deletions examples/demo-rollup/provers/risc0/guest-mock/Cargo.lock

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

12 changes: 6 additions & 6 deletions examples/demo-rollup/src/register_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use sov_rollup_interface::zk::Zkvm;
use sov_sequencer::get_sequencer_rpc;
use sov_stf_runner::get_ledger_rpc;

/// register sequencer rpc methods.
pub fn register_sequencer<Vm, Da>(
// register sequencer rpc methods.
pub(crate) fn register_sequencer<Vm, Da>(
da_service: Da,
app: &mut App<Vm, Da::Spec>,
methods: &mut jsonrpsee::RpcModule<()>,
Expand All @@ -29,8 +29,8 @@ where
.context("Failed to merge Txs RPC modules")
}

/// register ledger rpc methods.
pub fn register_ledger(
// register ledger rpc methods.
pub(crate) fn register_ledger(
ledger_db: LedgerDB,
methods: &mut jsonrpsee::RpcModule<()>,
) -> Result<(), anyhow::Error> {
Expand All @@ -41,8 +41,8 @@ pub fn register_ledger(
}

#[cfg(feature = "experimental")]
/// register ethereum methods.
pub fn register_ethereum<C: sov_modules_api::Context, Da: DaService>(
// register ethereum methods.
pub(crate) fn register_ethereum<C: sov_modules_api::Context, Da: DaService>(
da_service: Da,
eth_rpc_config: EthRpcConfig,
storage: C::Storage,
Expand Down
28 changes: 14 additions & 14 deletions examples/demo-rollup/src/rollup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ type ZkStf<Da, Vm> = AppTemplate<ZkDefaultContext, Da, Vm, Runtime<ZkDefaultCont

/// Dependencies needed to run the rollup.
pub struct Rollup<Vm: ZkvmHost, Da: DaService + Clone> {
/// 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, Da::Spec>,
// Implementation of the STF.
pub(crate) app: App<Vm, Da::Spec>,
// Data availability service.
pub(crate) da_service: Da,
// Ledger db.
pub(crate) ledger_db: LedgerDB,
// Runner configuration.
pub(crate) runner_config: RunnerConfig,
// Initial rollup configuration.
pub(crate) genesis_config: GenesisConfig<DefaultContext, Da::Spec>,
#[cfg(feature = "experimental")]
/// Configuration for the Ethereum RPC.
pub eth_rpc_config: EthRpcConfig,
/// Prover for the rollup.
// Configuration for the Ethereum RPC.
pub(crate) eth_rpc_config: EthRpcConfig,
// Prover for the rollup.
#[allow(clippy::type_complexity)]
pub prover: Option<Prover<ZkStf<Da::Spec, Vm::Guest>, Da, Vm>>,
pub(crate) prover: Option<Prover<ZkStf<Da::Spec, Vm::Guest>, Da, Vm>>,
}

pub fn configure_prover<Vm: ZkvmHost, Da: DaService>(
Expand Down
6 changes: 4 additions & 2 deletions examples/demo-rollup/tests/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::Path;

use demo_stf::genesis_config::GenesisPaths;
use sov_demo_rollup::{new_rollup_with_mock_da_from_config, DemoProverConfig};
use sov_rollup_interface::mocks::MockDaConfig;
use sov_rollup_interface::mocks::{MockAddress, MockDaConfig};
use sov_rollup_interface::zk::ZkvmHost;
use sov_stf_runner::{RollupConfig, RpcConfig, RunnerConfig, StorageConfig};
use tokio::sync::oneshot;
Expand All @@ -27,7 +27,9 @@ pub async fn start_rollup<Vm: ZkvmHost, P: AsRef<Path>>(
bind_port: 0,
},
},
da: MockDaConfig {},
da: MockDaConfig {
sender_address: MockAddress { addr: [0; 32] },
},
};

let rollup = new_rollup_with_mock_da_from_config(rollup_config, prover, genesis_paths)
Expand Down
15 changes: 2 additions & 13 deletions examples/demo-stf/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
use std::convert::AsRef;
use std::path::{Path, PathBuf};

use anyhow::{bail, Context as AnyhowContext};
use serde::de::DeserializeOwned;
use anyhow::bail;
use sov_accounts::AccountConfig;
use sov_bank::BankConfig;
use sov_chain_state::ChainStateConfig;
Expand All @@ -18,6 +17,7 @@ use sov_nft_module::NonFungibleTokenConfig;
use sov_rollup_interface::da::DaSpec;
use sov_sequencer_registry::SequencerConfig;
pub use sov_state::config::Config as StorageConfig;
use sov_stf_runner::read_json_file;
use sov_value_setter::ValueSetterConfig;

/// Creates config for a rollup with some default settings, the config is used in demos and tests.
Expand Down Expand Up @@ -141,17 +141,6 @@ fn create_genesis_config<C: Context, Da: DaSpec, P: AsRef<Path>>(
))
}

fn read_json_file<T: DeserializeOwned, P: AsRef<Path>>(path: P) -> anyhow::Result<T> {
let path_str = path.as_ref().display();

let data = std::fs::read_to_string(&path)
.with_context(|| format!("Failed to read genesis from {}", path_str))?;
let config: T = serde_json::from_str(&data)
.with_context(|| format!("Failed to parse genesis from {}", path_str))?;

Ok(config)
}

#[cfg(feature = "experimental")]
fn get_evm_config<P: AsRef<Path>>(
evm_path: P,
Expand Down
4 changes: 4 additions & 0 deletions examples/demo-stf/src/hooks_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ impl<C: Context, Da: DaSpec> TxHooks for Runtime<C, Da> {
tx: &Transaction<Self::Context>,
working_set: &mut WorkingSet<C>,
) -> anyhow::Result<<Self::Context as Spec>::Address> {
// Before executing a transaction, retrieve the sender's address from the accounts module
// and check the nonce
self.accounts.pre_dispatch_tx_hook(tx, working_set)
}

Expand All @@ -27,6 +29,7 @@ impl<C: Context, Da: DaSpec> TxHooks for Runtime<C, Da> {
tx: &Transaction<Self::Context>,
working_set: &mut WorkingSet<C>,
) -> anyhow::Result<()> {
// After executing each transaction, update the nonce
self.accounts.post_dispatch_tx_hook(tx, working_set)
}
}
Expand All @@ -41,6 +44,7 @@ impl<C: Context, Da: DaSpec> ApplyBlobHooks<Da::BlobTransaction> for Runtime<C,
blob: &mut Da::BlobTransaction,
working_set: &mut WorkingSet<C>,
) -> anyhow::Result<()> {
// Before executing each batch, check that the sender is registered as a sequencer
self.sequencer_registry.begin_blob_hook(blob, working_set)
}

Expand Down
1 change: 1 addition & 0 deletions full-node/sov-stf-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ publish = false
[dependencies]
anyhow = { workspace = true }
borsh = { workspace = true }
serde_json = { workspace = true }
serde = { workspace = true }
toml = { workspace = true, optional = true }
jsonrpsee = { workspace = true, features = ["http-client", "server"], optional = true }
Expand Down
2 changes: 2 additions & 0 deletions full-node/sov-stf-runner/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub fn from_toml_path<P: AsRef<Path>, R: DeserializeOwned>(path: P) -> anyhow::R
let mut file = File::open(path)?;
file.read_to_string(&mut contents)?;
}
tracing::debug!("Config file size: {} bytes", contents.len());
tracing::trace!("Config file contents: {}", &contents);

let result: R = toml::from_str(&contents)?;

Expand Down
20 changes: 20 additions & 0 deletions full-node/sov-stf-runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
#[cfg(feature = "native")]
mod config;

#[cfg(feature = "native")]
use std::path::Path;

#[cfg(feature = "native")]
use anyhow::Context;
use borsh::{BorshDeserialize, BorshSerialize};
#[cfg(feature = "native")]
pub use config::RpcConfig;
Expand All @@ -17,6 +22,8 @@ pub use config::{from_toml_path, RollupConfig, RunnerConfig, StorageConfig};
pub use ledger_rpc::get_ledger_rpc;
#[cfg(feature = "native")]
pub use runner::*;
#[cfg(feature = "native")]
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use sov_rollup_interface::da::DaSpec;
use sov_rollup_interface::stf::StateTransitionFunction;
Expand Down Expand Up @@ -47,3 +54,16 @@ where
/// The witness for the state transition
pub state_transition_witness: ST::Witness,
}

#[cfg(feature = "native")]
/// Reads json file.
pub fn read_json_file<T: DeserializeOwned, P: AsRef<Path>>(path: P) -> anyhow::Result<T> {
let path_str = path.as_ref().display();

let data = std::fs::read_to_string(&path)
.with_context(|| format!("Failed to read genesis from {}", path_str))?;
let config: T = serde_json::from_str(&data)
.with_context(|| format!("Failed to parse genesis from {}", path_str))?;

Ok(config)
}
5 changes: 4 additions & 1 deletion rollup-interface/src/state_machine/mocks/da.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,10 @@ impl DaService for MockDaService {

/// The configuration for mock da
#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct MockDaConfig {}
pub struct MockDaConfig {
/// The address to use to "submit" blobs on the mock da layer
pub sender_address: MockAddress,
}

#[derive(Clone, Default)]
/// DaVerifier used in tests.
Expand Down
72 changes: 72 additions & 0 deletions templates/rollup-template/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
[package]
name = "rollup-template"
version.workspace = true
edition.workspace = true
license.workspace = true
authors.workspace = true
homepage.workspace = true
publish.workspace = true
repository.workspace = true
rust-version.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
#stf dependencies
sov-modules-api = { path = "../../module-system/sov-modules-api" } # needs to re-export anyhow, serde, and borsh. native needs clap, serde_json, and jsonrpsee. Also, tracing
sov-state = { path = "../../module-system/sov-state" }
sov-accounts = { path = "../../module-system/module-implementations/sov-accounts" }
sov-bank = { path = "../../module-system/module-implementations/sov-bank" }
sov-sequencer-registry = { path = "../../module-system/module-implementations/sov-sequencer-registry" }
sov-modules-stf-template = { path = "../../module-system/sov-modules-stf-template/" }
sov-stf-runner = { path = "../../full-node/sov-stf-runner" }
borsh = { workspace = true }
clap = { workspace = true, optional = true }
serde = { workspace = true }
tracing = { workspace = true }
serde_json = { workspace = true, optional = true }
jsonrpsee = { workspace = true, optional = true }
anyhow = { workspace = true }

sov-db = { path = "../../full-node/db/sov-db", optional = true }
sov-sequencer = { path = "../../full-node/sov-sequencer", optional = true }
sov-rollup-interface = { path = "../../rollup-interface", features = ["mocks"] }
tokio = { workspace = true, optional = true }

# Change dependencies here to use a different DA layer or ZKVM
sov-risc0-adapter = { path = "../../adapters/risc0" }

# binary dependencies
tracing-subscriber = { version = "0.3.17", features = ["env-filter"], optional = true }

[dev-dependencies]
tempfile = { workspace = true }

[features]
default = ["native"]
native = [
"sov-modules-api/native",
"sov-accounts/native",
"sov-bank/native",
"sov-sequencer-registry/native",
"sov-risc0-adapter/native",
"sov-stf-runner/native",
"sov-modules-stf-template/native",
"sov-db",
"sov-sequencer",
"tokio",
"clap",
"serde_json",
"jsonrpsee",
"tracing-subscriber",
]

[[bin]]
name = "node"
path = "src/bin/node.rs"
required-features = ["native"]

[[bin]]
name = "cli_wallet"
path = "src/bin/cli_wallet.rs"
required-features = ["native"]
3 changes: 3 additions & 0 deletions templates/rollup-template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Rollup Template

This package is a convenient starting point for building a rollup using the Sovereign SDK
16 changes: 16 additions & 0 deletions templates/rollup-template/rollup_config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[da]
sender_address = "0101010101010101010101010101010101010101010101010101010101010101"

[storage]
# The path to the rollup's data directory. Paths that do not begin with `/` are interpreted as relative paths.
path = "demo_data"

# We define the rollup's genesis to occur at block number `start_height`. The rollup will ignore
# any blocks before this height
[runner]
start_height = 1

[runner.rpc_config]
# the host and port to bind the rpc server for
bind_host = "127.0.0.1"
bind_port = 12345
3 changes: 3 additions & 0 deletions templates/rollup-template/src/bin/cli_wallet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! This binary defines a cli wallet for interacting
//! with the rollup.
fn main() {}
Loading