From 7243a1cc9ce1eb6684f70e86c69c6e2728f99e70 Mon Sep 17 00:00:00 2001 From: David Edey Date: Wed, 5 Jun 2024 20:25:43 +0100 Subject: [PATCH 1/2] tweak: Small perf improvement on #946 Improve performance when mapping substates Improves on https://github.com/radixdlt/babylon-node/pull/946 --- .../substates/access_controller.rs | 2 +- .../substates/access_rules_module.rs | 4 +- .../core_api/conversions/substates/account.rs | 8 +- .../conversions/substates/account_locker.rs | 2 +- .../substates/consensus_manager.rs | 20 +- .../conversions/substates/metadata_module.rs | 2 +- .../src/core_api/conversions/substates/mod.rs | 182 +++++++++++++++--- .../core_api/conversions/substates/package.rs | 18 +- .../core_api/conversions/substates/pools.rs | 6 +- .../conversions/substates/resource.rs | 18 +- .../conversions/substates/royalty_module.rs | 4 +- 11 files changed, 200 insertions(+), 66 deletions(-) diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/access_controller.rs b/core-rust/core-api-server/src/core_api/conversions/substates/access_controller.rs index 449643f53e..4949d5e116 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/access_controller.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/access_controller.rs @@ -7,7 +7,7 @@ pub fn to_api_access_controller_substate( context: &MappingContext, substate: &AccessControllerV2StateFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_multi_versioned!( substate, AccessControllerFieldState, AccessControllerV2Substate { diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/access_rules_module.rs b/core-rust/core-api-server/src/core_api/conversions/substates/access_rules_module.rs index fba157124a..9ad05d1620 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/access_rules_module.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/access_rules_module.rs @@ -7,7 +7,7 @@ pub fn to_api_owner_role_substate( context: &MappingContext, substate: &RoleAssignmentOwnerFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, RoleAssignmentModuleFieldOwnerRole, OwnerRoleSubstate { owner_role_entry }, @@ -35,7 +35,7 @@ pub fn to_api_access_rule_entry( ModuleRoleKey { module, key } )) ); - Ok(key_value_store_optional_substate_versioned!( + Ok(key_value_store_optional_substate_single_versioned!( substate, RoleAssignmentModuleRuleEntry, models::ObjectRoleKey { diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/account.rs b/core-rust/core-api-server/src/core_api/conversions/substates/account.rs index 6f0db9ae64..522d076c21 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/account.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/account.rs @@ -7,7 +7,7 @@ pub fn to_api_account_state_substate( _context: &MappingContext, substate: &AccountDepositRuleFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, AccountFieldState, AccountSubstate { @@ -36,7 +36,7 @@ pub fn to_api_account_vault_entry( }) )) ); - Ok(key_value_store_mandatory_substate_versioned!( + Ok(key_value_store_mandatory_substate_single_versioned!( substate, AccountVaultEntry, models::ResourceKey { @@ -63,7 +63,7 @@ pub fn to_api_account_resource_preference_entry( ) )) ); - Ok(key_value_store_optional_substate_versioned!( + Ok(key_value_store_optional_substate_single_versioned!( substate, AccountResourcePreferenceEntry, models::ResourceKey { @@ -93,7 +93,7 @@ pub fn to_api_account_authorized_depositor_entry( ) )) ); - Ok(key_value_store_optional_substate_versioned!( + Ok(key_value_store_optional_substate_single_versioned!( substate, AccountAuthorizedDepositorEntry, models::AuthorizedDepositorKey { diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/account_locker.rs b/core-rust/core-api-server/src/core_api/conversions/substates/account_locker.rs index ad1ab42e0a..4c0b4c4223 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/account_locker.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/account_locker.rs @@ -18,7 +18,7 @@ pub fn to_api_account_locker_account_claim_entry( ) )) ); - Ok(key_value_store_mandatory_substate_versioned!( + Ok(key_value_store_mandatory_substate_single_versioned!( substate, AccountLockerAccountClaimsEntry, models::AccountAddressKey { diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/consensus_manager.rs b/core-rust/core-api-server/src/core_api/conversions/substates/consensus_manager.rs index f9ecf6c8c0..23b1da2e2b 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/consensus_manager.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/consensus_manager.rs @@ -18,7 +18,7 @@ pub fn to_api_registered_validators_by_stake_index_entry_substate( divided_stake, validator_address, } = key.clone().into_full_content(); - Ok(index_substate_versioned!( + Ok(index_substate_single_versioned!( substate, ConsensusManagerRegisteredValidatorsByStakeIndexEntry, models::ActiveValidatorKey { @@ -39,7 +39,7 @@ pub fn to_api_current_validator_set_substate( context: &MappingContext, substate: &ConsensusManagerCurrentValidatorSetFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, ConsensusManagerFieldCurrentValidatorSet, CurrentValidatorSetSubstate { validator_set } => { @@ -57,7 +57,7 @@ pub fn to_api_current_proposal_statistic_substate( _context: &MappingContext, substate: &ConsensusManagerCurrentProposalStatisticFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, ConsensusManagerFieldCurrentProposalStatistic, CurrentProposalStatisticSubstate { @@ -80,7 +80,7 @@ pub fn to_api_validator_rewards_substate( context: &MappingContext, substate: &ConsensusManagerValidatorRewardsFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, ConsensusManagerFieldValidatorRewards, ValidatorRewardsSubstate { @@ -129,7 +129,7 @@ pub fn to_api_validator_state_substate( context: &MappingContext, substate: &ValidatorStateFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, ValidatorFieldState, ValidatorState { @@ -210,7 +210,7 @@ pub fn to_api_validator_protocol_update_readiness_signal_substate( _context: &MappingContext, substate: &ValidatorProtocolUpdateReadinessSignalFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, ValidatorFieldProtocolUpdateReadinessSignal, ValidatorProtocolUpdateReadinessSignalSubstate { @@ -226,7 +226,7 @@ pub fn to_api_consensus_manager_state_substate( context: &MappingContext, substate: &ConsensusManagerStateFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, ConsensusManagerFieldState, ConsensusManagerSubstate { @@ -259,7 +259,7 @@ pub fn to_api_consensus_manager_config_substate( substate: &ConsensusManagerConfigurationFieldSubstate, ) -> Result { let usd_price_in_xrd = Decimal::try_from(USD_PRICE_IN_XRD).unwrap(); - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, ConsensusManagerFieldConfig, ConsensusManagerConfigSubstate { @@ -325,7 +325,7 @@ pub fn to_api_epoch_change_condition( pub fn to_api_current_time_substate( substate: &ConsensusManagerProposerMilliTimestampFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, ConsensusManagerFieldCurrentTime, ProposerMilliTimestampSubstate { epoch_milli }, @@ -338,7 +338,7 @@ pub fn to_api_current_time_substate( pub fn to_api_current_time_rounded_to_minutes_substate( substate: &ConsensusManagerProposerMinuteTimestampFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, ConsensusManagerFieldCurrentTimeRoundedToMinutes, ProposerMinuteTimestampSubstate { epoch_minute }, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/metadata_module.rs b/core-rust/core-api-server/src/core_api/conversions/substates/metadata_module.rs index 8c2be435f5..acb882f2a1 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/metadata_module.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/metadata_module.rs @@ -14,7 +14,7 @@ pub fn to_api_metadata_value_substate( entry_name )) ); - Ok(key_value_store_optional_substate_versioned!( + Ok(key_value_store_optional_substate_single_versioned!( substate, MetadataModuleEntry, models::MetadataKey { diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/mod.rs b/core-rust/core-api-server/src/core_api/conversions/substates/mod.rs index 170142608f..a2aa07989c 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/mod.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/mod.rs @@ -1,3 +1,5 @@ +#![allow(unused_imports, unused_macros)] + mod access_controller; mod access_rules_module; mod account; @@ -84,7 +86,35 @@ macro_rules! field_substate { } pub(crate) use field_substate; -macro_rules! field_substate_versioned { +macro_rules! field_substate_single_versioned { + ( + $substate:ident, + $substate_type:ident, + $value_unpacking:pat $(=> { + $($mapping:stmt)+ + })?, + Value $fields:tt$(,)? + ) => { + paste::paste! { + // The trailing semicolon after the $($($mapping)+)?; output is occasionally needed, + // eg if the mapping ends with a match statement. But otherwise it's reported as a + // redundant - so add this allow statement to allow us just to include it regardless. + #[allow(redundant_semicolons)] + models::Substate::[<$substate_type Substate>] { + is_locked: matches!($substate.lock_status(), LockStatus::Locked), + value: { + // NB: We should use compiler to unpack to ensure we map all fields + let $value_unpacking = $substate.payload().as_unique_version(); + $($($mapping)+)?; + Box::new(models::[<$substate_type Value>] $fields) + } + } + } + }; +} +pub(crate) use field_substate_single_versioned; + +macro_rules! field_substate_multi_versioned { ( $substate:ident, $substate_type:ident, @@ -101,9 +131,9 @@ macro_rules! field_substate_versioned { models::Substate::[<$substate_type Substate>] { is_locked: matches!($substate.lock_status(), LockStatus::Locked), value: { + let latest = create_latest_version_from_payload($substate.payload()); // NB: We should use compiler to unpack to ensure we map all fields - let $value_unpacking = &scrypto_clone($substate.payload()) - .fully_update_and_into_latest_version(); + let $value_unpacking = latest.as_ref(); $($($mapping)+)?; Box::new(models::[<$substate_type Value>] $fields) } @@ -111,7 +141,7 @@ macro_rules! field_substate_versioned { } }; } -pub(crate) use field_substate_versioned; +pub(crate) use field_substate_multi_versioned; macro_rules! system_field_substate { ( @@ -164,7 +194,32 @@ macro_rules! key_value_store_optional_substate { } pub(crate) use key_value_store_optional_substate; -macro_rules! key_value_store_optional_substate_versioned { +macro_rules! key_value_store_optional_substate_single_versioned { + ( + $substate:ident, + $substate_type:ident, + $key:expr, + $value_unpacking:pat => $fields:tt$(,)? + ) => { + paste::paste! { + models::Substate::[<$substate_type Substate>] { + is_locked: matches!($substate.lock_status(), LockStatus::Locked), + key: Box::new($key), + value: $substate + .get_optional_value() + .map(|opt| -> Result<_, MappingError> { + #[allow(clippy::let_unit_value)] + let $value_unpacking = opt.as_unique_version(); + Ok(Box::new(models::[<$substate_type Value>] $fields)) + }) + .transpose()?, + } + } + }; +} +pub(crate) use key_value_store_optional_substate_single_versioned; + +macro_rules! key_value_store_optional_substate_multi_versioned { ( $substate:ident, $substate_type:ident, @@ -178,9 +233,10 @@ macro_rules! key_value_store_optional_substate_versioned { value: $substate .get_optional_value() .map(|opt| -> Result<_, MappingError> { + let latest = create_latest_version_from_payload(opt); #[allow(clippy::let_unit_value)] - let $value_unpacking = &scrypto_clone(opt) - .fully_update_and_into_latest_version(); + // NB: We should use compiler to unpack to ensure we map all fields + let $value_unpacking = latest.as_ref(); Ok(Box::new(models::[<$substate_type Value>] $fields)) }) .transpose()?, @@ -188,7 +244,7 @@ macro_rules! key_value_store_optional_substate_versioned { } }; } -pub(crate) use key_value_store_optional_substate_versioned; +pub(crate) use key_value_store_optional_substate_multi_versioned; macro_rules! key_value_store_mandatory_substate { ( @@ -199,6 +255,7 @@ macro_rules! key_value_store_mandatory_substate { ) => { paste::paste! { { + // NB: We should use compiler to unpack to ensure we map all fields let $value_unpacking = $substate.get_definitely_present_value()?; models::Substate::[<$substate_type Substate>] { is_locked: matches!($substate.lock_status(), LockStatus::Locked), @@ -211,7 +268,7 @@ macro_rules! key_value_store_mandatory_substate { } pub(crate) use key_value_store_mandatory_substate; -macro_rules! key_value_store_mandatory_substate_versioned { +macro_rules! key_value_store_mandatory_substate_single_versioned { ( $substate:ident, $substate_type:ident, @@ -220,8 +277,8 @@ macro_rules! key_value_store_mandatory_substate_versioned { ) => { paste::paste! { { - let $value_unpacking = &scrypto_clone($substate.get_definitely_present_value()?) - .fully_update_and_into_latest_version(); + // NB: We should use compiler to unpack to ensure we map all fields + let $value_unpacking = $substate.get_definitely_present_value()?.as_unique_version(); models::Substate::[<$substate_type Substate>] { is_locked: matches!($substate.lock_status(), LockStatus::Locked), key: Box::new($key), @@ -231,7 +288,30 @@ macro_rules! key_value_store_mandatory_substate_versioned { } }; } -pub(crate) use key_value_store_mandatory_substate_versioned; +pub(crate) use key_value_store_mandatory_substate_single_versioned; + +macro_rules! key_value_store_mandatory_substate_multi_versioned { + ( + $substate:ident, + $substate_type:ident, + $key:expr, + $value_unpacking:pat => $fields:tt$(,)? + ) => { + paste::paste! { + { + let latest = create_latest_version_from_payload($substate.get_definitely_present_value()?); + // NB: We should use compiler to unpack to ensure we map all fields + let $value_unpacking = latest.as_ref(); + models::Substate::[<$substate_type Substate>] { + is_locked: matches!($substate.lock_status(), LockStatus::Locked), + key: Box::new($key), + value: Box::new(models::[<$substate_type Value>] $fields) + } + } + } + }; +} +pub(crate) use key_value_store_mandatory_substate_multi_versioned; macro_rules! index_substate { ( @@ -251,7 +331,28 @@ macro_rules! index_substate { } pub(crate) use index_substate; -macro_rules! index_substate_versioned { +macro_rules! index_substate_single_versioned { + ( + $substate:ident, + $substate_type:ident, + $key:expr, + $value_unpacking:pat => $fields:tt$(,)? + ) => { + paste::paste! { + { + let $value_unpacking = $substate.value().as_unique_version(); + models::Substate::[<$substate_type Substate>] { + is_locked: false, + key: Box::new($key), + value: Box::new(models::[<$substate_type Value>] $fields) + } + } + } + }; +} +pub(crate) use index_substate_single_versioned; + +macro_rules! index_substate_multi_versioned { ( $substate:ident, $substate_type:ident, @@ -260,8 +361,9 @@ macro_rules! index_substate_versioned { ) => { paste::paste! { { - let $value_unpacking = &scrypto_clone($substate.value()) - .fully_update_and_into_latest_version(); + let latest = create_latest_version_from_payload($substate.value()); + // NB: We should use compiler to unpack to ensure we map all fields + let $value_unpacking = latest.as_ref(); models::Substate::[<$substate_type Substate>] { is_locked: false, key: Box::new($key), @@ -271,7 +373,7 @@ macro_rules! index_substate_versioned { } }; } -pub(crate) use index_substate_versioned; +pub(crate) use index_substate_multi_versioned; trait WrapperMethods { fn get_definitely_present_value(&self) -> Result<&C, MappingError> { @@ -289,12 +391,44 @@ impl WrapperMethods for KeyValueEntrySubstate { } } -/// "Clones" an SBOR-encodable value. -/// Note: this hack is required since many of the Substate value structs do not support [`Clone`], -/// and the convenient "into latest" method (which we need in order to output the value according to -/// the "current" Core API schema) needs an owned instance. A true fix should involve either cloning -/// or some other way of "get latest from reference" on the Engine's side. -fn scrypto_clone(value: &T) -> T { - let bytes = scrypto_encode(value).expect("cannot encode"); - scrypto_decode(&bytes).expect("cannot decode") +/// Returns either a reference to the latest version if the payload is already at the latest version, +/// or does a more expensive clone, and then updates the payload. +/// +/// To avoid this overhead, if you know a payload is single versioned, you can just use `as_unique_version` +/// which only exists on single-versioned items. +fn create_latest_version_from_payload<'a, P, T>(payload: &'a P) -> SimpleCow<'a, T::LatestVersion> +where + P: core::ops::Deref, // Note - the payload itself isn't Versioned, but Derefs to the content which is Versioned. + T: ScryptoSbor + Versioned + 'a, +{ + let versioned_content = payload.deref(); + if let Some(latest) = versioned_content.as_latest_version() { + // Save on an expensive clone if we're already the latest version + SimpleCow::Borrowed(latest) + } else { + // Otherwise, we need to clone the value, but the type isn't necessarily Clone. + // So instead, we implement "clone" via SBOR-encoding value. + // Note: this hack is required since many of the Substate value structs do not support [`Clone`], + // and the convenient "into latest" method (which we need in order to output the value according to + // the "current" Core API schema) needs an owned instance. A true fix should involve either cloning + // or some other way of "get latest from reference" on the Engine's side. + let bytes = scrypto_encode(versioned_content).expect("cannot encode"); + let cloned = scrypto_decode::(&bytes).expect("cannot decode"); + SimpleCow::Owned(cloned.fully_update_and_into_latest_version()) + } +} + +// Unlike Cow, this doesn't require that B implements ToOwned / Clone. +pub enum SimpleCow<'a, B: 'a> { + Borrowed(&'a B), + Owned(B), +} + +impl<'a, B: 'a> AsRef for SimpleCow<'a, B> { + fn as_ref(&self) -> &B { + match self { + SimpleCow::Borrowed(b) => b, + SimpleCow::Owned(b) => b, + } + } } diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/package.rs b/core-rust/core-api-server/src/core_api/conversions/substates/package.rs index 6c29516817..0df0fc7ecd 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/package.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/package.rs @@ -7,7 +7,7 @@ pub fn to_api_package_royalty_accumulator_substate( context: &MappingContext, substate: &PackageRoyaltyAccumulatorFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, PackageFieldRoyaltyAccumulator, PackageRoyaltyAccumulator { royalty_vault }, @@ -34,7 +34,7 @@ pub fn to_api_package_code_vm_type_entry_substate( )) ); - Ok(key_value_store_mandatory_substate_versioned!( + Ok(key_value_store_mandatory_substate_single_versioned!( substate, PackageCodeVmTypeEntry, models::PackageCodeKey { @@ -63,7 +63,7 @@ pub fn to_api_package_code_original_code_entry_substate( )) ); - Ok(key_value_store_mandatory_substate_versioned!( + Ok(key_value_store_mandatory_substate_single_versioned!( substate, PackageCodeOriginalCodeEntry, models::PackageCodeKey { @@ -89,7 +89,7 @@ pub fn to_api_package_code_instrumented_code_entry_substate( )) ); - Ok(key_value_store_mandatory_substate_versioned!( + Ok(key_value_store_mandatory_substate_single_versioned!( substate, PackageCodeInstrumentedCodeEntry, models::PackageCodeKey { @@ -111,7 +111,7 @@ pub fn to_api_schema_entry_substate( TypedSubstateKey::Schema(TypedSchemaSubstateKey::SchemaKey(hash)) ); - Ok(key_value_store_mandatory_substate_versioned!( + Ok(key_value_store_mandatory_substate_single_versioned!( substate, SchemaEntry, models::SchemaKey { @@ -139,7 +139,7 @@ pub fn to_api_package_blueprint_definition_entry( )) ); - Ok(key_value_store_mandatory_substate_versioned!( + Ok(key_value_store_mandatory_substate_single_versioned!( substate, PackageBlueprintDefinitionEntry, to_api_blueprint_version_key(context, blueprint_version_key)?, @@ -165,7 +165,7 @@ pub fn to_api_package_blueprint_dependencies_entry( )) ); - Ok(key_value_store_mandatory_substate_versioned!( + Ok(key_value_store_mandatory_substate_single_versioned!( substate, PackageBlueprintDependenciesEntry, to_api_blueprint_version_key(context, blueprint_version_key)?, @@ -191,7 +191,7 @@ pub fn to_api_package_blueprint_royalty_entry( )) ); - Ok(key_value_store_mandatory_substate_versioned!( + Ok(key_value_store_mandatory_substate_single_versioned!( substate, PackageBlueprintRoyaltyEntry, to_api_blueprint_version_key(context, blueprint_version_key)?, @@ -239,7 +239,7 @@ pub fn to_api_package_auth_template_entry( ) )) ); - Ok(key_value_store_mandatory_substate_versioned!( + Ok(key_value_store_mandatory_substate_single_versioned!( substate, PackageBlueprintAuthTemplateEntry, to_api_blueprint_version_key(context, blueprint_version_key)?, diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/pools.rs b/core-rust/core-api-server/src/core_api/conversions/substates/pools.rs index efaa14e274..4b0228331b 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/pools.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/pools.rs @@ -7,7 +7,7 @@ pub fn to_api_one_resource_pool_substate( context: &MappingContext, substate: &OneResourcePoolStateFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, OneResourcePoolFieldState, OneResourcePoolState { @@ -28,7 +28,7 @@ pub fn to_api_two_resource_pool_substate( context: &MappingContext, substate: &TwoResourcePoolStateFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, TwoResourcePoolFieldState, TwoResourcePoolState { @@ -56,7 +56,7 @@ pub fn to_api_multi_resource_pool_substate( context: &MappingContext, substate: &MultiResourcePoolStateFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, MultiResourcePoolFieldState, MultiResourcePoolState { diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/resource.rs b/core-rust/core-api-server/src/core_api/conversions/substates/resource.rs index b0eabfca43..98826f7733 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/resource.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/resource.rs @@ -7,7 +7,7 @@ pub fn to_api_fungible_vault_balance_substate( _context: &MappingContext, substate: &FungibleVaultBalanceFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, FungibleVaultFieldBalance, balance, @@ -21,7 +21,7 @@ pub fn to_api_fungible_vault_frozen_status_substate( _context: &MappingContext, substate: &FungibleVaultFreezeStatusFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, FungibleVaultFieldFrozenStatus, VaultFrozenFlag { frozen }, @@ -46,7 +46,7 @@ pub fn to_api_non_fungible_vault_balance_substate( _context: &MappingContext, substate: &NonFungibleVaultBalanceFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, NonFungibleVaultFieldBalance, NonFungibleVaultBalance { amount }, @@ -60,7 +60,7 @@ pub fn to_api_non_fungible_vault_frozen_status_substate( _context: &MappingContext, substate: &NonFungibleVaultFreezeStatusFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, FungibleVaultFieldFrozenStatus, VaultFrozenFlag { frozen }, @@ -100,7 +100,7 @@ pub fn to_api_non_fungible_vault_contents_entry_substate( pub fn to_api_fungible_resource_manager_divisibility_substate( substate: &FungibleResourceManagerDivisibilityFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, FungibleResourceManagerFieldDivisibility, divisibility, @@ -113,7 +113,7 @@ pub fn to_api_fungible_resource_manager_divisibility_substate( pub fn to_api_fungible_resource_manager_total_supply_substate( substate: &FungibleResourceManagerTotalSupplyFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, FungibleResourceManagerFieldTotalSupply, total_supply, @@ -126,7 +126,7 @@ pub fn to_api_fungible_resource_manager_total_supply_substate( pub fn to_api_non_fungible_resource_manager_id_type_substate( substate: &NonFungibleResourceManagerIdTypeFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, NonFungibleResourceManagerFieldIdType, non_fungible_id_type, @@ -139,7 +139,7 @@ pub fn to_api_non_fungible_resource_manager_id_type_substate( pub fn to_api_non_fungible_resource_manager_total_supply_substate( substate: &NonFungibleResourceManagerTotalSupplyFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, NonFungibleResourceManagerFieldTotalSupply, total_supply, @@ -153,7 +153,7 @@ pub fn to_api_non_fungible_resource_manager_mutable_fields_substate( context: &MappingContext, substate: &NonFungibleResourceManagerMutableFieldsFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, NonFungibleResourceManagerFieldMutableFields, NonFungibleResourceManagerMutableFields { diff --git a/core-rust/core-api-server/src/core_api/conversions/substates/royalty_module.rs b/core-rust/core-api-server/src/core_api/conversions/substates/royalty_module.rs index bc76b4688f..0ff7746714 100644 --- a/core-rust/core-api-server/src/core_api/conversions/substates/royalty_module.rs +++ b/core-rust/core-api-server/src/core_api/conversions/substates/royalty_module.rs @@ -7,7 +7,7 @@ pub fn to_api_component_royalty_substate( context: &MappingContext, substate: &ComponentRoyaltyAccumulatorFieldSubstate, ) -> Result { - Ok(field_substate_versioned!( + Ok(field_substate_single_versioned!( substate, RoyaltyModuleFieldState, ComponentRoyaltySubstate { royalty_vault }, @@ -32,7 +32,7 @@ pub fn to_api_component_method_royalty_substate( TypedRoyaltyModuleSubstateKey::RoyaltyMethodRoyaltyEntryKey(method_name) ) ); - Ok(key_value_store_optional_substate_versioned!( + Ok(key_value_store_optional_substate_single_versioned!( substate, RoyaltyModuleMethodRoyaltyEntry, models::MainMethodKey { From 6dfea144a73dbe79cf7f36f6481166e3312d9e63 Mon Sep 17 00:00:00 2001 From: David Edey Date: Wed, 5 Jun 2024 20:26:02 +0100 Subject: [PATCH 2/2] fix: Please clippy (unrelated change) --- core-rust/state-manager/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core-rust/state-manager/src/lib.rs b/core-rust/state-manager/src/lib.rs index 461f8fb809..5786e40818 100644 --- a/core-rust/state-manager/src/lib.rs +++ b/core-rust/state-manager/src/lib.rs @@ -99,7 +99,6 @@ pub use crate::types::*; pub mod engine_prelude { pub use radix_common::prelude::*; - pub use radix_engine::*; pub use radix_engine::errors::*; pub use radix_engine::system::bootstrap::*; #[cfg(feature = "db_checker")] @@ -109,9 +108,10 @@ pub mod engine_prelude { pub use radix_engine::transaction::*; pub use radix_engine::updates::*; pub use radix_engine::vm::*; + pub use radix_engine::*; - pub use radix_engine_interface::blueprints::transaction_processor::*; pub use radix_engine_interface::blueprints::account::*; + pub use radix_engine_interface::blueprints::transaction_processor::*; pub use radix_engine_interface::prelude::*; pub use radix_substate_store_impls::state_tree::tree_store::*; @@ -125,12 +125,12 @@ pub mod engine_prelude { pub use radix_transaction_scenarios::scenario::*; pub use radix_transactions::builder::*; + pub use radix_transactions::define_raw_transaction_payload; pub use radix_transactions::errors::*; pub use radix_transactions::manifest::*; pub use radix_transactions::model::*; pub use radix_transactions::prelude::*; pub use radix_transactions::validation::*; - pub use radix_transactions::*; // Note: plain `pub use radix_engine::track::*` would clash with the top-level `utils::prelude` // (because it contains a private module of the same name)