Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/lower-min-…
Browse files Browse the repository at this point in the history
…rounds-per-epoch
  • Loading branch information
0xOmarA committed Sep 27, 2024
2 parents 2e9610e + 08e006d commit 9857c93
Show file tree
Hide file tree
Showing 23 changed files with 288 additions and 19 deletions.
58 changes: 57 additions & 1 deletion radix-common/src/constants/always_visible_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub use radix_common::constants::*;
// - Split bootstrapping into state flushing and transaction execution (the "chicken-and-egg" problem)
//
lazy_static! {
pub static ref ALWAYS_VISIBLE_GLOBAL_NODES: IndexSet<NodeId> = {
static ref ALWAYS_VISIBLE_GLOBAL_NODES_V1: IndexSet<NodeId> = {
indexset!(
// resource managers
XRD.into(),
Expand Down Expand Up @@ -49,4 +49,60 @@ lazy_static! {
TRANSACTION_TRACKER.into(),
)
};

static ref ALWAYS_VISIBLE_GLOBAL_NODES_V2: IndexSet<NodeId> = {
indexset!(
// resource managers
XRD.into(),
SECP256K1_SIGNATURE_RESOURCE.into(),
ED25519_SIGNATURE_RESOURCE.into(),
SYSTEM_EXECUTION_RESOURCE.into(),
PACKAGE_OF_DIRECT_CALLER_RESOURCE.into(),
GLOBAL_CALLER_RESOURCE.into(),
PACKAGE_OWNER_BADGE.into(),
VALIDATOR_OWNER_BADGE.into(),
IDENTITY_OWNER_BADGE.into(),
ACCOUNT_OWNER_BADGE.into(),
// packages
PACKAGE_PACKAGE.into(),
RESOURCE_PACKAGE.into(),
IDENTITY_PACKAGE.into(),
CONSENSUS_MANAGER_PACKAGE.into(),
ACCOUNT_PACKAGE.into(),
ACCESS_CONTROLLER_PACKAGE.into(),
TRANSACTION_PROCESSOR_PACKAGE.into(),
METADATA_MODULE_PACKAGE.into(),
ROYALTY_MODULE_PACKAGE.into(),
ROLE_ASSIGNMENT_MODULE_PACKAGE.into(),
GENESIS_HELPER_PACKAGE.into(),
FAUCET_PACKAGE.into(),
POOL_PACKAGE.into(),
TRANSACTION_TRACKER_PACKAGE.into(),
LOCKER_PACKAGE.into(),
// components
CONSENSUS_MANAGER.into(),
TRANSACTION_TRACKER.into(),
)
};
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Sbor)]
pub enum AlwaysVisibleGlobalNodesVersion {
V1,
V2,
}

impl AlwaysVisibleGlobalNodesVersion {
pub const fn latest() -> Self {
Self::V2
}
}

pub fn always_visible_global_nodes(
version: AlwaysVisibleGlobalNodesVersion,
) -> &'static IndexSet<NodeId> {
match version {
AlwaysVisibleGlobalNodesVersion::V1 => &ALWAYS_VISIBLE_GLOBAL_NODES_V1,
AlwaysVisibleGlobalNodesVersion::V2 => &ALWAYS_VISIBLE_GLOBAL_NODES_V2,
}
}
7 changes: 7 additions & 0 deletions radix-engine-tests/assets/blueprints/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 radix-engine-tests/assets/blueprints/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ members = [
"oracles/oracle_v2",
"oracles/oracle_v3",
"steal",
"locker-factory",
]
resolver = "2"

Expand Down
10 changes: 10 additions & 0 deletions radix-engine-tests/assets/blueprints/locker-factory/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "locker-factory"
version = "1.0.0"
edition = "2021"

[dependencies]
scrypto = { path = "../../../../scrypto" }

[lib]
crate-type = ["cdylib", "lib"]
19 changes: 19 additions & 0 deletions radix-engine-tests/assets/blueprints/locker-factory/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use scrypto::prelude::*;

#[blueprint]
mod factory {
struct Factory;

impl Factory {
pub fn new() -> Global<Factory> {
Self {}
.instantiate()
.prepare_to_globalize(OwnerRole::None)
.globalize()
}

pub fn create(&self) -> FungibleBucket {
Blueprint::<AccountLocker>::instantiate_simple(true).1
}
}
}
68 changes: 68 additions & 0 deletions radix-engine-tests/tests/protocol/always_visible_global_nodes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use radix_engine_tests::common::*;
use scrypto_test::prelude::*;

