Commit 5935e5ac authored by Bastian Köcher's avatar Bastian Köcher Committed by André Silva
Browse files

Update to latest Substrate master (#320)

* Make `collator::Network` require `Send + Sync` to make it work

* Update packages

* Update to latest Substrate

* Make it compile and make tests work

* Use `polkadot-master`

* Fix CI

* Remove `build.sh` from readmes

* Delete old stuff

* Bring one back
parent c3e99e3a
Pipeline #42819 passed with stages
in 21 minutes and 20 seconds
......@@ -84,7 +84,6 @@ test-linux-stable: &test
variables:
- $DEPLOY_TAG
script:
- ./scripts/build.sh --locked
- time cargo test --all --release --verbose --locked
- sccache -s
......@@ -107,7 +106,6 @@ build-linux-release: &build
tags:
- linux-docker
script:
- ./scripts/build.sh --locked
- time cargo build --release --verbose
- mkdir -p ./artifacts
- mv ./target/release/polkadot ./artifacts/.
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -142,7 +142,6 @@ Then build the code:
[source, shell]
----
./scripts/init.sh # Install WebAssembly. Update Rust
./scripts/build.sh # Builds the WebAssembly binaries
cargo build # Builds all native code
----
......
......@@ -23,5 +23,5 @@ native_executor_instance!(
pub Executor,
polkadot_runtime::api::dispatch,
polkadot_runtime::native_version,
include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm")
polkadot_runtime::WASM_BINARY
);
......@@ -33,9 +33,8 @@ use polkadot_primitives::parachain::{
StructuredUnroutedIngress,
};
use substrate_network::{
PeerId, RequestId, Context, Event, message, generic_message,
specialization::NetworkSpecialization as Specialization,
StatusMessage as GenericFullStatus
PeerId, RequestId, Context, StatusMessage as GenericFullStatus,
specialization::{Event, NetworkSpecialization as Specialization},
};
use self::validation::{LiveValidationSessions, RecentValidatorIds, InsertedRecentKey};
use self::collator_pool::{CollatorPool, Role, Action};
......@@ -573,24 +572,17 @@ impl Specialization<Block> for PolkadotProtocol {
&mut self,
ctx: &mut dyn Context<Block>,
who: PeerId,
message: &mut Option<message::Message<Block>>
message: Vec<u8>,
) {
match message.take() {
Some(generic_message::Message::ChainSpecific(raw)) => {
match Message::decode(&mut raw.as_slice()) {
Some(msg) => {
ctx.report_peer(who.clone(), benefit::VALID_FORMAT);
self.on_polkadot_message(ctx, who, msg)
},
None => {
trace!(target: "p_net", "Bad message from {}", who);
ctx.report_peer(who, cost::INVALID_FORMAT);
*message = Some(generic_message::Message::ChainSpecific(raw));
}
}
match Message::decode(&mut &message[..]) {
Some(msg) => {
ctx.report_peer(who.clone(), benefit::VALID_FORMAT);
self.on_polkadot_message(ctx, who, msg)
},
None => {
trace!(target: "p_net", "Bad message from {}", who);
ctx.report_peer(who, cost::INVALID_FORMAT);
}
Some(other) => *message = Some(other),
_ => {}
}
}
......
......@@ -29,9 +29,8 @@ use polkadot_primitives::parachain::{
use substrate_primitives::crypto::UncheckedInto;
use parity_codec::Encode;
use substrate_network::{
PeerId, Context, config::Roles,
message::generic::ConsensusMessage,
specialization::NetworkSpecialization, generic_message::Message as GenericMessage
PeerId, Context, config::Roles, message::generic::ConsensusMessage,
specialization::NetworkSpecialization,
};
use futures::Future;
......@@ -107,7 +106,7 @@ fn make_validation_session(parent_hash: Hash, local_key: SessionKey) -> SessionP
fn on_message(protocol: &mut PolkadotProtocol, ctx: &mut TestContext, from: PeerId, message: Message) {
let encoded = message.encode();
protocol.on_message(ctx, from, &mut Some(GenericMessage::ChainSpecific(encoded)));
protocol.on_message(ctx, from, encoded);
}
#[test]
......
......@@ -15,6 +15,7 @@ rstd = { package = "sr-std", git = "https://github.com/paritytech/substrate", br
[dev-dependencies]
tiny-keccak = "1.4"
adder = { path = "../test-parachains/adder" }
[features]
default = ["std"]
......
......@@ -60,7 +60,7 @@ impl Externalities for DummyExt {
}
}
const TEST_CODE: &[u8] = include_bytes!("res/adder.wasm");
const TEST_CODE: &[u8] = adder::WASM_BINARY;
fn hash_state(state: u64) -> [u8; 32] {
tiny_keccak::keccak256(state.encode().as_slice())
......
......@@ -77,6 +77,10 @@ pub type SessionKey = ed25519::Public;
/// that 32 bits may be multiplied with a balance in 128 bits without worrying about overflow.
pub type Balance = u128;
/// The aura crypto scheme defined via the keypair type.
#[cfg(feature = "std")]
pub type AuraPair = ed25519::Pair;
/// The Ed25519 pub key of an session that belongs to an Aura authority of the chain.
pub type AuraId = ed25519::Public;
......
......@@ -3,6 +3,7 @@ name = "polkadot-runtime"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
build = "build.rs"
[dependencies]
bitvec = { version = "0.8", default-features = false, features = ["alloc"] }
......@@ -46,10 +47,14 @@ libsecp256k1 = "0.2.1"
tiny-keccak = "1.4.2"
keyring = { package = "substrate-keyring", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
substrate-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
trie-db = "0.12"
trie-db = "0.14"
[build-dependencies]
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.1" }
[features]
default = ["std"]
no_std = []
std = [
"bitvec/std",
"primitives/std",
......
// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
......@@ -14,8 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
//! The Polkadot runtime reexported for WebAssembly compile.
use wasm_builder_runner::{build_current_project, WasmBuilderSource};
#![cfg_attr(not(feature = "std"), no_std)]
pub use polkadot_runtime::*;
fn main() {
build_current_project("wasm_binary.rs", WasmBuilderSource::Crates("1.0.3"));
}
\ No newline at end of file
......@@ -37,11 +37,11 @@ use client::{
runtime_api as client_api, impl_runtime_apis,
};
use sr_primitives::{
ApplyResult, generic, transaction_validity::TransactionValidity, create_runtime_str,
ApplyResult, generic, transaction_validity::TransactionValidity, create_runtime_str, key_types,
traits::{BlakeTwo256, Block as BlockT, DigestFor, StaticLookup, Convert}, impl_opaque_keys
};
use version::RuntimeVersion;
use grandpa::fg_primitives::{self, ScheduledChange};
use grandpa::{AuthorityId as GrandpaId, fg_primitives::{self, ScheduledChange}};
use council::motions as council_motions;
#[cfg(feature = "std")]
use council::seats as council_seats;
......@@ -63,6 +63,10 @@ pub use sr_primitives::{Permill, Perbill};
pub use timestamp::BlockPeriod;
pub use srml_support::StorageValue;
// Make the WASM binary available.
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
/// Runtime version.
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("polkadot"),
......@@ -182,7 +186,10 @@ parameter_types! {
type SessionHandlers = (Grandpa, Aura);
impl_opaque_keys! {
pub struct SessionKeys(grandpa::AuthorityId, AuraId);
pub struct SessionKeys {
#[id(key_types::ED25519)]
pub ed25519: GrandpaId,
}
}
// NOTE: `SessionHandler` and `SessionKeys` are co-dependent: One key will be used for each handler.
......@@ -197,6 +204,14 @@ impl session::Trait for Runtime {
type ShouldEndSession = session::PeriodicSessions<Period, Offset>;
type Event = Event;
type Keys = SessionKeys;
type SelectInitialValidators = Staking;
type ValidatorId = AccountId;
type ValidatorIdOf = staking::StashOf<Self>;
}
impl session::historical::Trait for Runtime {
type FullIdentification = staking::Exposure<AccountId, Balance>;
type FullIdentificationOf = staking::ExposureOf<Self>;
}
/// Converter for currencies to votes.
......@@ -228,6 +243,7 @@ impl staking::Trait for Runtime {
type Reward = ();
type SessionsPerEra = SessionsPerEra;
type BondingDuration = BondingDuration;
type SessionInterface = Self;
}
parameter_types! {
......@@ -333,7 +349,7 @@ impl parachains::Trait for Runtime {
}
parameter_types!{
pub const LeasePeriod: BlockNumber = 100000;
pub const LeasePeriod: BlockNumber = 100_000;
pub const EndingPeriod: BlockNumber = 1000;
}
......
......@@ -865,6 +865,14 @@ mod tests {
type ShouldEndSession = session::PeriodicSessions<Period, Offset>;
type SessionHandler = ();
type Event = ();
type SelectInitialValidators = staking::Module<Self>;
type ValidatorId = crate::AccountId;
type ValidatorIdOf = staking::StashOf<Self>;
}
impl session::historical::Trait for Test {
type FullIdentification = staking::Exposure<crate::AccountId, Balance>;
type FullIdentificationOf = staking::ExposureOf<Self>;
}
impl timestamp::Trait for Test {
......@@ -914,6 +922,7 @@ mod tests {
type Reward = ();
type SessionsPerEra = SessionsPerEra;
type BondingDuration = BondingDuration;
type SessionInterface = Self;
}
impl Trait for Test {
......@@ -949,7 +958,6 @@ mod tests {
];
t.extend(session::GenesisConfig::<Test>{
validators: validator_keys.iter().map(|k| crate::AccountId::from(*k)).collect(),
keys: vec![],
}.build_storage().unwrap().0);
t.extend(GenesisConfig::<Test>{
......
This source diff could not be displayed because it is too large. You can view the blob instead.
[package]
name = "polkadot-runtime-wasm"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[lib]
name = "polkadot_runtime"
crate-type = ["cdylib"]
[dependencies]
polkadot-runtime = { path = "..", default-features = false }
[features]
default = []
std = [
"polkadot-runtime/std",
]
[profile.release]
panic = "abort"
lto = true
[workspace]
members = []
#!/usr/bin/env bash
set -e
if cargo --version | grep -q "nightly"; then
CARGO_CMD="cargo"
else
CARGO_CMD="cargo +nightly"
fi
RUSTFLAGS="-C link-arg=--export-table" $CARGO_CMD build --target=wasm32-unknown-unknown --release $@
for i in polkadot_runtime
do
wasm-gc target/wasm32-unknown-unknown/release/$i.wasm target/wasm32-unknown-unknown/release/$i.compact.wasm
done
#!/usr/bin/env bash
# This script assumes that all pre-requisites are installed.
set -e
PROJECT_ROOT=`git rev-parse --show-toplevel`
source `dirname "$0"`/common.sh
export CARGO_INCREMENTAL=0
# Save current directory.
pushd .
cd $ROOT
for SRC in "${SRCS[@]}"
do
echo "*** Building wasm binaries in $SRC"
cd "$PROJECT_ROOT/$SRC"
./build.sh "$@"
cd - >> /dev/null
done
# Restore initial directory.
popd
......@@ -24,6 +24,7 @@ client = { package = "substrate-client", git = "https://github.com/paritytech/su
aura = { package = "substrate-consensus-aura", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
consensus_common = { package = "substrate-consensus-common", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
grandpa = { package = "substrate-finality-grandpa", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
grandpa_primitives = { package = "substrate-finality-grandpa-primitives", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
inherents = { package = "substrate-inherents", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
service = { package = "substrate-service", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
telemetry = { package = "substrate-telemetry", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
......
......@@ -21,7 +21,7 @@ use polkadot_primitives::{AccountId, SessionKey};
use polkadot_runtime::{
GenesisConfig, CouncilSeatsConfig, DemocracyConfig, SystemConfig, AuraConfig,
SessionConfig, StakingConfig, TimestampConfig, BalancesConfig, Perbill, SessionKeys,
GrandpaConfig, SudoConfig, IndicesConfig, CuratedGrandpaConfig, StakerStatus,
GrandpaConfig, SudoConfig, IndicesConfig, CuratedGrandpaConfig, StakerStatus, WASM_BINARY,
};
use telemetry::TelemetryEndpoints;
use hex_literal::hex;
......@@ -76,8 +76,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
GenesisConfig {
system: Some(SystemConfig {
// TODO: Change after Substrate 1252 is fixed (https://github.com/paritytech/substrate/issues/1252)
code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm").to_vec(),
code: WASM_BINARY.to_vec(),
changes_trie_config: Default::default(),
}),
balances: Some(BalancesConfig {
......@@ -93,10 +92,9 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
.collect::<Vec<_>>(),
}),
session: Some(SessionConfig {
validators: initial_authorities.iter().map(|x| x.1.clone()).collect(),
keys: initial_authorities.iter().map(|x| (
x.1.clone(),
SessionKeys(x.2.clone(), x.2.clone()),
SessionKeys { ed25519: x.2.clone() },
)).collect::<Vec<_>>(),
}),
staking: Some(StakingConfig {
......@@ -203,8 +201,7 @@ pub fn testnet_genesis(
GenesisConfig {
system: Some(SystemConfig {
// TODO: Change after Substrate 1252 is fixed (https://github.com/paritytech/substrate/issues/1252)
code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm").to_vec(),
code: WASM_BINARY.to_vec(),
changes_trie_config: Default::default(),
}),
indices: Some(IndicesConfig {
......@@ -215,10 +212,9 @@ pub fn testnet_genesis(
vesting: vec![],
}),
session: Some(SessionConfig {
validators: initial_authorities.iter().map(|x| x.1.clone()).collect(),
keys: initial_authorities.iter().map(|x| (
x.1.clone(),
SessionKeys(x.2.clone(), x.2.clone()),
SessionKeys { ed25519: x.2.clone() },
)).collect::<Vec<_>>(),
}),
staking: Some(StakingConfig {
......@@ -277,7 +273,16 @@ fn development_config_genesis() -> GenesisConfig {
/// Development config (single validator Alice)
pub fn development_config() -> ChainSpec {
ChainSpec::from_genesis("Development", "dev", development_config_genesis, vec![], None, Some(DEFAULT_PROTOCOL_ID), None, None)
ChainSpec::from_genesis(
"Development",
"dev",
development_config_genesis,
vec![],
None,
Some(DEFAULT_PROTOCOL_ID),
None,
None,
)
}
fn local_testnet_genesis() -> GenesisConfig {
......@@ -293,5 +298,14 @@ fn local_testnet_genesis() -> GenesisConfig {
/// Local testnet config (multivalidator Alice + Bob)
pub fn local_testnet_config() -> ChainSpec {
ChainSpec::from_genesis("Local Testnet", "local_testnet", local_testnet_genesis, vec![], None, Some(DEFAULT_PROTOCOL_ID), None, None)
ChainSpec::from_genesis(
"Local Testnet",
"local_testnet",
local_testnet_genesis,
vec![],
None,
Some(DEFAULT_PROTOCOL_ID),
None,
None,
)
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment