Skip to content

Commit

Permalink
Refactor genesis and stdlib builder (#719)
Browse files Browse the repository at this point in the history
* [Genesis] Refactor stdlib and genesis build
* [ci] Run the rooch-framework-test via 1 thread
  • Loading branch information
jolestar authored Aug 30, 2023
1 parent 5486900 commit 1b5fbed
Show file tree
Hide file tree
Showing 52 changed files with 1,018 additions and 1,360 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/check_build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ jobs:
- name: Build
run: cargo build
- name: Execute rust tests
run: cargo nextest run --workspace --all-features
run: cargo nextest run --workspace --all-features --exclude rooch-framework-tests -v
- name: Execute the framework test with 1 thread
run: cargo nextest run -p rooch-framework-tests -v -j 1
- name: Run CLI integration test
# cargo-nextest does not support the CLI integration test powered by Cucumber Rust.
# Use cargo test to run CLI integration tests.
Expand Down
11 changes: 11 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ num-derive = "0.3.3"
num-traits = "0.2.15"
once_cell = "1.10.0"
parking_lot = "0.12.1"
pathdiff = "0.2.1"
petgraph = "0.5.1"
primitive-types = { version = "0.12.1", features = ["serde", "arbitrary"] }
prost = "0.11"
Expand Down
21 changes: 12 additions & 9 deletions crates/rooch-executor/src/actor/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ use rooch_types::transaction::{AbstractTransaction, TransactionSequenceMapping};
use rooch_types::H256;

pub struct ExecutorActor {
genesis: RoochGenesis,
moveos: MoveOS,
rooch_store: RoochStore,
}
Expand All @@ -55,43 +56,45 @@ type ValidateAuthenticatorResult =
Result<(TxValidateResult, Vec<FunctionCall>, Vec<FunctionCall>), VMStatus>;

impl ExecutorActor {
pub fn new(moveos_store: MoveOSStore, rooch_store: RoochStore) -> Result<Self> {
let genesis: &RoochGenesis = &rooch_genesis::ROOCH_GENESIS;
pub fn new(chain_id: u64, moveos_store: MoveOSStore, rooch_store: RoochStore) -> Result<Self> {
let genesis: RoochGenesis = rooch_genesis::RoochGenesis::build(chain_id)?;
let moveos = MoveOS::new(moveos_store, genesis.all_natives(), genesis.config.clone())?;

let executor = Self {
genesis,
moveos,
rooch_store,
};
executor.init_or_check_genesis()
}

fn init_or_check_genesis(mut self) -> Result<Self> {
let genesis: &RoochGenesis = &rooch_genesis::ROOCH_GENESIS;
if self.moveos.state().is_genesis() {
let genesis_result = self
.moveos
.init_genesis(genesis.genesis_txs(), genesis.genesis_ctx())?;
.init_genesis(self.genesis.genesis_txs(), self.genesis.genesis_ctx())?;
let genesis_state_root = genesis_result
.last()
.expect("Genesis result must not empty")
.0;

//TODO should we save the genesis txs to sequencer?
for (genesis_tx, (state_root, genesis_tx_output)) in
genesis.genesis_txs().into_iter().zip(genesis_result)
self.genesis.genesis_txs().into_iter().zip(genesis_result)
{
self.handle_tx_output(genesis_tx.tx_hash(), state_root, genesis_tx_output)?;
let tx_hash = genesis_tx.tx_hash();
self.handle_tx_output(tx_hash, state_root, genesis_tx_output)?;
}

debug_assert!(
genesis_state_root == genesis.genesis_state_root(),
genesis_state_root == self.genesis.genesis_state_root(),
"Genesis state root mismatch"
);
let genesis_info = GenesisInfo::new(genesis.genesis_package_hash(), genesis_state_root);
let genesis_info =
GenesisInfo::new(self.genesis.genesis_package_hash(), genesis_state_root);
self.moveos.config_store().save_genesis(genesis_info)?;
} else {
genesis.check_genesis(self.moveos.config_store())?;
self.genesis.check_genesis(self.moveos.config_store())?;
}
Ok(self)
}
Expand Down
5 changes: 3 additions & 2 deletions crates/rooch-framework-tests/src/binding_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use moveos_store::MoveOSStore;
use moveos_types::module_binding::{ModuleBinding, MoveFunctionCaller};
use rooch_executor::actor::{executor::ExecutorActor, messages::ExecuteTransactionResult};
use rooch_store::RoochStore;
use rooch_types::transaction::AbstractTransaction;
use rooch_types::{chain_id::RoochChainID, transaction::AbstractTransaction};

pub struct RustBindingTest {
executor: ExecutorActor,
Expand All @@ -17,7 +17,8 @@ impl RustBindingTest {
pub fn new() -> Result<Self> {
let moveos_store = MoveOSStore::mock_moveos_store()?;
let rooch_store = RoochStore::mock_rooch_store()?;
let executor = ExecutorActor::new(moveos_store, rooch_store)?;
let executor =
ExecutorActor::new(RoochChainID::DEV.chain_id().id(), moveos_store, rooch_store)?;
Ok(Self { executor })
}

Expand Down
Loading

0 comments on commit 1b5fbed

Please sign in to comment.