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

Add setFee and setFeePerWU #1968

Merged
merged 7 commits into from
Jan 15, 2025
Merged

Add setFee and setFeePerWU #1968

merged 7 commits into from
Jan 15, 2025

Conversation

Geometer1729
Copy link
Member

Closes #1626

@Geometer1729 Geometer1729 marked this pull request as ready for review January 13, 2025 14:16
@Geometer1729 Geometer1729 requested review from a team as code owners January 13, 2025 14:16
src/lib/mina/transaction.ts Outdated Show resolved Hide resolved
@dfstio
Copy link

dfstio commented Jan 14, 2025

This PR clears the proof and signature authorizations for all AccountUpdates. At the same time, for many txs, only the signature of the feePayer should be changed. Is it possible to differentiate between the signatures and proofs that should be changed in case of fee change and those that can stay the same?

@mitschabaude
Copy link
Collaborator

mitschabaude commented Jan 14, 2025

At the same time, for many txs, only the signature of the feePayer should be changed. Is it possible to differentiate between the signatures and proofs that should be changed in case of fee change and those that can stay the same?

I would go even further: It's currently not possibly that any proofs are invalidated by a fee change, because they can't refer to the fee payer.

Signatures are affected if and only if they have useFullCommitment = true.

So you can actually be fully precise with invalidation.

CHANGELOG.md Outdated
@@ -17,6 +17,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased](https://github.com/o1-labs/o1js/compare/b857516...HEAD)

### Added
- `setFee` and `setFeePerWU` for `Transaction` and `PendingTransaction`
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add the link to this PR to this changelog entry?

/**
* setFeePerWU is the same as {@link Transaction.setFeeWU(newFeePerWU)} but for a {@link PendingTransaction}.
*/
setFeePerWU(newFeePerWU:UInt64):TransactionPromise<false,false>;
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] As a style choice, I think setFeePerWeightUnit is a better choice for the name of this method.

@@ -544,6 +572,26 @@ function newTransaction(transaction: ZkappCommand, proofsEnabled?: boolean) {
}
return pendingTransaction;
},
setFeePerWU(newFeePerWU:UInt64) {
//Currently WU is just the number of accountUpdates + 1
//https://github.com/MinaProtocol/mina/blob/a0a2adf6b1dce7af889250ff469a35ae4afa512f/src/lib/mina_base/zkapp_command.ml#L803-L823
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the weight of a zkapp_command, which ends up being different than the weight of a signed command:

Also, there is this other formula for "cost", which I think is the most relevant formula to use for this context: https://github.com/MinaProtocol/mina/blob/a0a2adf6b1dce7af889250ff469a35ae4afa512f/src/lib/mina_base/zkapp_command.ml#L1317, ( duplicated in o1js here:

let totalTimeRequired =
)

(*10.26*np + 10.08*n2 + 9.14*n1 < 69.45*)

The way I understand it, this formula estimates how long it will take to snark a transaction, which is turn is what makes snark workers want more payment. Number of account updates +1 doesn't count proofs at all. I think we should disambiguate "cost" and "weight" to make sure we are capturing the right thing with this new method.

Copy link
Contributor

@Shigoto-dev19 Shigoto-dev19 left a comment

Choose a reason for hiding this comment

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

looks good to me! I will approve once the requested changes are applied.

@dfstio
Copy link

dfstio commented Jan 15, 2025

au.body.useFullCommitment is Bool, therefore the condition if (au.body.useFullCommitment) will always be true

Copy link
Contributor

@45930 45930 left a comment

Choose a reason for hiding this comment

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

*/
setFee(newFee:UInt64) : TransactionPromise<Proven,false>;
/**
* setFeePerSnarkCost behaves identically to {@link setFee} but the fee is given per Account Update in the transaction. This is useful because nodes prioritize transactions by fee per weight unit.
Copy link
Contributor

Choose a reason for hiding this comment

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

but the fee is given per Account Update in the transaction. This is useful because nodes prioritize transactions by fee per weight unit.

This seems to describe the previous behavior. Should be updated to mention snark cost instead of weight unit, and mention proofs as well as AccountUpdates. Might be nice to {@link getTotalTimeRequired} as well, but I'm not sure that's a public function.

Copy link
Member Author

Choose a reason for hiding this comment

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

The link at least works in my LSP

*/
setFee(newFee:UInt64):TransactionPromise<boolean,false>;
/**
* setFeePerSnarkCost is the same as {@link Transaction.setFeeWU(newFeePerWU)} but for a {@link PendingTransaction}.
Copy link
Contributor

Choose a reason for hiding this comment

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

Update here as well

@Geometer1729
Copy link
Member Author

Thanks everyone, for bearing with me and catching all those mistakes.

@Geometer1729 Geometer1729 merged commit 82db28b into main Jan 15, 2025
29 checks passed
@Geometer1729 Geometer1729 deleted the brian/increaseFee branch January 15, 2025 17:16
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.

Specify fee per weight unit
6 participants