Skip to content

Commit

Permalink
Make rollup-template more similar to demo-rollup (#1029)
Browse files Browse the repository at this point in the history
* Add stf crate

* add template-stf crate

* Update rollu-template

* Update tests

* Update tests

* fix deps

* fix lint
  • Loading branch information
bkolad authored Oct 12, 2023
1 parent 0ba2bf3 commit 0890fd1
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 52 deletions.
23 changes: 23 additions & 0 deletions Cargo.lock

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

51 changes: 18 additions & 33 deletions templates/rollup-template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,60 +13,45 @@ rust-version.workspace = true

[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-modules-api = { path = "../../module-system/sov-modules-api", features = ["native"] }
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" }
sov-accounts = { path = "../../module-system/module-implementations/sov-accounts", features = ["native"]}
sov-bank = { path = "../../module-system/module-implementations/sov-bank", features = ["native"] }
sov-sequencer-registry = { path = "../../module-system/module-implementations/sov-sequencer-registry", features = ["native"] }
sov-modules-stf-template = { path = "../../module-system/sov-modules-stf-template/", features = ["native"] }
sov-stf-runner = { path = "../../full-node/sov-stf-runner", features = ["native"] }
borsh = { workspace = true }
clap = { workspace = true, optional = true }
clap = { workspace = true }
serde = { workspace = true }
tracing = { workspace = true }
serde_json = { workspace = true, optional = true }
jsonrpsee = { workspace = true, optional = true }
serde_json = { workspace = true }
jsonrpsee = { workspace = true }
anyhow = { workspace = true }

sov-db = { path = "../../full-node/db/sov-db", optional = true }
sov-sequencer = { path = "../../full-node/sov-sequencer", optional = true }
template-stf = { path = "./stf", features = ["native"] }

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

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

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

[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",
]
default = []

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

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

2 changes: 1 addition & 1 deletion templates/rollup-template/src/bin/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use std::path::PathBuf;
use anyhow::Context;
use rollup_template::da::{start_da_service, DaConfig};
use rollup_template::rollup::Rollup;
use rollup_template::stf::{get_genesis_config, GenesisPaths};
use sov_risc0_adapter::host::Risc0Host;
use sov_rollup_interface::mocks::{MockAddress, MOCK_SEQUENCER_DA_ADDRESS};
use sov_stf_runner::{from_toml_path, RollupConfig};
use template_stf::{get_genesis_config, GenesisPaths};
use tracing::info;
use tracing_subscriber::filter::LevelFilter;
use tracing_subscriber::EnvFilter;
Expand Down
2 changes: 1 addition & 1 deletion templates/rollup-template/src/bin/verifier.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! This binary implements the verification logic for the rollup. This is the code that runs inside
//! of the zkvm in order to generate proofs for the rollup.
use rollup_template::da::new_da_verifier;
use rollup_template::stf::{zk_stf, RollupVerifier};
use rollup_template::zkvm::ZkvmGuest;
use template_stf::{zk_stf, RollupVerifier};

fn main() {
let guest = ZkvmGuest::new();
Expand Down
4 changes: 0 additions & 4 deletions templates/rollup-template/src/da.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@
//! Your rollup full node will automatically switch to the new DA layer.
/// The type alias for the DA layer configuration. Change the contents of this alias if you change DA layers.
#[cfg(feature = "native")]
pub type DaConfig = sov_rollup_interface::mocks::MockDaConfig;
/// The type alias for the DA layer verifier. Change the contents of this alias if you change DA layers.
pub type DaVerifier = MockDaVerifier;
/// The type alias for the DA service. Change the contents of this alias if you change DA layers.
#[cfg(feature = "native")]
pub type DaService = sov_rollup_interface::mocks::MockDaService;

use sov_rollup_interface::da::DaVerifier as _;
use sov_rollup_interface::mocks::MockDaVerifier;
#[cfg(feature = "native")]
use sov_stf_runner::RollupConfig;

/// Creates a new instance of the DA Service
#[cfg(feature = "native")]
pub async fn start_da_service(rollup_config: &RollupConfig<DaConfig>) -> DaService {
DaService::new(rollup_config.da.sender_address)
}
Expand Down
2 changes: 0 additions & 2 deletions templates/rollup-template/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#![deny(missing_docs)]
#![doc = include_str!("../README.md")]
pub mod da;
pub mod stf;

#[cfg(feature = "native")]
pub mod rollup;
pub mod zkvm;
4 changes: 1 addition & 3 deletions templates/rollup-template/src/rollup/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Defines the rollup full node implementation, including logic for configuring
//! and starting the rollup node.
#[cfg(feature = "native")]
mod rpc;

use serde::de::DeserializeOwned;
Expand All @@ -11,10 +9,10 @@ use sov_modules_stf_template::AppTemplate;
use sov_rollup_interface::services::da::DaService;
use sov_rollup_interface::zk::ZkvmHost;
use sov_stf_runner::{Prover, RollupConfig, RunnerConfig, StateTransitionRunner};
use template_stf::{get_rpc_methods, GenesisConfig, Runtime, StfWithBuilder};
use tokio::sync::oneshot;

use self::rpc::{register_ledger, register_sequencer};
use crate::stf::{get_rpc_methods, GenesisConfig, Runtime, StfWithBuilder};

type ZkStf<Da, Vm> = AppTemplate<ZkDefaultContext, Da, Vm, Runtime<ZkDefaultContext, Da>>;

Expand Down
3 changes: 1 addition & 2 deletions templates/rollup-template/src/rollup/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use sov_modules_stf_template::{SequencerOutcome, TxEffect};
use sov_rollup_interface::services::da::DaService;
use sov_sequencer::get_sequencer_rpc;
use sov_stf_runner::get_ledger_rpc;

use crate::stf::StfWithBuilder;
use template_stf::StfWithBuilder;

/// register sequencer rpc methods.
pub(crate) fn register_sequencer<Vm, Da>(
Expand Down
43 changes: 43 additions & 0 deletions templates/rollup-template/stf/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "template-stf"
version = { workspace = true }
edition = { workspace = true }
resolver = "2"
authors = { workspace = true }
license = { workspace = true }
homepage = "sovereign.xyz"
publish = false

[dependencies]
sov-modules-api = { path = "../../../module-system/sov-modules-api" }
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" }
sov-sequencer = { path = "../../../full-node/sov-sequencer", optional = true }
sov-rollup-interface = { path = "../../../rollup-interface" }
tracing = { workspace = true }

serde_json = { workspace = true, optional = true }
serde = { workspace = true }
jsonrpsee = { workspace = true, optional = true }
borsh = { workspace = true }
anyhow = { workspace = true }
clap = { workspace = true, optional = true }

[features]
default = []
native = [
"sov-modules-api/native",
"sov-accounts/native",
"sov-bank/native",
"sov-sequencer-registry/native",
"sov-modules-stf-template/native",
"sov-stf-runner/native",
"serde_json",
"jsonrpsee",
"sov-sequencer",
"clap",
]
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ use sov_state::{ProverStorage, Storage};
use super::runtime::Runtime;

/// The "native" version of the STF and a batch builder
pub(crate) struct StfWithBuilder<Vm: Zkvm, Da: DaSpec> {
pub struct StfWithBuilder<Vm: Zkvm, Da: DaSpec> {
pub stf: AppTemplate<DefaultContext, Da, Vm, Runtime<DefaultContext, Da>>,
pub batch_builder: Option<FiFoStrictBatchBuilder<Runtime<DefaultContext, Da>, DefaultContext>>,
}

#[cfg(feature = "native")]
impl<Vm: Zkvm, Da: DaSpec> StfWithBuilder<Vm, Da> {
/// Create a new rollup instance
pub(crate) fn new(storage_config: sov_stf_runner::StorageConfig) -> Self {
pub fn new(storage_config: sov_stf_runner::StorageConfig) -> Self {
let config = sov_state::config::Config {
path: storage_config.path,
};
Expand All @@ -42,7 +42,7 @@ impl<Vm: Zkvm, Da: DaSpec> StfWithBuilder<Vm, Da> {
}
}

pub(crate) fn get_storage(&self) -> <DefaultContext as Spec>::Storage {
pub fn get_storage(&self) -> <DefaultContext as Spec>::Storage {
self.stf.current_storage.clone()
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod hooks;
mod runtime;

#[cfg(feature = "native")]
pub(crate) use builder::*;
pub use builder::*;
#[cfg(feature = "native")]
pub use genesis_config::*;
pub use runtime::*;
2 changes: 1 addition & 1 deletion templates/rollup-template/tests/bank/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use std::net::SocketAddr;
use borsh::BorshSerialize;
use jsonrpsee::core::client::{Subscription, SubscriptionClientT};
use jsonrpsee::rpc_params;
use rollup_template::stf::RuntimeCall;
use sov_modules_api::default_context::DefaultContext;
use sov_modules_api::default_signature::private_key::DefaultPrivateKey;
use sov_modules_api::transaction::Transaction;
use sov_modules_api::{PrivateKey, Spec};
use sov_risc0_adapter::host::Risc0Host;
use sov_rollup_interface::mocks::MockDaSpec;
use sov_sequencer::utils::SimpleClient;
use template_stf::RuntimeCall;

use super::test_helpers::start_rollup;
const TOKEN_SALT: u64 = 0;
Expand Down
2 changes: 1 addition & 1 deletion templates/rollup-template/tests/test_helpers.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::net::SocketAddr;

use rollup_template::rollup::Rollup;
use rollup_template::stf::GenesisConfig;
use sov_modules_api::default_context::DefaultContext;
use sov_rollup_interface::mocks::{MockDaConfig, MockDaService, MockDaSpec};
use sov_rollup_interface::zk::ZkvmHost;
use sov_stf_runner::{RollupConfig, RpcConfig, RunnerConfig, StorageConfig};
use template_stf::GenesisConfig;
use tokio::sync::oneshot;

pub async fn start_rollup<Vm: ZkvmHost>(rpc_reporting_channel: oneshot::Sender<SocketAddr>) {
Expand Down

0 comments on commit 0890fd1

Please sign in to comment.