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

Commit

Permalink
pvf-precheck: Strip PastCodeMeta
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pepyakin committed Nov 29, 2021
1 parent 8988cef commit 7798ce2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 280 deletions.
7 changes: 0 additions & 7 deletions roadmap/implementers-guide/src/runtime/paras.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,6 @@ CodeByHash: map ValidationCodeHash => Option<ValidationCode>
* `note_new_head(ParaId, HeadData, BlockNumber)`: note that a para has progressed to a new head,
where the new head was executed in the context of a relay-chain block with given number. This will
apply pending code upgrades based on the block number provided. If an upgrade took place it will clear the `UpgradeGoAheadSignal`.
* `validation_code_at(ParaId, at: BlockNumber, assume_intermediate: Option<BlockNumber>)`: Fetches
the validation code to be used when validating a block in the context of the given relay-chain
height. A second block number parameter may be used to tell the lookup to proceed as if an
intermediate parablock has been included at the given relay-chain height. This may return past,
current, or (with certain choices of `assume_intermediate`) future code. `assume_intermediate`, if
provided, must be before `at`. If the validation code has been pruned, this will return `None`.
* `validation_code_hash_at(ParaId, at: BlockNumber, assume_intermediate: Option<BlockNumber>)`: Just like `validation_code_at`, but returns the code hash.
* `lifecycle(ParaId) -> Option<ParaLifecycle>`: Return the `ParaLifecycle` of a para.
* `is_parachain(ParaId) -> bool`: Returns true if the para ID references any live parachain,
including those which may be transitioning to a parathread in the future.
Expand Down
21 changes: 6 additions & 15 deletions runtime/parachains/src/inclusion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ use primitives::v1::{
ValidatorIndex, ValidityAttestation,
};
use scale_info::TypeInfo;
use sp_runtime::{
traits::{One, Saturating},
DispatchError,
};
use sp_runtime::{traits::One, DispatchError};
use sp_std::{collections::btree_set::BTreeSet, prelude::*};

pub use pallet::*;
Expand Down Expand Up @@ -950,7 +947,6 @@ impl<T: Config> CandidateCheckContext<T> {
backed_candidate: &BackedCandidate<<T as frame_system::Config>::Hash>,
) -> Result<(), Error<T>> {
let para_id = backed_candidate.descriptor().para_id;
let now = self.now;

// we require that the candidate is in the context of the parent block.
ensure!(
Expand All @@ -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)
// A candidate for a parachain without current validation code is not scheduled.
.ok_or_else(|| Error::<T>::UnscheduledCandidate)?;
ensure!(
Expand Down Expand Up @@ -1016,13 +1012,10 @@ impl<T: Config> CandidateCheckContext<T> {

// if any, the code upgrade attempt is allowed.
if let Some(new_validation_code) = new_validation_code {
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
});
ensure!(valid_upgrade_attempt, AcceptanceCheckErr::PrematureCodeUpgrade);
ensure!(
<paras::Pallet<T>>::can_upgrade_validation_code(para_id),
AcceptanceCheckErr::PrematureCodeUpgrade,
);
ensure!(
new_validation_code.0.len() <= self.config.max_code_size as _,
AcceptanceCheckErr::NewCodeTooLarge,
Expand Down Expand Up @@ -2322,8 +2315,6 @@ pub(crate) mod tests {
expected_at,
&cfg,
);

assert_eq!(Paras::last_code_upgrade(chain_a, true), Some(expected_at));
}

assert_noop!(
Expand Down
Loading

0 comments on commit 7798ce2

Please sign in to comment.