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

pvf-precheck: Strip PastCodeMeta #4408

Merged
merged 1 commit into from
Dec 8, 2021

Conversation

pepyakin
Copy link
Contributor

@pepyakin pepyakin commented Nov 29, 2021

This PR is a part of
#3211.

This PR prepares ground for the following runtime changes required for
PVF pre-checking. Specifically, we do several changes here:

  1. We remove validation_code_at and validation_code_hash_at. Those
    functions are not used. They were added in the early days with intent
    to use it later but turned out that we do not need them.
  2. We replace validation_code_hash_at with just current_code_hash
    for the case of inclusion and candidate checking.
  3. We also replace last_code_upgrade with a direct query into
    FutureCodeHash and UpgradeRestrictionSignal. Those in conjunction
    should replace the logic that was used for allowing/disallowing
    upgrades. This requires special attention of the reviewers.
  4. Then we remove the machinery required to support those queries.
    Specifically the code related to UseCodeAt. We do not need it since
    we do not answer the historical queries. However, we still leave all
    the data on-chain. At some point we may clean it up, but that would
    be needed to be done with a dedicated migration which can be done as
    follow-up.
  5. Some now irrelevant tests were removed and/or adapted.

NOTE: This fixes a small bug related to parachain upgrades. Before, the acceptance function would allow the following behavior:

  • a parachain upgrades the code.
  • parachain does not produce blocks
  • at or after expected_at block, the parachain produces a block that schedules an upgrade.

After this change this is not allowed. This is because we do not allow an upgrade until FutureCodeHash is cleared and FutureCodeHash is consumed by a enacting a candidate that has the relay-parent ≥ expected_at.

I say that this is a bug because even though such a candidate will pass the acceptance check, the upgrade it signals won't be enacted. This is because enacting consists of scheduling the upgrade first if any and only then calling note_new_head. schedule_code_upgrade bails if there is a pending upgrade and the pending upgrade only is enacted by note_new_head.

@pepyakin
Copy link
Contributor Author

pepyakin commented Nov 29, 2021

Current dependencies on/for this PR:

This comment was auto-generated by Graphite and will continue to be automatically updated while this PR remains open.

@github-actions github-actions bot added the A0-please_review Pull request needs code review. label Nov 29, 2021
@pepyakin pepyakin added 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. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit. labels Nov 29, 2021
@pepyakin pepyakin force-pushed the pep-precheck-candidate-validation branch from 8988cef to 485f7a2 Compare November 30, 2021 11:41
@pepyakin pepyakin force-pushed the pep-precheck-candidate-validation branch from 485f7a2 to 7afadb3 Compare November 30, 2021 11:55
@pepyakin pepyakin force-pushed the pep-precheck-candidate-validation branch from 7afadb3 to 19f746f Compare November 30, 2021 12:07
@pepyakin pepyakin force-pushed the pep-precheck-candidate-validation branch from 19f746f to 9c18425 Compare November 30, 2021 15:48
/// If a candidate from the specified parachain were submitted at the current block, this
/// function returns if that candidate passes the acceptance criteria.
pub(crate) fn can_upgrade_validation_code(id: ParaId) -> bool {
FutureCodeHash::<T>::get(&id).is_none() && UpgradeRestrictionSignal::<T>::get(&id).is_none()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This predicate seems to be equivalent to the previous condition, i.e.:

let valid_upgrade_attempt = <paras::Pallet<T>>::last_code_upgrade(para_id, true)
				.map_or(true, |last| {
					last <= self.relay_parent_number &&
						self.relay_parent_number.saturating_sub(last) >=
							self.config.validation_upgrade_frequency
				});

But needs double-checking

@rphmeier
Copy link
Contributor

rphmeier commented Nov 30, 2021

We remove validation_code_at and validation_code_hash_at. Those functions are not used. They were added in the early days with intent to use it later but turned out that we do not need them.

let validation_code_hash = <paras::Pallet<T>>::validation_code_hash_at(para_id, now, None)
// A candidate for a parachain without current validation code is not scheduled.
.ok_or_else(|| Error::<T>::UnscheduledCandidate)?;
ensure!(
backed_candidate.descriptor().validation_code_hash == validation_code_hash,
Error::<T>::InvalidValidationCodeHash,

We might want to keep it so this snippet can be altered as a part of asynchronous backing. Otherwise code changes would result in service interruptions for a few blocks. Worth noting.

@@ -962,7 +958,7 @@ impl<T: Config> CandidateCheckContext<T> {
Error::<T>::NotCollatorSigned,
);

let validation_code_hash = <paras::Pallet<T>>::validation_code_hash_at(para_id, now, None)
let validation_code_hash = <paras::Pallet<T>>::current_code_hash(para_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

i.e. this was previously future-proof changes to add asynchronous backing (old relay parent where code hadn't yet changed) but is not future-proof anymore

Copy link
Contributor

@rphmeier rphmeier Nov 30, 2021

Choose a reason for hiding this comment

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

Probably fine, from a product perspective - if we build parachains 1 block in advance then a code upgrade block would lead to a 6 second service interruption. Workarounds possible but not needed for the moment

Base automatically changed from pep-precheck-candidate-validation to master November 30, 2021 23:53
@pepyakin pepyakin force-pushed the pep-strip-pastcodemeta branch 3 times, most recently from 7e91fa0 to a0ec003 Compare December 3, 2021 12:28
@pepyakin
Copy link
Contributor Author

pepyakin commented Dec 3, 2021

@rphmeier when I wrote this code that thought crossed my mind. I had to chase it away because I felt it was overthinking: it's not easy to predict the precise API that will actually be required by async execution and at the same time there is no benefit for that either: we can easily add/remove parameters and shuffle the code around when the time comes (and when we a better grasp of the actual needs). Then this change also does not alter any on-chain storage, so we can actually restore any code from git history and it will work. Although I had planned to remove the storage eventually as well.

I am also a bit confused since I was under impression that the context should be passed through a relay-chain state merkle proof. That's why here I thought it is acceptable to remove the historical data from the current state.

@rphmeier
Copy link
Contributor

rphmeier commented Dec 6, 2021

Yeah, it's fine as is. The latest version of contextual execution might not need merkle proofs

This PR is a part of
#3211.

This PR prepares ground for the following runtime changes required for
PVF pre-checking. Specifically, we do several changes here:

1. We remove `validation_code_at` and `validation_code_hash_at`. Those
   functions are not used. They were added in the early days with intent
   to use it later but turned out that we do not need them.
2. We replace `validation_code_hash_at` with just `current_code_hash`
   for the case of inclusion and candidate checking.
3. We also replace `last_code_upgrade` with a direct query into
   `FutureCodeHash` and `UpgradeRestrictionSignal`. Those in conjunction
   should replace the logic that was used for allowing/disallowing
   upgrades. This requires special attention of the reviewers.
4. Then we remove the machinery required to support those queries.
   Specifically the code related to `UseCodeAt`. We do not need it since
   we do not answer the historical queries. However, we still leave all
   the data on-chain. At some point we may clean it up, but that would
   be needed to be done with a dedicated migration which can be done as
   follow-up.
5. Some now irrelevant tests were removed and/or adapted.
@pepyakin
Copy link
Contributor Author

pepyakin commented Dec 8, 2021

bot merge

@paritytech-processbot
Copy link

Bot will approve on the behalf of @pepyakin, since they are a team lead, in an attempt to reach the minimum approval count

@paritytech-processbot paritytech-processbot bot merged commit 0779003 into master Dec 8, 2021
@paritytech-processbot paritytech-processbot bot deleted the pep-strip-pastcodemeta branch December 8, 2021 11:39
@pepyakin
Copy link
Contributor Author

pepyakin commented Dec 8, 2021

(merged assuming this was an implicit approval and due to that this is a small change)

pepyakin added a commit that referenced this pull request Dec 27, 2021
This commit incorporates the changes made to the runtime in the
following PRs:

- #4408
- #4457
- #4540
- #4542
- #4581

Note that this PR does not include the description of the PVF
pre-checker subsystem. This should be addressed within
#4611
pepyakin added a commit that referenced this pull request Dec 28, 2021
This commit incorporates the changes made to the runtime in the
following PRs:

- #4408
- #4457
- #4540
- #4542
- #4581

Note that this PR does not include the description of the PVF
pre-checker subsystem. This should be addressed within
#4611

Co-authored-by: sandreim <54316454+sandreim@users.noreply.github.com>
pepyakin added a commit that referenced this pull request Dec 28, 2021
This commit incorporates the changes made to the runtime in the
following PRs:

- #4408
- #4457
- #4540
- #4542
- #4581

Note that this PR does not include the description of the PVF
pre-checker subsystem. This should be addressed within
#4611

Co-authored-by: sandreim <54316454+sandreim@users.noreply.github.com>
pepyakin added a commit that referenced this pull request Dec 29, 2021
This commit incorporates the changes made to the runtime in the
following PRs:

- #4408
- #4457
- #4540
- #4542
- #4581

Note that this PR does not include the description of the PVF
pre-checker subsystem. This should be addressed within
#4611

Co-authored-by: sandreim <54316454+sandreim@users.noreply.github.com>
drahnr pushed a commit that referenced this pull request Jan 4, 2022
This commit incorporates the changes made to the runtime in the
following PRs:

- #4408
- #4457
- #4540
- #4542
- #4581

Note that this PR does not include the description of the PVF
pre-checker subsystem. This should be addressed within
#4611

Co-authored-by: sandreim <54316454+sandreim@users.noreply.github.com>
Wizdave97 pushed a commit to ComposableFi/polkadot that referenced this pull request Feb 3, 2022
This commit incorporates the changes made to the runtime in the
following PRs:

- paritytech#4408
- paritytech#4457
- paritytech#4540
- paritytech#4542
- paritytech#4581

Note that this PR does not include the description of the PVF
pre-checker subsystem. This should be addressed within
paritytech#4611

Co-authored-by: sandreim <54316454+sandreim@users.noreply.github.com>
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. 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. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants