Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify customization of protocol updates and align better with node #1788

Merged
merged 30 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
82d0c7a
feat: Adds ProtocolBuilder and ProtocolExecuotor
dhedey Apr 28, 2024
0c46424
refactor: Improvements to metering tests
dhedey Apr 29, 2024
e1395ea
tweak: Updates scenario dumping
dhedey Apr 30, 2024
b48a0c8
Merge branch 'develop' into tweak/protocol-update-builders
dhedey Apr 30, 2024
dee3bad
fix: Fix compile errors
dhedey Apr 30, 2024
b759ed2
tweak: Minor simplification
dhedey Apr 30, 2024
4e36461
tweak: Ensure logs in transaction receipt respect ansi setting
dhedey Apr 30, 2024
a0d9b54
fix: Fix no-std test build
dhedey Apr 30, 2024
b0d901b
fix: Fix radix engine tests
dhedey Apr 30, 2024
1e960e9
chore: Regenerate all transaction scenario dumps
dhedey Apr 30, 2024
99db4b7
fix: Use `as_bytes` instead of `as_ref` on `NodeId`.
0xOmarA Apr 30, 2024
e56631b
Merge remote-tracking branch 'origin/develop' into tweak/protocol-upd…
0xOmarA May 2, 2024
a9d79aa
Merge remote-tracking branch 'origin/develop' into tweak/protocol-upd…
0xOmarA May 2, 2024
693b66d
test: add a test for scenario metadata
0xOmarA May 2, 2024
d5fc908
tweak: use a network definition reference in the scenario executor
0xOmarA May 2, 2024
3aacc9f
tweak: edit a comment on a function on the scenario executor
0xOmarA May 2, 2024
8fe24c1
tweak: rename ValidScenariosFrom to SpecificScenariosByName
0xOmarA May 2, 2024
0df37b9
refactor: generate `ProtocolVersion` and `ProtocolUpdate` enums from …
0xOmarA May 2, 2024
3e263f6
tweak: Use `AsRef<NodeId>` instead of `Into<NodeId> + AsRef<NodeId>`
0xOmarA May 2, 2024
bbb051e
tweak: make the protocol update state update generation functions pri…
0xOmarA May 2, 2024
dd84234
tweak: Convert `UpdateSetting<()>` to `UpdateSetting<NoSettings>`
0xOmarA May 2, 2024
0838536
fix: add kernel-boot to the BootLoaderFieldKind
0xOmarA May 2, 2024
8102af8
feat: Add `KernelBoot` field
0xOmarA May 2, 2024
e2d602f
refactor: stop scenarios executor from failing on already bootstrappe…
0xOmarA May 2, 2024
0fa708f
tweak: address various review comments
0xOmarA May 2, 2024
3807785
Merge pull request #1789 from radixdlt/tweak/protocol-update-builders…
0xOmarA May 2, 2024
b4628f2
bugfix: fix compilation
0xOmarA May 3, 2024
1492e53
fix: Fixed tests
0xOmarA May 3, 2024
312ad9a
fix: pin CI version to avoid wasmer issue
0xOmarA May 3, 2024
8e6f1a5
Revert "bugfix: fix compilation"
0xOmarA May 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .github/actions/setup-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ runs:
- name: Install Rust toolchain
uses: RDXWorks-actions/toolchain@master
with:
toolchain: stable
toolchain: 1.77.2
default: true
target: wasm32-unknown-unknown
components: rustfmt

- name: Install nextest
uses: RDXWorks-actions/install-action@nextest
Expand Down
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,3 @@ zeroize = { version = "1.3.0" }
# crashing the engine.
[profile.release]
panic = "unwind"

[profile.test]
panic = "unwind"
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(),
0xOmarA marked this conversation as resolved.
Show resolved Hide resolved
};
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
75 changes: 9 additions & 66 deletions radix-clis/src/resim/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ use radix_engine::blueprints::consensus_manager::{
};
use radix_engine::blueprints::models::FieldPayload;
use radix_engine::system::bootstrap::Bootstrapper;
use radix_engine::system::system_db_reader::{
ObjectCollectionKey, SystemDatabaseReader, SystemDatabaseWriter,
};
use radix_engine::system::system_db_reader::*;
use radix_engine::transaction::execute_and_commit_transaction;
use radix_engine::transaction::ExecutionConfig;
use radix_engine::transaction::TransactionOutcome;
Expand All @@ -81,7 +79,6 @@ use radix_engine_interface::prelude::*;
use radix_engine_interface::types::FromPublicKey;
use radix_rust::ContextualDisplay;
use radix_substate_store_impls::rocks_db::RocksdbSubstateStore;
use radix_substate_store_interface::interface::SubstateDatabase;
use radix_substate_store_queries::typed_substate_layout::*;
use radix_transactions::manifest::decompile;
use radix_transactions::model::TestTransaction;
Expand Down Expand Up @@ -169,7 +166,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 @@ -197,9 +196,7 @@ pub fn handle_system_transaction<O: std::io::Write>(
let encoder = AddressBech32Encoder::for_simulator();
let display_context = TransactionReceiptDisplayContextBuilder::new()
.encoder(&encoder)
.schema_lookup_callback(|event_type_identifier: &EventTypeIdentifier| {
get_event_schema(&db, event_type_identifier)
})
.schema_lookup_from_db(&db)
.build();
writeln!(out, "{}", receipt.display(display_context)).map_err(Error::IOError)?;
}
Expand Down Expand Up @@ -240,7 +237,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 All @@ -265,9 +264,7 @@ pub fn handle_manifest<O: std::io::Write>(
let encoder = AddressBech32Encoder::for_simulator();
let display_context = TransactionReceiptDisplayContextBuilder::new()
.encoder(&encoder)
.schema_lookup_callback(|event_type_identifier: &EventTypeIdentifier| {
get_event_schema(&db, event_type_identifier)
})
.schema_lookup_from_db(&db)
.build();
writeln!(out, "{}", receipt.display(display_context)).map_err(Error::IOError)?;
}
Expand Down Expand Up @@ -381,60 +378,6 @@ pub fn get_blueprint_id(component_address: ComponentAddress) -> Result<Blueprint
Ok(object_info.blueprint_info.blueprint_id)
}

