radix_common/constants/
always_visible_nodes.rs

1use crate::*;
2use lazy_static::lazy_static;
3use radix_common::types::*;
4use sbor::rust::prelude::*;
5
6pub use radix_common::constants::*;
7
8// Currently, functions and methods can reference these well-known nodes without declaring
9// the dependency in the package info.
10//
11// To avoid creating references from various places, a list of well-known nodes is crafted
12// and added to every call frame, as a temporary solution.
13//
14// To remove it, we will have to:
15// - Add Scrypto support for declaring dependencies
16// - Split bootstrapping into state flushing and transaction execution (the "chicken-and-egg" problem)
17//
18lazy_static! {
19    static ref ALWAYS_VISIBLE_GLOBAL_NODES_V1: IndexSet<NodeId> = {
20        indexset!(
21            // resource managers
22            XRD.into(),
23            SECP256K1_SIGNATURE_RESOURCE.into(),
24            ED25519_SIGNATURE_RESOURCE.into(),
25            SYSTEM_EXECUTION_RESOURCE.into(),
26            PACKAGE_OF_DIRECT_CALLER_RESOURCE.into(),
27            GLOBAL_CALLER_RESOURCE.into(),
28            PACKAGE_OWNER_BADGE.into(),
29            VALIDATOR_OWNER_BADGE.into(),
30            IDENTITY_OWNER_BADGE.into(),
31            ACCOUNT_OWNER_BADGE.into(),
32            // packages
33            PACKAGE_PACKAGE.into(),
34            RESOURCE_PACKAGE.into(),
35            IDENTITY_PACKAGE.into(),
36            CONSENSUS_MANAGER_PACKAGE.into(),
37            ACCOUNT_PACKAGE.into(),
38            ACCESS_CONTROLLER_PACKAGE.into(),
39            TRANSACTION_PROCESSOR_PACKAGE.into(),
40            METADATA_MODULE_PACKAGE.into(),
41            ROYALTY_MODULE_PACKAGE.into(),
42            ROLE_ASSIGNMENT_MODULE_PACKAGE.into(),
43            GENESIS_HELPER_PACKAGE.into(),
44            FAUCET_PACKAGE.into(),
45            POOL_PACKAGE.into(),
46            TRANSACTION_TRACKER_PACKAGE.into(),
47            // components
48            CONSENSUS_MANAGER.into(),
49            TRANSACTION_TRACKER.into(),
50        )
51    };
52
53    static ref ALWAYS_VISIBLE_GLOBAL_NODES_V2: IndexSet<NodeId> = {
54        indexset!(
55            // resource managers
56            XRD.into(),
57            SECP256K1_SIGNATURE_RESOURCE.into(),
58            ED25519_SIGNATURE_RESOURCE.into(),
59            SYSTEM_EXECUTION_RESOURCE.into(),
60            PACKAGE_OF_DIRECT_CALLER_RESOURCE.into(),
61            GLOBAL_CALLER_RESOURCE.into(),
62            PACKAGE_OWNER_BADGE.into(),
63            VALIDATOR_OWNER_BADGE.into(),
64            IDENTITY_OWNER_BADGE.into(),
65            ACCOUNT_OWNER_BADGE.into(),
66            // packages
67            PACKAGE_PACKAGE.into(),
68            RESOURCE_PACKAGE.into(),
69            IDENTITY_PACKAGE.into(),
70            CONSENSUS_MANAGER_PACKAGE.into(),
71            ACCOUNT_PACKAGE.into(),
72            ACCESS_CONTROLLER_PACKAGE.into(),
73            TRANSACTION_PROCESSOR_PACKAGE.into(),
74            METADATA_MODULE_PACKAGE.into(),
75            ROYALTY_MODULE_PACKAGE.into(),
76            ROLE_ASSIGNMENT_MODULE_PACKAGE.into(),
77            GENESIS_HELPER_PACKAGE.into(),
78            FAUCET_PACKAGE.into(),
79            POOL_PACKAGE.into(),
80            TRANSACTION_TRACKER_PACKAGE.into(),
81            LOCKER_PACKAGE.into(),
82            // components
83            CONSENSUS_MANAGER.into(),
84            TRANSACTION_TRACKER.into(),
85        )
86    };
87}
88
89#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Sbor)]
90pub enum AlwaysVisibleGlobalNodesVersion {
91    V1,
92    V2,
93}
94
95impl AlwaysVisibleGlobalNodesVersion {
96    pub const fn latest() -> Self {
97        Self::V2
98    }
99}
100
101pub fn always_visible_global_nodes(
102    version: AlwaysVisibleGlobalNodesVersion,
103) -> &'static IndexSet<NodeId> {
104    match version {
105        AlwaysVisibleGlobalNodesVersion::V1 => &ALWAYS_VISIBLE_GLOBAL_NODES_V1,
106        AlwaysVisibleGlobalNodesVersion::V2 => &ALWAYS_VISIBLE_GLOBAL_NODES_V2,
107    }
108}