Skip to content

Commit

Permalink
feat: Add ProtocolBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
dhedey committed Apr 28, 2024
1 parent b82a7db commit 4cade4d
Show file tree
Hide file tree
Showing 44 changed files with 1,513 additions and 1,434 deletions.
24 changes: 11 additions & 13 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
{
"rust-analyzer.linkedProjects": [
// Root Workspace & CLIs.
"Cargo.toml",
"radix-clis/Cargo.toml",
// Various blueprints we have.
"examples/everything/Cargo.toml",
"examples/hello-world/Cargo.toml",
"examples/no-std/Cargo.toml",
"radix-clis/tests/blueprints/Cargo.toml",
"radix-engine-tests/assets/blueprints/Cargo.toml",
"radix-engine/assets/blueprints/Cargo.toml",
"radix-transaction-scenarios/assets/blueprints/Cargo.toml",
"scrypto-compiler/tests/assets/scenario_1/Cargo.toml",
"scrypto-compiler/tests/assets/scenario_2/Cargo.toml",
"scrypto-test/assets/blueprints/Cargo.toml",
"scrypto-test/tests/blueprints/Cargo.toml",
// "examples/everything/Cargo.toml",
// "examples/hello-world/Cargo.toml",
// "examples/no-std/Cargo.toml",
// "radix-clis/tests/blueprints/Cargo.toml",
// "radix-engine-tests/assets/blueprints/Cargo.toml",
// "radix-engine/assets/blueprints/Cargo.toml",
// "radix-transaction-scenarios/assets/blueprints/Cargo.toml",
// "scrypto-compiler/tests/assets/scenario_1/Cargo.toml",
// "scrypto-compiler/tests/assets/scenario_2/Cargo.toml",
// "scrypto-test/assets/blueprints/Cargo.toml",
// "scrypto-test/tests/blueprints/Cargo.toml",
],
"cSpell.words": [
"accesscontroller",
Expand Down
24 changes: 12 additions & 12 deletions radix-clis/src/resim/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::resim::*;
use radix_common::prelude::*;
use radix_engine::updates::ProtocolUpdates;
use radix_substate_store_interface::db_key_mapper::*;
use radix_substate_store_interface::interface::*;
use radix_engine::updates::*;
use std::env;
use std::fs;
use std::path::PathBuf;
Expand All @@ -13,6 +11,7 @@ pub struct SimulatorEnvironment {
pub db: RocksdbSubstateStore,
// VMs
pub scrypto_vm: ScryptoVm<DefaultWasmEngine>,
pub network_definition: NetworkDefinition,
}

impl SimulatorEnvironment {
Expand All @@ -23,7 +22,11 @@ impl SimulatorEnvironment {
// Create the VMs
let scrypto_vm = ScryptoVm::<DefaultWasmEngine>::default();

let mut env = Self { db, scrypto_vm };
let mut env = Self {
db,
scrypto_vm,
network_definition: NetworkDefinition::simulator(),
};
env.bootstrap();

Ok(env)
Expand All @@ -42,17 +45,14 @@ impl SimulatorEnvironment {
let vm = VmInit::new(&self.scrypto_vm, NoExtension);

// Bootstrap
Bootstrapper::new(NetworkDefinition::simulator(), &mut self.db, vm, false)
Bootstrapper::new(self.network_definition.clone(), &mut self.db, vm, false)
.bootstrap_test_default();

// Run the protocol updates - unlike the test runner, the user has no way in whether they
// Run the protocol updates - for now, unlike the test runner, the user has no way in whether they
// get these protocol updates or not.
for state_updates in
ProtocolUpdates::all().generate_state_updates(&self.db, &NetworkDefinition::simulator())
{
let db_updates = state_updates.create_database_updates::<SpreadPrefixKeyMapper>();
self.db.commit(&db_updates);
}
ProtocolBuilder::for_network(&self.network_definition)
.until_latest_protocol_version()
.commit_each_protocol_update(&mut self.db);
}
}

Expand Down
8 changes: 6 additions & 2 deletions radix-clis/src/resim/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ pub fn handle_system_transaction<O: std::io::Write>(
print_receipt: bool,
out: &mut O,
) -> Result<TransactionReceipt, Error> {
let SimulatorEnvironment { mut db, scrypto_vm } = SimulatorEnvironment::new()?;
let SimulatorEnvironment {
mut db, scrypto_vm, ..
} = SimulatorEnvironment::new()?;
let vm_init = VmInit::new(&scrypto_vm, NoExtension);

let nonce = get_nonce()?;
Expand Down Expand Up @@ -240,7 +242,9 @@ pub fn handle_manifest<O: std::io::Write>(
Ok(None)
}
None => {
let SimulatorEnvironment { mut db, scrypto_vm } = SimulatorEnvironment::new()?;
let SimulatorEnvironment {
mut db, scrypto_vm, ..
} = SimulatorEnvironment::new()?;
let vm_init = VmInit::new(&scrypto_vm, NoExtension);

let sks = get_signing_keys(signing_keys)?;
Expand Down
9 changes: 4 additions & 5 deletions radix-engine-tests/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,10 @@ pub mod path_macros {
};
}

#[macro_export]
macro_rules! path_local_metering_assets {
($folder: expr) => {
concat!(env!("CARGO_MANIFEST_DIR"), "/assets/metering/", $folder)
};
// Not a macro, because it needs to support a variable folder, but here
// for consistency
pub fn path_local_metering_assets(folder: &str) -> String {
format!("{}/assets/metering/{}", env!("CARGO_MANIFEST_DIR"), folder)
}

pub use crate::include_local_wasm_str;
Expand Down
Loading

0 comments on commit 4cade4d

Please sign in to comment.