pub fn get_event_schema<S: SubstateDatabase>(
db: &S,
event_type_identifier: &EventTypeIdentifier,
) -> Option<(LocalTypeId, VersionedScryptoSchema)> {
let system_reader = SystemDatabaseReader::new(db);

let (blueprint_id, event_name) = match event_type_identifier {
EventTypeIdentifier(Emitter::Method(node_id, node_module), event_name) => {
let blueprint_id = system_reader.get_blueprint_id(node_id, *node_module).ok()?;
(blueprint_id, event_name)
}
EventTypeIdentifier(Emitter::Function(blueprint_id), event_name) => {
(blueprint_id.clone(), event_name)
}
};

let version_key = BlueprintVersionKey::new_default(blueprint_id.blueprint_name.as_str());
let bp_definition: VersionedPackageBlueprintVersionDefinition = system_reader
.read_object_collection_entry(
blueprint_id.package_address.as_node_id(),
ModuleId::Main,
ObjectCollectionKey::KeyValue(
PackageCollection::BlueprintVersionDefinitionKeyValue.collection_index(),
&version_key,
),
)
.unwrap()?;

let bp_interface = bp_definition
.fully_update_and_into_latest_version()
.interface;

let event_def = bp_interface.events.get(event_name)?;
match event_def {
BlueprintPayloadDef::Static(type_id) => {
let schema: VersionedScryptoSchema = system_reader
.read_object_collection_entry(
blueprint_id.package_address.as_node_id(),
ModuleId::Main,
ObjectCollectionKey::KeyValue(
PackageCollection::SchemaKeyValue.collection_index(),
&type_id.0,
),
)
.unwrap()?;

Some((type_id.1, schema))
}
BlueprintPayloadDef::Generic(..) => {
panic!("Not expecting any events to use generics")
}
}
}

pub fn db_upsert_timestamps(
milli_timestamp: ProposerMilliTimestampSubstate,
minute_timestamp: ProposerMinuteTimestampSubstate,
Expand Down
4 changes: 2 additions & 2 deletions radix-common/src/data/manifest/custom_formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ impl FormattableCustomExtension for ManifestCustomExtension {
if let Ok(bech32) = encoder.encode(node_id.as_ref()) {
write!(f, "\"{}\"", bech32)?;
} else {
write!(f, "\"{}\"", hex::encode(node_id.as_ref()))?;
write!(f, "\"{}\"", hex::encode(node_id.as_bytes()))?;
}
} else {
write!(f, "\"{}\"", hex::encode(node_id.as_ref()))?;
write!(f, "\"{}\"", hex::encode(node_id.as_bytes()))?;
}
}
ManifestAddress::Named(address_id) => {
Expand Down
4 changes: 2 additions & 2 deletions radix-common/src/data/manifest/custom_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ impl SerializableCustomExtension for ManifestCustomExtension {
(SerializableType::String(bech32), false)
} else {
(
SerializableType::String(hex::encode(node_id.as_ref())),
SerializableType::String(hex::encode(node_id.as_bytes())),
true,
)
}
} else {
(
SerializableType::String(hex::encode(node_id.as_ref())),
SerializableType::String(hex::encode(node_id.as_bytes())),
true,
)
}
Expand Down
10 changes: 10 additions & 0 deletions radix-common/src/types/addresses/component_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ impl ComponentAddress {
self.0.to_vec()
}

pub fn as_bytes(&self) -> &[u8] {
self.as_ref()
}
0xOmarA marked this conversation as resolved.
Show resolved Hide resolved

pub fn virtual_account_from_public_key<P: Into<PublicKey> + Clone>(
public_key: &P,
) -> ComponentAddress {
Expand Down Expand Up @@ -133,6 +137,12 @@ impl AsRef<[u8]> for ComponentAddress {
}
}