#[test]
fn locker_package_is_not_globally_visible_in_bottlenose() {
// Arrange
let mut ledger = LedgerSimulatorBuilder::new()
.with_custom_protocol(|builder| builder.from_bootstrap_to(ProtocolVersion::Bottlenose))
.build();
let package_address = ledger.publish_package_simple(PackageLoader::get("locker-factory"));
let component_address = ledger
.execute_manifest(
ManifestBuilder::new()
.lock_fee_from_faucet()
.call_function(package_address, "Factory", "new", ())
.build(),
vec![],
)
.expect_commit_success()
.new_component_addresses()
.first()
.copied()
.unwrap();
let (_, _, account) = ledger.new_account(false);

// Act
let manifest = ManifestBuilder::new()
.lock_fee_from_faucet()
.call_method(component_address, "create", ())
.try_deposit_entire_worktop_or_abort(account, None)
.build();
let receipt = ledger.execute_manifest(manifest, vec![]);

// Assert
receipt.expect_commit_failure();
}

#[test]
fn locker_package_is_globally_visible_in_cuttlefish() {
// Arrange
let mut ledger = LedgerSimulatorBuilder::new().build();
let package_address = ledger.publish_package_simple(PackageLoader::get("locker-factory"));
let component_address = ledger
.execute_manifest(
ManifestBuilder::new()
.lock_fee_from_faucet()
.call_function(package_address, "Factory", "new", ())
.build(),
vec![],
)
.expect_commit_success()
.new_component_addresses()
.first()
.copied()
.unwrap();
let (_, _, account) = ledger.new_account(false);

// Act
let manifest = ManifestBuilder::new()
.lock_fee_from_faucet()
.call_method(component_address, "create", ())
.try_deposit_entire_worktop_or_abort(account, None)
.build();
let receipt = ledger.execute_manifest(manifest, vec![]);

// Assert
receipt.expect_commit_success();
}
1 change: 1 addition & 0 deletions radix-engine-tests/tests/protocol/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// We used to use automod, but it breaks various tools
// such as cargo fmt, so let's just list them explicitly.
mod always_visible_global_nodes;
mod consensus_manager;
mod cuttlefish_transaction_changes;
mod protocol_updates;
Expand Down
10 changes: 8 additions & 2 deletions radix-engine/src/kernel/call_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ pub struct CallFrame<C, L> {

next_handle: SubstateHandle,
open_substates: IndexMap<SubstateHandle, OpenedSubstate<L>>,

/// The set of nodes that are always globally visible.
always_visible_global_nodes: &'static IndexSet<NodeId>,
}

/// Represents an error when creating a new frame.
Expand Down Expand Up @@ -557,11 +560,12 @@ pub enum SubstateDiffError {
ContainsDuplicateOwns,
}

#[derive(Debug, Default)]
#[derive(Debug)]
pub struct CallFrameInit<C> {
pub data: C,
pub global_addresses: IndexSet<GlobalAddress>,
pub direct_accesses: IndexSet<InternalAddress>,
pub always_visible_global_nodes: &'static IndexSet<NodeId>,
}

impl<C, L: Clone> CallFrame<C, L> {
Expand All @@ -574,6 +578,7 @@ impl<C, L: Clone> CallFrame<C, L> {
owned_root_nodes: index_set_new(),
next_handle: 0u32,
open_substates: index_map_new(),
always_visible_global_nodes: init.always_visible_global_nodes,
};

for global_ref in init.global_addresses {
Expand All @@ -600,6 +605,7 @@ impl<C, L: Clone> CallFrame<C, L> {
owned_root_nodes: index_set_new(),
next_handle: 0u32,
open_substates: index_map_new(),
always_visible_global_nodes: parent.always_visible_global_nodes,
};

// Copy references and move nodes
Expand Down Expand Up @@ -1384,7 +1390,7 @@ impl<C, L: Clone> CallFrame<C, L> {
if let Some(reference_type) = self.stable_references.get(node_id) {
visibilities.insert(Visibility::StableReference(reference_type.clone()));
}
if ALWAYS_VISIBLE_GLOBAL_NODES.contains(node_id) {
if self.always_visible_global_nodes.contains(node_id) {
visibilities.insert(Visibility::StableReference(StableReferenceType::Global));
}

Expand Down
32 changes: 28 additions & 4 deletions radix-engine/src/kernel/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub type KernelBootSubstate = KernelBoot;
))]
pub enum KernelBoot {
V1,
V2(AlwaysVisibleGlobalNodesVersion),
}

impl KernelBoot {
Expand All @@ -52,6 +53,21 @@ impl KernelBoot {
pub fn babylon() -> Self {
Self::V1
}

pub fn cuttlefish() -> Self {
Self::V2(AlwaysVisibleGlobalNodesVersion::V2)
}

pub fn always_visible_global_nodes_version(&self) -> AlwaysVisibleGlobalNodesVersion {
match self {
KernelBoot::V1 => AlwaysVisibleGlobalNodesVersion::V1,
KernelBoot::V2(version) => *version,
}
}

pub fn always_visible_global_nodes(&self) -> &'static IndexSet<NodeId> {
always_visible_global_nodes(self.always_visible_global_nodes_version())
}
}

pub struct KernelInit<
Expand Down Expand Up @@ -125,11 +141,13 @@ impl<'h, S: SubstateDatabase> BootLoader<'h, S> {
v.borrow_mut();
});

