Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Take into account proof size for transaction payment and priority #13958

Merged
merged 22 commits into from
Jun 13, 2023

Conversation

Ank4n
Copy link
Contributor

@Ank4n Ank4n commented Apr 20, 2023

closes #13898.

Currently, TargetedFeeAdjustment takes into account only ref_time dimension of the weight. This is not an issue with relay chain since we should not charge transactions for proof_size on the relay chain. On parachain though, PoV size is limited to 5 MB and an attacker could fill the block with storage size without paying an appropriate fee.

These changes will take into account proof_size while adjusting the fee. It does so by first taking a ratio of dimension/max_dimension and taking the largest ratio. We call it limiting dimension as it is the scarcer resource and use this dimension for the calculation of the next fee multiplier.

The PR also takes into account proof_size for calculation of transaction priority. We look into how many transactions we can fill in the block by looking at the resource (dimension) that is depleted more (hence called limiting dimension) while filling the block.

Considerations for parachains using pallet transaction-payment

Care needs to be taken to set the max PoV size for a chain. A really high value would mean block is never full based on the proof_size dimension, while a too low value would mean block is constantly full and transaction fees would keep increasing for the chain. An optimal maximum PoV size would ensure a high correlation between the block fullness based on each weight dimension.

@Ank4n Ank4n added A3-in_progress Pull request is in progress. No review needed at this stage. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D9-needsaudit 👮 PR contains changes to fund-managing logic that should be properly reviewed and externally audited labels Apr 24, 2023
@Ank4n
Copy link
Contributor Author

Ank4n commented Apr 25, 2023

bot rebase

@paritytech-processbot
Copy link

Rebased

@Ank4n Ank4n requested a review from ggwpez April 26, 2023 07:52
@Ank4n Ank4n marked this pull request as ready for review April 26, 2023 07:52
@Ank4n Ank4n requested review from kianenigma and bkchr April 30, 2023 20:08
@Ank4n
Copy link
Contributor Author

Ank4n commented May 11, 2023

bot rebase

@paritytech-processbot
Copy link

Rebased

@paritytech-processbot
Copy link

Rebased

@paritytech-processbot paritytech-processbot bot requested a review from a team May 31, 2023 20:46
@Ank4n
Copy link
Contributor Author

Ank4n commented Jun 1, 2023

I would like to see some empirical numbers here: what is the proof size going to be in Polkadot? should we even take it into account in Polkadot?

The ref time is limited to 2sec currently while proof size has no limit (u64::Max). The ideal block fullness with normal transactions is set to 25% (0.5 sec, 4.6 * 10^6 terabytes). With current values, practically ref time will always be the limiting dimension and proof size will never be taken into account.

Update: Received feedback that we should not charge for proof size on relay chain so the above makes sense.

@Ank4n
Copy link
Contributor Author

Ank4n commented Jun 6, 2023

bot rebase

@paritytech-processbot
Copy link

Rebased

Copy link
Member

@ggwpez ggwpez left a comment

Choose a reason for hiding this comment

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

LGTM codewise

frame/transaction-payment/src/lib.rs Outdated Show resolved Hide resolved
Ank4n and others added 3 commits June 6, 2023 18:03
@Ank4n
Copy link
Contributor Author

Ank4n commented Jun 6, 2023

And what is the average proof size weight in a parachain right now? Will the new dimension cause the tx-fees to skyrocket, if the proof size is always more than the targeted 25% that is used?

I looked at statemine and bifrost and they seem to have pretty empty blocks averaging less than 1% fullness by both ref_time and proof_size. They shouldn't cause any issue in the near future. But fine tuning tx fees would be a matter of setting correct max bounds for the proof_size such that block fullness by each dimensions are not too far away from each other.

The full results are here.

@jakoblell jakoblell added D1-audited 👍 PR contains changes to fund-managing logic that has been properly reviewed and externally audited and removed D9-needsaudit 👮 PR contains changes to fund-managing logic that should be properly reviewed and externally audited labels Jun 8, 2023
Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

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

Code LGTM but I think the labeling is wrong here: This PR will significantly affect parachains and should be labled as note-worthy and have direction for parachain teams to consider.

@Ank4n Ank4n added B1-note_worthy Changes should be noted in the release notes and removed B0-silent Changes should not be mentioned in any release notes labels Jun 12, 2023
@Ank4n
Copy link
Contributor Author

Ank4n commented Jun 12, 2023

Code LGTM but I think the labeling is wrong here: This PR will significantly affect parachains and should be labled as note-worthy and have direction for parachain teams to consider.

Does each parachain use separate PoV limits? Cumulus picks the PoV limit from here https://github.com/paritytech/polkadot/blob/master/primitives/src/v5/mod.rs#L385.

@Ank4n Ank4n added the T1-runtime This PR/Issue is related to the topic “runtime”. label Jun 12, 2023
@kianenigma
Copy link
Contributor

https://github.com/paritytech/polkadot/blob/master/primitives/src/v5/mod.rs#L385

Yes I think still different parachains assign different PoV limit via frame_system::Config::BlockWeight's second dimension.

@Ank4n Ank4n merged commit 84b565d into master Jun 13, 2023
@Ank4n Ank4n deleted the ankan/13898-look-at-all-weight-dimensions branch June 13, 2023 13:53
nathanwhit pushed a commit to nathanwhit/substrate that referenced this pull request Jul 19, 2023
…ritytech#13958)

* use both proof size and weight

* old tests pass, todo: add tests for weight proof size

* refactor priority calculation

* refactor

* normalize dimensions

* refactor

* update comments

* use higher resolution

* test multiplier can grow

* restore ref time test cases

* fix hacky test

* fmt

* update tests

* revert to original error rate

* update targetedFeeAdjustment doc

* Update frame/transaction-payment/src/lib.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* import defensive

---------

Co-authored-by: parity-processbot <>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B1-note_worthy Changes should be noted in the release notes C1-low PR touches the given topic and has a low impact on builders. D1-audited 👍 PR contains changes to fund-managing logic that has been properly reviewed and externally audited T1-runtime This PR/Issue is related to the topic “runtime”.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Take into account proof size for transaction payment and priority
4 participants