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

feat: Add in place update support to versioned macro #1755

Merged
merged 21 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
70b4298
feat: Add in place update support to versioned macro
dhedey Mar 30, 2024
62fc8ae
fix: Build error and warning fixes
dhedey Mar 30, 2024
bcfc9dc
tweak: Payload types implement HasUniqueLatestVersion
dhedey Mar 31, 2024
7641bd6
Merge branch 'develop' into tweak/versioned-macro-improvements
dhedey Apr 11, 2024
c2720e5
feat: Add #[sbor(as_type)] and update versioned
dhedey Apr 20, 2024
b2b3af1
tweak: Small tweaks to `evaluate_eager_macros`
dhedey Apr 20, 2024
69e5cfb
Merge branch 'develop' into tweak/versioned-macro-improvements
dhedey Apr 20, 2024
4e8d53b
fix: Fix sbor as_type encode which wasn't saved
dhedey Apr 21, 2024
e8e1b7f
tweak: Implement SBOR for Nibble using transparent
dhedey Apr 21, 2024
d83f581
fix: Fix comments
dhedey Apr 22, 2024
cf03392
fix: Fix versioned discriminators to be 0-indexed
dhedey Apr 22, 2024
c351677
feature: Add support for StaticMultiVersioned
dhedey Apr 22, 2024
f364d7c
fix: Fix scrypto-test compilation
dhedey Apr 22, 2024
b790c58
Merge branch 'develop' into tweak/versioned-macro-improvements
dhedey Apr 22, 2024
de54681
fix: Fixed package_invalid tests
dhedey Apr 22, 2024
ce662a2
feat: Fixed eager macro, used it for define_versioned!
dhedey Apr 23, 2024
9e20772
fix: Fix scrypto_env tests
dhedey Apr 23, 2024
36053ba
fix: Fix formatting
dhedey Apr 23, 2024
de487ac
fix: Fix radix-sbor-derive tests
dhedey Apr 23, 2024
75bcfa6
markups: Tweaks to versioned method naming and eager_replace calls
dhedey Apr 23, 2024
a675f6d
fix: Fixes eager_replace test which was compiler-version dependent
dhedey Apr 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/everything/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 examples/hello-world/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 examples/no-std/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions radix-blueprint-schema-init/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ impl Default for BlueprintSchemaInit {
fn default() -> Self {
Self {
generics: Vec::new(),
schema: VersionedScryptoSchema::V1(SchemaV1 {
schema: Schema {
type_kinds: Vec::new(),
type_metadata: Vec::new(),
type_validations: Vec::new(),
}),
}
.into_versioned(),
state: BlueprintStateSchemaInit::default(),
events: BlueprintEventSchemaInit::default(),
types: BlueprintTypeSchemaInit::default(),
Expand Down
1 change: 1 addition & 0 deletions radix-clis/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions radix-clis/src/replay/cmd_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl CommittedTxnReader {
let next_identifiers: VersionedCommittedTransactionIdentifiers =
scrypto_decode(next_identifiers_bytes.1.as_ref()).unwrap();
let expected_state_root_hash = next_identifiers
.into_latest()
.fully_update_and_into_latest_version()
.resultant_ledger_hashes
.state_root
.0;
Expand All @@ -208,7 +208,7 @@ impl CommittedTxnReader {

define_single_versioned! {
#[derive(Debug, Clone, Sbor)]
pub enum VersionedCommittedTransactionIdentifiers => CommittedTransactionIdentifiers = CommittedTransactionIdentifiersV1
pub VersionedCommittedTransactionIdentifiers(CommittedTransactionIdentifiersVersions) => CommittedTransactionIdentifiers = CommittedTransactionIdentifiersV1
}

#[derive(Debug, Clone, Sbor)]
Expand Down
15 changes: 10 additions & 5 deletions radix-clis/src/resim/dumper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ pub fn dump_package<T: SubstateDatabase, O: std::io::Write>(
output,
"{}: {} bytes",
"Code size".green().bold(),
substate.into_value().unwrap().into_latest().code.len()
substate
.into_value()
.unwrap()
.fully_update_and_into_latest_version()
.code
.len()
);

let metadata = get_entity_metadata(package_address.as_node_id(), substate_db);
Expand Down Expand Up @@ -232,7 +237,7 @@ pub fn dump_resource_manager<T: SubstateDatabase, O: std::io::Write>(
NonFungibleResourceManagerField::TotalSupply.into(),
)
.map_err(|_| EntityDumpError::InvalidStore("Missing Total Supply".to_string()))?
.into_latest();
.fully_update_and_into_latest_version();

writeln!(
output,
Expand All @@ -249,7 +254,7 @@ pub fn dump_resource_manager<T: SubstateDatabase, O: std::io::Write>(
FungibleResourceManagerField::Divisibility.into(),
)
.map_err(|_| EntityDumpError::InvalidStore("Missing Divisibility".to_string()))?
.into_latest();
.fully_update_and_into_latest_version();

writeln!(output, "{}: {}", "Resource Type".green().bold(), "Fungible");
writeln!(
Expand All @@ -270,7 +275,7 @@ pub fn dump_resource_manager<T: SubstateDatabase, O: std::io::Write>(
FungibleResourceManagerField::TotalSupply.into(),
)
.map_err(|_| EntityDumpError::InvalidStore("Missing Total Supply".to_string()))?
.into_latest();
.fully_update_and_into_latest_version();

writeln!(
output,
Expand Down Expand Up @@ -306,7 +311,7 @@ fn get_entity_metadata<T: SubstateDatabase>(
let map_key = key.into_map();
let key = scrypto_decode::<String>(&map_key).unwrap();
let value = scrypto_decode::<MetadataEntryEntryPayload>(&value).unwrap();
(key, value.into_latest())
(key, value.fully_update_and_into_latest_version())
})
.collect()
}
8 changes: 4 additions & 4 deletions radix-clis/src/resim/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,9 @@ pub fn get_event_schema<S: SubstateDatabase>(
)
.unwrap()?;

let bp_interface = match bp_definition {
VersionedPackageBlueprintVersionDefinition::V1(blueprint) => blueprint.interface,
};
let bp_interface = bp_definition
.fully_update_and_into_latest_version()
.interface;

let event_def = bp_interface.events.get(event_name)?;
match event_def {
Expand Down Expand Up @@ -489,7 +489,7 @@ pub fn db_upsert_epoch(epoch: Epoch) -> Result<(), Error> {
started: true,
})
})
.into_latest();
.fully_update_and_into_latest_version();

consensus_mgr_state.epoch = epoch;

Expand Down
6 changes: 3 additions & 3 deletions radix-clis/src/scrypto_bindgen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ where
) -> Result<SchemaTypeKind<ScryptoCustomSchema>, schema::SchemaError> {
self.lookup_schema(&type_identifier.0)
.ok_or(schema::SchemaError::FailedToGetSchemaFromSchemaHash)?
.as_latest_ref()
.as_latest_version()
.ok_or(schema::SchemaError::FailedToGetSchemaFromSchemaHash)?
.resolve_type_kind(type_identifier.1)
.ok_or(schema::SchemaError::NonExistentLocalTypeIndex(
Expand All @@ -125,7 +125,7 @@ where
) -> Result<TypeMetadata, schema::SchemaError> {
self.lookup_schema(&type_identifier.0)
.ok_or(schema::SchemaError::FailedToGetSchemaFromSchemaHash)?
.as_latest_ref()
.as_latest_version()
.ok_or(schema::SchemaError::FailedToGetSchemaFromSchemaHash)?
.resolve_type_metadata(type_identifier.1)
.ok_or(schema::SchemaError::NonExistentLocalTypeIndex(
Expand All @@ -140,7 +140,7 @@ where
) -> Result<TypeValidation<ScryptoCustomTypeValidation>, schema::SchemaError> {
self.lookup_schema(&type_identifier.0)
.ok_or(schema::SchemaError::FailedToGetSchemaFromSchemaHash)?
.as_latest_ref()
.as_latest_version()
.ok_or(schema::SchemaError::FailedToGetSchemaFromSchemaHash)?
.resolve_type_validation(type_identifier.1)
.ok_or(schema::SchemaError::NonExistentLocalTypeIndex(
Expand Down
1 change: 1 addition & 0 deletions radix-common/src/data/scrypto/custom_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::internal_prelude::*;

pub type ScryptoTypeKind<L> = TypeKind<ScryptoCustomTypeKind, L>;
pub type VersionedScryptoSchema = VersionedSchema<ScryptoCustomSchema>;
pub type ScryptoSchema = Schema<ScryptoCustomSchema>;
pub type ScryptoTypeData<L> = TypeData<ScryptoCustomTypeKind, L>;

/// A schema for the values that a codec can decode / views as valid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ mod test {
mutable_fields,
} = ds
{
let VersionedSchema::V1(s) = schema;
let s = schema.fully_update_and_into_latest_version();
assert_eq!(s.type_kinds.len(), 1);
assert_eq!(s.type_metadata.len(), 1);
assert_eq!(s.type_validations.len(), 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use sbor::SborEnum;

#[cfg_attr(feature = "fuzzing", derive(Arbitrary))]
#[derive(Debug, Clone, Eq, PartialEq, ScryptoSbor, ManifestSbor)]
#[sbor(categorize_types = "U, O")]
pub enum GenericMetadataValue<U, O> {
#[sbor(discriminator(METADATA_VALUE_STRING_DISCRIMINATOR))]
String(String),
Expand Down
2 changes: 1 addition & 1 deletion radix-engine-interface/src/types/kv_store_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use sbor::rust::prelude::*;

#[cfg_attr(feature = "fuzzing", derive(Arbitrary))]
#[derive(Debug, Clone, Eq, PartialEq, ScryptoSbor, ManifestSbor)]
#[sbor(transparent)]
#[sbor(transparent, categorize_types = "K")]
pub struct KeyValueStoreInit<K: Hash + Eq + PartialEq, V> {
pub data: IndexMap<K, KeyValueStoreInitEntry<V>>,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use sbor::*;
use scrypto::prelude::*;
use scrypto::radix_blueprint_schema_init::*;

Expand All @@ -21,11 +20,7 @@ pub extern "C" fn BadFunctionSchema_schema() -> Slice {
);

// Empty Schema
let empty_schema = VersionedScryptoSchema::V1(SchemaV1 {
type_kinds: Vec::new(),
type_metadata: Vec::new(),
type_validations: Vec::new(),
});
let empty_schema = Schema::empty().into_versioned();

let return_data = scrypto::blueprints::package::BlueprintDefinitionInit {
blueprint_type: scrypto::blueprints::package::BlueprintType::default(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,8 @@ mod max_sbor_depth {
impl MaxSborDepthTest {
pub fn write_kv_store_entry_with_depth(buffer: Vec<u8>) {
// Create KeyValueStore<Any, Any>
let schema = VersionedScryptoSchema::V1(SchemaV1 {
type_kinds: vec![],
type_metadata: vec![],
type_validations: vec![],
});
let kv_store = ScryptoVmV1Api::kv_store_new(KeyValueStoreDataSchema::Local {
additional_schema: schema,
additional_schema: Schema::empty().into(),
key_type: LocalTypeId::from(ANY_TYPE),
value_type: LocalTypeId::from(ANY_TYPE),
allow_ownership: false,
Expand Down
7 changes: 1 addition & 6 deletions radix-engine-tests/tests/kernel/test_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,7 @@ fn references_read_from_state_are_visible_in_tests1() {
.with_component_state::<VersionedTwoResourcePoolState, _, _, _>(
radiswap_pool_component,
|state, env| {
let VersionedTwoResourcePoolState::V1(
radix_engine::blueprints::pool::v1::substates::two_resource_pool::Substate {
vaults: [(_, vault1), (_, _)],
..
},
) = state;
let [(_, vault1), (_, _)] = &mut state.as_unique_version_mut().vaults;
vault1.amount(env)
},
)
Expand Down
16 changes: 8 additions & 8 deletions radix-engine-tests/tests/system/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ fn test_genesis_resource_with_initial_allocation(owned_resource: bool) {
)
.unwrap()
.into_payload()
.into_latest();
.fully_update_and_into_latest_version();
assert_eq!(total_supply, allocation_amount);

let reader = SystemDatabaseReader::new(&substate_db);
Expand All @@ -288,7 +288,7 @@ fn test_genesis_resource_with_initial_allocation(owned_resource: bool) {
),
)
.unwrap()
.map(|v| v.into_latest());
.map(|v| v.fully_update_and_into_latest_version());

if let Some(MetadataValue::String(symbol)) = entry {
assert_eq!(symbol, "TST");
Expand Down Expand Up @@ -317,10 +317,10 @@ fn test_genesis_resource_with_initial_allocation(owned_resource: bool) {
.unwrap();
assert!(substate.is_locked());
assert_eq!(
substate.into_value(),
Some(VersionedMetadataEntry::V1(MetadataValue::StringArray(
substate.into_value().map(|v| v.into_unique_version()),
Some(MetadataValue::StringArray(
vec!["badge".to_owned()]
)))
))
);

assert_eq!(
Expand Down Expand Up @@ -491,7 +491,7 @@ fn test_genesis_stake_allocation() {
),
)
.unwrap()
.map(|v| v.into_latest());
.map(|v| v.fully_update_and_into_latest_version());
if let Some(MetadataValue::Url(url)) = validator_url_entry {
assert_eq!(
url,
Expand Down Expand Up @@ -532,7 +532,7 @@ fn test_genesis_time() {
ConsensusManagerField::ProposerMinuteTimestamp.field_index(),
)
.unwrap()
.into_latest();
.fully_update_and_into_latest_version();

assert_eq!(timestamp.epoch_minute, 123);
}
Expand Down Expand Up @@ -758,7 +758,7 @@ fn test_bootstrap_should_create_consensus_manager_with_sorted_validator_index()
ObjectCollectionKey::SortedIndex(0, u16::from_be_bytes(sort_prefix), &address),
)
.expect("validator cannot be read")
.map(|versioned| versioned.into_latest())
.map(|versioned| versioned.fully_update_and_into_latest_version())
.expect("validator not found");

assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion radix-engine-tests/tests/system/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ fn test_basic_package_missing_export() {

schema: BlueprintSchemaInit {
generics: vec![],
schema: VersionedScryptoSchema::V1(SchemaV1 {
schema: VersionedScryptoSchema::from_latest_version(SchemaV1 {
type_kinds: vec![],
type_metadata: vec![],
type_validations: vec![],
Expand Down
2 changes: 1 addition & 1 deletion radix-engine-tests/tests/system/schema_sanity_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ fn native_blueprints_with_typed_addresses_have_expected_schema() {
panic!("Generic output!")
};

let schema = blueprint_definition.schema.schema.into_latest();
let schema = blueprint_definition.schema.schema.fully_update_and_into_latest_version();
let type_kind = schema.resolve_type_kind(local_type_index).unwrap();
let type_validation = schema.resolve_type_validation(local_type_index).unwrap();

Expand Down
1 change: 1 addition & 0 deletions radix-engine/assets/blueprints/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions radix-engine/src/blueprints/access_controller/blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ impl AccessControllerBlueprint {
let access_controller = {
let access_controller: AccessControllerStateFieldPayload =
api.field_read_typed(handle)?;
access_controller.into_latest()
access_controller.fully_update_and_into_latest_version()
};
access_controller.recovery_badge
};
Expand Down Expand Up @@ -1175,7 +1175,7 @@ where

let access_controller = {
let access_controller: AccessControllerStateFieldPayload = api.field_read_typed(handle)?;
access_controller.into_latest()
access_controller.fully_update_and_into_latest_version()
};

let rtn = access_controller.transition(api, input)?;
Expand All @@ -1201,7 +1201,7 @@ where

let mut access_controller = {
let access_controller: AccessControllerStateFieldPayload = api.field_read_typed(handle)?;
access_controller.into_latest()
access_controller.fully_update_and_into_latest_version()
};

let rtn = access_controller.transition_mut(api, input)?;
Expand Down
8 changes: 4 additions & 4 deletions radix-engine/src/blueprints/account/blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ impl AccountBlueprint {
)?;
api.key_value_entry_set_typed(
kv_store_entry_lock_handle,
&VersionedAccountResourcePreference::V1(resource_preference),
&AccountResourcePreferenceVersions::V1(resource_preference).into_versioned(),
)?;
api.key_value_entry_close(kv_store_entry_lock_handle)?;

Expand Down Expand Up @@ -1281,7 +1281,7 @@ impl AccountBlueprint {
)?;
let deposit_rule = api
.field_read_typed::<AccountDepositRuleFieldPayload>(handle)?
.into_latest();
.fully_update_and_into_latest_version();
let default = deposit_rule.default_deposit_rule;
api.field_close(handle)?;

Expand Down Expand Up @@ -1314,7 +1314,7 @@ impl AccountBlueprint {
.key_value_entry_get_typed::<AccountResourceVaultEntryPayload>(
kv_store_entry_lock_handle,
)?
.map(|v| v.into_latest());
.map(|v| v.fully_update_and_into_latest_version());

match entry {
Some(vault) => Ok(vault),
Expand Down Expand Up @@ -1427,7 +1427,7 @@ impl AccountBlueprint {
.key_value_entry_get_typed::<AccountResourcePreferenceEntryPayload>(
kv_store_entry_lock_handle,
)?
.map(|v| v.into_latest());
.map(|v| v.fully_update_and_into_latest_version());
api.key_value_entry_close(kv_store_entry_lock_handle)?;
Ok(entry)
}
Expand Down
Loading
Loading