mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 05:51:02 +00:00
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:
Generated
+2032
-1769
File diff suppressed because it is too large
Load Diff
@@ -457,6 +457,7 @@ mod tests {
|
||||
NativeExecutor::<polkadot_service::PolkadotExecutor>::new(
|
||||
Interpreted,
|
||||
None,
|
||||
1,
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -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-consensus = { 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-primitives = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
||||
|
||||
@@ -18,18 +18,22 @@
|
||||
//!
|
||||
//! Contains message send between collators and logic to process them.
|
||||
|
||||
use sp_api::ProvideRuntimeApi;
|
||||
use sp_blockchain::Error as ClientError;
|
||||
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_primitives::parachain::ValidatorId;
|
||||
use polkadot_primitives::{
|
||||
parachain::{ParachainHost, ValidatorId},
|
||||
Block as PBlock,
|
||||
};
|
||||
use polkadot_statement_table::{SignedStatement, Statement};
|
||||
use polkadot_validation::check_statement;
|
||||
|
||||
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
|
||||
/// valid parachain-block candidate.
|
||||
@@ -37,21 +41,27 @@ use std::marker::PhantomData;
|
||||
/// the justification.
|
||||
///
|
||||
/// Note: if no justification is provided the annouce is considered valid.
|
||||
pub struct JustifiedBlockAnnounceValidator<B> {
|
||||
pub struct JustifiedBlockAnnounceValidator<B, P> {
|
||||
authorities: Vec<ValidatorId>,
|
||||
phantom: PhantomData<B>,
|
||||
polkadot_client: Arc<P>,
|
||||
}
|
||||
|
||||
impl<B: BlockT> JustifiedBlockAnnounceValidator<B> {
|
||||
pub fn new(authorities: Vec<ValidatorId>) -> Self {
|
||||
impl<B, P> JustifiedBlockAnnounceValidator<B, P> {
|
||||
pub fn new(authorities: Vec<ValidatorId>, polkadot_client: Arc<P>) -> Self {
|
||||
Self {
|
||||
authorities,
|
||||
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(
|
||||
&mut self,
|
||||
header: &B::Header,
|
||||
@@ -89,6 +99,12 @@ impl<B: BlockT> BlockAnnounceValidator<B> for JustifiedBlockAnnounceValidator<B>
|
||||
},
|
||||
} = 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.
|
||||
let signer = self.authorities.get(sender as usize).ok_or_else(|| {
|
||||
Box::new(ClientError::BadJustification(
|
||||
@@ -98,7 +114,7 @@ impl<B: BlockT> BlockAnnounceValidator<B> for JustifiedBlockAnnounceValidator<B>
|
||||
})?;
|
||||
|
||||
// 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(
|
||||
"block announced justification signature is invalid".to_string(),
|
||||
)) as Box<_>);
|
||||
|
||||
@@ -54,10 +54,12 @@ fn call_validate_block(
|
||||
Some(1024),
|
||||
sp_io::SubstrateHostFunctions::host_functions(),
|
||||
false,
|
||||
1,
|
||||
);
|
||||
|
||||
executor.call_in_wasm(
|
||||
&WASM_BINARY,
|
||||
None,
|
||||
"validate_block",
|
||||
¶ms,
|
||||
&mut ext_ext,
|
||||
|
||||
@@ -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" }
|
||||
sc-network = { 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" }
|
||||
sc-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -19,7 +19,7 @@ use wasm_builder_runner::WasmBuilder;
|
||||
fn main() {
|
||||
WasmBuilder::new()
|
||||
.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()
|
||||
.import_memory()
|
||||
.build()
|
||||
|
||||
@@ -24,11 +24,10 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
||||
|
||||
use sp_api::impl_runtime_apis;
|
||||
use sp_core::OpaqueMetadata;
|
||||
use sp_runtime::traits::{
|
||||
BlakeTwo256, Block as BlockT, ConvertInto, StaticLookup, Verify,
|
||||
};
|
||||
use sp_runtime::traits::{BlakeTwo256, Block as BlockT, ConvertInto, StaticLookup, Verify};
|
||||
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,
|
||||
};
|
||||
use sp_std::prelude::*;
|
||||
@@ -321,8 +320,11 @@ impl_runtime_apis! {
|
||||
}
|
||||
|
||||
impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
|
||||
fn validate_transaction(tx: <Block as BlockT>::Extrinsic) -> TransactionValidity {
|
||||
Executive::validate_transaction(tx)
|
||||
fn validate_transaction(
|
||||
source: TransactionSource,
|
||||
tx: <Block as BlockT>::Extrinsic,
|
||||
) -> TransactionValidity {
|
||||
Executive::validate_transaction(source, tx)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ use sc_service;
|
||||
use sp_core::{Pair, Public};
|
||||
|
||||
/// 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
|
||||
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
|
||||
|
||||
@@ -22,14 +22,13 @@ use std::sync::Arc;
|
||||
use parachain_runtime::Block;
|
||||
|
||||
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_runtime::{
|
||||
traits::{Block as BlockT, Hash as HashT, Header as HeaderT},
|
||||
BuildStorage,
|
||||
};
|
||||
use sc_network::config::TransportConfig;
|
||||
use polkadot_service::ChainSpec as ChainSpecPolkadot;
|
||||
|
||||
use codec::Encode;
|
||||
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.run(
|
||||
config,
|
||||
|config: Configuration<_, _>| Ok(new_full_start!(config).0),
|
||||
|config: Configuration| Ok(new_full_start!(config).0),
|
||||
)
|
||||
},
|
||||
Some(Subcommand::ExportGenesisState(params)) => {
|
||||
@@ -89,7 +88,7 @@ pub fn run(version: sc_cli::VersionInfo) -> sc_cli::Result<()> {
|
||||
info!(" by {}, 2019", version.author);
|
||||
info!("Chain specification: {}", config.expect_chain_spec().name());
|
||||
info!("Node name: {}", config.name);
|
||||
info!("Roles: {:?}", config.roles);
|
||||
info!("Roles: {:?}", config.role);
|
||||
info!("Parachain id: {:?}", crate::PARA_ID);
|
||||
|
||||
// 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,
|
||||
);
|
||||
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_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,
|
||||
load_spec_polkadot,
|
||||
&version,
|
||||
@@ -126,20 +125,20 @@ pub fn run(version: sc_cli::VersionInfo) -> sc_cli::Result<()> {
|
||||
use_yamux_flow_control: false,
|
||||
};
|
||||
|
||||
match config.roles {
|
||||
ServiceRoles::LIGHT => unimplemented!("Light client not supported!"),
|
||||
match config.role {
|
||||
ServiceRole::Light => unimplemented!("Light client not supported!"),
|
||||
_ => crate::service::run_collator(config, key, polkadot_config),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn load_spec(_: &str) -> Result<Option<chain_spec::ChainSpec>, String> {
|
||||
Ok(Some(chain_spec::get_chain_spec()))
|
||||
fn load_spec(_: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
|
||||
Ok(Box::new(chain_spec::get_chain_spec()))
|
||||
}
|
||||
|
||||
fn load_spec_polkadot(_: &str) -> Result<Option<ChainSpecPolkadot>, String> {
|
||||
Some(polkadot_service::ChainSpec::from_json_bytes(
|
||||
fn load_spec_polkadot(_: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
|
||||
polkadot_service::PolkadotChainSpec::from_json_bytes(
|
||||
&include_bytes!("../res/polkadot_chainspec.json")[..],
|
||||
)).transpose()
|
||||
).map(|r| Box::new(r) as Box<_>)
|
||||
}
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use parachain_runtime::{self, GenesisConfig};
|
||||
|
||||
use sc_executor::native_executor_instance;
|
||||
use sc_service::{AbstractService, Configuration};
|
||||
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`
|
||||
///
|
||||
/// This function blocks until done.
|
||||
pub fn run_collator<E: sc_service::ChainSpecExtension>(
|
||||
parachain_config: Configuration<GenesisConfig, E>,
|
||||
pub fn run_collator(
|
||||
parachain_config: Configuration,
|
||||
key: Arc<CollatorPair>,
|
||||
mut polkadot_config: polkadot_collator::Configuration,
|
||||
) -> sc_cli::Result<()> {
|
||||
|
||||
@@ -15,30 +15,39 @@
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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;
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
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;
|
||||
|
||||
fn run_command_and_kill(signal: Signal) {
|
||||
let _ = fs::remove_dir_all("polkadot_argument_parsing");
|
||||
let mut cmd = Command::new(cargo_bin("cumulus-test-parachain-collator"))
|
||||
.args(&[
|
||||
"-d", "polkadot_argument_parsing", "--", "--bootnodes",
|
||||
"-d",
|
||||
"polkadot_argument_parsing",
|
||||
"--",
|
||||
"--bootnodes",
|
||||
"/ip4/127.0.0.1/tcp/30333/p2p/Qmbx43psh7LVkrYTRXisUpzCubbgYojkejzAgj5mteDnxy",
|
||||
"--bootnodes",
|
||||
"/ip4/127.0.0.1/tcp/50500/p2p/Qma6SpS7tzfCrhtgEVKR9Uhjmuv55ovC3kY6y6rPBxpWd",
|
||||
"/ip4/127.0.0.1/tcp/50500/p2p/Qma6SpS7tzfCrhtgEVKR9Uhjmuv55ovC3kY6y6rPBxpWde",
|
||||
])
|
||||
.spawn()
|
||||
.unwrap();
|
||||
|
||||
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();
|
||||
assert_eq!(
|
||||
common::wait_for(&mut cmd, 30).map(|x| x.success()),
|
||||
|
||||
@@ -19,7 +19,7 @@ use wasm_builder_runner::WasmBuilder;
|
||||
fn main() {
|
||||
WasmBuilder::new()
|
||||
.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()
|
||||
.import_memory()
|
||||
.build()
|
||||
|
||||
Reference in New Issue
Block a user