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

CheckWeight: account for extrinsic len as proof size #4765

Merged
merged 14 commits into from
Jun 14, 2024

Conversation

sandreim
Copy link
Contributor

@sandreim sandreim commented Jun 11, 2024

Fix #4743 which allows us to remove the defensive limit on pov size in Cumulus after relay chain gets upgraded with these changes. Also add unit test to ensure CheckWeight - StorageWeightReclaim integration works.

TODO:

  • PRDoc
  • Add a len to all the other tests in storage weight reclaim and call CheckWeight::pre_dispatch

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
@sandreim sandreim added the T1-FRAME This PR/Issue is related to core FRAME, the framework. label Jun 11, 2024
@sandreim sandreim requested a review from a team as a code owner June 11, 2024 17:49
@sandreim sandreim requested review from skunert and bkchr June 11, 2024 17:56
Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
Copy link
Member

@eskimor eskimor left a comment

Choose a reason for hiding this comment

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

Looks sensible.

cumulus/primitives/storage-weight-reclaim/src/lib.rs Outdated Show resolved Hide resolved
let extrinsic_weight = info
.weight
.saturating_add(maximum_weight.get(info.class).base_extrinsic)
.saturating_add(Weight::from_parts(0, len as u64));
Copy link
Member

Choose a reason for hiding this comment

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

Stupid question: Is this also used for inherents? (Does this have any influence on weights on the relaychain as relevant to parachain consensus?)

Copy link
Member

Choose a reason for hiding this comment

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

Specifically: We already add lengths to the weight in paras inherent for checking within the paras inherent to not exceed the weight e.g. here. I hope we are not counting it twice now?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand what is the reasoning is for this. Why are we setting the proof size there? On relay chains the maximum proof size is U64::MAX AFAIK, effectively disabling any proof size related checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point @skunert . I think we should remove and clean the code in parachain inherent. Proof size is indeed only relevant for parachain runtimes.

Copy link
Member

Choose a reason for hiding this comment

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

Do we not need this excape hatch for the Mandatory inherents to avoid what happend on the rococo parachains?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What happened on Rococo parachains ?

Copy link
Member

Choose a reason for hiding this comment

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

It got stuck because an inherent ran a lazy migration that loaded a big Key pair and overflowed the PoV limit.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ggwpez Sorry for the late reply, I thought about the rococo situation before approval here.

So we don't have an explicit mechanism for mandatory extrinsics here because we will go into these two branches dring the weight checks:

  1. This one because for mandatory max_total is None:
  2. This one because reserved is also None for mandatory extrinsics:
    // There is either no limit in reserved pool (`None`),
    // or we are below the limit.
    _ => {},

Of course what I described above is not guaranteed. Parachain teams can define in their runtime whatever they want. This is what the typical weight definition looks like (note no specifics defined for mandatory):

pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder()
.base_block(BlockExecutionWeight::get())
.for_class(DispatchClass::all(), |weights| {
weights.base_extrinsic = ExtrinsicBaseWeight::get();
})
.for_class(DispatchClass::Normal, |weights| {
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
})
.for_class(DispatchClass::Operational, |weights| {
weights.max_total = Some(MAXIMUM_BLOCK_WEIGHT);
// Operational transactions have some extra reserved space, so that they
// are included even if block reached `MAXIMUM_BLOCK_WEIGHT`.
weights.reserved = Some(
MAXIMUM_BLOCK_WEIGHT - NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT
);
})
.avg_block_initialization(AVERAGE_ON_INITIALIZE_RATIO)
.build_or_panic();

The builder has None set by default, which makes sense:

let initial =
if class == DispatchClass::Mandatory { None } else { Some(Weight::zero()) };
WeightsPerClass {
base_extrinsic: constants::ExtrinsicBaseWeight::get(),
max_extrinsic: None,
max_total: initial,
reserved: initial,
}

So with this PR the weight checking falls in line with the rest of the extrinsics. If someone has actually set a limit on mandatory weight class, they are living dangerous without the changes of this PR already. If some pallet returns max weight like the session pallet in the rococo case, we would already go over the limit together with on_initialize.

Copy link
Member

Choose a reason for hiding this comment

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

Okay i see. Thanks for the elaborate explanation!

This reverts commit 2211d15.

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
@sandreim sandreim changed the title Cumulus: collate with max pov size (remove 50% limit) CheckWeight: account for extrinsic len as proof size Jun 12, 2024
Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: test-linux-stable 3/3
Logs: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/6446842

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
Copy link
Contributor

@skunert skunert 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, thank you!

@ggwpez ggwpez self-requested a review June 14, 2024 11:56
@sandreim sandreim added this pull request to the merge queue Jun 14, 2024
Merged via the queue into master with commit ae0b3bf Jun 14, 2024
162 checks passed
@sandreim sandreim deleted the sandreim/block_len_weight branch June 14, 2024 13:15
github-merge-queue bot pushed a commit that referenced this pull request Jun 18, 2024
Glutton currently is useful mostly for stress testing relay chain
validators. It is unusable for testing the collator networking and block
announcement and import scenarios. This PR resolves that by improving
glutton pallet to also buff up the blocks, up to the runtime configured
`BlockLength`.

### How it works
Includes an additional inherent in each parachain block. The `garbage`
argument passed to the inherent is filled with trash data. It's size is
computed by applying the newly introduced `block_length` percentage to
the maximum block length for mandatory dispatch class. After
#4765 is merged, the
length of inherent extrinsic will be added to the total block proof
size.

The remaining weight is burnt in `on_idle` as configured by the
`storage` percentage parameter.


TODO:
- [x] PRDoc
- [x] Readme update
- [x] Add tests

---------

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
TarekkMA pushed a commit to moonbeam-foundation/polkadot-sdk that referenced this pull request Aug 2, 2024
Fix paritytech#4743 which allows
us to remove the defensive limit on pov size in Cumulus after relay
chain gets upgraded with these changes. Also add unit test to ensure
`CheckWeight` - `StorageWeightReclaim` integration works.

TODO:
- [x] PRDoc
- [x] Add a len to all the other tests in storage weight reclaim and
call `CheckWeight::pre_dispatch`

---------

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
TarekkMA pushed a commit to moonbeam-foundation/polkadot-sdk that referenced this pull request Aug 2, 2024
Glutton currently is useful mostly for stress testing relay chain
validators. It is unusable for testing the collator networking and block
announcement and import scenarios. This PR resolves that by improving
glutton pallet to also buff up the blocks, up to the runtime configured
`BlockLength`.

### How it works
Includes an additional inherent in each parachain block. The `garbage`
argument passed to the inherent is filled with trash data. It's size is
computed by applying the newly introduced `block_length` percentage to
the maximum block length for mandatory dispatch class. After
paritytech#4765 is merged, the
length of inherent extrinsic will be added to the total block proof
size.

The remaining weight is burnt in `on_idle` as configured by the
`storage` percentage parameter.


TODO:
- [x] PRDoc
- [x] Readme update
- [x] Add tests

---------

Signed-off-by: Andrei Sandu <andrei-mihail@parity.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T1-FRAME This PR/Issue is related to core FRAME, the framework.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make on_idle WeightMeter factor in block size
5 participants