Skip to content

Commit

Permalink
demo-std refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
bkolad committed Oct 8, 2023
1 parent 62e450d commit 5a5c7c2
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 68 deletions.
58 changes: 0 additions & 58 deletions examples/demo-stf/src/app.rs

This file was deleted.

68 changes: 58 additions & 10 deletions examples/demo-stf/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
//#![deny(missing_docs)]
//#![doc = include_str!("../README.md")]

mod app;
pub use app::*;

#[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::DaSpec;
use sov_rollup_interface::da::DaVerifier;
pub use sov_state::ArrayWitness;
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
Expand All @@ -32,3 +39,44 @@ pub type AppVerifier<DA, Zk> = StateTransitionVerifier<
DA,
Zk,
>;

/// Contains StateTransitionFunction and other necessary dependencies needed for implementing a full node.
#[cfg(feature = "native")]
pub struct App<Vm: Zkvm, Da: DaSpec> {
/// Concrete state transition function.
pub stf: AppTemplate<DefaultContext, Da, Vm, Runtime<DefaultContext, Da>>,
/// Batch builder.
pub batch_builder: Option<FiFoStrictBatchBuilder<Runtime<DefaultContext, Da>, DefaultContext>>,
}

#[cfg(feature = "native")]
impl<Vm: Zkvm, Da: DaSpec> App<Vm, Da> {
/// 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),
}
}

pub fn get_storage(&self) -> <DefaultContext as Spec>::Storage {
self.stf.current_storage.clone()
}
}

/// Create `StateTransitionFunction` for Zk context.
pub fn create_zk_app_template<Vm: Zkvm, Da: DaSpec>(
) -> AppTemplate<ZkDefaultContext, Da, Vm, Runtime<ZkDefaultContext, Da>> {
let storage = ZkStorage::new();
AppTemplate::new(storage, Runtime::default())
}

0 comments on commit 5a5c7c2

Please sign in to comment.