From 1c3f77f812e7f0e36e96db5066baa20fa225752f Mon Sep 17 00:00:00 2001 From: Blazej Kolad Date: Mon, 9 Oct 2023 15:23:07 +0200 Subject: [PATCH] Add docs for `dmo-stf`. (#998) * Make app a private module * Create ZkApp * fix configure_prover * Docs for wallet cli * Remove read_private_key * Cleanup * Move create_zk_app_template back * demo-std refactoring * fix lint * Remove experimrntal runtime * fix expose_rpc macro * Add docs * cleanup * fix lint * fix ci * Fix Cargo.toml * fix create_genesis_config * Fix Readme * update doc --- examples/demo-prover/benches/prover_bench.rs | 2 +- .../methods/guest-celestia/src/bin/rollup.rs | 3 +- .../methods/guest-mock/src/bin/mock_da.rs | 5 +- examples/demo-rollup/benches/rollup_bench.rs | 2 +- .../benches/rollup_coarse_measure.rs | 2 +- examples/demo-rollup/src/register_rpc.rs | 2 +- examples/demo-rollup/src/rollup.rs | 16 +-- examples/demo-rollup/src/sov-cli/main.rs | 2 +- examples/demo-rollup/tests/bank/mod.rs | 2 +- examples/demo-stf/README.md | 16 ++- examples/demo-stf/src/app.rs | 56 ----------- examples/demo-stf/src/cli.rs | 10 +- examples/demo-stf/src/genesis_config.rs | 39 +++----- examples/demo-stf/src/lib.rs | 70 +++++++++++-- examples/demo-stf/src/runtime.rs | 99 ++++++++----------- examples/demo-stf/src/tests/stf_tests.rs | 25 ++++- full-node/sov-ethereum/src/lib.rs | 2 +- .../sov-modules-macros/src/rpc/expose_rpc.rs | 3 + 18 files changed, 180 insertions(+), 176 deletions(-) delete mode 100644 examples/demo-stf/src/app.rs diff --git a/examples/demo-prover/benches/prover_bench.rs b/examples/demo-prover/benches/prover_bench.rs index 68e5bcff4..b34198e4f 100644 --- a/examples/demo-prover/benches/prover_bench.rs +++ b/examples/demo-prover/benches/prover_bench.rs @@ -8,8 +8,8 @@ use std::sync::{Arc, Mutex}; use anyhow::Context; use const_rollup_config::{ROLLUP_NAMESPACE_RAW, SEQUENCER_DA_ADDRESS}; -use demo_stf::app::App; use demo_stf::genesis_config::{get_genesis_config, GenesisPaths}; +use demo_stf::App; use log4rs::config::{Appender, Config, Root}; use methods::ROLLUP_ELF; use regex::Regex; diff --git a/examples/demo-prover/methods/guest-celestia/src/bin/rollup.rs b/examples/demo-prover/methods/guest-celestia/src/bin/rollup.rs index 729d0d734..742584634 100644 --- a/examples/demo-prover/methods/guest-celestia/src/bin/rollup.rs +++ b/examples/demo-prover/methods/guest-celestia/src/bin/rollup.rs @@ -3,10 +3,9 @@ #![no_main] use const_rollup_config::ROLLUP_NAMESPACE_RAW; -use demo_stf::app::create_zk_app_template; +use demo_stf::{create_zk_app_template, AppVerifier}; use sov_celestia_adapter::types::NamespaceId; use sov_celestia_adapter::verifier::CelestiaVerifier; -use demo_stf::AppVerifier; use sov_risc0_adapter::guest::Risc0Guest; // The rollup stores its data in the namespace b"sov-test" on Celestia diff --git a/examples/demo-prover/methods/guest-mock/src/bin/mock_da.rs b/examples/demo-prover/methods/guest-mock/src/bin/mock_da.rs index dc24324a0..210977fdb 100644 --- a/examples/demo-prover/methods/guest-mock/src/bin/mock_da.rs +++ b/examples/demo-prover/methods/guest-mock/src/bin/mock_da.rs @@ -1,7 +1,6 @@ #![no_main] -use demo_stf::app::create_zk_app_template; -use demo_stf::AppVerifier; +use demo_stf::{create_zk_app_template, AppVerifier}; use sov_risc0_adapter::guest::Risc0Guest; use sov_rollup_interface::mocks::MockDaVerifier; @@ -13,7 +12,7 @@ pub fn main() { let mut stf_verifier = AppVerifier::new(create_zk_app_template::(), MockDaVerifier {}); - + stf_verifier .run_block(guest) .expect("Prover must be honest"); diff --git a/examples/demo-rollup/benches/rollup_bench.rs b/examples/demo-rollup/benches/rollup_bench.rs index 4b0855710..08aa75eb7 100644 --- a/examples/demo-rollup/benches/rollup_bench.rs +++ b/examples/demo-rollup/benches/rollup_bench.rs @@ -6,8 +6,8 @@ use std::time::Duration; use anyhow::Context; use criterion::{criterion_group, criterion_main, Criterion}; -use demo_stf::app::App; use demo_stf::genesis_config::{get_genesis_config, GenesisPaths}; +use demo_stf::App; use rng_xfers::{RngDaService, RngDaSpec}; use sov_db::ledger_db::{LedgerDB, SlotCommit}; use sov_risc0_adapter::host::Risc0Verifier; diff --git a/examples/demo-rollup/benches/rollup_coarse_measure.rs b/examples/demo-rollup/benches/rollup_coarse_measure.rs index e9118b499..d37e6c4f4 100644 --- a/examples/demo-rollup/benches/rollup_coarse_measure.rs +++ b/examples/demo-rollup/benches/rollup_coarse_measure.rs @@ -5,8 +5,8 @@ use std::sync::Arc; use std::time::{Duration, Instant}; use anyhow::Context; -use demo_stf::app::App; use demo_stf::genesis_config::{get_genesis_config, GenesisPaths}; +use demo_stf::App; use prometheus::{Histogram, HistogramOpts, Registry}; use rng_xfers::{RngDaService, RngDaSpec}; use sov_db::ledger_db::{LedgerDB, SlotCommit}; diff --git a/examples/demo-rollup/src/register_rpc.rs b/examples/demo-rollup/src/register_rpc.rs index 57d1a340b..9f119dc69 100644 --- a/examples/demo-rollup/src/register_rpc.rs +++ b/examples/demo-rollup/src/register_rpc.rs @@ -1,7 +1,7 @@ //! Full-Node specific RPC methods. use anyhow::Context; -use demo_stf::app::App; +use demo_stf::App; use sov_celestia_adapter::verifier::address::CelestiaAddress; use sov_db::ledger_db::LedgerDB; #[cfg(feature = "experimental")] diff --git a/examples/demo-rollup/src/rollup.rs b/examples/demo-rollup/src/rollup.rs index a17edb1fa..90585ffd6 100644 --- a/examples/demo-rollup/src/rollup.rs +++ b/examples/demo-rollup/src/rollup.rs @@ -4,12 +4,9 @@ use std::str::FromStr; use anyhow::Context; use const_rollup_config::SEQUENCER_DA_ADDRESS; -#[cfg(feature = "experimental")] -use demo_stf::app::DefaultPrivateKey; -use demo_stf::app::{create_zk_app_template, App, DefaultContext}; use demo_stf::genesis_config::{get_genesis_config, GenesisPaths, StorageConfig}; use demo_stf::runtime::{get_rpc_methods, GenesisConfig, Runtime}; -use demo_stf::AppVerifier; +use demo_stf::{create_zk_app_template, App, AppVerifier}; #[cfg(feature = "experimental")] use secp256k1::SecretKey; use sov_celestia_adapter::verifier::address::CelestiaAddress; @@ -20,7 +17,9 @@ use sov_cli::wallet_state::PrivateKeyAndAddress; use sov_db::ledger_db::LedgerDB; #[cfg(feature = "experimental")] use sov_ethereum::experimental::EthRpcConfig; -use sov_modules_api::default_context::ZkDefaultContext; +use sov_modules_api::default_context::{DefaultContext, ZkDefaultContext}; +#[cfg(feature = "experimental")] +use sov_modules_api::default_signature::private_key::DefaultPrivateKey; use sov_modules_stf_template::AppTemplate; use sov_rollup_interface::mocks::{ MockAddress, MockDaConfig, MockDaService, MOCK_SEQUENCER_DA_ADDRESS, @@ -69,9 +68,10 @@ pub fn configure_prover( da_verifier: Da::Verifier, ) -> Prover, Da, Vm> { let config = match cfg { - DemoProverConfig::Simulate => { - ProofGenConfig::Simulate(AppVerifier::new(create_zk_app_template(), da_verifier)) - } + DemoProverConfig::Simulate => ProofGenConfig::Simulate(AppVerifier::new( + create_zk_app_template::(), + da_verifier, + )), DemoProverConfig::Execute => ProofGenConfig::Execute, DemoProverConfig::Prove => ProofGenConfig::Prover, }; diff --git a/examples/demo-rollup/src/sov-cli/main.rs b/examples/demo-rollup/src/sov-cli/main.rs index 1447f19f3..685cadc7d 100644 --- a/examples/demo-rollup/src/sov-cli/main.rs +++ b/examples/demo-rollup/src/sov-cli/main.rs @@ -1,6 +1,6 @@ #[tokio::main] async fn main() -> Result<(), anyhow::Error> { - demo_stf::cli::run::< + demo_stf::cli::run_wallet::< ::Spec, >() .await diff --git a/examples/demo-rollup/tests/bank/mod.rs b/examples/demo-rollup/tests/bank/mod.rs index 3dd6ef5af..4a1ef54ec 100644 --- a/examples/demo-rollup/tests/bank/mod.rs +++ b/examples/demo-rollup/tests/bank/mod.rs @@ -1,7 +1,6 @@ use std::net::SocketAddr; use borsh::BorshSerialize; -use demo_stf::app::DefaultPrivateKey; use demo_stf::genesis_config::GenesisPaths; use demo_stf::runtime::RuntimeCall; use jsonrpsee::core::client::{Subscription, SubscriptionClientT}; @@ -9,6 +8,7 @@ use jsonrpsee::rpc_params; use methods::MOCK_DA_ELF; use sov_demo_rollup::DemoProverConfig; 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; diff --git a/examples/demo-stf/README.md b/examples/demo-stf/README.md index c0bbc94b7..59c3c7dcc 100644 --- a/examples/demo-stf/README.md +++ b/examples/demo-stf/README.md @@ -60,15 +60,27 @@ The final piece of the puzzle is your app's runtime. A runtime is just a list of module to your app, just add an additional field to the runtime. ```rust +use sov_modules_api::{Genesis, DispatchCall, MessageCodec, Context}; +use sov_modules_api::macros::expose_rpc; +use sov_sequencer::Sequencer; +use sov_rollup_interface::da::DaSpec; +#[cfg(feature = "native")] +use sov_accounts::{AccountsRpcImpl, AccountsRpcServer}; +#[cfg(feature = "native")] +use sov_bank::{BankRpcImpl, BankRpcServer}; +#[cfg(feature = "native")] +use sov_sequencer_registry::{SequencerRegistryRpcImpl, SequencerRegistryRpcServer}; + + #[cfg_attr( feature = "native", expose_rpc(DefaultContext) )] #[derive(Genesis, DispatchCall, MessageCodec)] #[serialization(borsh::BorshDeserialize, borsh::BorshSerialize)] -pub struct MyRuntime { +pub struct MyRuntime { #[allow(unused)] - sequencer: sov_sequencer_registry::Sequencer, + sequencer: sov_sequencer_registry::SequencerRegistry, #[allow(unused)] bank: sov_bank::Bank, diff --git a/examples/demo-stf/src/app.rs b/examples/demo-stf/src/app.rs deleted file mode 100644 index 358cfd479..000000000 --- a/examples/demo-stf/src/app.rs +++ /dev/null @@ -1,56 +0,0 @@ -#[cfg(feature = "native")] -pub use sov_modules_api::default_context::DefaultContext; -pub use sov_modules_api::default_context::ZkDefaultContext; -#[cfg(feature = "native")] -pub use sov_modules_api::default_signature::private_key::DefaultPrivateKey; -#[cfg(feature = "native")] -use sov_modules_api::Spec; -use sov_modules_stf_template::AppTemplate; -pub use sov_modules_stf_template::Batch; -use sov_rollup_interface::da::DaSpec; -use sov_rollup_interface::zk::Zkvm; -#[cfg(feature = "native")] -use sov_sequencer::batch_builder::FiFoStrictBatchBuilder; -#[cfg(feature = "native")] -use sov_state::config::Config as StorageConfig; -use sov_state::ZkStorage; -#[cfg(feature = "native")] -use sov_state::{ProverStorage, Storage}; - -use crate::runtime::Runtime; - -#[cfg(feature = "native")] -pub struct App { - pub stf: AppTemplate>, - pub batch_builder: Option, DefaultContext>>, -} - -#[cfg(feature = "native")] -impl App { - pub fn new(storage_config: StorageConfig) -> Self { - let storage = - ProverStorage::with_config(storage_config).expect("Failed to open prover storage"); - let app = AppTemplate::new(storage.clone(), Runtime::default()); - let batch_size_bytes = 1024 * 100; // 100 KB - let batch_builder = FiFoStrictBatchBuilder::new( - batch_size_bytes, - u32::MAX as usize, - Runtime::default(), - storage, - ); - Self { - stf: app, - batch_builder: Some(batch_builder), - } - } - - pub fn get_storage(&self) -> ::Storage { - self.stf.current_storage.clone() - } -} - -pub fn create_zk_app_template( -) -> AppTemplate> { - let storage = ZkStorage::new(); - AppTemplate::new(storage, Runtime::default()) -} diff --git a/examples/demo-stf/src/cli.rs b/examples/demo-stf/src/cli.rs index 86523900f..2d003d8da 100644 --- a/examples/demo-stf/src/cli.rs +++ b/examples/demo-stf/src/cli.rs @@ -1,3 +1,4 @@ +//! Generates wallet cli for the runtime. use sov_cli::wallet_state::WalletState; use sov_cli::workflows::keys::KeyWorkflow; use sov_cli::workflows::rpc::RpcWorkflows; @@ -14,7 +15,7 @@ type Ctx = DefaultContext; #[derive(clap::Subcommand)] #[command(author, version, about, long_about = None)] -pub enum Workflows { +enum Workflows { #[clap(subcommand)] Transactions( TransactionWorkflow< @@ -30,12 +31,13 @@ pub enum Workflows { #[derive(clap::Parser)] #[command(author, version, about, long_about = None)] -pub struct App { +struct CliApp { #[clap(subcommand)] workflow: Workflows, } -pub async fn run( +/// Runs wallet cli. +pub async fn run_wallet( ) -> Result<(), anyhow::Error> { let app_dir = wallet_dir()?; std::fs::create_dir_all(app_dir.as_ref())?; @@ -44,7 +46,7 @@ pub async fn run( let mut wallet_state: WalletState, Ctx> = WalletState::load(&wallet_state_path)?; - let invocation = App::::parse(); + let invocation = CliApp::::parse(); match invocation.workflow { Workflows::Transactions(tx) => tx diff --git a/examples/demo-stf/src/genesis_config.rs b/examples/demo-stf/src/genesis_config.rs index 29f9e41b1..5f538e731 100644 --- a/examples/demo-stf/src/genesis_config.rs +++ b/examples/demo-stf/src/genesis_config.rs @@ -1,3 +1,7 @@ +//! While the `GenesisConfig` type for `Rollup` is generated from the underlying runtime through a macro, +//! specific module configurations are obtained from files. This code is responsible for the logic +//! that transforms module genesis data into Rollup genesis data. + use std::convert::AsRef; use std::path::Path; @@ -6,7 +10,6 @@ use serde::de::DeserializeOwned; use sov_accounts::AccountConfig; use sov_bank::BankConfig; use sov_chain_state::ChainStateConfig; -use sov_cli::wallet_state::PrivateKeyAndAddress; #[cfg(feature = "experimental")] use sov_evm::EvmConfig; pub use sov_modules_api::default_context::DefaultContext; @@ -20,18 +23,22 @@ use sov_value_setter::ValueSetterConfig; /// Creates config for a rollup with some default settings, the config is used in demos and tests. use crate::runtime::GenesisConfig; -pub const LOCKED_AMOUNT: u64 = 50; -pub const DEMO_TOKEN_NAME: &str = "sov-demo-token"; - /// Paths pointing to genesis files. pub struct GenesisPaths> { + /// Bank genesis path. pub bank_genesis_path: P, + /// Sequencer Registry genesis path. pub sequencer_genesis_path: P, + /// Value Setter genesis path. pub value_setter_genesis_path: P, + /// Accounts genesis path. pub accounts_genesis_path: P, + /// Chain State genesis path. pub chain_state_genesis_path: P, + /// Nft genesis path. pub nft_path: P, #[cfg(feature = "experimental")] + /// EVM genesis path. pub evm_genesis_path: P, } @@ -108,9 +115,9 @@ fn create_genesis_config>( chain_state_config, value_setter_config, accounts_config, + nft_config, #[cfg(feature = "experimental")] evm_config, - nft_config, )) } @@ -141,25 +148,3 @@ fn get_evm_config>( Ok(config) } - -pub fn read_private_key() -> PrivateKeyAndAddress { - // TODO fix the hardcoded path: #872 - let token_deployer_data = - std::fs::read_to_string("../test-data/keys/token_deployer_private_key.json") - .expect("Unable to read file to string"); - - let token_deployer: PrivateKeyAndAddress = serde_json::from_str(&token_deployer_data) - .unwrap_or_else(|_| { - panic!( - "Unable to convert data {} to PrivateKeyAndAddress", - &token_deployer_data - ) - }); - - assert!( - token_deployer.is_matching_to_default(), - "Inconsistent key data" - ); - - token_deployer -} diff --git a/examples/demo-stf/src/lib.rs b/examples/demo-stf/src/lib.rs index c5a640213..bf30e33ed 100644 --- a/examples/demo-stf/src/lib.rs +++ b/examples/demo-stf/src/lib.rs @@ -1,20 +1,30 @@ -pub mod app; +#![deny(missing_docs)] +#![doc = include_str!("../README.md")] +#[cfg(feature = "native")] +pub mod cli; #[cfg(feature = "native")] pub mod genesis_config; -pub mod hooks_impl; +mod hooks_impl; pub mod runtime; #[cfg(test)] -pub mod tests; - -#[cfg(feature = "native")] -pub mod cli; - +mod tests; use runtime::Runtime; +#[cfg(feature = "native")] +use sov_modules_api::default_context::DefaultContext; use sov_modules_api::default_context::ZkDefaultContext; +#[cfg(feature = "native")] +use sov_modules_api::Spec; use sov_modules_stf_template::AppTemplate; -use sov_rollup_interface::da::DaVerifier; -pub use sov_state::ArrayWitness; +use sov_rollup_interface::da::{DaSpec, DaVerifier}; +use sov_rollup_interface::zk::Zkvm; +#[cfg(feature = "native")] +use sov_sequencer::batch_builder::FiFoStrictBatchBuilder; +#[cfg(feature = "native")] +use sov_state::config::Config as StorageConfig; +use sov_state::ZkStorage; +#[cfg(feature = "native")] +use sov_state::{ProverStorage, Storage}; use sov_stf_runner::verifier::StateTransitionVerifier; /// A verifier for the demo rollup @@ -28,3 +38,45 @@ pub type AppVerifier = StateTransitionVerifier< DA, Zk, >; + +/// Contains StateTransitionFunction and other necessary dependencies needed for implementing a full node. +#[cfg(feature = "native")] +pub struct App { + /// Concrete state transition function. + pub stf: AppTemplate>, + /// Batch builder. + pub batch_builder: Option, DefaultContext>>, +} + +#[cfg(feature = "native")] +impl App { + /// Creates a new `App`. + pub fn new(storage_config: StorageConfig) -> Self { + let storage = + ProverStorage::with_config(storage_config).expect("Failed to open prover storage"); + let app = AppTemplate::new(storage.clone(), Runtime::default()); + let batch_size_bytes = 1024 * 100; // 100 KB + let batch_builder = FiFoStrictBatchBuilder::new( + batch_size_bytes, + u32::MAX as usize, + Runtime::default(), + storage, + ); + Self { + stf: app, + batch_builder: Some(batch_builder), + } + } + + /// Gets underlying storage. + pub fn get_storage(&self) -> ::Storage { + self.stf.current_storage.clone() + } +} + +/// Create `StateTransitionFunction` for Zk context. +pub fn create_zk_app_template( +) -> AppTemplate> { + let storage = ZkStorage::new(); + AppTemplate::new(storage, Runtime::default()) +} diff --git a/examples/demo-stf/src/runtime.rs b/examples/demo-stf/src/runtime.rs index 4c293a9cc..1d9c42a0d 100644 --- a/examples/demo-stf/src/runtime.rs +++ b/examples/demo-stf/src/runtime.rs @@ -1,3 +1,36 @@ +//! The Rollup entrypoint. +//! +//! On a high level, the rollup node receives serialized call messages from the DA layer and executes them as atomic transactions. +//! Upon reception, the message has to be deserialized and forwarded to an appropriate module. +//! +//! The module-specific logic is implemented by module creators, but all the glue code responsible for message +//! deserialization/forwarding is handled by a rollup `runtime`. +//! +//! In order to define the runtime we need to specify all the modules supported by our rollup (see the `Runtime` struct bellow) +//! +//! The `Runtime` together with associated interfaces (`Genesis`, `DispatchCall`, `MessageCodec`) +//! and derive macros defines: +//! - how the rollup modules are wired up together. +//! - how the state of the rollup is initialized. +//! - how messages are dispatched to appropriate modules. +//! +//! Runtime lifecycle: +//! +//! 1. Initialization: +//! When a rollup is deployed for the first time, it needs to set its genesis state. +//! The `#[derive(Genesis)` macro will generate `Runtime::genesis(config)` method which returns +//! `Storage` with the initialized state. +//! +//! 2. Calls: +//! The `Module` interface defines a `call` method which accepts a module-defined type and triggers the specific `module logic.` +//! In general, the point of a call is to change the module state, but if the call throws an error, +//! no module specific state is updated (the transaction is reverted). +//! +//! `#[derive(MessageCodec)` adds deserialization capabilities to the `Runtime` (implements `decode_call` method). +//! `Runtime::decode_call` accepts serialized call message and returns a type that implements the `DispatchCall` trait. +//! The `DispatchCall` implementation (derived by a macro) forwards the message to the appropriate module and executes its `call` method. + +#![allow(unused_doc_comments)] #[cfg(feature = "native")] use sov_accounts::{AccountsRpcImpl, AccountsRpcServer}; #[cfg(feature = "native")] @@ -24,42 +57,7 @@ use sov_sequencer_registry::{SequencerRegistryRpcImpl, SequencerRegistryRpcServe #[cfg(feature = "native")] use sov_value_setter::{ValueSetterRpcImpl, ValueSetterRpcServer}; -/// The Rollup entrypoint. -/// -/// On a high level, the rollup node receives serialized call messages from the DA layer and executes them as atomic transactions. -/// Upon reception, the message has to be deserialized and forwarded to an appropriate module. -/// -/// The module-specific logic is implemented by module creators, but all the glue code responsible for message -/// deserialization/forwarding is handled by a rollup `runtime`. -/// -/// In order to define the runtime we need to specify all the modules supported by our rollup (see the `Runtime` struct bellow) -/// -/// The `Runtime` together with associated interfaces (`Genesis`, `DispatchCall`, `MessageCodec`) -/// and derive macros defines: -/// - how the rollup modules are wired up together. -/// - how the state of the rollup is initialized. -/// - how messages are dispatched to appropriate modules. -/// -/// Runtime lifecycle: -/// -/// 1. Initialization: -/// When a rollup is deployed for the first time, it needs to set its genesis state. -/// The `#[derive(Genesis)` macro will generate `Runtime::genesis(config)` method which returns -/// `Storage` with the initialized state. -/// -/// 2. Calls: -/// The `Module` interface defines a `call` method which accepts a module-defined type and triggers the specific `module logic.` -/// In general, the point of a call is to change the module state, but if the call throws an error, -/// no state is updated (the transaction is reverted). -/// -/// `#[derive(MessageCodec)` adds deserialization capabilities to the `Runtime` (implements `decode_call` method). -/// `Runtime::decode_call` accepts serialized call message and returns a type that implements the `DispatchCall` trait. -/// The `DispatchCall` implementation (derived by a macro) forwards the message to the appropriate module and executes its `call` method. -/// -/// Similar mechanism works for queries with the difference that queries are submitted by users directly to the rollup node -/// instead of going through the DA layer. - -#[cfg(not(feature = "experimental"))] +/// The `demo-stf runtime`. #[cfg_attr(feature = "native", derive(CliWallet), expose_rpc)] #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] #[serialization(borsh::BorshDeserialize, borsh::BorshSerialize)] @@ -68,37 +66,26 @@ use sov_value_setter::{ValueSetterRpcImpl, ValueSetterRpcServer}; serialization(serde::Serialize, serde::Deserialize) )] pub struct Runtime { + /// The Bank module. pub bank: sov_bank::Bank, + /// The Sequencer Registry module. pub sequencer_registry: sov_sequencer_registry::SequencerRegistry, #[cfg_attr(feature = "native", cli_skip)] + /// The Blob Storage module. pub blob_storage: sov_blob_storage::BlobStorage, #[cfg_attr(feature = "native", cli_skip)] + /// The Chain State module. pub chain_state: sov_chain_state::ChainState, + /// The Value Setter module. pub value_setter: sov_value_setter::ValueSetter, + /// The Accounts module. pub accounts: sov_accounts::Accounts, + /// The NFT module. pub nft: sov_nft_module::NonFungibleToken, -} - -#[cfg(feature = "experimental")] -#[cfg_attr(feature = "native", derive(CliWallet), expose_rpc)] -#[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] -#[serialization(borsh::BorshDeserialize, borsh::BorshSerialize)] -#[cfg_attr( - feature = "native", - serialization(serde::Serialize, serde::Deserialize) -)] -pub struct Runtime { - pub bank: sov_bank::Bank, - pub sequencer_registry: sov_sequencer_registry::SequencerRegistry, - #[cfg_attr(feature = "native", cli_skip)] - pub blob_storage: sov_blob_storage::BlobStorage, - #[cfg_attr(feature = "native", cli_skip)] - pub chain_state: sov_chain_state::ChainState, - pub value_setter: sov_value_setter::ValueSetter, - pub accounts: sov_accounts::Accounts, + #[cfg(feature = "experimental")] #[cfg_attr(feature = "native", cli_skip)] + /// The EVM module. pub evm: sov_evm::Evm, - pub nft: sov_nft_module::NonFungibleToken, } impl sov_modules_stf_template::Runtime for Runtime diff --git a/examples/demo-stf/src/tests/stf_tests.rs b/examples/demo-stf/src/tests/stf_tests.rs index 70077abab..17dc7d210 100644 --- a/examples/demo-stf/src/tests/stf_tests.rs +++ b/examples/demo-stf/src/tests/stf_tests.rs @@ -1,17 +1,17 @@ #[cfg(test)] pub mod test { + use sov_cli::wallet_state::PrivateKeyAndAddress; use sov_data_generators::bank_data::get_default_token_address; use sov_data_generators::{has_tx_events, new_test_blob_from_batch}; use sov_modules_api::default_context::DefaultContext; use sov_modules_api::default_signature::private_key::DefaultPrivateKey; - use sov_modules_api::{PrivateKey, WorkingSet}; + use sov_modules_api::{Context, PrivateKey, WorkingSet}; use sov_modules_stf_template::{Batch, SequencerOutcome}; use sov_rollup_interface::mocks::{MockBlock, MockDaSpec, MOCK_SEQUENCER_DA_ADDRESS}; use sov_rollup_interface::stf::StateTransitionFunction; use sov_state::ProverStorage; - use crate::genesis_config::read_private_key; use crate::runtime::Runtime; use crate::tests::da_simulation::simulate_da; use crate::tests::{create_new_app_template_for_tests, get_genesis_config_for_tests, C}; @@ -217,4 +217,25 @@ pub mod test { // Assert that there are no events assert!(!has_tx_events(&apply_blob_outcome)); } + + fn read_private_key() -> PrivateKeyAndAddress { + let token_deployer_data = + std::fs::read_to_string("../test-data/keys/token_deployer_private_key.json") + .expect("Unable to read file to string"); + + let token_deployer: PrivateKeyAndAddress = serde_json::from_str(&token_deployer_data) + .unwrap_or_else(|_| { + panic!( + "Unable to convert data {} to PrivateKeyAndAddress", + &token_deployer_data + ) + }); + + assert!( + token_deployer.is_matching_to_default(), + "Inconsistent key data" + ); + + token_deployer + } } diff --git a/full-node/sov-ethereum/src/lib.rs b/full-node/sov-ethereum/src/lib.rs index 264e5420a..0a9e4bbe0 100644 --- a/full-node/sov-ethereum/src/lib.rs +++ b/full-node/sov-ethereum/src/lib.rs @@ -12,7 +12,6 @@ pub mod experimental { use std::sync::{Arc, Mutex}; use borsh::ser::BorshSerialize; - use demo_stf::app::DefaultPrivateKey; use demo_stf::runtime::{DefaultContext, Runtime}; use ethers::types::{Bytes, H256}; use jsonrpsee::types::ErrorObjectOwned; @@ -22,6 +21,7 @@ pub mod experimental { }; use reth_rpc_types::{CallRequest, TransactionRequest, TypedTransactionRequest}; use sov_evm::{CallMessage, Evm, RlpEvmTransaction}; + use sov_modules_api::default_signature::private_key::DefaultPrivateKey; use sov_modules_api::transaction::Transaction; use sov_modules_api::utils::to_jsonrpsee_error_object; use sov_modules_api::{EncodeCall, WorkingSet}; diff --git a/module-system/sov-modules-macros/src/rpc/expose_rpc.rs b/module-system/sov-modules-macros/src/rpc/expose_rpc.rs index 96451b5e3..77bf55479 100644 --- a/module-system/sov-modules-macros/src/rpc/expose_rpc.rs +++ b/module-system/sov-modules-macros/src/rpc/expose_rpc.rs @@ -70,6 +70,7 @@ impl ExposeRpcMacro { let mut rpc_trait_impls = proc_macro2::TokenStream::new(); for field in fields { + let attrs = field.attrs; let ty = match field.ty { syn::Type::Path(type_path) => type_path.clone(), _ => panic!("Expected a path type"), @@ -91,6 +92,7 @@ impl ExposeRpcMacro { syn::Ident::new(&format!("{}RpcServer", &module_ident), module_ident.span()); let merge_operation = quote! { + #(#attrs)* module .merge(#rpc_server_ident:: #field_path_args ::into_rpc(r.clone())) .unwrap(); @@ -99,6 +101,7 @@ impl ExposeRpcMacro { merge_operations.extend(merge_operation); let rpc_trait_impl = quote! { + #(#attrs)* impl #impl_generics #rpc_trait_ident #field_path_args for RpcStorage #ty_generics #where_clause { /// Get a working set on top of the current storage fn get_working_set(&self) -> ::sov_modules_api::WorkingSet<#context_type>