// Unused for now
let _ = kernel_boot;

// Upper Layer Initialization
let system_init_result = E::init(&mut self.track, &executable, callback_init);
let system_init_result = E::init(
&mut self.track,
&executable,
callback_init,
kernel_boot.always_visible_global_nodes(),
);

let (mut system, call_frame_inits) = match system_init_result {
Ok(success) => success,
Expand Down Expand Up @@ -308,6 +326,7 @@ pub struct Kernel<
callback: &'g mut M,
}

#[cfg(feature = "radix_engine_tests")]
impl<'g, M: KernelCallbackObject<CallFrameData: Default>, S: CommitableSubstateStore>
Kernel<'g, M, S>
{
Expand All @@ -324,6 +343,9 @@ impl<'g, M: KernelCallbackObject<CallFrameData: Default>, S: CommitableSubstateS
data: M::CallFrameData::default(),
direct_accesses: Default::default(),
global_addresses: Default::default(),
always_visible_global_nodes: always_visible_global_nodes(
AlwaysVisibleGlobalNodesVersion::latest(),
),
}],
)
}
Expand Down Expand Up @@ -1238,12 +1260,14 @@ where
substate_io: SubstateIO<'g, S>,
id_allocator: &'g mut IdAllocator,
callback: &'g mut M,
always_visible_global_nodes: &'static IndexSet<NodeId>,
) -> Kernel<'g, M, S> {
Self {
stacks: KernelStacks::new(vec![CallFrameInit {
data: M::CallFrameData::default(),
direct_accesses: Default::default(),
global_addresses: Default::default(),
always_visible_global_nodes,
}]),
substate_io,
id_allocator,
Expand Down
Binary file modified radix-engine/src/kernel/kernel_boot_substate_cuttlefish_schema.bin
Binary file not shown.
1 change: 1 addition & 0 deletions radix-engine/src/kernel/kernel_callback_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ pub trait KernelTransactionExecutor: KernelCallbackObject {
store: &mut impl CommitableSubstateStore,
executable: &Self::Executable,
init: Self::Init,
always_visible_global_nodes: &'static IndexSet<NodeId>,
) -> Result<(Self, Vec<CallFrameInit<Self::CallFrameData>>), Self::Receipt>;

/// Start execution
Expand Down
15 changes: 12 additions & 3 deletions radix-engine/src/system/system_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,7 @@ impl<V: SystemCallbackObject> System<V> {
references: &IndexSet<Reference>,
modules: &mut SystemModuleMixer,
store: &mut impl CommitableSubstateStore,
always_visible_global_nodes: &IndexSet<NodeId>,
) -> Result<(IndexSet<GlobalAddress>, IndexSet<InternalAddress>), BootloadingError> {
let mut global_addresses = indexset!();
let mut direct_accesses = indexset!();
Expand All @@ -1079,7 +1080,7 @@ impl<V: SystemCallbackObject> System<V> {
for reference in references.iter() {
let node_id = &reference.0;

if ALWAYS_VISIBLE_GLOBAL_NODES.contains(node_id) {
if always_visible_global_nodes.contains(node_id) {
// Allow always visible node and do not add reference
continue;
}
Expand Down Expand Up @@ -1116,16 +1117,22 @@ impl<V: SystemCallbackObject> System<V> {
intents: impl Iterator<Item = &'a ExecutableIntent>,
modules: &mut SystemModuleMixer,
store: &mut impl CommitableSubstateStore,
always_visible_global_nodes: &'static IndexSet<NodeId>,
) -> Result<Vec<CallFrameInit<Actor>>, BootloadingError> {
let mut init_call_frames = vec![];
for intent in intents {
let (global_addresses, direct_accesses) =
Self::reference_check(&intent.references, modules, store)?;
let (global_addresses, direct_accesses) = Self::reference_check(
&intent.references,
modules,
store,
always_visible_global_nodes,
)?;

init_call_frames.push(CallFrameInit {
data: Actor::Root,
global_addresses,
direct_accesses,
always_visible_global_nodes,
});
}

Expand Down Expand Up @@ -1494,6 +1501,7 @@ impl<V: SystemCallbackObject> KernelTransactionExecutor for System<V> {
store: &mut impl CommitableSubstateStore,
executable: &ExecutableTransaction,
init_input: Self::Init,
always_visible_global_nodes: &'static IndexSet<NodeId>,
) -> Result<(Self, Vec<CallFrameInit<Actor>>), Self::Receipt> {
// Dump executable
#[cfg(not(feature = "alloc"))]
Expand Down Expand Up @@ -1575,6 +1583,7 @@ impl<V: SystemCallbackObject> KernelTransactionExecutor for System<V> {
executable.all_intents(),
&mut modules,
store,
always_visible_global_nodes,
) {
Ok(call_frame_inits) => call_frame_inits,
Err(error) => return Err(Self::create_rejection_receipt(error, modules)),
Expand Down
Loading

0 comments on commit 9857c93

Please sign in to comment.