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

feature: Added PreviewTransactionV2 #1980

Merged
merged 17 commits into from
Oct 29, 2024
Merged

feature: Added PreviewTransactionV2 #1980

merged 17 commits into from
Oct 29, 2024

Conversation

dhedey
Copy link
Contributor

@dhedey dhedey commented Oct 27, 2024

Summary

Adds support for a PreviewTransactionV2, and the preview API in the node will use its payload bytes (a slight pivot from V1 where the preview model was taken in JSON). It can be created from the TransactionV2Builder.

This PR also includes various refactors to the TransactionValidator as part of enabling validation of PreviewTransactionV2s:

  • Moved reference and sig count validation into the right place so it's harder to accidentally miss, and feels more natural. Generally I was trying to architect it so that it's hard to miss a check when introducing new variants (at least in v2).
  • Sig validation takes preview mode as well as non-preview mode, so that the cost of sig validation can be taken into account for the cost estimate. This also allows sig validation to be performed last as it's one of the most expensive parts of validation.
  • Adds a location to all the validation errors so it tells you which intent the error is in.

And also took on another small refactor:

  • Adds an assert_matches!(..) macro so we get better test output on failure for lots of tests.

Testing

  • Additional tests on validation of transactions with invalid signatures
  • Various preview v2 tests in preview_v2.rs

Copy link

github-actions bot commented Oct 27, 2024

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

@dhedey dhedey changed the title feaure: Added PreviewTransactionIntentV2 feature: Added PreviewTransactionIntentV2 Oct 27, 2024
Copy link

github-actions bot commented Oct 27, 2024

Benchmark for 052893b

Click to view benchmark
Test Base PR %
costing::bench_prepare_wasm 44.1±0.16ms 44.9±0.17ms +1.81%
costing::decode_encoded_i8_array_to_manifest_raw_value 19.6±0.05ms 19.4±0.04ms -1.02%
costing::decode_encoded_i8_array_to_manifest_value 42.4±0.10ms 42.3±0.06ms -0.24%
costing::decode_encoded_tuple_array_to_manifest_raw_value 63.2±0.10ms 61.1±0.08ms -3.32%
costing::decode_encoded_tuple_array_to_manifest_value 121.1±1.47ms 102.0±0.13ms -15.77%
costing::decode_encoded_u8_array_to_manifest_raw_value 25.6±0.06µs 32.2±0.12µs +25.78%
costing::decode_encoded_u8_array_to_manifest_value 42.4±0.06ms 42.1±0.05ms -0.71%
costing::decode_rpd_to_manifest_raw_value 12.4±0.03µs 13.0±0.02µs +4.84%
costing::decode_rpd_to_manifest_value 10.8±0.02µs 11.0±0.03µs +1.85%
costing::deserialize_wasm 1237.7±4.77µs 1250.3±5.00µs +1.02%
costing::execute_transaction_creating_big_vec_substates 696.6±9.06ms 685.2±8.91ms -1.64%
costing::execute_transaction_reading_big_vec_substates 585.0±1.86ms 599.2±0.67ms +2.43%
costing::instantiate_flash_loan 2.2±8.91ms 989.4±783.11µs -55.03%
costing::instantiate_radiswap 1076.2±1419.45µs 939.9±650.12µs -12.66%
costing::scrypto_malloc 502.2±0.54ms 595.6±1.21ms +18.60%
costing::scrypto_sbor_decode 486.7±0.90ms 561.9±1.20ms +15.45%
costing::scrypto_sha256 358.5±0.95ms 390.2±1.09ms +8.84%
costing::spin_loop_v1 467.5±0.29ms 617.1±0.46ms +32.00%
costing::spin_loop_v2 948.2±4.39ms 2.7±0.01s +184.75%
costing::validate_sbor_payload 29.3±0.05µs 29.3±0.10µs 0.00%
costing::validate_sbor_payload_bytes 258.1±0.61ns 247.3±1.01ns -4.18%
costing::validate_secp256k1 76.7±0.05µs 76.5±0.07µs -0.26%
costing::validate_wasm 33.4±0.03ms 34.1±0.04ms +2.10%
decimal::add/0 8.4±0.00ns 8.4±0.00ns 0.00%
decimal::add/rust-native 9.8±0.00ns 9.8±0.00ns 0.00%
decimal::add/wasmi 216.6±0.21ns 225.4±1.01ns +4.06%
decimal::add/wasmi-call-native 2.1±0.00µs 2.1±0.00µs 0.00%
decimal::div/0 169.3±0.43ns 169.3±0.19ns 0.00%
decimal::from_string/0 156.8±0.14ns 156.5±0.09ns -0.19%
decimal::mul/0 128.4±0.15ns 128.4±0.11ns 0.00%
decimal::mul/rust-native 126.4±0.05ns 127.8±0.05ns +1.11%
decimal::mul/wasmi 11.4±0.06µs 12.1±0.06µs +6.14%
decimal::mul/wasmi-call-native 2.2±0.00µs 2.5±0.01µs +13.64%
decimal::pow/0 592.8±0.21ns 595.7±0.39ns +0.49%
decimal::pow/rust-native 588.2±0.33ns 590.7±1.27ns +0.43%
decimal::pow/wasmi 58.3±0.87µs 58.9±0.56µs +1.03%
decimal::pow/wasmi-call-native 3.2±0.01µs 3.2±0.00µs 0.00%
decimal::root/0 8.1±0.02µs 8.0±0.01µs -1.23%
decimal::sub/0 8.2±0.01ns 8.3±0.00ns +1.22%
decimal::to_string/0 439.3±0.34ns 444.9±0.60ns +1.27%
large_transaction_processing::prepare 2.5±0.00ms 2.5±0.00ms 0.00%
large_transaction_processing::prepare_and_decompile 6.2±0.02ms 6.2±0.01ms 0.00%
large_transaction_processing::prepare_and_decompile_and_recompile 31.7±0.28ms 32.2±0.29ms +1.58%
metadata_validation::validate_urls 4.8±0.03µs 4.8±0.02µs 0.00%
precise_decimal::add/0 9.0±0.01ns 9.0±0.01ns 0.00%
precise_decimal::add/rust-native 10.6±0.02ns 10.7±0.02ns +0.94%
precise_decimal::add/wasmi 274.4±1.20ns 281.7±1.02ns +2.66%
precise_decimal::add/wasmi-call-native 2.8±0.01µs 2.8±0.01µs 0.00%
precise_decimal::div/0 329.0±2.12ns 292.5±0.48ns -11.09%
precise_decimal::from_string/0 202.5±0.51ns 201.3±0.16ns -0.59%
precise_decimal::mul/0 337.4±1.27ns 336.3±1.14ns -0.33%
precise_decimal::mul/rust-native 284.8±0.31ns 285.4±0.67ns +0.21%
precise_decimal::mul/wasmi 33.4±0.36µs 33.6±0.09µs +0.60%
precise_decimal::mul/wasmi-call-native 3.1±0.01µs 3.1±0.01µs 0.00%
precise_decimal::pow/0 1729.7±2.88ns 1731.5±4.09ns +0.10%
precise_decimal::pow/rust-native 1359.3±1.56ns 1385.9±2.47ns +1.96%
precise_decimal::pow/wasmi 167.2±0.98µs 163.3±0.54µs -2.33%
precise_decimal::pow/wasmi-call-native 5.3±0.02µs 5.4±0.01µs +1.89%
precise_decimal::root/0 58.5±0.02µs 57.4±0.01µs -1.88%
precise_decimal::sub/0 9.2±0.04ns 9.1±0.06ns -1.09%
precise_decimal::to_string/0 691.4±0.43ns 720.0±0.91ns +4.14%
schema::validate_payload 393.7±0.75µs 379.9±0.51µs -3.51%
transaction::radiswap 4.8±0.06ms 4.8±0.01ms 0.00%
transaction::transfer 1819.9±4.15µs 1825.8±1.85µs +0.32%
transaction_validation::validate_manifest 43.1±0.02µs 43.1±0.02µs 0.00%
transaction_validation::verify_bls_2KB 1064.1±15.00µs 1004.8±13.61µs -5.57%
transaction_validation::verify_bls_32B 1007.5±22.08µs 1004.6±13.86µs -0.29%
transaction_validation::verify_ecdsa 74.6±0.36µs 74.6±0.13µs 0.00%
transaction_validation::verify_ed25519 43.9±0.06µs 42.0±0.08µs -4.33%

@dhedey dhedey marked this pull request as ready for review October 28, 2024 01:49
@dhedey dhedey changed the title feature: Added PreviewTransactionIntentV2 feature: Added PreviewTransactionV2 Oct 28, 2024
@dhedey dhedey changed the base branch from feature/allow-v1-transactions-to-still-duplicate-notary to develop October 29, 2024 00:00
.iter()
.zip(non_root_subintent_signatures)
.enumerate()
{
Copy link
Member

Choose a reason for hiding this comment

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

We're not validating the length of signatures?

Copy link
Contributor Author

@dhedey dhedey Oct 29, 2024

Choose a reason for hiding this comment

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

This happens on line 1394 inside add_non_root because it's shared logic - and I believe there are existing tests that cover this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there aren't explicit tests for subintent signatures, I'll add them 👍

Copy link
Member

Choose a reason for hiding this comment

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

I vaguely remember that I added such a test.

Copy link
Member

Choose a reason for hiding this comment

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

too_many_signatures_should_be_rejected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We missed a test on signature count on the root manifest, so I've added that.

.located(TransactionValidationErrorLocation::AcrossTransaction),
);
}
for (index, (subintent, signatures)) in non_root_subintents
Copy link
Member

Choose a reason for hiding this comment

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

Minor: signatures => public_keys

@dhedey dhedey merged commit 10dd7f0 into develop Oct 29, 2024
31 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