Skip to content

Commit

Permalink
Simplify generics in AppTemplate. (#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkolad authored Aug 16, 2023
1 parent 6371c32 commit aefb10f
Show file tree
Hide file tree
Showing 25 changed files with 255 additions and 395 deletions.
21 changes: 1 addition & 20 deletions examples/demo-nft-module/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,23 +463,4 @@ pub struct Runtime<C: sov_modules_api::Context> {
#[allow(unused)]
nft: demo_nft_module::NonFungibleToken<C>,
}
```

And then this `Runtime` can be used in the State Transition Function runner to execute transactions.
Here's an example of how to do it with `AppTemplate` from `sov-default-stf`:

```rust, ignore
fn new(runtime_config: Self::RuntimeConfig) -> Self {
let runtime = Runtime::new();
let storage = ZkStorage::with_config(runtime_config).expect("Failed to open zk storage");
let app: AppTemplate<
ZkDefaultContext,
Runtime<ZkDefaultContext>,
Vm,
> = AppTemplate::new(storage, runtime);
Self(app)
}
```

The `AppTemplate` uses `runtime` to dispatch calls during execution of the `apply_batch` method.
Detailed instructions on how to set up a rollup can be found in the [`demo-rollup` documentation](../demo-rollup/README.md).
```
5 changes: 2 additions & 3 deletions examples/demo-prover/host/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use demo_stf::genesis_config::create_demo_genesis_config;
use jupiter::da_service::{CelestiaService, DaServiceConfig};
use jupiter::types::NamespaceId;
use jupiter::verifier::address::CelestiaAddress;
use jupiter::verifier::{ChainValidityCondition, RollupParams};
use jupiter::verifier::{CelestiaSpec, RollupParams};
use methods::{ROLLUP_ELF, ROLLUP_ID};
use risc0_adapter::host::{Risc0Host, Risc0Verifier};
use serde::Deserialize;
Expand Down Expand Up @@ -57,8 +57,7 @@ async fn main() -> Result<(), anyhow::Error> {

let sequencer_private_key = DefaultPrivateKey::generate();

let mut app: App<Risc0Verifier, ChainValidityCondition, jupiter::BlobWithSender> =
App::new(rollup_config.runner.storage.clone());
let mut app: App<Risc0Verifier, CelestiaSpec> = App::new(rollup_config.runner.storage.clone());

let is_storage_empty = app.get_storage().is_empty();

Expand Down
4 changes: 1 addition & 3 deletions examples/demo-prover/methods/guest/src/bin/rollup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ pub fn main() {
env::write(&"blobs have been read\n");

// Step 2: Apply blobs
let mut app = create_zk_app_template::<Risc0Guest, ChainValidityCondition, BlobWithSender>(
prev_state_root_hash,
);
let mut app = create_zk_app_template::<Risc0Guest, CelestiaSpec>(prev_state_root_hash);

let witness: ArrayWitness = guest.read_from_host();
env::write(&"Witness have been read\n");
Expand Down
22 changes: 2 additions & 20 deletions examples/demo-rollup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ This is a demo full node running a simple Sovereign SDK rollup on [Celestia](htt
- [Remote setup](#remote-setup)
- [How to Customize This Example](#how-to-customize-this-example)
- [1. Initialize the DA Service](#1-initialize-the-da-service)
- [2. Initialize the State Transition Function](#2-initialize-the-state-transition-function)
- [3. Run the Main Loop](#3-run-the-main-loop)
- [2. Run the Main Loop](#2-run-the-main-loop)
- [Disclaimer](#disclaimer)
- [Interacting with your Node via RPC](#interacting-with-your-node-via-rpc)
- [Key Concepts](#key-concepts)
Expand Down Expand Up @@ -380,24 +379,7 @@ a remote node. Whichever option you pick, simply place the URL and authenticatio
in the `rollup_config.toml` file and it will be
automatically picked up by the node implementation. For this tutorial, the Makefile below (which also helps start a local Celestia instance) handles this step for you.

### 2. Initialize the State Transition Function

The next step is to initialize your state transition function.

```rust
use demo_stf::app::App;
use risc0_adapter::host::Risc0Verifier;
use jupiter::verifier::ChainValidityCondition;
use sov_stf_runner::StorageConfig;
use std::path::PathBuf;

let config = StorageConfig { path: PathBuf::from("path_readme") };

let mut app: App<Risc0Verifier, ChainValidityCondition, jupiter::BlobWithSender> =
App::new(config);
```

### 3. Run the Main Loop
### 2. Run the Main Loop

The full node implements a simple loop for processing blocks. The workflow is:

Expand Down
10 changes: 10 additions & 0 deletions examples/demo-rollup/benches/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*

- [Native Benchmarks](#native-benchmarks)
- [Methodology](#methodology)
- [Makefile](#makefile)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

# Native Benchmarks
Native benchmarks refer to the performance of the rollup SDK in native mode - this does not involve proving
## Methodology
Expand Down
10 changes: 3 additions & 7 deletions examples/demo-rollup/benches/rollup_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ use demo_stf::app::App;
use demo_stf::genesis_config::create_demo_genesis_config;
use jupiter::verifier::address::CelestiaAddress;
use risc0_adapter::host::Risc0Verifier;
use rng_xfers::RngDaService;
use rng_xfers::{RngDaService, RngDaSpec};
use sov_db::ledger_db::{LedgerDB, SlotCommit};
use sov_modules_api::default_signature::private_key::DefaultPrivateKey;
use sov_modules_api::PrivateKey;
use sov_rollup_interface::mocks::{
MockBlob, MockBlock, MockBlockHeader, MockHash, MockValidityCond,
};
use sov_rollup_interface::mocks::{MockBlock, MockBlockHeader, MockHash, MockValidityCond};
use sov_rollup_interface::services::da::DaService;
use sov_rollup_interface::stf::StateTransitionFunction;
use sov_stf_runner::{from_toml_path, RollupConfig};
Expand Down Expand Up @@ -46,9 +44,7 @@ fn rollup_bench(_bench: &mut Criterion) {

let da_service = Arc::new(RngDaService::new());

let demo_runner = App::<Risc0Verifier, MockValidityCond, MockBlob<CelestiaAddress>>::new(
rollup_config.runner.storage,
);
let demo_runner = App::<Risc0Verifier, RngDaSpec>::new(rollup_config.runner.storage);

let mut demo = demo_runner.stf;
let sequencer_private_key = DefaultPrivateKey::generate();
Expand Down
10 changes: 3 additions & 7 deletions examples/demo-rollup/benches/rollup_coarse_measure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ use demo_stf::genesis_config::create_demo_genesis_config;
use jupiter::verifier::address::CelestiaAddress;
use prometheus::{Histogram, HistogramOpts, Registry};
use risc0_adapter::host::Risc0Verifier;
use rng_xfers::RngDaService;
use rng_xfers::{RngDaService, RngDaSpec};
use sov_db::ledger_db::{LedgerDB, SlotCommit};
use sov_modules_api::default_signature::private_key::DefaultPrivateKey;
use sov_modules_api::PrivateKey;
use sov_rollup_interface::mocks::{
MockBlob, MockBlock, MockBlockHeader, MockHash, MockValidityCond,
};
use sov_rollup_interface::mocks::{MockBlock, MockBlockHeader, MockHash, MockValidityCond};
use sov_rollup_interface::services::da::DaService;
use sov_rollup_interface::stf::StateTransitionFunction;
use sov_stf_runner::{from_toml_path, RollupConfig};
Expand Down Expand Up @@ -94,9 +92,7 @@ async fn main() -> Result<(), anyhow::Error> {

let da_service = Arc::new(RngDaService::new());

let demo_runner = App::<Risc0Verifier, MockValidityCond, MockBlob<CelestiaAddress>>::new(
rollup_config.runner.storage,
);
let demo_runner = App::<Risc0Verifier, RngDaSpec>::new(rollup_config.runner.storage);

let mut demo = demo_runner.stf;
let sequencer_private_key = DefaultPrivateKey::generate();
Expand Down
15 changes: 15 additions & 0 deletions examples/demo-rollup/remote_setup.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*

- [Remote setup](#remote-setup)
- [Set up Celestia](#set-up-celestia)
- [Submitting transactions](#submitting-transactions)
- [Install celestia-appd](#install-celestia-appd)
- [Create local keypair](#create-local-keypair)
- [Create bank transaction](#create-bank-transaction)
- [Submit blob to celestia](#submit-blob-to-celestia)
- [Verify the supply of the new token created](#verify-the-supply-of-the-new-token-created)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Remote setup

This readme covers the steps necessary to setup the sovereign-sdk to work with a remote DA network which includes
Expand Down
60 changes: 60 additions & 0 deletions examples/demo-rollup/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,62 @@
#![deny(missing_docs)]
#![doc = include_str!("../README.md")]

pub mod register_rpc;

use std::str::FromStr;

use const_rollup_config::{ROLLUP_NAMESPACE_RAW, SEQUENCER_DA_ADDRESS};
use demo_stf::app::DefaultPrivateKey;
use demo_stf::genesis_config::create_demo_genesis_config;
use demo_stf::runtime::GenesisConfig;
use jupiter::types::NamespaceId;
use jupiter::verifier::address::CelestiaAddress;
use sov_db::ledger_db::LedgerDB;
use sov_modules_api::default_context::DefaultContext;

/// 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
pub const ROLLUP_NAMESPACE: NamespaceId = NamespaceId(ROLLUP_NAMESPACE_RAW);

/// Initializes a [`LedgerDB`] using the provided `path`.
pub fn initialize_ledger(path: impl AsRef<std::path::Path>) -> LedgerDB {
LedgerDB::with_path(path).expect("Ledger DB failed to open")
}

/// TODO: Remove this when sov-cli is in its own crate.
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct HexKey {
hex_priv_key: String,
address: String,
}

/// Configure our rollup with a centralized sequencer using the SEQUENCER_DA_ADDRESS
/// address constant. Since the centralize sequencer's address is consensus critical,
/// it has to be hardcoded as a constant, rather than read from the config at runtime.
///
/// If you want to customize the rollup to accept transactions from your own celestia
/// address, simply change the value of the SEQUENCER_DA_ADDRESS to your own address.
/// For example:
/// ```rust,no_run
/// const SEQUENCER_DA_ADDRESS: [u8;47] = *b"celestia1qp09ysygcx6npted5yc0au6k9lner05yvs9208";
/// ```
pub fn get_genesis_config() -> GenesisConfig<DefaultContext> {
let hex_key: HexKey = serde_json::from_slice(include_bytes!(
"../../test-data/keys/token_deployer_private_key.json"
))
.expect("Broken key data file");
let sequencer_private_key = DefaultPrivateKey::from_hex(&hex_key.hex_priv_key).unwrap();
assert_eq!(
sequencer_private_key.default_address().to_string(),
hex_key.address,
"Inconsistent key data",
);
let sequencer_da_address = CelestiaAddress::from_str(SEQUENCER_DA_ADDRESS).unwrap();
create_demo_genesis_config(
100000000,
sequencer_private_key.default_address(),
sequencer_da_address.as_ref().to_vec(),
&sequencer_private_key,
&sequencer_private_key,
)
}
Loading

0 comments on commit aefb10f

Please sign in to comment.