Skip to content

Commit

Permalink
Merge pull request #2053 from radixdlt/feature/add-dugong
Browse files Browse the repository at this point in the history
Feature/add dugong
  • Loading branch information
dhedey authored Jan 15, 2025
2 parents ce63b05 + 7298418 commit ddd968a
Show file tree
Hide file tree
Showing 545 changed files with 50,226 additions and 209 deletions.
5 changes: 5 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
> _Please remove this section once you confirm you follow its guidance._
## Summary

<!--
> [!TIP]
>
Expand All @@ -20,18 +21,22 @@
-->

## Testing

<!--
> [!TIP]
>
> Explain what testing / verification is done, including manual testing or automated testing.
-->

## Changelog

<!--
> [!TIP]
>
> If the change in your PR is a new feature, or could affect or break any users/integrators, including scrypto developers, dApp developers, transaction creators, or internal integrators, then it likely will need an update to the CHANGELOG.md file.
>
> Changelog entries should include a link to the PR like: [#2053](https://github.com/radixdlt/radixdlt-scrypto/pull/2053) so may need to be added after the PR is created.
>
> After making any required updates, write either of these two:
> * "The changelog has been updated to capture XX changes which affect XX"
> * "The changelog was not updated because this change has no user-facing impact"
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

> Other incidental features or changes which shouldn't break existing integrations, but are worthy of mention to scrypto developers, dApp developers or other integrators.
* *Pending...*
* [#2053](https://github.com/radixdlt/radixdlt-scrypto/pull/2053) - Minor updates to improve the `name` and `description` of the native node module packages.

# v1.3.x - [Cuttlefish](https://docs.radixdlt.com/docs/cuttlefish)

Expand Down
111 changes: 81 additions & 30 deletions radix-common/src/state/state_updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ impl StateUpdates {
self
}

pub fn mut_add_node_updates(
&mut self,
node_id: impl Into<NodeId>,
node_updates: impl Into<NodeStateUpdates>,
) {
let Some(node_updates) = node_updates.into().rebuild_without_empty_entries() else {
return;
};
self.of_node(node_id).mut_add_updates(node_updates);
}

pub fn rebuild_without_empty_entries(self) -> Self {
Self {
by_node: self
Expand Down Expand Up @@ -161,6 +172,20 @@ impl NodeStateUpdates {
.mut_set_substate(key.into_substate_key(), value);
}

pub fn mut_add_updates(&mut self, other: impl Into<Self>) {
let Self::Delta {
by_partition: other_by_partition,
} = other.into();
for (partition_number, partition_state_updates) in other_by_partition {
// Avoid creating empty updates
if partition_state_updates.is_no_op() {
continue;
}
self.of_partition(partition_number)
.mut_add_updates(partition_state_updates);
}
}

/// Starts a Partition-level update.
pub fn of_partition(&mut self, partition_num: PartitionNumber) -> &mut PartitionStateUpdates {
match self {
Expand Down Expand Up @@ -224,6 +249,13 @@ impl Default for PartitionStateUpdates {
}

impl PartitionStateUpdates {
pub fn is_no_op(&self) -> bool {
match self {
PartitionStateUpdates::Delta { by_substate } => by_substate.is_empty(),
PartitionStateUpdates::Batch(BatchPartitionStateUpdate::Reset { .. }) => false,
}
}

pub fn set_substate<'a>(
mut self,
key: impl ResolvableSubstateKey<'a>,
Expand All @@ -233,6 +265,18 @@ impl PartitionStateUpdates {
self
}

pub fn mut_add_updates<'a>(&mut self, other: impl Into<Self>) {
match other.into() {
PartitionStateUpdates::Delta { by_substate } => {
self.mut_update_substates(by_substate);
}
// If we reset, we replace the current state with the reset state
other @ PartitionStateUpdates::Batch(BatchPartitionStateUpdate::Reset { .. }) => {
*self = other;
}
}
}

pub fn mut_set_substate<'a>(
&mut self,
key: impl ResolvableSubstateKey<'a>,
Expand Down Expand Up @@ -279,19 +323,9 @@ impl PartitionStateUpdates {
PartitionStateUpdates::Delta { by_substate } => {
by_substate.insert(substate_key, database_update);
}
PartitionStateUpdates::Batch(BatchPartitionStateUpdate::Reset {
new_substate_values,
}) => match database_update {
DatabaseUpdate::Set(new_value) => {
new_substate_values.insert(substate_key, new_value);
}
DatabaseUpdate::Delete => {
let existed = new_substate_values.swap_remove(&substate_key).is_some();
if !existed {
panic!("inconsistent update: delete of substate {:?} not existing in reset partition", substate_key);
}
}
},
PartitionStateUpdates::Batch(batch_updates) => {
batch_updates.mut_update_substate(substate_key, database_update);
}
}
}

Expand All @@ -310,23 +344,11 @@ impl PartitionStateUpdates {
updates: impl IntoIterator<Item = (SubstateKey, DatabaseUpdate)>,
) {
match self {
PartitionStateUpdates::Delta { by_substate } => by_substate.extend(updates),
PartitionStateUpdates::Batch(BatchPartitionStateUpdate::Reset {
new_substate_values,
}) => {
for (substate_key, database_update) in updates {
match database_update {
DatabaseUpdate::Set(new_value) => {
new_substate_values.insert(substate_key, new_value);
}
DatabaseUpdate::Delete => {
let existed = new_substate_values.swap_remove(&substate_key).is_some();
if !existed {
panic!("inconsistent update: delete of substate {:?} not existing in reset partition", substate_key);
}
}
}
}
PartitionStateUpdates::Delta { by_substate } => {
by_substate.extend(updates);
}
PartitionStateUpdates::Batch(batch_updates) => {
batch_updates.mut_update_substates(updates);
}
}
}
Expand Down Expand Up @@ -393,6 +415,35 @@ pub enum BatchPartitionStateUpdate {
},
}

impl BatchPartitionStateUpdate {
pub fn mut_update_substates(
&mut self,
updates: impl IntoIterator<Item = (SubstateKey, DatabaseUpdate)>,
) {
for (substate_key, database_update) in updates {
self.mut_update_substate(substate_key, database_update);
}
}

pub fn mut_update_substate(
&mut self,
substate_key: SubstateKey,
database_update: DatabaseUpdate,
) {
let BatchPartitionStateUpdate::Reset {
new_substate_values,
} = self;
match database_update {
DatabaseUpdate::Set(new_value) => {
new_substate_values.insert(substate_key, new_value);
}
DatabaseUpdate::Delete => {
new_substate_values.swap_remove(&substate_key);
}
}
}
}

/// An update of a single substate's value.
#[derive(Debug, Clone, Hash, PartialEq, Eq, Sbor, PartialOrd, Ord)]
pub enum DatabaseUpdate {
Expand Down
61 changes: 61 additions & 0 deletions radix-engine-tests/assets/metering/dugong/cost_crypto_utils.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
Total Cost (XRD) , 1.04592820779, 100.0%
- Execution Cost (XRD) , 0.6682258, 63.9%
- Finalization Cost (XRD) , 0.0102517, 1.0%
- Storage Cost (XRD) , 0.36745070779, 35.1%
- Tipping Cost (XRD) , 0, 0.0%
- Royalty Cost (XRD) , 0, 0.0%
Execution Cost Breakdown , 13364516, 100.0%
- AfterInvoke , 518, 0.0%
- AllocateNodeId , 1455, 0.0%
- BeforeInvoke , 7800, 0.1%
- Blake2b256Hash , 91, 0.0%
- Bls12381G2SignatureAggregate , 243986, 1.8%
- Bls12381V1AggregateVerify , 2001824, 15.0%
- Bls12381V1FastAggregateVerify , 632277, 4.7%
- Bls12381V1Verify , 461378, 3.5%
- CheckReference , 80024, 0.6%
- CloseSubstate , 18576, 0.1%
- CreateNode , 13376, 0.1%
- DropNode , 23681, 0.2%
- Ed25519Verify , 14737, 0.1%
- EmitEvent , 556, 0.0%
- GetOwnedNodes , 1000, 0.0%
- Keccak256Hash , 215, 0.0%
- LockFee , 500, 0.0%
- MarkSubstateAsTransient , 55, 0.0%
- OpenSubstate::GlobalFungibleResourceManager , 121872, 0.9%
- OpenSubstate::GlobalGenericComponent , 43690, 0.3%
- OpenSubstate::GlobalPackage , 3484661, 26.1%
- OpenSubstate::InternalFungibleVault , 90202, 0.7%
- OpenSubstate::InternalGenericComponent , 18682, 0.1%
- OpenSubstate::InternalKeyValueStore , 40536, 0.3%
- PinNode , 180, 0.0%
- PrepareWasmCode , 2269642, 17.0%
- QueryActor , 1000, 0.0%
- ReadSubstate , 2340609, 17.5%
- RunNativeCode::Worktop_drop , 17918, 0.1%
- RunNativeCode::get_amount_FungibleVault , 14451, 0.1%
- RunNativeCode::lock_fee , 45243, 0.3%
- RunWasmCode::CryptoScrypto_blake2b_256_hash , 9086, 0.1%
- RunWasmCode::CryptoScrypto_bls12381_g2_signature_aggregate , 400427, 3.0%
- RunWasmCode::CryptoScrypto_bls12381_v1_aggregate_verify , 281194, 2.1%
- RunWasmCode::CryptoScrypto_bls12381_v1_fast_aggregate_verify , 233124, 1.7%
- RunWasmCode::CryptoScrypto_bls12381_v1_verify , 66503, 0.5%
- RunWasmCode::CryptoScrypto_ed25519_verify , 46414, 0.3%
- RunWasmCode::CryptoScrypto_keccak256_hash , 8880, 0.1%
- RunWasmCode::CryptoScrypto_secp256k1_ecdsa_verify , 58421, 0.4%
- RunWasmCode::CryptoScrypto_secp256k1_ecdsa_verify_and_key_recover , 47242, 0.4%
- RunWasmCode::Faucet_lock_fee , 25290, 0.2%
- Secp256k1EcdsaVerify , 14705, 0.1%
- Secp256k1EcdsaVerifyAndKeyRecover , 14705, 0.1%
- SetCallFrameData , 606, 0.0%
- SwitchStack , 1000, 0.0%
- ValidateTxPayload , 151120, 1.1%
- VerifyTxSignatures , 7000, 0.1%
- WriteSubstate , 8064, 0.1%
Finalization Cost Breakdown , 205034, 100.0%
- CommitEvents , 5007, 2.4%
- CommitIntentStatus , 0, 0.0%
- CommitLogs , 0, 0.0%
- CommitStateUpdates::GlobalGenericComponent , 100018, 48.8%
- CommitStateUpdates::InternalFungibleVault , 100009, 48.8%
Loading

0 comments on commit ddd968a

Please sign in to comment.