impl AsRef<NodeId> for ComponentAddress {
fn as_ref(&self) -> &NodeId {
&self.0
}
}

impl TryFrom<[u8; NodeId::LENGTH]> for ComponentAddress {
type Error = ParseComponentAddressError;

Expand Down
10 changes: 10 additions & 0 deletions radix-common/src/types/addresses/global_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ impl GlobalAddress {
self.0.to_vec()
}

pub fn as_bytes(&self) -> &[u8] {
self.as_ref()
}

pub fn as_node_id(&self) -> &NodeId {
&self.0
}
Expand Down Expand Up @@ -99,6 +103,12 @@ impl AsRef<[u8]> for GlobalAddress {
}
}

impl AsRef<NodeId> for GlobalAddress {
fn as_ref(&self) -> &NodeId {
&self.0
}
}

impl TryFrom<[u8; NodeId::LENGTH]> for GlobalAddress {
type Error = ParseGlobalAddressError;

Expand Down
10 changes: 10 additions & 0 deletions radix-common/src/types/addresses/internal_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ impl InternalAddress {
self.0.to_vec()
}

pub fn as_bytes(&self) -> &[u8] {
self.as_ref()
}

pub fn as_node_id(&self) -> &NodeId {
&self.0
}
Expand Down Expand Up @@ -89,6 +93,12 @@ impl AsRef<[u8]> for InternalAddress {
}
}

impl AsRef<NodeId> for InternalAddress {
fn as_ref(&self) -> &NodeId {
&self.0
}
}

impl TryFrom<[u8; NodeId::LENGTH]> for InternalAddress {
type Error = ParseInternalAddressError;

Expand Down
10 changes: 10 additions & 0 deletions radix-common/src/types/addresses/package_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ impl PackageAddress {
self.0.to_vec()
}

pub fn as_bytes(&self) -> &[u8] {
self.as_ref()
}

pub fn as_node_id(&self) -> &NodeId {
&self.0
}
Expand Down Expand Up @@ -100,6 +104,12 @@ impl AsRef<[u8]> for PackageAddress {
}
}

impl AsRef<NodeId> for PackageAddress {
fn as_ref(&self) -> &NodeId {
&self.0
}
}

impl TryFrom<[u8; NodeId::LENGTH]> for PackageAddress {
type Error = ParsePackageAddressError;

Expand Down
10 changes: 10 additions & 0 deletions radix-common/src/types/addresses/resource_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ impl ResourceAddress {
self.0.to_vec()
}

pub fn as_bytes(&self) -> &[u8] {
self.as_ref()
}

pub fn as_node_id(&self) -> &NodeId {
&self.0
}
Expand Down Expand Up @@ -92,6 +96,12 @@ impl AsRef<[u8]> for ResourceAddress {
}
}

impl AsRef<NodeId> for ResourceAddress {
fn as_ref(&self) -> &NodeId {
&self.0
}
}

impl TryFrom<[u8; NodeId::LENGTH]> for ResourceAddress {
type Error = ParseResourceAddressError;

Expand Down
2 changes: 1 addition & 1 deletion radix-common/src/types/blueprint_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl BlueprintId {
}

pub fn len(&self) -> usize {
self.package_address.as_ref().len() + self.blueprint_name.len()
self.package_address.as_bytes().len() + self.blueprint_name.len()
}
}

Expand Down
6 changes: 6 additions & 0 deletions radix-common/src/types/node_and_substate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ impl NodeId {
}
}

impl AsRef<NodeId> for NodeId {
fn as_ref(&self) -> &NodeId {
self
}
}

impl AsRef<[u8]> for NodeId {
fn as_ref(&self) -> &[u8] {
&self.0
Expand Down
10 changes: 8 additions & 2 deletions radix-common/src/types/type_identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ pub enum GlobalTypeAddress {
/// Note - this type provides scoping to a schema even for well-known types where
/// the schema is irrelevant.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Sbor)]
pub struct FullyScopedTypeId<T: Into<NodeId>>(pub T, pub SchemaHash, pub LocalTypeId);
pub struct FullyScopedTypeId<T: AsRef<NodeId>>(pub T, pub SchemaHash, pub LocalTypeId);

impl<T: AsRef<NodeId>> FullyScopedTypeId<T> {
pub fn into_general(self) -> FullyScopedTypeId<NodeId> {
FullyScopedTypeId(*self.0.as_ref(), self.1, self.2)
}
}

/// An identifier for a type in the context of a schema.
///
Expand All @@ -48,7 +54,7 @@ pub struct FullyScopedTypeId<T: Into<NodeId>>(pub T, pub SchemaHash, pub LocalTy
pub struct ScopedTypeId(pub SchemaHash, pub LocalTypeId);

impl ScopedTypeId {
pub fn under_node<T: Into<NodeId>>(self, node: T) -> FullyScopedTypeId<T> {
pub fn under_node<T: AsRef<NodeId>>(self, node: T) -> FullyScopedTypeId<T> {
FullyScopedTypeId(node, self.0, self.1)
}
}
Expand Down
Loading
Loading