Upgradeable validation functions (#918)

* upgrade primitives to allow changing validation function

* set up storage schema for old parachains code

* fix compilation errors

* fix test compilation

* add some tests for past code meta

* most of the runtime logic for code upgrades

* implement old-code pruning

* add a couple tests

* clean up remaining TODOs

* add a whole bunch of tests for runtime functionality

* remove unused function

* fix runtime compilation

* extract some primitives to parachain crate

* add validation-code upgrades to validation params and result

* extend validation params with code upgrade fields

* provide maximums to validation params

* port test-parachains

* add a code-upgrader test-parachain and tests

* fix collator tests

* move test-parachains to own folder to work around compilation errors

* fix test compilation

* update the Cargo.lock

* fix parachains tests

* remove dbg! invocation

* use new pool in code-upgrader

* bump lockfile

* link TODO to issue
This commit is contained in:
Robert Habermeier
2020-04-06 10:43:19 -04:00
committed by GitHub
parent b31b52dddf
commit 10cec3b591
43 changed files with 1830 additions and 444 deletions
+18 -19
View File
@@ -23,13 +23,13 @@ use codec::Encode;
use polkadot_erasure_coding as erasure;
use polkadot_primitives::parachain::{
CollationInfo, PoVBlock, LocalValidationData, GlobalValidationSchedule, OmittedValidationData,
AvailableData, FeeSchedule, CandidateCommitments, ErasureChunk, HeadData, ParachainHost,
Id as ParaId, AbridgedCandidateReceipt,
AvailableData, FeeSchedule, CandidateCommitments, ErasureChunk, ParachainHost,
Id as ParaId, AbridgedCandidateReceipt
};
use polkadot_primitives::{Block, BlockId, Balance, Hash};
use parachain::{
wasm_executor::{self, ExecutionMode},
UpwardMessage, ValidationParams,
primitives::{UpwardMessage, ValidationParams},
};
use runtime_primitives::traits::{BlakeTwo256, Hash as HashT};
use sp_api::ProvideRuntimeApi;
@@ -95,7 +95,7 @@ impl ExternalitiesInner {
}
fn apply_message_fee(&mut self, message_len: usize) -> Result<(), String> {
let fee = self.fee_schedule.compute_fee(message_len);
let fee = self.fee_schedule.compute_message_fee(message_len);
let new_fees_charged = self.fees_charged.saturating_add(fee);
if new_fees_charged > self.free_balance {
Err("could not cover fee.".into())
@@ -160,8 +160,7 @@ impl FullOutput {
pub struct ValidatedCandidate<'a> {
pov_block: &'a PoVBlock,
global_validation: &'a GlobalValidationSchedule,
parent_head: &'a HeadData,
balance: Balance,
local_validation: &'a LocalValidationData,
upward_messages: Vec<UpwardMessage>,
fees: Balance,
}
@@ -173,18 +172,14 @@ impl<'a> ValidatedCandidate<'a> {
let ValidatedCandidate {
pov_block,
global_validation,
parent_head,
balance,
local_validation,
upward_messages,
fees,
} = self;
let omitted_validation = OmittedValidationData {
global_validation: global_validation.clone(),
local_validation: LocalValidationData {
parent_head: parent_head.clone(),
balance,
},
local_validation: local_validation.clone(),
};
let available_data = AvailableData {
@@ -216,6 +211,7 @@ impl<'a> ValidatedCandidate<'a> {
upward_messages,
fees,
erasure_root,
new_validation_code: None,
};
Ok(FullOutput {
@@ -244,8 +240,12 @@ pub fn validate<'a>(
}
let params = ValidationParams {
parent_head: local_validation.parent_head.0.clone(),
block_data: pov_block.block_data.0.clone(),
parent_head: local_validation.parent_head.clone(),
block_data: pov_block.block_data.clone(),
max_code_size: global_validation.max_code_size,
max_head_data_size: global_validation.max_head_data_size,
relay_chain_height: global_validation.block_number,
code_upgrade_allowed: local_validation.code_upgrade_allowed,
};
// TODO: remove when ext does not do this.
@@ -266,7 +266,7 @@ pub fn validate<'a>(
execution_mode,
) {
Ok(result) => {
if result.head_data == collation.head_data.0 {
if result.head_data == collation.head_data {
let (upward_messages, fees) = Arc::try_unwrap(ext.0)
.map_err(|_| "<non-unique>")
.expect("Wasm executor drops passed externalities on completion; \
@@ -277,8 +277,7 @@ pub fn validate<'a>(
Ok(ValidatedCandidate {
pov_block,
global_validation,
parent_head: &local_validation.parent_head,
balance: local_validation.balance,
local_validation,
upward_messages,
fees,
})
@@ -352,13 +351,13 @@ pub fn full_output_validation_with_api<P>(
mod tests {
use super::*;
use parachain::wasm_executor::Externalities as ExternalitiesTrait;
use parachain::ParachainDispatchOrigin;
use parachain::primitives::ParachainDispatchOrigin;
#[test]
fn ext_checks_fees_and_updates_correctly() {
let mut ext = ExternalitiesInner {
upward: vec![
UpwardMessage{ data: vec![42], origin: ParachainDispatchOrigin::Parachain },
UpwardMessage { data: vec![42], origin: ParachainDispatchOrigin::Parachain },
],
fees_charged: 0,
free_balance: 1_000_000,