Look at the upgrade go-ahead and restriction signals (#517)

* Look at the upgrade go-ahead and restriction signals

* Update Cargo.toml

* Drop old docs for validation code

* Update tests

* Fix typo

* Add doc-comments for read_optional_entry

* Add a note about ValidationData

* Introduce migration for removing unused storage entry

* Fix indentation

* Use intra-doc link syntax

* Double-check that GoAhead signal is not spurious

* fmt

* Drop commented code

* Fix typos

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* Add a weight for StorageVersion write

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

Co-authored-by: Chris Sosnin <chris125_@live.com>
Co-authored-by: Chris Sosnin <48099298+slumber@users.noreply.github.com>
Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Sergei Shulepov
2021-10-12 18:08:23 +02:00
committed by GitHub
parent 9fc6015ac0
commit 3b3f9dca1d
6 changed files with 245 additions and 88 deletions
+29 -1
View File
@@ -17,12 +17,12 @@
use cumulus_primitives_core::{
relay_chain, AbridgedHostConfiguration, AbridgedHrmpChannel, ParaId,
};
use polkadot_primitives::v1::UpgradeGoAhead;
use sp_runtime::traits::HashFor;
use sp_state_machine::MemoryDB;
use sp_std::collections::btree_map::BTreeMap;
/// Builds a sproof (portmanteau of 'spoof' and 'proof') of the relay chain state.
#[derive(Clone)]
pub struct RelayStateSproofBuilder {
/// The para id of the current parachain.
///
@@ -36,6 +36,7 @@ pub struct RelayStateSproofBuilder {
pub host_config: AbridgedHostConfiguration,
pub dmq_mqc_head: Option<relay_chain::Hash>,
pub upgrade_go_ahead: Option<UpgradeGoAhead>,
pub relay_dispatch_queue_size: Option<(u32, u32)>,
pub hrmp_ingress_channel_index: Option<Vec<ParaId>>,
pub hrmp_egress_channel_index: Option<Vec<ParaId>>,
@@ -59,6 +60,7 @@ impl Default for RelayStateSproofBuilder {
validation_upgrade_delay: 6,
},
dmq_mqc_head: None,
upgrade_go_ahead: None,
relay_dispatch_queue_size: None,
hrmp_ingress_channel_index: None,
hrmp_egress_channel_index: None,
@@ -68,6 +70,26 @@ impl Default for RelayStateSproofBuilder {
}
}
// TODO: derive `Copy` and `Clone` for `UpgradeGoAhead` to avoid manual implementation.
impl Clone for RelayStateSproofBuilder {
fn clone(&self) -> Self {
RelayStateSproofBuilder {
para_id: self.para_id,
host_config: self.host_config.clone(),
dmq_mqc_head: self.dmq_mqc_head.clone(),
upgrade_go_ahead: self.upgrade_go_ahead.as_ref().map(|u| match u {
UpgradeGoAhead::Abort => UpgradeGoAhead::Abort,
UpgradeGoAhead::GoAhead => UpgradeGoAhead::GoAhead,
}),
relay_dispatch_queue_size: self.relay_dispatch_queue_size,
hrmp_ingress_channel_index: self.hrmp_ingress_channel_index.clone(),
hrmp_egress_channel_index: self.hrmp_egress_channel_index.clone(),
hrmp_channels: self.hrmp_channels.clone(),
current_slot: self.current_slot.clone(),
}
}
}
impl RelayStateSproofBuilder {
/// Returns a mutable reference to HRMP channel metadata for a channel (`sender`, `self.para_id`).
///
@@ -120,6 +142,12 @@ impl RelayStateSproofBuilder {
relay_dispatch_queue_size.encode(),
);
}
if let Some(upgrade_go_ahead) = self.upgrade_go_ahead {
insert(
relay_chain::well_known_keys::upgrade_go_ahead_signal(self.para_id),
upgrade_go_ahead.encode(),
);
}
if let Some(hrmp_ingress_channel_index) = self.hrmp_ingress_channel_index {
let mut sorted = hrmp_ingress_channel_index.clone();
sorted.sort();