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

refactor: Moves all transaction models into radix-transactions #1871

Merged
merged 3 commits into from
Aug 15, 2024

Conversation

dhedey
Copy link
Contributor

@dhedey dhedey commented Aug 10, 2024

Summary

  • Adds ScryptoDescribe to the transaction models so that I can assert that the NotarizedTransactionV1 schema is fixed
    • Technically speaking I should create a ManifestSchema and use that; but this is good enough for now, to protect us from accidentally breaking transaction models! Nearly all types map 1:1 between these schemas. We can look to adjust in future.
  • Pulls all the transaction models from the node into radix-transactions:
    • Because of the existence of the Flash transaction, this required moving the StateUpdates models into radix-common from radix-engine / track - which I was initially a bit hesitant about, but I think actually works quite nicely. (radix-common is already aware of some of the nuances of nodes and things).
    • Allows us to delete the duplication in radix-clis
    • Enables the VersionedTransactionPayload to be complete
  • Fixes new compiler warnings in rust 1.80.0

Testing

N/A - just a refactor, existing tests cover it.

Update Recommendations

  • Some types to do with database updates have been moved into the radix_common::prelude::*.
  • Various transaction models can be deleted from the node as they're now in Scrypto (although a few methods interfacing these transactions with the node will need to be kept on the node side)

Copy link

Phylum Report Link

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were shifted-and-lifted.

@@ -264,25 +263,6 @@ impl ExecutionConfig {
}
}

pub struct SubstateBootStore<'a, S: SubstateDatabase> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was unused, so I deleted it as part of the fixing of compiler warnings from 1.80

