From 1c535562b8260c0bce7642aa61e9ace9643cb34c Mon Sep 17 00:00:00 2001 From: bkolad Date: Mon, 30 Oct 2023 12:35:00 +0100 Subject: [PATCH] Add docs --- crates/rollup/src/lib.rs | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/crates/rollup/src/lib.rs b/crates/rollup/src/lib.rs index 5df8602..003d008 100644 --- a/crates/rollup/src/lib.rs +++ b/crates/rollup/src/lib.rs @@ -5,7 +5,6 @@ use async_trait::async_trait; use sov_db::ledger_db::LedgerDB; use sov_modules_api::default_context::{DefaultContext, ZkDefaultContext}; use sov_modules_api::Spec; -use sov_modules_rollup_template::{register_rpc, RollupTemplate, WalletTemplate}; use sov_risc0_adapter::host::Risc0Host; use sov_rollup_interface::mocks::{MockDaConfig, MockDaService, MockDaSpec}; use sov_rollup_interface::services::da::DaService; @@ -17,33 +16,48 @@ use stf_starter::Runtime; /// Rollup with [`MockDaService`]. pub struct StarterRollup {} +/// This is the place, where all the rollup components come together and +/// they can be easily swapped with alternative implementations as needed. #[async_trait] -impl RollupTemplate for StarterRollup { +impl sov_modules_rollup_template::RollupTemplate for StarterRollup { + /// This component defines the Data Availability layer. type DaService = MockDaService; + /// DaSpec & DaConfig are derived from DaService. type DaSpec = MockDaSpec; - type DaConfig = MockDaConfig; + + /// The concrete ZkVm used in the rollup. type Vm = Risc0Host<'static>; + /// Context for the Zero Knowledge environment. type ZkContext = ZkDefaultContext; + /// Context for the ZNative environment. type NativeContext = DefaultContext; + /// Manager for the native storage lifecycle. type StorageManager = sov_state::storage_manager::ProverStorageManager; - type ZkRuntime = Runtime; + /// Runtime for the Zero Knowledge environment. + type ZkRuntime = Runtime; + /// Runtime for the Native environment. type NativeRuntime = Runtime; + /// This method generates RPC methods for the rollup, allowing for extension with custom endpoints. fn create_rpc_methods( &self, storage: &::Storage, ledger_db: &LedgerDB, da_service: &Self::DaService, ) -> anyhow::Result> { - register_rpc::( - storage, ledger_db, da_service, - ) + sov_modules_rollup_template::register_rpc::< + Self::NativeRuntime, + Self::NativeContext, + Self::DaService, + >(storage, ledger_db, da_service) } + // Below, we provide the methods for setting up dependencies for the Rollup. + async fn create_da_service( &self, rollup_config: &RollupConfig, @@ -51,7 +65,10 @@ impl RollupTemplate for StarterRollup { MockDaService::new(rollup_config.da.sender_address) } - fn create_storage_manager(&self, rollup_config: &RollupConfig) -> anyhow::Result { + fn create_storage_manager( + &self, + rollup_config: &RollupConfig, + ) -> anyhow::Result { let storage_config = StorageConfig { path: rollup_config.storage.path.clone(), }; @@ -74,4 +91,5 @@ impl RollupTemplate for StarterRollup { } } -impl WalletTemplate for StarterRollup {} +// Here we get `free` Wallet implementation. +impl sov_modules_rollup_template::WalletTemplate for StarterRollup {}