Update to latest Polkadot & Substrate (#75)

* Start fixing compilation errors

* Switch to git version of `WasmBuilder`

* Fix compilation

* More updates

* Adapt to latest Substrate/Polkadot changes
This commit is contained in:
Bastian Köcher
2020-04-06 21:55:32 +02:00
committed by GitHub
parent f54a6e8b4d
commit d4562c3a48
14 changed files with 2176 additions and 1881 deletions
+2032 -1769
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -457,6 +457,7 @@ mod tests {
NativeExecutor::<polkadot_service::PolkadotExecutor>::new( NativeExecutor::<polkadot_service::PolkadotExecutor>::new(
Interpreted, Interpreted,
None, None,
1,
) )
) )
) )
+1
View File
@@ -11,6 +11,7 @@ sc-client = { git = "https://github.com/paritytech/substrate", branch = "cumulus
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" } sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" } sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
# polkadot deps # polkadot deps
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" } polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
+24 -8
View File
@@ -18,18 +18,22 @@
//! //!
//! Contains message send between collators and logic to process them. //! Contains message send between collators and logic to process them.
use sp_api::ProvideRuntimeApi;
use sp_blockchain::Error as ClientError; use sp_blockchain::Error as ClientError;
use sp_consensus::block_validation::{BlockAnnounceValidator, Validation}; use sp_consensus::block_validation::{BlockAnnounceValidator, Validation};
use sp_runtime::traits::Block as BlockT; use sp_runtime::{generic::BlockId, traits::Block as BlockT};
use polkadot_network::legacy::gossip::{GossipMessage, GossipStatement}; use polkadot_network::legacy::gossip::{GossipMessage, GossipStatement};
use polkadot_primitives::parachain::ValidatorId; use polkadot_primitives::{
parachain::{ParachainHost, ValidatorId},
Block as PBlock,
};
use polkadot_statement_table::{SignedStatement, Statement}; use polkadot_statement_table::{SignedStatement, Statement};
use polkadot_validation::check_statement; use polkadot_validation::check_statement;
use codec::{Decode, Encode}; use codec::{Decode, Encode};
use std::marker::PhantomData; use std::{marker::PhantomData, sync::Arc};
/// Validate that data is a valid justification from a relay-chain validator that the block is a /// Validate that data is a valid justification from a relay-chain validator that the block is a
/// valid parachain-block candidate. /// valid parachain-block candidate.
@@ -37,21 +41,27 @@ use std::marker::PhantomData;
/// the justification. /// the justification.
/// ///
/// Note: if no justification is provided the annouce is considered valid. /// Note: if no justification is provided the annouce is considered valid.
pub struct JustifiedBlockAnnounceValidator<B> { pub struct JustifiedBlockAnnounceValidator<B, P> {
authorities: Vec<ValidatorId>, authorities: Vec<ValidatorId>,
phantom: PhantomData<B>, phantom: PhantomData<B>,
polkadot_client: Arc<P>,
} }
impl<B: BlockT> JustifiedBlockAnnounceValidator<B> { impl<B, P> JustifiedBlockAnnounceValidator<B, P> {
pub fn new(authorities: Vec<ValidatorId>) -> Self { pub fn new(authorities: Vec<ValidatorId>, polkadot_client: Arc<P>) -> Self {
Self { Self {
authorities, authorities,
phantom: Default::default(), phantom: Default::default(),
polkadot_client,
} }
} }
} }
impl<B: BlockT> BlockAnnounceValidator<B> for JustifiedBlockAnnounceValidator<B> { impl<B: BlockT, P> BlockAnnounceValidator<B> for JustifiedBlockAnnounceValidator<B, P>
where
P: ProvideRuntimeApi<PBlock>,
P::Api: ParachainHost<PBlock>,
{
fn validate( fn validate(
&mut self, &mut self,
header: &B::Header, header: &B::Header,
@@ -89,6 +99,12 @@ impl<B: BlockT> BlockAnnounceValidator<B> for JustifiedBlockAnnounceValidator<B>
}, },
} = gossip_statement; } = gossip_statement;
let signing_context = self
.polkadot_client
.runtime_api()
.signing_context(&BlockId::Hash(relay_chain_leaf))
.map_err(|e| Box::new(ClientError::Msg(format!("{:?}", e))) as Box<_>)?;
// Check that the signer is a legit validator. // Check that the signer is a legit validator.
let signer = self.authorities.get(sender as usize).ok_or_else(|| { let signer = self.authorities.get(sender as usize).ok_or_else(|| {
Box::new(ClientError::BadJustification( Box::new(ClientError::BadJustification(
@@ -98,7 +114,7 @@ impl<B: BlockT> BlockAnnounceValidator<B> for JustifiedBlockAnnounceValidator<B>
})?; })?;
// Check statement is correctly signed. // Check statement is correctly signed.
if !check_statement(&statement, &signature, signer.clone(), &relay_chain_leaf) { if !check_statement(&statement, &signature, signer.clone(), &signing_context) {
return Err(Box::new(ClientError::BadJustification( return Err(Box::new(ClientError::BadJustification(
"block announced justification signature is invalid".to_string(), "block announced justification signature is invalid".to_string(),
)) as Box<_>); )) as Box<_>);
@@ -54,10 +54,12 @@ fn call_validate_block(
Some(1024), Some(1024),
sp_io::SubstrateHostFunctions::host_functions(), sp_io::SubstrateHostFunctions::host_functions(),
false, false,
1,
); );
executor.call_in_wasm( executor.call_in_wasm(
&WASM_BINARY, &WASM_BINARY,
None,
"validate_block", "validate_block",
&params, &params,
&mut ext_ext, &mut ext_ext,
+1 -1
View File
@@ -35,7 +35,7 @@ sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" } sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-network = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" } sc-network = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-client = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" } sc-client = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" } sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch", version = "0.8.0-alpha.5" }
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" } sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
sc-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" } sc-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -19,7 +19,7 @@ use wasm_builder_runner::WasmBuilder;
fn main() { fn main() {
WasmBuilder::new() WasmBuilder::new()
.with_current_project() .with_current_project()
.with_wasm_builder_from_crates("1.0.9") .with_wasm_builder_from_git("https://github.com/paritytech/substrate.git", "0b30207969fdde85e0dad785750757399cd0e3e4")
.export_heap_base() .export_heap_base()
.import_memory() .import_memory()
.build() .build()
+8 -6
View File
@@ -24,11 +24,10 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
use sp_api::impl_runtime_apis; use sp_api::impl_runtime_apis;
use sp_core::OpaqueMetadata; use sp_core::OpaqueMetadata;
use sp_runtime::traits::{ use sp_runtime::traits::{BlakeTwo256, Block as BlockT, ConvertInto, StaticLookup, Verify};
BlakeTwo256, Block as BlockT, ConvertInto, StaticLookup, Verify,
};
use sp_runtime::{ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys, transaction_validity::TransactionValidity, create_runtime_str, generic, impl_opaque_keys,
transaction_validity::{TransactionSource, TransactionValidity},
AnySignature, ApplyExtrinsicResult, AnySignature, ApplyExtrinsicResult,
}; };
use sp_std::prelude::*; use sp_std::prelude::*;
@@ -321,8 +320,11 @@ impl_runtime_apis! {
} }
impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime { impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
fn validate_transaction(tx: <Block as BlockT>::Extrinsic) -> TransactionValidity { fn validate_transaction(
Executive::validate_transaction(tx) source: TransactionSource,
tx: <Block as BlockT>::Extrinsic,
) -> TransactionValidity {
Executive::validate_transaction(source, tx)
} }
} }
+1 -1
View File
@@ -21,7 +21,7 @@ use sc_service;
use sp_core::{Pair, Public}; use sp_core::{Pair, Public};
/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
pub type ChainSpec = sc_service::ChainSpec<GenesisConfig>; pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>;
/// Helper function to generate a crypto pair from seed /// Helper function to generate a crypto pair from seed
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public { pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
+12 -13
View File
@@ -22,14 +22,13 @@ use std::sync::Arc;
use parachain_runtime::Block; use parachain_runtime::Block;
use sc_client::genesis; use sc_client::genesis;
use sc_service::{Configuration, Roles as ServiceRoles, config::PrometheusConfig}; use sc_service::{Configuration, Role as ServiceRole, config::PrometheusConfig};
use sp_core::hexdisplay::HexDisplay; use sp_core::hexdisplay::HexDisplay;
use sp_runtime::{ use sp_runtime::{
traits::{Block as BlockT, Hash as HashT, Header as HeaderT}, traits::{Block as BlockT, Hash as HashT, Header as HeaderT},
BuildStorage, BuildStorage,
}; };
use sc_network::config::TransportConfig; use sc_network::config::TransportConfig;
use polkadot_service::ChainSpec as ChainSpecPolkadot;
use codec::Encode; use codec::Encode;
use log::info; use log::info;
@@ -51,7 +50,7 @@ pub fn run(version: sc_cli::VersionInfo) -> sc_cli::Result<()> {
subcommand.update_config(&mut config, load_spec, &version)?; subcommand.update_config(&mut config, load_spec, &version)?;
subcommand.run( subcommand.run(
config, config,
|config: Configuration<_, _>| Ok(new_full_start!(config).0), |config: Configuration| Ok(new_full_start!(config).0),
) )
}, },
Some(Subcommand::ExportGenesisState(params)) => { Some(Subcommand::ExportGenesisState(params)) => {
@@ -89,7 +88,7 @@ pub fn run(version: sc_cli::VersionInfo) -> sc_cli::Result<()> {
info!(" by {}, 2019", version.author); info!(" by {}, 2019", version.author);
info!("Chain specification: {}", config.expect_chain_spec().name()); info!("Chain specification: {}", config.expect_chain_spec().name());
info!("Node name: {}", config.name); info!("Node name: {}", config.name);
info!("Roles: {:?}", config.roles); info!("Roles: {:?}", config.role);
info!("Parachain id: {:?}", crate::PARA_ID); info!("Parachain id: {:?}", crate::PARA_ID);
// TODO // TODO
@@ -101,7 +100,7 @@ pub fn run(version: sc_cli::VersionInfo) -> sc_cli::Result<()> {
[version.executable_name.to_string()].iter().chain(opt.relaychain_args.iter()), [version.executable_name.to_string()].iter().chain(opt.relaychain_args.iter()),
&version, &version,
); );
let allow_private_ipv4 = !polkadot_opt.run.network_config.no_private_ipv4; let allow_private_ipv4 = !polkadot_opt.run.base.network_config.no_private_ipv4;
polkadot_config.rpc_http = Some(DEFAULT_POLKADOT_RPC_HTTP.parse().unwrap()); polkadot_config.rpc_http = Some(DEFAULT_POLKADOT_RPC_HTTP.parse().unwrap());
polkadot_config.rpc_ws = Some(DEFAULT_POLKADOT_RPC_WS.parse().unwrap()); polkadot_config.rpc_ws = Some(DEFAULT_POLKADOT_RPC_WS.parse().unwrap());
@@ -111,7 +110,7 @@ pub fn run(version: sc_cli::VersionInfo) -> sc_cli::Result<()> {
) )
); );
polkadot_opt.run.update_config( polkadot_opt.run.base.update_config(
&mut polkadot_config, &mut polkadot_config,
load_spec_polkadot, load_spec_polkadot,
&version, &version,
@@ -126,20 +125,20 @@ pub fn run(version: sc_cli::VersionInfo) -> sc_cli::Result<()> {
use_yamux_flow_control: false, use_yamux_flow_control: false,
}; };
match config.roles { match config.role {
ServiceRoles::LIGHT => unimplemented!("Light client not supported!"), ServiceRole::Light => unimplemented!("Light client not supported!"),
_ => crate::service::run_collator(config, key, polkadot_config), _ => crate::service::run_collator(config, key, polkadot_config),
} }
}, },
} }
} }
fn load_spec(_: &str) -> Result<Option<chain_spec::ChainSpec>, String> { fn load_spec(_: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(Some(chain_spec::get_chain_spec())) Ok(Box::new(chain_spec::get_chain_spec()))
} }
fn load_spec_polkadot(_: &str) -> Result<Option<ChainSpecPolkadot>, String> { fn load_spec_polkadot(_: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
Some(polkadot_service::ChainSpec::from_json_bytes( polkadot_service::PolkadotChainSpec::from_json_bytes(
&include_bytes!("../res/polkadot_chainspec.json")[..], &include_bytes!("../res/polkadot_chainspec.json")[..],
)).transpose() ).map(|r| Box::new(r) as Box<_>)
} }
+2 -4
View File
@@ -16,8 +16,6 @@
use std::sync::Arc; use std::sync::Arc;
use parachain_runtime::{self, GenesisConfig};
use sc_executor::native_executor_instance; use sc_executor::native_executor_instance;
use sc_service::{AbstractService, Configuration}; use sc_service::{AbstractService, Configuration};
use sc_finality_grandpa::{FinalityProofProvider as GrandpaFinalityProofProvider, StorageAndProofProvider}; use sc_finality_grandpa::{FinalityProofProvider as GrandpaFinalityProofProvider, StorageAndProofProvider};
@@ -73,8 +71,8 @@ macro_rules! new_full_start {
/// Run a collator node with the given parachain `Configuration` and relaychain `Configuration` /// Run a collator node with the given parachain `Configuration` and relaychain `Configuration`
/// ///
/// This function blocks until done. /// This function blocks until done.
pub fn run_collator<E: sc_service::ChainSpecExtension>( pub fn run_collator(
parachain_config: Configuration<GenesisConfig, E>, parachain_config: Configuration,
key: Arc<CollatorPair>, key: Arc<CollatorPair>,
mut polkadot_config: polkadot_collator::Configuration, mut polkadot_config: polkadot_collator::Configuration,
) -> sc_cli::Result<()> { ) -> sc_cli::Result<()> {
@@ -15,30 +15,39 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>. // along with Substrate. If not, see <http://www.gnu.org/licenses/>.
use assert_cmd::cargo::cargo_bin; use assert_cmd::cargo::cargo_bin;
use std::{convert::TryInto, process::Command, thread, time::Duration, fs}; use std::{convert::TryInto, fs, process::Command, thread, time::Duration};
mod common; mod common;
#[test] #[test]
#[cfg(unix)] #[cfg(unix)]
fn polkadot_argument_parsing() { fn polkadot_argument_parsing() {
use nix::sys::signal::{kill, Signal::{self, SIGINT, SIGTERM}}; use nix::sys::signal::{
kill,
Signal::{self, SIGINT, SIGTERM},
};
use nix::unistd::Pid; use nix::unistd::Pid;
fn run_command_and_kill(signal: Signal) { fn run_command_and_kill(signal: Signal) {
let _ = fs::remove_dir_all("polkadot_argument_parsing"); let _ = fs::remove_dir_all("polkadot_argument_parsing");
let mut cmd = Command::new(cargo_bin("cumulus-test-parachain-collator")) let mut cmd = Command::new(cargo_bin("cumulus-test-parachain-collator"))
.args(&[ .args(&[
"-d", "polkadot_argument_parsing", "--", "--bootnodes", "-d",
"polkadot_argument_parsing",
"--",
"--bootnodes",
"/ip4/127.0.0.1/tcp/30333/p2p/Qmbx43psh7LVkrYTRXisUpzCubbgYojkejzAgj5mteDnxy", "/ip4/127.0.0.1/tcp/30333/p2p/Qmbx43psh7LVkrYTRXisUpzCubbgYojkejzAgj5mteDnxy",
"--bootnodes", "--bootnodes",
"/ip4/127.0.0.1/tcp/50500/p2p/Qma6SpS7tzfCrhtgEVKR9Uhjmuv55ovC3kY6y6rPBxpWd", "/ip4/127.0.0.1/tcp/50500/p2p/Qma6SpS7tzfCrhtgEVKR9Uhjmuv55ovC3kY6y6rPBxpWde",
]) ])
.spawn() .spawn()
.unwrap(); .unwrap();
thread::sleep(Duration::from_secs(20)); thread::sleep(Duration::from_secs(20));
assert!(cmd.try_wait().unwrap().is_none(), "the process should still be running"); assert!(
cmd.try_wait().unwrap().is_none(),
"the process should still be running"
);
kill(Pid::from_raw(cmd.id().try_into().unwrap()), signal).unwrap(); kill(Pid::from_raw(cmd.id().try_into().unwrap()), signal).unwrap();
assert_eq!( assert_eq!(
common::wait_for(&mut cmd, 30).map(|x| x.success()), common::wait_for(&mut cmd, 30).map(|x| x.success()),
+1 -1
View File
@@ -19,7 +19,7 @@ use wasm_builder_runner::WasmBuilder;
fn main() { fn main() {
WasmBuilder::new() WasmBuilder::new()
.with_current_project() .with_current_project()
.with_wasm_builder_from_crates("1.0.9") .with_wasm_builder_from_git("https://github.com/paritytech/substrate.git", "0b30207969fdde85e0dad785750757399cd0e3e4")
.export_heap_base() .export_heap_base()
.import_memory() .import_memory()
.build() .build()