Update to latest polkadot & substrate (#266)

This commit is contained in:
Alexander Krupenkin
2020-12-16 12:50:05 +03:00
committed by GitHub
parent c84c9b6bb0
commit 8226063135
10 changed files with 352 additions and 243 deletions
+306 -211
View File
File diff suppressed because it is too large Load Diff
+15 -11
View File
@@ -19,7 +19,8 @@
use cumulus_network::WaitToAnnounce;
use cumulus_primitives::{
inherents::{self, VALIDATION_DATA_IDENTIFIER},
well_known_keys, ValidationData, InboundHrmpMessage, OutboundHrmpMessage, InboundDownwardMessage,
well_known_keys, InboundDownwardMessage, InboundHrmpMessage, OutboundHrmpMessage,
ValidationData,
};
use cumulus_runtime::ParachainBlockData;
@@ -52,7 +53,7 @@ use log::{debug, error, info, trace};
use futures::prelude::*;
use std::{marker::PhantomData, sync::Arc, time::Duration, collections::BTreeMap};
use std::{collections::BTreeMap, marker::PhantomData, sync::Arc, time::Duration};
use parking_lot::Mutex;
@@ -147,8 +148,7 @@ where
///
/// Returns `None` in case of an error.
fn retrieve_dmq_contents(&self, relay_parent: PHash) -> Option<Vec<InboundDownwardMessage>> {
self
.polkadot_client
self.polkadot_client
.runtime_api()
.dmq_contents_with_context(
&BlockId::hash(relay_parent),
@@ -169,11 +169,11 @@ where
/// collating for.
///
/// Empty channels are also included.
fn retrieve_all_inbound_hrmp_channel_contents(&self, relay_parent: PHash)
-> Option<BTreeMap<ParaId, Vec<InboundHrmpMessage>>>
{
self
.polkadot_client
fn retrieve_all_inbound_hrmp_channel_contents(
&self,
relay_parent: PHash,
) -> Option<BTreeMap<ParaId, Vec<InboundHrmpMessage>>> {
self.polkadot_client
.runtime_api()
.inbound_hrmp_channels_contents_with_context(
&BlockId::hash(relay_parent),
@@ -221,7 +221,8 @@ where
let message_ingestion_data = {
let downward_messages = self.retrieve_dmq_contents(relay_parent)?;
let horizontal_messages = self.retrieve_all_inbound_hrmp_channel_contents(relay_parent)?;
let horizontal_messages =
self.retrieve_all_inbound_hrmp_channel_contents(relay_parent)?;
inherents::MessageIngestionType {
downward_messages,
@@ -230,7 +231,10 @@ where
};
inherent_data
.put_data(inherents::MESSAGE_INGESTION_IDENTIFIER, &message_ingestion_data)
.put_data(
inherents::MESSAGE_INGESTION_IDENTIFIER,
&message_ingestion_data,
)
.map_err(|e| {
error!(
target: "cumulus-collator",
+2 -2
View File
@@ -33,8 +33,8 @@ use sp_std::{cmp, prelude::*};
use cumulus_primitives::{
inherents::{MessageIngestionType, MESSAGE_INGESTION_IDENTIFIER},
well_known_keys, DownwardMessageHandler, HrmpMessageHandler, OutboundHrmpMessage,
UpwardMessage, ParaId,
well_known_keys, DownwardMessageHandler, HrmpMessageHandler, OutboundHrmpMessage, ParaId,
UpwardMessage,
};
// TODO: these should be not a constant, but sourced from the relay-chain configuration.
+1 -1
View File
@@ -180,7 +180,7 @@ where
"validation failed because a justification is needed if the block at the top of the chain."
);
Ok(Validation::Failure)
Ok(Validation::Failure { disconnect: false })
} else {
Ok(Validation::Success { is_new_best: false })
}
+1 -1
View File
@@ -176,7 +176,7 @@ fn invalid_if_no_data_exceeds_best_known_number() {
assert_eq!(
res.unwrap(),
Validation::Failure,
Validation::Failure { disconnect: false },
"validation fails if no justification and block number >= best known number",
);
}
+2 -5
View File
@@ -36,12 +36,9 @@ pub type OutboundHrmpMessage = polkadot_primitives::v1::OutboundHrmpMessage<Para
/// Identifiers and types related to Cumulus Inherents
pub mod inherents {
use sp_inherents::InherentIdentifier;
use sp_std::{
vec::Vec,
collections::btree_map::BTreeMap,
};
use super::{InboundDownwardMessage, InboundHrmpMessage, ParaId};
use sp_inherents::InherentIdentifier;
use sp_std::{collections::btree_map::BTreeMap, vec::Vec};
/// Inherent identifier for message ingestion inherent.
pub const MESSAGE_INGESTION_IDENTIFIER: InherentIdentifier = *b"msgingst";
+6 -1
View File
@@ -117,7 +117,12 @@ where
let parachain_config = prepare_node_config(parachain_config);
let polkadot_full_node =
cumulus_service::build_polkadot_full_node(polkadot_config, collator_key.public())?;
cumulus_service::build_polkadot_full_node(polkadot_config, collator_key.public()).map_err(
|e| match e {
polkadot_service::Error::Sub(x) => x,
s => format!("{}", s).into(),
},
)?;
let params = new_partial(&parachain_config)?;
params
@@ -29,10 +29,10 @@ use codec::{Decode, Encode};
use cumulus_primitives::{
well_known_keys::{
NEW_VALIDATION_CODE, PROCESSED_DOWNWARD_MESSAGES, UPWARD_MESSAGES, VALIDATION_DATA,
HRMP_WATERMARK, HRMP_OUTBOUND_MESSAGES,
HRMP_OUTBOUND_MESSAGES, HRMP_WATERMARK, NEW_VALIDATION_CODE, PROCESSED_DOWNWARD_MESSAGES,
UPWARD_MESSAGES, VALIDATION_DATA,
},
UpwardMessage, ValidationData, OutboundHrmpMessage,
OutboundHrmpMessage, UpwardMessage, ValidationData,
};
use sp_core::storage::{ChildInfo, TrackedStorageKey};
use sp_externalities::{
@@ -175,10 +175,7 @@ pub fn validate_block<B: BlockT, E: ExecuteBlock<B>>(params: ValidationParams) -
let hrmp_watermark = overlay
.storage(HRMP_WATERMARK)
.flatten()
.map(|v| {
Decode::decode(&mut &v[..])
.expect("HRMP watermark is not encoded correctly")
})
.map(|v| Decode::decode(&mut &v[..]).expect("HRMP watermark is not encoded correctly"))
.unwrap_or(validation_data.persisted.block_number);
ValidationResult {
+10 -3
View File
@@ -296,11 +296,18 @@ pub fn prepare_node_config(mut parachain_config: Configuration) -> Configuration
pub fn build_polkadot_full_node(
config: Configuration,
collator_id: CollatorId,
) -> sc_service::error::Result<PFullNode<PClient>> {
) -> Result<PFullNode<PClient>, polkadot_service::Error> {
let is_light = matches!(config.role, Role::Light);
if is_light {
Err("Light client not supported.".into())
Err(polkadot_service::Error::Sub(
"Light client not supported.".into(),
))
} else {
polkadot_service::build_full(config, polkadot_service::IsCollator::Yes(collator_id), None)
polkadot_service::build_full(
config,
polkadot_service::IsCollator::Yes(collator_id),
None,
None,
)
}
}
+5 -1
View File
@@ -157,7 +157,11 @@ where
let polkadot_full_node = polkadot_test_service::new_full(
polkadot_config,
polkadot_service::IsCollator::Yes(collator_key.public()),
)?;
)
.map_err(|e| match e {
polkadot_service::Error::Sub(x) => x,
s => format!("{}", s).into(),
})?;
let client = params.client.clone();
let backend = params.backend.clone();