@@ -1169,7 +1169,7 @@ impl<K: Clone> From<LeafNode<K>> for Node<K> {

impl<P: Clone> Node<P> {
/// Creates the [`Internal`](Node::Internal) variant.
#[cfg(any(test, feature = "fuzzing"))]
#[cfg(test)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fuzzing feature mention was a remanent from when we imported the code originally and as of 1.80 the compiler catches that this isn't a supported feature in the crate.

@@ -0,0 +1,544 @@
use crate::internal_prelude::*;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were shifted-and-lifted out of the very long instruction file

@@ -0,0 +1,65 @@
use super::*;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was shifted-and-lifted from node.

@@ -0,0 +1,134 @@
use super::*;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was shifted-and-lifted from node.

@dhedey dhedey force-pushed the refactor/commonize-transactions branch from 05cca54 to 472ece9 Compare August 10, 2024 04:30
Copy link

github-actions bot commented Aug 10, 2024

Docker tags
docker.io/radixdlt/private-scrypto-builder:f1ea88289d

Copy link

github-actions bot commented Aug 10, 2024

Benchmark for f1ea882

Click to view benchmark
Test Base PR %
costing::bench_prepare_wasm 63.5±0.15ms 63.4±0.14ms -0.16%
costing::decode_encoded_i8_array_to_manifest_raw_value 19.5±0.03ms 19.6±0.04ms +0.51%
costing::decode_encoded_i8_array_to_manifest_value 42.6±0.11ms 41.5±0.07ms -2.58%
costing::decode_encoded_tuple_array_to_manifest_raw_value 63.6±0.18ms 61.1±0.36ms -3.93%
costing::decode_encoded_tuple_array_to_manifest_value 98.5±0.18ms 98.9±0.22ms +0.41%
costing::decode_encoded_u8_array_to_manifest_raw_value 32.3±0.14µs 32.7±0.14µs +1.24%
costing::decode_encoded_u8_array_to_manifest_value 42.6±0.10ms 41.6±0.31ms -2.35%
costing::decode_rpd_to_manifest_raw_value 12.5±0.03µs 13.0±0.04µs +4.00%
costing::decode_rpd_to_manifest_value 10.8±0.04µs 10.9±0.03µs +0.93%
costing::deserialize_wasm 1269.4±6.18µs 1257.8±3.80µs -0.91%
costing::execute_transaction_creating_big_vec_substates 700.3±13.18ms 704.9±12.96ms +0.66%
costing::execute_transaction_reading_big_vec_substates 589.9±0.94ms 581.9±2.18ms -1.36%
costing::instantiate_flash_loan 948.9±810.32µs 1128.4±1639.83µs +18.92%
costing::instantiate_radiswap 1054.2±1203.74µs 1161.6±1982.28µs +10.19%
costing::spin_loop 21.5±0.08ms 21.4±0.07ms -0.47%
costing::validate_sbor_payload 32.7±0.11µs 32.5±0.08µs -0.61%
costing::validate_sbor_payload_bytes 272.3±3.42ns 256.3±1.03ns -5.88%
costing::validate_secp256k1 77.1±0.34µs 77.0±0.79µs -0.13%
costing::validate_wasm 33.7±0.06ms 35.1±0.08ms +4.15%
decimal::add/0 8.4±0.00ns 8.4±0.02ns 0.00%
decimal::add/rust-native 9.8±0.01ns 9.8±0.03ns 0.00%
decimal::add/wasmi 230.4±1.09ns 217.7±0.80ns -5.51%
decimal::add/wasmi-call-native 2.1±0.00µs 2.1±0.00µs 0.00%
decimal::div/0 187.0±0.29ns 187.3±0.39ns +0.16%
decimal::from_string/0 154.8±0.21ns 163.6±0.43ns +5.68%
decimal::mul/0 149.6±0.17ns 150.3±0.27ns +0.47%
decimal::mul/rust-native 145.8±0.33ns 147.7±0.46ns +1.30%
decimal::mul/wasmi 10.7±0.05µs 11.1±0.05µs +3.74%
decimal::mul/wasmi-call-native 2.2±0.00µs 2.3±0.00µs +4.55%
decimal::pow/0 706.4±1.51ns 702.1±1.86ns -0.61%
decimal::pow/rust-native 676.7±1.26ns 668.2±1.75ns -1.26%
decimal::pow/wasmi 52.4±0.33µs 52.3±0.19µs -0.19%
decimal::pow/wasmi-call-native 2.4±0.00µs 2.4±0.00µs 0.00%
decimal::root/0 7.8±0.01µs 7.7±0.02µs -1.28%
decimal::sub/0 8.7±0.05ns 8.8±0.07ns +1.15%
decimal::to_string/0 443.1±0.93ns 441.4±0.56ns -0.38%
precise_decimal::add/0 9.0±0.01ns 9.0±0.02ns 0.00%
precise_decimal::add/rust-native 10.9±0.33ns 10.7±0.02ns -1.83%
precise_decimal::add/wasmi 270.8±1.00ns 261.8±0.82ns -3.32%
precise_decimal::add/wasmi-call-native 2.8±0.01µs 2.8±0.00µs 0.00%
precise_decimal::div/0 358.9±1.28ns 317.2±0.31ns -11.62%
precise_decimal::from_string/0 204.8±1.04ns 200.9±0.16ns -1.90%
precise_decimal::mul/0 362.9±0.75ns 362.4±0.45ns -0.14%
precise_decimal::mul/rust-native 317.9±0.84ns 320.5±0.71ns +0.82%
precise_decimal::mul/wasmi 30.9±0.23µs 29.9±0.19µs -3.24%
precise_decimal::mul/wasmi-call-native 3.2±0.00µs 3.1±0.01µs -3.13%
precise_decimal::pow/0 1956.2±7.89ns 2.0±0.01µs +2.24%
precise_decimal::pow/rust-native 1541.7±2.89ns 1575.8±4.31ns +2.21%
precise_decimal::pow/wasmi 147.4±0.87µs 146.3±0.73µs -0.75%
precise_decimal::pow/wasmi-call-native 5.6±0.01µs 5.5±0.02µs -1.79%
precise_decimal::root/0 60.9±0.12µs 56.6±0.10µs -7.06%
precise_decimal::sub/0 9.2±0.14ns 9.1±0.05ns -1.09%
precise_decimal::to_string/0 764.6±4.74ns 711.7±3.07ns -6.92%
schema::validate_payload 381.7±1.32µs 381.7±0.84µs 0.00%
transaction::radiswap 5.2±0.04ms 5.3±0.05ms +1.92%
transaction::transfer 1920.2±5.23µs 1934.0±5.13µs +0.72%
transaction_processing::prepare 2.4±0.01ms 2.4±0.00ms 0.00%
transaction_processing::prepare_and_decompile 6.0±0.02ms 6.1±0.02ms +1.67%
transaction_processing::prepare_and_decompile_and_recompile 26.8±2.69ms 25.4±1.95ms -5.22%
transaction_validation::validate_manifest 43.0±0.09µs 42.9±0.16µs -0.23%
transaction_validation::verify_bls_2KB 1048.1±17.61µs 1002.6±7.62µs -4.34%
transaction_validation::verify_bls_32B 1003.4±13.22µs 1029.8±31.34µs +2.63%
transaction_validation::verify_ecdsa 74.9±0.22µs 74.7±0.14µs -0.27%
transaction_validation::verify_ed25519 55.5±0.17µs 55.8±0.17µs +0.54%

@dhedey dhedey marked this pull request as ready for review August 12, 2024 14:06
Copy link
Contributor

@jakrawcz-rdx jakrawcz-rdx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only have minor remarks, please address whatever makes sense and 🟢 !

@@ -98,6 +98,7 @@ pub fn run() -> Result<(), String> {
blobs,
..
}) => (instructions.0, blobs.blobs),
_ => return Err("Transaction type not currently supported".to_string()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(minor)

Suggested change
_ => return Err("Transaction type not currently supported".to_string()),
other_type => return Err(format!("Transaction type {:?} not currently supported", other_type)),

@@ -177,7 +170,7 @@ pub trait WriteableTreeStore {
/// avoid this potential performance implication by having an explicit way of associating an
/// "unchanged" Substate with its new tree leaf.
pub enum AssociatedSubstateValue<'v> {
Upserted(&'v DbSubstateValue),
Upserted(&'v [u8]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I quite like the well-named types instead of arbitrary bytes. Even if it's just an alias, it documents things a bit.

(minor; you can say "but here it literally means arbitrary bytes" and I will be ok)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah broadly I agree with you! :)

However, here DbSubstateValue = Vec<u8> - I wanted to change it to the more natural &[u8] rather than using &Vec<u8>.

I don't really like the type alias pattern for these sorts of types because they don't protect anything; I prefer new types.

Arguably that's what AssociatedSubstateValue is already :) - however, imo really it should wrap a RawScryptoValue<'a> - that's essentially what this PR tries to do: #1860


impl DatabaseUpdate {
pub fn as_change(&self) -> SubstateChange<'_> {
/// Uses the given [`DatabaseKeyMapper`] to express self using database-level key encoding.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nitpick) you can now drop this rustdoc from impls

}

/// A 1:1 counterpart of [`DatabaseUpdate`], but operating on references.
pub enum DatabaseUpdateRef<'v> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice; if we are touching this, should we go for:

pub enum DatabaseUpdateWithValueOrRef<V> {
...
}

pub type DatabaseUpdate = DatabaseUpdateWithValueOrRef<DbSubstateValue>;

pub type DatabaseUpdateRef<'v> = DatabaseUpdateWithValueOrRef<&'v [u8]>;

(please disregard if it does not deduplicate any "common" handling code and just makes things harder ;p)

Copy link
Contributor Author

@dhedey dhedey Aug 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we have #1860 I think it's natural to formulate it as:

pub enum DatabaseUpdate<'v> {
    Set(RawScryptoPayload<'v>),
    Delete,
}
pub type OwnedDatabaseUpdate = DatabaseUpdate<'static>;

(Happy to debate naming) So perhaps we can wait for that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, We Can! ®️

@dhedey dhedey merged commit f3b7e04 into develop Aug 15, 2024
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants