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

Introduce priority fee field for transaction and receipt #11228

Merged
merged 9 commits into from May 14, 2024

Conversation

bowenwang1996
Copy link
Collaborator

A first step towards near/NEPs#541 by introducing a priority field in both transaction and receipt. This is not entirely trivial due to the need to maintain backward compatibility. This PR accomplishes backward compatibility by leveraging the account id serialization and implement manual deserialization for the new transaction and receipt structures. While this PR appears to be quite large, most of the changes are trivial. The core of the changes are the serialization/deserialization of transaction and receipt.

While this change introduces the new versions, they are prohibited from being used in the current protocol until the introduction of the protocol change that leverages priorities.

@bowenwang1996 bowenwang1996 marked this pull request as ready for review May 3, 2024 17:20
@bowenwang1996 bowenwang1996 requested a review from a team as a code owner May 3, 2024 17:20
Copy link
Contributor

@jakmeier jakmeier left a comment

Choose a reason for hiding this comment

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

Looks about right to me.

My main comment is more of a discussion around serialization.
Functionally, I only question the priority policy on deleted account balance refunds, which may or may not be correct already.

And yeah, this is a nasty change... I am glad I only have to review it and didn't have to implement it. :P
But definitely 👍 on doing this change of fields in its own PR, so the meat of the changes can be in more focussed PRs.

core/primitives/src/transaction.rs Show resolved Hide resolved
core/primitives/src/receipt.rs Show resolved Hide resolved
Comment on lines +302 to +326
/// Gas refund does not inherit priority from its parent receipt and has no priority associated with it
/// NOTE: The access key may be replaced by the owner, so the execution can't rely that the
/// access key is the same and it should use best effort for the refund.
pub fn new_gas_refund(
receiver_id: &AccountId,
refund: Balance,
signer_public_key: PublicKey,
priority: ReceiptPriority,
) -> Self {
Receipt {
predecessor_id: "system".parse().unwrap(),
receiver_id: receiver_id.clone(),
receipt_id: CryptoHash::default(),
match priority {
ReceiptPriority::Priority(priority) => Receipt::V1(ReceiptV1 {
predecessor_id: "system".parse().unwrap(),
receiver_id: receiver_id.clone(),
receipt_id: CryptoHash::default(),

receipt: ReceiptEnum::Action(ActionReceipt {
signer_id: receiver_id.clone(),
signer_public_key,
gas_price: 0,
output_data_receivers: vec![],
input_data_ids: vec![],
actions: vec![Action::Transfer(TransferAction { deposit: refund })],
receipt: ReceiptEnum::Action(ActionReceipt {
signer_id: receiver_id.clone(),
signer_public_key,
gas_price: 0,
output_data_receivers: vec![],
input_data_ids: vec![],
actions: vec![Action::Transfer(TransferAction { deposit: refund })],
}),
priority,
}),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I agree with gas refunds not inheriting priority, as described in the comment.

But doesn't the code do the opposite? Based on the comment, I would expect that instead of priority as a new parameter to this function, we add a new parameter protocol_version and selects between NoPriority or Priority(0) depending on feature activation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I don't want to introduce a new protocol version in this PR (because it is supposed to be a no-op) so I didn't go with that approach. I can also change this code to only generate V0 for now if it is confusing

core/primitives/src/receipt.rs Outdated Show resolved Hide resolved
core/primitives/src/transaction.rs Show resolved Hide resolved
result.new_receipts.push(Receipt::new_balance_refund(
&delete_account.beneficiary_id,
account_balance,
ReceiptPriority::NoPriority,
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this inherit the priority? Or is that only for balance refunds when execution failed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because no priority generates v0. I want this PR to involve no protocol change so have to do it this way

/// A receipt type
pub receipt: ReceiptEnum,
/// Priority of a receipt
pub priority: u64,
Copy link
Contributor

Choose a reason for hiding this comment

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

could we also wrap this with a struct such as
pub struct Priority(u64)
to not use u64 directly but the surrounding type?
also is 0 top priority and the larger the number the less priority? can you add comment on this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah that is a good point. How exactly priority works has not been decided.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I'll address this issue in a following PR as this one is quite large and is difficult to merge into master due to conflicts.

@bowenwang1996
Copy link
Collaborator Author

@jakmeier @tayfunelmas I plan to merge this PR and iterate on some of the comments in a following one as it is getting quite large and difficult to merge into master. Also, I don't think we need u64 for priority and a u16 is likely sufficient.

@jakmeier
Copy link
Contributor

@jakmeier @tayfunelmas I plan to merge this PR and iterate on some of the comments in a following one as it is getting quite large and difficult to merge into master. Also, I don't think we need u64 for priority and a u16 is likely sufficient.

Makes sense. Even just to avoid endless merge conflicts, let's merge this sooner rather than later.

Copy link

codecov bot commented May 14, 2024

Codecov Report

Attention: Patch coverage is 68.41530% with 289 lines in your changes are missing coverage. Please review.

Project coverage is 70.98%. Comparing base (6cee52d) to head (791f94a).
Report is 7 commits behind head on master.

Files Patch % Lines
core/primitives/src/receipt.rs 65.86% 52 Missing and 19 partials ⚠️
tools/mirror/src/chain_tracker.rs 0.00% 33 Missing ⚠️
tools/mirror/src/lib.rs 0.00% 33 Missing ⚠️
core/primitives/src/transaction.rs 80.12% 7 Missing and 24 partials ⚠️
chain/indexer/src/streamer/utils.rs 0.00% 22 Missing ⚠️
chain/rosetta-rpc/src/lib.rs 0.00% 21 Missing ⚠️
core/primitives/src/test_utils.rs 70.68% 17 Missing ⚠️
core/primitives/src/views.rs 44.44% 10 Missing ⚠️
runtime/runtime/src/verifier.rs 89.47% 3 Missing and 3 partials ⚠️
core/store/src/genesis/state_applier.rs 0.00% 5 Missing ⚠️
... and 19 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11228      +/-   ##
==========================================
- Coverage   70.99%   70.98%   -0.01%     
==========================================
  Files         781      782       +1     
  Lines      155507   156203     +696     
  Branches   155507   156203     +696     
==========================================
+ Hits       110405   110885     +480     
- Misses      40331    40506     +175     
- Partials     4771     4812      +41     
Flag Coverage Δ
backward-compatibility 0.24% <0.00%> (-0.01%) ⬇️
db-migration 0.24% <0.00%> (-0.01%) ⬇️
genesis-check 1.40% <0.00%> (-0.01%) ⬇️
integration-tests 37.19% <34.20%> (-0.04%) ⬇️
linux 69.05% <66.52%> (+0.02%) ⬆️
linux-nightly 70.45% <67.21%> (-0.02%) ⬇️
macos 52.51% <54.99%> (+0.05%) ⬆️
pytests 1.62% <0.00%> (-0.01%) ⬇️
sanity-checks 1.41% <0.00%> (-0.01%) ⬇️
unittests 65.41% <65.60%> (-0.01%) ⬇️
upgradability 0.29% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bowenwang1996 bowenwang1996 added this pull request to the merge queue May 14, 2024
Merged via the queue into near:master with commit a9a6eff May 14, 2024
26 of 29 checks passed
@bowenwang1996 bowenwang1996 deleted the transaction-priority-fee branch May 14, 2024 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants