Skip to content

Commit

Permalink
[no ci] Start working on test for runner initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
citizen-stig committed Dec 18, 2023
1 parent 92d34af commit 80d87e7
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion full-node/sov-stf-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ sov-sequencer = { path = "../sov-sequencer" }

sov-state = { path = "../../module-system/sov-state", features = ["native"] }
sov-modules-api = { path = "../../module-system/sov-modules-api", features = ["native"] }
sov-stf-runner = {path = ".", features = ["mock"] }
sov-stf-runner = { path = ".", features = ["mock"] }

sov-mock-da = { path = "../../adapters/mock-da", features = ["native"] }
sov-mock-zkvm = { path = "../../adapters/mock-zkvm" }
sov-prover-storage-manager = { path = "../sov-prover-storage-manager" }


[features]
Expand Down
7 changes: 3 additions & 4 deletions full-node/sov-stf-runner/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ where
pub async fn run_in_process(&mut self) -> Result<(), anyhow::Error> {
for height in self.start_height.. {
debug!("Requesting data for height {}", height);
// TOD0: https://github.com/Sovereign-Labs/sovereign-sdk/issues/1217
// TODO(https://github.com/Sovereign-Labs/sovereign-sdk/issues/1217)
// STF runner should handle re-org
// Assumes we are on chains with instant finality and no change of head happens
let filtered_block = self.da_service.get_block_at(height).await?;
Expand All @@ -188,7 +188,6 @@ where

let mut data_to_commit = SlotCommit::new(filtered_block.clone());

// TODO: Handle an error
let pre_state = self
.storage_manager
.create_storage_on(filtered_block.header())?;
Expand Down Expand Up @@ -249,11 +248,11 @@ where
Ok(ProofSubmissionStatus::Success) => {
break;
}
// TODO(#1185): Add timeout handling.
// TODO(https://github.com/Sovereign-Labs/sovereign-sdk/issues/1185): Add timeout handling.
Ok(ProofSubmissionStatus::ProofGenerationInProgress) => {
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await
}
// TODO(#1185): Add handling for DA submission errors.
// TODO(https://github.com/Sovereign-Labs/sovereign-sdk/issues/1185): Add handling for DA submission errors.
Err(e) => panic!("{:?}", e),
}
}
Expand Down
2 changes: 1 addition & 1 deletion full-node/sov-stf-runner/tests/prover_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use sov_stf_runner::{
};

#[tokio::test]
async fn test_sucesfull_prover_execution() -> Result<(), ProverServiceError> {
async fn test_successful_prover_execution() -> Result<(), ProverServiceError> {
let TestProver {
prover_service, vm, ..
} = make_new_prover();
Expand Down
111 changes: 111 additions & 0 deletions full-node/sov-stf-runner/tests/runner_initialization.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
use sov_db::ledger_db::LedgerDB;
use sov_mock_da::{
MockAddress, MockBlockHeader, MockDaConfig, MockDaService, MockDaSpec, MockDaVerifier,
MockValidityCond,
};
use sov_mock_zkvm::MockZkvm;
use sov_rollup_interface::da::DaSpec;
use sov_rollup_interface::storage::HierarchicalStorageManager;
use sov_stf_runner::mock::MockStf;
use sov_stf_runner::{
InitVariant, ParallelProverService, RollupConfig, RollupProverConfig, RpcConfig, RunnerConfig,
StateTransitionRunner, StorageConfig,
};

struct MockStorageManager<Da: DaSpec> {
phantom_data: std::marker::PhantomData<Da>,
}

impl<Da: DaSpec> Default for MockStorageManager<Da> {
fn default() -> Self {
Self {
phantom_data: std::marker::PhantomData,
}
}
}

impl<Da: DaSpec> HierarchicalStorageManager<Da> for MockStorageManager<Da> {
type NativeStorage = ();
type NativeChangeSet = ();

fn create_storage_on(
&mut self,
_block_header: &Da::BlockHeader,
) -> anyhow::Result<Self::NativeStorage> {
Ok(())
}

fn create_finalized_storage(&mut self) -> anyhow::Result<Self::NativeStorage> {
Ok(())
}

fn save_change_set(
&mut self,
_block_header: &Da::BlockHeader,
_change_set: Self::NativeChangeSet,
) -> anyhow::Result<()> {
Ok(())
}

fn finalize(&mut self, _block_header: &Da::BlockHeader) -> anyhow::Result<()> {
Ok(())
}
}

type Stf = MockStf<MockValidityCond>;
#[tokio::test]
async fn init_and_restart() {
let tmpdir = tempfile::tempdir().unwrap();
let address = MockAddress::new([11u8; 32]);
let rollup_config = RollupConfig::<MockDaConfig> {
storage: StorageConfig {
path: tmpdir.path().to_path_buf(),
},
runner: RunnerConfig {
start_height: 1,
rpc_config: RpcConfig {
bind_host: "127.0.0.1".to_string(),
bind_port: 0,
},
},
da: MockDaConfig {
sender_address: address,
},
};

let da_service = MockDaService::new(address);

let ledger_db = LedgerDB::with_path(tmpdir.path()).unwrap();

let stf = Stf::default();

let storage_manager = MockStorageManager::<MockDaSpec>::default();

let init_variant: InitVariant<MockStf<MockValidityCond>, MockZkvm, MockDaSpec> =
InitVariant::Genesis {
genesis_block_header: MockBlockHeader::from_height(0),
};

let genesis_config = ();

let vm = MockZkvm::default();
let verifier = MockDaVerifier::default();

let prover_config = RollupProverConfig::Prove;

let prover_service =
ParallelProverService::new(vm, stf.clone(), verifier, prover_config, (), 1);

// TODO: Extend test, probably with different STF
let _runner = StateTransitionRunner::new(
rollup_config.runner,
da_service,
ledger_db,
stf,
storage_manager,
init_variant,
genesis_config,
prover_service,
)
.unwrap();
}
2 changes: 1 addition & 1 deletion module-system/sov-modules-rollup-blueprint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub trait RollupBlueprint: Sized + Send + Sync {
.map(|(number, _)| prover_storage.get_root_hash(number.0))
.transpose()?;

// TODO: How to handle that?
// TODO(https://github.com/Sovereign-Labs/sovereign-sdk/issues/1218)
let rpc_methods = self.create_rpc_methods(&prover_storage, &ledger_db, &da_service)?;

let native_stf = StfBlueprint::new();
Expand Down

0 comments on commit 80d87e7

Please sign in to comment.