Skip to content

Commit

Permalink
Plug in sov-chain-state module (#776)
Browse files Browse the repository at this point in the history
* Introduce Da generic in demo-stf

* Move sov-cli to demo-rollup

* Clean up sov-cli usage
  • Loading branch information
citizen-stig authored and preston-evans98 committed Sep 14, 2023
1 parent ca204f1 commit 17665f5
Show file tree
Hide file tree
Showing 29 changed files with 164 additions and 117 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions adapters/celestia/src/verifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ impl DaSpec for CelestiaSpec {

type BlobTransaction = BlobWithSender;

type ValidityCondition = ChainValidityCondition;

type InclusionMultiProof = Vec<EtxProof>;

type CompletenessProof = Vec<RelevantRowProof>;

type ChainParams = RollupParams;

type ValidityCondition = ChainValidityCondition;
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
Expand Down
5 changes: 5 additions & 0 deletions examples/demo-rollup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ license = { workspace = true }
homepage = "sovereign.xyz"
publish = false
resolver = "2"
default-run = "sov-demo-rollup"

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

Expand Down Expand Up @@ -77,3 +78,7 @@ harness = false
[[bench]]
name = "rollup_coarse_measure"
harness = false

[[bin]]
name = "sov-cli"
path = "src/sov-cli/main.rs"
2 changes: 1 addition & 1 deletion examples/demo-rollup/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ else
endif

build-sov-cli:
cd ../demo-stf && cargo build --bin sov-cli --features=native
cargo build --bin sov-cli

test-generate-create-token-tx: check-container-running build-sov-cli
$(SOV_CLI_REL_PATH) transactions import from-file bank --path ../test-data/requests/create_token.json
Expand Down
9 changes: 6 additions & 3 deletions examples/demo-rollup/benches/rng_xfers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ fn generate_transfers(n: usize, start_nonce: u64) -> Vec<u8> {
},
};
let enc_msg =
<Runtime<DefaultContext> as EncodeCall<Bank<DefaultContext>>>::encode_call(msg);
<Runtime<DefaultContext, RngDaSpec> as EncodeCall<Bank<DefaultContext>>>::encode_call(
msg,
);
let tx =
Transaction::<DefaultContext>::new_signed_tx(&pk, enc_msg, start_nonce + (i as u64));
let ser_tx = tx.try_to_vec().unwrap();
Expand All @@ -68,7 +70,8 @@ fn generate_create(start_nonce: u64) -> Vec<u8> {
minter_address,
authorized_minters: vec![minter_address],
};
let enc_msg = <Runtime<DefaultContext> as EncodeCall<Bank<DefaultContext>>>::encode_call(msg);
let enc_msg =
<Runtime<DefaultContext, RngDaSpec> as EncodeCall<Bank<DefaultContext>>>::encode_call(msg);
let tx = Transaction::<DefaultContext>::new_signed_tx(&pk, enc_msg, start_nonce);
let ser_tx = tx.try_to_vec().unwrap();
message_vec.push(ser_tx);
Expand All @@ -95,10 +98,10 @@ impl DaSpec for RngDaSpec {
type SlotHash = MockHash;
type BlockHeader = MockBlockHeader;
type BlobTransaction = MockBlob;
type ValidityCondition = MockValidityCond;
type InclusionMultiProof = [u8; 32];
type CompletenessProof = ();
type ChainParams = ();
type ValidityCondition = MockValidityCond;
}

#[async_trait]
Expand Down
8 changes: 4 additions & 4 deletions examples/demo-rollup/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub use rollup::{new_rollup_with_celestia_da, Rollup};
use sov_cli::wallet_state::{HexPrivateAndAddress, PrivateKeyAndAddress};
use sov_db::ledger_db::LedgerDB;
use sov_modules_api::default_context::DefaultContext;
use sov_rollup_interface::BasicAddress;
use sov_rollup_interface::da::{BlobReaderTrait, DaSpec};

/// 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 All @@ -35,9 +35,9 @@ pub fn initialize_ledger(path: impl AsRef<std::path::Path>) -> LedgerDB {
/// ```rust,no_run
/// const SEQUENCER_DA_ADDRESS: &str = "celestia1qp09ysygcx6npted5yc0au6k9lner05yvs9208";
/// ```
pub fn get_genesis_config<A: BasicAddress>(
sequencer_da_address: A,
) -> GenesisConfig<DefaultContext> {
pub fn get_genesis_config<Da: DaSpec>(
sequencer_da_address: <<Da as DaSpec>::BlobTransaction as BlobReaderTrait>::Address,
) -> GenesisConfig<DefaultContext, Da> {
let hex_key: HexPrivateAndAddress = serde_json::from_slice(include_bytes!(
"../../test-data/keys/token_deployer_private_key.json"
))
Expand Down
8 changes: 4 additions & 4 deletions examples/demo-rollup/src/register_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ use sov_sequencer::get_sequencer_rpc;
use sov_stf_runner::get_ledger_rpc;

/// register sequencer rpc methods.
pub fn register_sequencer<Vm, DA>(
da_service: DA,
app: &mut App<Vm, DA::Spec>,
pub fn register_sequencer<Vm, Da>(
da_service: Da,
app: &mut App<Vm, Da::Spec>,
methods: &mut jsonrpsee::RpcModule<()>,
) -> Result<(), anyhow::Error>
where
DA: DaService,
Da: DaService,
Vm: Zkvm,
{
let batch_builder = app.batch_builder.take().unwrap();
Expand Down
12 changes: 6 additions & 6 deletions examples/demo-rollup/src/rollup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ use crate::{get_genesis_config, initialize_ledger, ROLLUP_NAMESPACE};
const TX_SIGNER_PRIV_KEY_PATH: &str = "../test-data/keys/tx_signer_private_key.json";

/// Dependencies needed to run the rollup.
pub struct Rollup<Vm: Zkvm, DA: DaService + Clone> {
pub struct Rollup<Vm: Zkvm, Da: DaService + Clone> {
/// Implementation of the STF.
pub app: App<Vm, DA::Spec>,
pub app: App<Vm, Da::Spec>,
/// Data availability service.
pub da_service: DA,
pub da_service: Da,
/// Ledger db.
pub ledger_db: LedgerDB,
/// Runner configuration.
pub runner_config: RunnerConfig,
/// Initial rollup configuration.
pub genesis_config: GenesisConfig<DefaultContext>,
pub genesis_config: GenesisConfig<DefaultContext, Da::Spec>,
#[cfg(feature = "experimental")]
/// Configuration for the Ethereum RPC.
pub eth_rpc_config: EthRpcConfig,
Expand Down Expand Up @@ -98,7 +98,7 @@ pub fn read_tx_signer_priv_key() -> Result<DefaultPrivateKey, anyhow::Error> {
Ok(priv_key)
}

impl<Vm: Zkvm, DA: DaService<Error = anyhow::Error> + Clone> Rollup<Vm, DA> {
impl<Vm: Zkvm, Da: DaService<Error = anyhow::Error> + Clone> Rollup<Vm, Da> {
/// Runs the rollup.
pub async fn run(self) -> Result<(), anyhow::Error> {
self.run_and_report_rpc_port(None).await
Expand All @@ -110,7 +110,7 @@ impl<Vm: Zkvm, DA: DaService<Error = anyhow::Error> + Clone> Rollup<Vm, DA> {
channel: Option<oneshot::Sender<SocketAddr>>,
) -> Result<(), anyhow::Error> {
let storage = self.app.get_storage();
let mut methods = get_rpc_methods::<DefaultContext>(storage);
let mut methods = get_rpc_methods::<DefaultContext, Da::Spec>(storage);

// register rpc methods
{
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions examples/demo-rollup/src/sov-cli/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
demo_stf::cli::run::<
<celestia::CelestiaService as sov_rollup_interface::services::da::DaService>::Spec,
>()
.await
}
5 changes: 4 additions & 1 deletion examples/demo-rollup/tests/bank/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use jsonrpsee::rpc_params;
use sov_modules_api::default_context::DefaultContext;
use sov_modules_api::transaction::Transaction;
use sov_modules_api::{PrivateKey, Spec};
use sov_rollup_interface::mocks::MockDaSpec;
use sov_sequencer::utils::SimpleClient;

use super::test_helpers::start_rollup;
Expand All @@ -24,7 +25,9 @@ async fn send_test_create_token_tx(rpc_address: SocketAddr) -> Result<(), anyhow
TOKEN_SALT,
);

let msg = RuntimeCall::bank(sov_bank::CallMessage::<DefaultContext>::CreateToken {
let msg = RuntimeCall::<DefaultContext, MockDaSpec>::bank(sov_bank::CallMessage::<
DefaultContext,
>::CreateToken {
salt: TOKEN_SALT,
token_name: TOKEN_NAME.to_string(),
initial_balance: 1000,
Expand Down
6 changes: 2 additions & 4 deletions examples/demo-stf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ license = { workspace = true }
homepage = "sovereign.xyz"
publish = false

[[bin]]
name = "sov-cli"
path = "src/sov-cli/main.rs"

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

[dependencies]
Expand All @@ -32,6 +28,7 @@ sov-cli = { path = "../../module-system/sov-cli", optional = true }
sov-sequencer-registry = { path = "../../module-system/module-implementations/sov-sequencer-registry" }
sov-blob-storage = { path = "../../module-system/module-implementations/sov-blob-storage" }
sov-bank = { path = "../../module-system/module-implementations/sov-bank" }
sov-chain-state = { path = "../../module-system/module-implementations/sov-chain-state" }
sov-modules-stf-template = { path = "../../module-system/sov-modules-stf-template" }
sov-value-setter = { path = "../../module-system/module-implementations/examples/sov-value-setter" }
sov-accounts = { path = "../../module-system/module-implementations/sov-accounts" }
Expand All @@ -58,6 +55,7 @@ native = [
"sov-accounts/native",
"sov-sequencer-registry/native",
"sov-blob-storage/native",
"sov-chain-state/native",
"sov-value-setter/native",
"sov-modules-api/native",
"sov-rollup-interface/mocks",
Expand Down
12 changes: 6 additions & 6 deletions examples/demo-stf/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ use sov_stf_runner::StorageConfig;
use crate::runtime::Runtime;

#[cfg(feature = "native")]
pub struct App<Vm: Zkvm, DA: DaSpec> {
pub stf: AppTemplate<DefaultContext, DA, Vm, Runtime<DefaultContext>>,
pub batch_builder: Option<FiFoStrictBatchBuilder<Runtime<DefaultContext>, DefaultContext>>,
pub struct App<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> App<Vm, DA> {
impl<Vm: Zkvm, Da: DaSpec> App<Vm, Da> {
pub fn new(storage_config: StorageConfig) -> Self {
let storage =
ProverStorage::with_config(storage_config).expect("Failed to open prover storage");
Expand All @@ -49,9 +49,9 @@ impl<Vm: Zkvm, DA: DaSpec> App<Vm, DA> {
}
}

pub fn create_zk_app_template<Vm: Zkvm, DA: DaSpec>(
pub fn create_zk_app_template<Vm: Zkvm, Da: DaSpec>(
runtime_config: [u8; 32],
) -> AppTemplate<ZkDefaultContext, DA, Vm, Runtime<ZkDefaultContext>> {
) -> AppTemplate<ZkDefaultContext, Da, Vm, Runtime<ZkDefaultContext, Da>> {
let storage = ZkStorage::with_config(runtime_config).expect("Failed to open zk storage");
AppTemplate::new(storage, Runtime::default())
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use demo_stf::runtime::{Runtime, RuntimeCall, RuntimeSubcommand};
use sov_cli::wallet_state::WalletState;
use sov_cli::workflows::keys::KeyWorkflow;
use sov_cli::workflows::rpc::RpcWorkflows;
Expand All @@ -7,17 +6,20 @@ use sov_cli::{clap, wallet_dir};
use sov_modules_api::clap::Parser;
use sov_modules_api::cli::{FileNameArg, JsonStringArg};
use sov_modules_api::default_context::DefaultContext;
use sov_rollup_interface::da::DaSpec;

type Ctx = sov_modules_api::default_context::DefaultContext;
use crate::runtime::{Runtime, RuntimeCall, RuntimeSubcommand};

type Ctx = DefaultContext;

#[derive(clap::Subcommand)]
#[command(author, version, about, long_about = None)]
pub enum Workflows {
pub enum Workflows<Da: DaSpec> {
#[clap(subcommand)]
Transactions(
TransactionWorkflow<
RuntimeSubcommand<FileNameArg, DefaultContext>,
RuntimeSubcommand<JsonStringArg, DefaultContext>,
RuntimeSubcommand<FileNameArg, DefaultContext, Da>,
RuntimeSubcommand<JsonStringArg, DefaultContext, Da>,
>,
),
#[clap(subcommand)]
Expand All @@ -28,23 +30,24 @@ pub enum Workflows {

#[derive(clap::Parser)]
#[command(author, version, about, long_about = None)]
pub struct App {
pub struct App<Da: DaSpec> {
#[clap(subcommand)]
workflow: Workflows,
workflow: Workflows<Da>,
}

pub async fn main() -> Result<(), anyhow::Error> {
pub async fn run<Da: DaSpec>() -> Result<(), anyhow::Error> {
let app_dir = wallet_dir()?;
std::fs::create_dir_all(app_dir.as_ref())?;
let wallet_state_path = app_dir.as_ref().join("wallet_state.json");
let mut wallet_state: WalletState<RuntimeCall<Ctx>, Ctx> =

let mut wallet_state: WalletState<RuntimeCall<Ctx, Da>, Ctx> =
WalletState::load(&wallet_state_path)?;

let invocation = App::parse();
let invocation = App::<Da>::parse();

match invocation.workflow {
Workflows::Transactions(tx) => tx
.run::<Runtime<DefaultContext>, DefaultContext, JsonStringArg, _, _, _>(
.run::<Runtime<DefaultContext, Da>, DefaultContext, JsonStringArg, _, _, _>(
&mut wallet_state,
app_dir,
)?,
Expand All @@ -53,7 +56,5 @@ pub async fn main() -> Result<(), anyhow::Error> {
inner.run(&mut wallet_state, app_dir).await?;
}
}
wallet_state.save(wallet_state_path)?;

Ok(())
wallet_state.save(wallet_state_path)
}
18 changes: 13 additions & 5 deletions examples/demo-stf/src/genesis_config.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use sov_chain_state::ChainStateConfig;
#[cfg(feature = "experimental")]
use sov_evm::{AccountData, EvmConfig, SpecId};
pub use sov_modules_api::default_context::DefaultContext;
use sov_modules_api::default_signature::private_key::DefaultPrivateKey;
use sov_modules_api::utils::generate_address;
use sov_modules_api::{Context, PrivateKey, PublicKey};
use sov_rollup_interface::da::DaSpec;
pub use sov_state::config::Config as StorageConfig;
use sov_value_setter::ValueSetterConfig;

Expand All @@ -15,12 +17,12 @@ pub const LOCKED_AMOUNT: u64 = 50;
pub const DEMO_SEQ_PUB_KEY_STR: &str = "seq_pub_key";
pub const DEMO_TOKEN_NAME: &str = "sov-demo-token";

pub fn create_demo_genesis_config<C: Context>(
pub fn create_demo_genesis_config<C: Context, Da: DaSpec>(
initial_sequencer_balance: u64,
sequencer_address: C::Address,
sequencer_da_address: Vec<u8>,
value_setter_admin_private_key: &DefaultPrivateKey,
) -> GenesisConfig<C> {
) -> GenesisConfig<C, Da> {
let token_config: sov_bank::TokenConfig<C> = sov_bank::TokenConfig {
token_name: DEMO_TOKEN_NAME.to_owned(),
address_and_balances: vec![(sequencer_address.clone(), initial_sequencer_balance)],
Expand Down Expand Up @@ -57,10 +59,16 @@ pub fn create_demo_genesis_config<C: Context>(
.try_into()
.expect("EVM module initialized with invalid address");

let chain_state_config = ChainStateConfig {
// TODO: Put actual value
initial_slot_height: 0,
};

GenesisConfig::new(
bank_config,
sequencer_registry_config,
(),
chain_state_config,
value_setter_config,
sov_accounts::AccountConfig { pub_keys: vec![] },
#[cfg(feature = "experimental")]
Expand All @@ -79,11 +87,11 @@ pub fn create_demo_genesis_config<C: Context>(
)
}

pub fn create_demo_config(
pub fn create_demo_config<Da: DaSpec>(
initial_sequencer_balance: u64,
value_setter_admin_private_key: &DefaultPrivateKey,
) -> GenesisConfig<DefaultContext> {
create_demo_genesis_config::<DefaultContext>(
) -> GenesisConfig<DefaultContext, Da> {
create_demo_genesis_config::<DefaultContext, Da>(
initial_sequencer_balance,
generate_address::<DefaultContext>(DEMO_SEQ_PUB_KEY_STR),
DEMO_SEQUENCER_DA_ADDRESS.to_vec(),
Expand Down
Loading

0 comments on commit 17665f5

Please sign in to comment.