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

Parachains should charge for proof size weight #2326

Merged
merged 9 commits into from
Mar 17, 2023

Conversation

ggwpez
Copy link
Member

@ggwpez ggwpez commented Mar 15, 2023

Closes #2322, depends on paritytech/substrate#13612

Currently the parachains do not charge weight for the proof size component of call weights.
With this MR it will calculate one fee for ref-time and one for proof-size and choose the larger one. This affects all parachain runtimes. There are some sanity checks in place for Statemin*.
Eventually we went a more compact and automated implementation, but that would require breaking changes in Substrate, so skipping that for now.

Use the trait directly instead of something that will have a blanket
implementation for it.

Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
@ggwpez ggwpez added the A3-in_progress Pull request is in progress. No review needed at this stage. label Mar 15, 2023
@paritytech-ci paritytech-ci requested review from a team March 15, 2023 16:50
Copy link
Contributor

@joepetrowski joepetrowski left a comment

Choose a reason for hiding this comment

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

Some documentation typos/bad find/replace I think. But logic looks good.

Comment on lines +93 to +95
// Map 10kb proof to 1 CENT.
let p = super::currency::CENTS;
let q = 10_000;
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose we don't have a reference on the Relay Chain.

Copy link
Member Author

@ggwpez ggwpez Mar 15, 2023

Choose a reason for hiding this comment

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

Yes, since the relay chain has u64::MAX as max block proof-size whereas parachains only have 5 MiB.
We will probably need some further adjustments to find the sweet-spot, but for now this should provide something that we can work with.

There are going to be changes in Substrate soon that increase the proof size of everything (until we have https://github.com/paritytech/substrate/issues/13501), so to prevent accidental fuckups i added the tests that 1K transfers fit in a block.

parachains/runtimes/assets/statemine/src/lib.rs Outdated Show resolved Hide resolved
parachains/runtimes/assets/statemine/src/lib.rs Outdated Show resolved Hide resolved
parachains/runtimes/assets/statemint/src/constants.rs Outdated Show resolved Hide resolved
parachains/runtimes/assets/statemint/src/lib.rs Outdated Show resolved Hide resolved
parachains/runtimes/assets/statemint/src/lib.rs Outdated Show resolved Hide resolved
parachains/runtimes/assets/westmint/src/constants.rs Outdated Show resolved Hide resolved
ggwpez and others added 4 commits March 16, 2023 15:18
Co-authored-by: joe petrowski <[email protected]>
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
@@ -55,13 +56,45 @@ pub mod fee {
/// - Setting it to `0` will essentially disable the weight fee.
/// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged.
pub struct WeightToFee;
impl WeightToFeePolynomial for WeightToFee {
impl frame_support::weights::WeightToFee for WeightToFee {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be simplified by implementing WeightToFee for Tuple? or too many tuples impls? 🙈

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes we could do a simple maximum norm. In the long run i would rather make the traits 2D weight compatible in Substrate, so we wont need it.

Copy link
Member Author

Choose a reason for hiding this comment

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

For now it is fine or? Since this targets 0.9.38.1

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah nah, you would be confused if it is addition, or max or what.

I suppose we can provide some nice helpers at he substrate layer though:

struct RefTimeWeightCostPerMicroSec<Balance, Cost: Get<Balance>>(..);
impl WeightToFee for RefTimeConstPerMicroSec { .. }

struct ProofSizeWeightCostPerKByte<Balance, Cost: Get<Balance>>(..);
impl WeightToFee for RefTimeConstPerMicroSec { .. }

Or even a more generic:

struct CostPerUnit<Balance, Cost: Get<Balance>, Unit: ops::Div<Balance>>; 

I think you can see where I am going with this. Just an idea

Copy link
Contributor

Choose a reason for hiding this comment

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

For now it is fine or? Since this targets 0.9.38.1

Yeah fine for now. Perhaps a follow-up issue that you can mentor?

@paritytech-ci paritytech-ci requested a review from a team March 16, 2023 16:38
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.

End of the day, all runtimes want to express:

  1. I want x unit of balance per ref_time unit.
  2. I want y unit of balance per proof_size unit.
  3. Take the max of them.

Perhaps we can provide structs that easily let you express x and y the former two as Get or const GENERIC.

@ggwpez
Copy link
Member Author

ggwpez commented Mar 16, 2023

cc @xlc in case you want to review.

@ggwpez
Copy link
Member Author

ggwpez commented Mar 17, 2023

bot merge

@paritytech-processbot
Copy link

Waiting for commit status.

@paritytech-processbot
Copy link

Merge cancelled due to error. Error: Checks failed for b6ca4b5

@ggwpez ggwpez added 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. T5-parachains This PR/Issue is related to Parachains. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit T7-system_parachains This PR/Issue is related to System Parachains. T1-runtime This PR/Issue is related to the topic “runtime”. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Mar 17, 2023
@ggwpez ggwpez removed T7-system_parachains This PR/Issue is related to System Parachains. T1-runtime This PR/Issue is related to the topic “runtime”. labels Mar 17, 2023
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
@ggwpez ggwpez added T1-runtime This PR/Issue is related to the topic “runtime”. and removed T5-parachains This PR/Issue is related to Parachains. labels Mar 17, 2023
@ggwpez
Copy link
Member Author

ggwpez commented Mar 17, 2023

The label check here only allows me to set T0, T1 or T2. Why do we then have the other T* labels?
They sound very useful but cant be used @the-right-joyce?

@ggwpez
Copy link
Member Author

ggwpez commented Mar 17, 2023

bot merge

@paritytech-processbot paritytech-processbot bot merged commit 91b3512 into master Mar 17, 2023
@paritytech-processbot paritytech-processbot bot deleted the oty-charge-proof-size branch March 17, 2023 16:25
@ggwpez ggwpez added T7-system_parachains This PR/Issue is related to System Parachains. T5-parachains This PR/Issue is related to Parachains. labels Mar 17, 2023
ordian added a commit that referenced this pull request Mar 21, 2023
* master:
  Companion for #13624 (#2354)
  Introduce Fellowship into Collectives (#2186)
  NFTs 2.0 on Statemine (#2314)
  Bump assert_cmd from 2.0.8 to 2.0.10 (#2341)
  Bump clap from 4.1.8 to 4.1.11 (#2352)
  Companion for substrate #13312: Rename `Deterministic` to `Enforce` (#2350)
  [Companion #13634] keystore overhaul (iter) (#2345)
  Revert #2304 (#2349)
  Deprecate Currency: Companion for #12951 (#2334)
  Bump ci-linux image for rust 1.68
  Always pass port to jsonrpsee WebSocket client (#2339)
  bump zombienet to v1.3.40 (#2348)
  Improve build times by disabling wasm-builder in `no_std` (#2308)
  Bump toml from 0.7.2 to 0.7.3 (#2340)
  Bump serde from 1.0.152 to 1.0.156 (#2329)
  Parachains should charge for proof size weight (#2326)
  dmp-queue: Store messages if already processed more than the maximum (#2343)
  [Companion  #13615] Keystore overhaul (#2336)
  Bump quote from 1.0.23 to 1.0.26 (#2331)
AurevoirXavier added a commit to darwinia-network/darwinia that referenced this pull request Jul 11, 2023
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. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit T1-runtime This PR/Issue is related to the topic “runtime”. T5-parachains This PR/Issue is related to Parachains. T7-system_parachains This PR/Issue is related to System Parachains.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Not charging for proof weight
5 participants