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

Add docs #3

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
This package is a convenient starting point for building a rollup using the Sovereign SDK:

# The repo structure:
- `crates/stf`: The `STF` is derived from the `Runtime` and is used in the `rollup` and `provers` crates.
- `crates/provers`: This crate is responsible for creating proofs for the `STF`.
- `crates/rollup`: This crate runs the `STF` and offers additional full-node functionalities.

# How to run the sov-rollup-starter:
#### 1. Change the working directory:

```shell,test-ci
$ cd crates/rollup/
```

#### 2. Cleanup database:
#### 2. If you want to run a fresh rollup, clean the database:

```sh,test-ci
$ make clean-db
```

#### 3. Starting the node:
If you want to run a fresh rollup remove the `rollup-starter-data` folder.
#### 3. Start the rollup node:

This will compile and start the rollup node:

```shell,test-ci,bashtestmd:long-running,bashtestmd:wait-until=RPC
$ cargo run --bin node
```

#### 4. In another shell run:
#### 4. Submit a token creation transaction to the `bank` module:

```sh,test-ci
$ make test-create-token
```

#### 5. Test if token creation succeeded
#### 5. Test if token creation succeeded:

```sh,test-ci
$ make test-bank-supply-of
Expand Down
40 changes: 29 additions & 11 deletions crates/rollup/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//#![deny(missing_docs)]
//#![doc = include_str!("../README.md")]
#![deny(missing_docs)]
//! StarterRollup provides a minimal self-contained rollup implementation

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;
Expand All @@ -17,41 +16,59 @@ 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<DefaultStorageSpec>;
type ZkRuntime = Runtime<Self::ZkContext, Self::DaSpec>;

/// Runtime for the Zero Knowledge environment.
type ZkRuntime = Runtime<Self::ZkContext, Self::DaSpec>;
/// Runtime for the Native environment.
type NativeRuntime = Runtime<Self::NativeContext, Self::DaSpec>;

/// This function generates RPC methods for the rollup, allowing for extension with custom endpoints.
fn create_rpc_methods(
&self,
storage: &<Self::NativeContext as Spec>::Storage,
ledger_db: &LedgerDB,
da_service: &Self::DaService,
) -> anyhow::Result<jsonrpsee::RpcModule<()>> {
register_rpc::<Self::NativeRuntime, Self::NativeContext, Self::DaService>(
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<Self::DaConfig>,
) -> Self::DaService {
MockDaService::new(rollup_config.da.sender_address)
}

fn create_storage_manager(&self, rollup_config: &RollupConfig<Self::DaConfig>) -> anyhow::Result<Self::StorageManager> {
fn create_storage_manager(
&self,
rollup_config: &RollupConfig<Self::DaConfig>,
) -> anyhow::Result<Self::StorageManager> {
let storage_config = StorageConfig {
path: rollup_config.storage.path.clone(),
};
Expand All @@ -74,4 +91,5 @@ impl RollupTemplate for StarterRollup {
}
}

impl WalletTemplate for StarterRollup {}
// Here we get a `free` Wallet implementation.
impl sov_modules_rollup_template::WalletTemplate for StarterRollup {}