-
Notifications
You must be signed in to change notification settings - Fork 123
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
[ON HOLD] Feature: Full declare_native_blueprint_state
macro
#1318
Conversation
6a7c239
to
69e29e2
Compare
Generics are now supported, as is a simplified define_single_versioned
69e29e2
to
24aaef8
Compare
Benchmark for 0f3006cClick to view benchmark
|
use sbor::LocalTypeIndex; | ||
use crate::internal_prelude::*; | ||
|
||
define_wrapped_hash!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice macro!
@@ -195,7 +188,7 @@ pub fn to_typed_substate_key( | |||
} | |||
SCHEMAS_PARTITION => { | |||
let key = substate_key.for_map().ok_or_else(|| error("Schema key"))?; | |||
TypedSubstateKey::Schema(TypedSchemaSubstateKey::SchemaKey( | |||
TypedSubstateKey::SchemaModule(TypedSchemaSubstateKey::SchemaKey( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: I wouldn't consider this a module. In our model a module is specifically something with logic/methods. In this case the schemas are just there as data for use.
} | ||
|
||
/// This is used mostly for flashing | ||
pub fn into_kernel_main_partitions(self, feature_checks: [<$blueprint_ident FeatureChecks>]) -> Result<NodeSubstates, RuntimeError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is right place for doing kernel mappings. The problem is that this mapping now needs to be maintained in multiple places and enforces the requirement that the mapping is static and may never change in the future, losing flexibility/updatability. The proper mechanism instead would be to use "System Layer" code to do this mapping.
); | ||
} | ||
let mut partitions = package_state_init | ||
.into_kernel_main_partitions(own_features.into()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't be the PackageStateInit
which should decide where things are mapped, an example of why this model is off.
@@ -738,139 +589,26 @@ pub fn create_bootstrap_package_partitions( | |||
|
|||
fn globalize_package<Y>( | |||
package_address_reservation: Option<GlobalAddressReservation>, | |||
package_structure: PackageStructure, | |||
mut package_state_init: PackageStateInit, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting idea!
blueprint_version_auth_configs, | ||
code_vm_type: vm_type_substates, | ||
code_original_code: original_code_substates, | ||
code_instrumented_code: instrumented_code_substates, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice structure!
@@ -1493,16 +1154,16 @@ impl PackageRoyaltyNativeBlueprint { | |||
if royalty_charge.is_non_zero() { | |||
let handle = api.kernel_open_substate( | |||
receiver, | |||
MAIN_BASE_PARTITION, | |||
&PackageField::Royalty.into(), | |||
PackagePartition::Field.as_main_partition(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, would rather not rely on outside system code to specify what the main_partition is.
type Error = (); | ||
|
||
fn try_from(offset: PartitionOffset) -> Result<Self, Self::Error> { | ||
// NOTE: This should really be a fixed mapping - but it's hard to do with declarative macros |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is this mapping really shouldn't be done here.
description: "Enables the package royalty substate", | ||
} | ||
}, | ||
instance_schema_types: {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generic_arguments?
declare_native_blueprint_state
macro
declare_native_blueprint_state
macrodeclare_native_blueprint_state
macro
PR status update
This full PR has been parked, and instead, will do it in bits (starting with just the core versioned models + schema stuff) - will create a new PR to capture that.
Replacement PR 2023: #1358
Extension PR 2024: #1744
Summary
The goal of this PR is to introduce a more structured / type-safe mechanism for interfacing with our native substates... and to enable easily wrapping them with lazily-upgradable versioned enum wrappers in a type-safe way.
This PR has:
versioned!
macro to make versioning easydeclare_native_blueprint_state
macro to create typed native substate models which creates:Generic "Versioned" data model
In terms of versioning conventions, I believe we are going to:
When implementing for X = Schema, I decided the following naming schema fitted best - keeping code looking as neat as possible:
VersionedX
is the versioned enum type. This will be used for substate contents, or other types which need versioning.X
is a type alias created for "latest version of this type"XV1
is the concrete type which should be created, which maps to the type alias.Questions to be answered before proceeding:
Changes for integrators
I'll merge this into the node. This shouldn't have any impact outside of Scrypto and Node.