Skip to content

Commit

Permalink
Update substrate (paritytech#878)
Browse files Browse the repository at this point in the history
* Switch branch

* Small changes

* Update substrate branch

* Switch

* Revert "Switch branch"

This reverts commit b9d48b2.

* fix

* add `wipe` and `commit`

* Remove deprecated_host_interface

* Switch branch

* HasherFor -> HashFor

* More HasherFor changes

* Final touches

* Revert "Switch branch"

This reverts commit d0da273.

Co-authored-by: thiolliere <[email protected]>
Co-authored-by: Shawn Tabrizi <[email protected]>
  • Loading branch information
3 people authored and General-Beck committed Mar 19, 2020
1 parent 1f0f72c commit 0218b0c
Show file tree
Hide file tree
Showing 19 changed files with 1,394 additions and 1,310 deletions.
2,582 changes: 1,321 additions & 1,261 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions availability-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use polkadot_primitives::{
ParachainHost, AvailableData, OmittedValidationData,
},
};
use sp_runtime::traits::{BlakeTwo256, Hash as HashT, HasherFor};
use sp_runtime::traits::{BlakeTwo256, Hash as HashT, HashFor};
use sp_blockchain::{Result as ClientResult};
use client::{
BlockchainEvents, BlockBody,
Expand Down Expand Up @@ -199,7 +199,7 @@ impl Store {
P::Api: ParachainHost<Block>,
P::Api: ApiExt<Block, Error=sp_blockchain::Error>,
// Rust bug: https://github.com/rust-lang/rust/issues/24159
sp_api::StateBackendFor<P, Block>: sp_api::StateBackend<HasherFor<Block>>,
sp_api::StateBackendFor<P, Block>: sp_api::StateBackend<HashFor<Block>>,
{
let to_worker = self.to_worker.clone();

Expand Down
10 changes: 5 additions & 5 deletions availability-store/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::thread;

use log::{error, info, trace, warn};
use sp_blockchain::{Result as ClientResult};
use sp_runtime::traits::{Header as HeaderT, Block as BlockT, HasherFor};
use sp_runtime::traits::{Header as HeaderT, Block as BlockT, HashFor, BlakeTwo256};
use sp_api::{ApiExt, ProvideRuntimeApi};
use client::{
BlockchainEvents, BlockBody,
Expand Down Expand Up @@ -205,7 +205,7 @@ where
P: ProvideRuntimeApi<Block>,
P::Api: ParachainHost<Block, Error = sp_blockchain::Error>,
// Rust bug: https://github.com/rust-lang/rust/issues/24159
sp_api::StateBackendFor<P, Block>: sp_api::StateBackend<HasherFor<Block>>,
sp_api::StateBackendFor<P, Block>: sp_api::StateBackend<HashFor<Block>>,
{
let api = client.runtime_api();

Expand All @@ -229,7 +229,7 @@ where
P::Api: ParachainHost<Block> + ApiExt<Block, Error=sp_blockchain::Error>,
S: Sink<WorkerMsg> + Clone + Send + Sync + Unpin,
// Rust bug: https://github.com/rust-lang/rust/issues/24159
sp_api::StateBackendFor<P, Block>: sp_api::StateBackend<HasherFor<Block>>,
sp_api::StateBackendFor<P, Block>: sp_api::StateBackend<HashFor<Block>>,
{
let mut finality_notification_stream = client.finality_notification_stream();

Expand Down Expand Up @@ -613,7 +613,7 @@ impl<I, P> BlockImport<Block> for AvailabilityBlockImport<I, P> where
P: ProvideRuntimeApi<Block> + ProvideCache<Block>,
P::Api: ParachainHost<Block, Error = sp_blockchain::Error>,
// Rust bug: https://github.com/rust-lang/rust/issues/24159
sp_api::StateBackendFor<P, Block>: sp_api::StateBackend<sp_core::Blake2Hasher>
sp_api::StateBackendFor<P, Block>: sp_api::StateBackend<BlakeTwo256>
{
type Error = ConsensusError;
type Transaction = sp_api::TransactionFor<P, Block>;
Expand Down Expand Up @@ -726,7 +726,7 @@ impl<I, P> AvailabilityBlockImport<I, P> {
P::Api: ParachainHost<Block>,
P::Api: ApiExt<Block, Error = sp_blockchain::Error>,
// Rust bug: https://github.com/rust-lang/rust/issues/24159
sp_api::StateBackendFor<P, Block>: sp_api::StateBackend<HasherFor<Block>>,
sp_api::StateBackendFor<P, Block>: sp_api::StateBackend<HashFor<Block>>,
{
let (signal, exit) = exit_future::signal();

Expand Down
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ tokio = { version = "0.2.10", features = ["rt-threaded"], optional = true }

wasm-bindgen = { version = "0.2.57", optional = true }
wasm-bindgen-futures = { version = "0.4.7", optional = true }
browser-utils = { package = "browser-utils", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", optional = true }
browser-utils = { package = "substrate-browser-utils", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", optional = true }

[features]
default = [ "wasmtime", "rocksdb", "cli" ]
Expand Down
10 changes: 5 additions & 5 deletions cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use log::info;
use sp_core::Blake2Hasher;
use sp_runtime::traits::BlakeTwo256;
use service::{IsKusama, Block, self, RuntimeApiCollection, TFullClient};
use sp_api::ConstructRuntimeApi;
use sc_executor::NativeExecutionDispatch;
Expand Down Expand Up @@ -116,7 +116,7 @@ where
D: service::NativeExecutionDispatch + 'static,
// Rust bug: https://github.com/rust-lang/rust/issues/24159
<<R as ConstructRuntimeApi<Block, TFullClient<Block, R, D>>>::RuntimeApi as sp_api::ApiExt<Block>>::StateBackend:
sp_api::StateBackend<Blake2Hasher>,
sp_api::StateBackend<BlakeTwo256>,
// Rust bug: https://github.com/rust-lang/rust/issues/43580
R: ConstructRuntimeApi<
Block,
Expand All @@ -140,11 +140,11 @@ where
// We can't simply use `service::TLightClient` due to a
// Rust bug: https://github.com/rust-lang/rust/issues/43580
type TLightClient<Runtime, Dispatch> = sc_client::Client<
sc_client::light::backend::Backend<sc_client_db::light::LightStorage<Block>, Blake2Hasher>,
sc_client::light::backend::Backend<sc_client_db::light::LightStorage<Block>, BlakeTwo256>,
sc_client::light::call_executor::GenesisCallExecutor<
sc_client::light::backend::Backend<sc_client_db::light::LightStorage<Block>, Blake2Hasher>,
sc_client::light::backend::Backend<sc_client_db::light::LightStorage<Block>, BlakeTwo256>,
sc_client::LocalCallExecutor<
sc_client::light::backend::Backend<sc_client_db::light::LightStorage<Block>, Blake2Hasher>,
sc_client::light::backend::Backend<sc_client_db::light::LightStorage<Block>, BlakeTwo256>,
sc_executor::NativeExecutor<Dispatch>
>
>,
Expand Down
9 changes: 5 additions & 4 deletions collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ use std::time::Duration;
use futures::{future, Future, Stream, FutureExt, TryFutureExt, StreamExt, task::Spawn};
use log::warn;
use sc_client::BlockchainEvents;
use sp_core::{Pair, Blake2Hasher};
use sp_core::Pair;
use sp_runtime::traits::BlakeTwo256;
use polkadot_primitives::{
BlockId, Hash, Block,
parachain::{
Expand Down Expand Up @@ -145,14 +146,14 @@ pub trait BuildParachainContext {
<PolkadotClient<B, E, R> as ProvideRuntimeApi<Block>>::Api: RuntimeApiCollection<Extrinsic>,
// Rust bug: https://github.com/rust-lang/rust/issues/24159
<<PolkadotClient<B, E, R> as ProvideRuntimeApi<Block>>::Api as sp_api::ApiExt<Block>>::StateBackend:
sp_api::StateBackend<Blake2Hasher>,
sp_api::StateBackend<BlakeTwo256>,
Extrinsic: codec::Codec + Send + Sync + 'static,
E: sc_client::CallExecutor<Block> + Clone + Send + Sync + 'static,
SP: Spawn + Clone + Send + Sync + 'static,
R: Send + Sync + 'static,
B: sc_client_api::Backend<Block> + 'static,
// Rust bug: https://github.com/rust-lang/rust/issues/24159
B::State: sp_api::StateBackend<Blake2Hasher>;
B::State: sp_api::StateBackend<BlakeTwo256>;
}

/// Parachain context needed for collation.
Expand Down Expand Up @@ -236,7 +237,7 @@ fn build_collator_service<S, P, Extrinsic>(
S::Backend: service::Backend<service::Block>,
// Rust bug: https://github.com/rust-lang/rust/issues/24159
<S::Backend as service::Backend<service::Block>>::State:
sp_api::StateBackend<sp_runtime::traits::HasherFor<Block>>,
sp_api::StateBackend<sp_runtime::traits::HashFor<Block>>,
// Rust bug: https://github.com/rust-lang/rust/issues/24159
S::CallExecutor: service::CallExecutor<service::Block>,
// Rust bug: https://github.com/rust-lang/rust/issues/24159
Expand Down
6 changes: 3 additions & 3 deletions network/src/legacy/tests/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use polkadot_primitives::parachain::{
use parking_lot::Mutex;
use sp_blockchain::Result as ClientResult;
use sp_api::{ApiRef, Core, RuntimeVersion, StorageProof, ApiErrorExt, ApiExt, ProvideRuntimeApi};
use sp_runtime::traits::{Block as BlockT, HasherFor, NumberFor};
use sp_runtime::traits::{Block as BlockT, HashFor, NumberFor};
use sp_state_machine::ChangesTrieState;

use std::collections::HashMap;
Expand Down Expand Up @@ -206,7 +206,7 @@ impl ApiErrorExt for RuntimeApi {
}

impl ApiExt<Block> for RuntimeApi {
type StateBackend = sp_state_machine::InMemoryBackend<sp_api::HasherFor<Block>>;
type StateBackend = sp_state_machine::InMemoryBackend<HashFor<Block>>;

fn map_api_result<F: FnOnce(&Self) -> Result<R, E>, R, E>(
&self,
Expand All @@ -228,7 +228,7 @@ impl ApiExt<Block> for RuntimeApi {
fn into_storage_changes(
&self,
_: &Self::StateBackend,
_: Option<&ChangesTrieState<HasherFor<Block>, NumberFor<Block>>>,
_: Option<&ChangesTrieState<HashFor<Block>, NumberFor<Block>>>,
_: <Block as sp_api::BlockT>::Hash,
) -> std::result::Result<sp_api::StorageChanges<Self::StateBackend, Block>, String>
where Self: Sized
Expand Down
3 changes: 0 additions & 3 deletions network/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,9 +758,6 @@ async fn statement_import_loop<Api>(
if let Some(producer) = producer {
trace!(target: "validation", "driving statement work to completion");

let table = table.clone();
let gossip_handle = gossip_handle.clone();

let work = producer.prime(api.clone()).validate();
let work = future::select(work.boxed(), exit.clone()).map(drop);
let _ = executor.spawn(work);
Expand Down
9 changes: 8 additions & 1 deletion parachain/src/wasm_executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ pub fn validate_candidate<E: Externalities + 'static>(
/// The host functions provided by the wasm executor to the parachain wasm blob.
type HostFunctions = (
sp_io::SubstrateHostFunctions,
sc_executor::deprecated_host_interface::SubstrateExternals,
crate::wasm_api::parachain::HostFunctions,
);

Expand Down Expand Up @@ -251,6 +250,14 @@ impl sp_externalities::Externalities for ValidationExternalities {
fn next_storage_key(&self, _: &[u8]) -> Option<Vec<u8>> {
panic!("next_storage_key: unsupported feature for parachain validation")
}

fn wipe(&mut self) {
panic!("wipe: unsupported feature for parachain validation")
}

fn commit(&mut self) {
panic!("commit: unsupported feature for parachain validation")
}
}

impl sp_externalities::ExtensionStore for ValidationExternalities {
Expand Down
10 changes: 9 additions & 1 deletion runtime/common/src/attestations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,19 @@ impl RewardAttestation for () {

impl<T: staking::Trait> RewardAttestation for staking::Module<T> {
fn reward_immediate(validator_indices: impl IntoIterator<Item=u32>) {
use staking::SessionInterface;

// The number of points to reward for a validity statement.
// https://research.web3.foundation/en/latest/polkadot/Token%20Economics/#payment-details
const STAKING_REWARD_POINTS: u32 = 20;

Self::reward_by_indices(validator_indices.into_iter().map(|i| (i, STAKING_REWARD_POINTS)))
let validators = T::SessionInterface::validators();

let validator_rewards = validator_indices.into_iter()
.filter_map(|i| validators.get(i as usize).cloned())
.map(|v| (v, STAKING_REWARD_POINTS));

Self::reward_by_ids(validator_rewards);
}
}

Expand Down
3 changes: 2 additions & 1 deletion runtime/common/src/parachains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,7 @@ mod tests {
pub const SlashDeferDuration: staking::EraIndex = 7;
pub const AttestationPeriod: BlockNumber = 100;
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const MaxNominatorRewardedPerValidator: u32 = 64;
}

impl staking::Trait for Test {
Expand All @@ -1039,6 +1040,7 @@ mod tests {
type SessionInterface = Self;
type Time = timestamp::Module<Test>;
type RewardCurve = RewardCurve;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
}

impl attestations::Trait for Test {
Expand Down Expand Up @@ -1159,7 +1161,6 @@ mod tests {
}.assimilate_storage(&mut t).unwrap();

staking::GenesisConfig::<Test> {
current_era: 0,
stakers,
validator_count: 10,
minimum_validator_count: 8,
Expand Down
2 changes: 2 additions & 0 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ parameter_types! {
// 28 eras in which slashes can be cancelled (7 days).
pub const SlashDeferDuration: staking::EraIndex = 28;
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const MaxNominatorRewardedPerValidator: u32 = 64;
}

impl staking::Trait for Runtime {
Expand All @@ -292,6 +293,7 @@ impl staking::Trait for Runtime {
type SlashCancelOrigin = collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilCollective>;
type SessionInterface = Self;
type RewardCurve = RewardCurve;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
}

parameter_types! {
Expand Down
2 changes: 2 additions & 0 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ parameter_types! {
pub const BondingDuration: staking::EraIndex = 28;
pub const SlashDeferDuration: staking::EraIndex = 28;
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const MaxNominatorRewardedPerValidator: u32 = 64;
}

impl staking::Trait for Runtime {
Expand All @@ -299,6 +300,7 @@ impl staking::Trait for Runtime {
type SlashCancelOrigin = collective::EnsureProportionAtLeast<_3, _4, AccountId, CouncilCollective>;
type SessionInterface = Self;
type RewardCurve = RewardCurve;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ system_rpc_runtime_api = { package = "frame-system-rpc-runtime-api", git = "http
codec = { package = "parity-scale-codec", version = "1.1.0" }
sp-session = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
sp-offchain = { package = "sp-offchain", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
prometheus-endpoint = { package = "substrate-prometheus-endpoint", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }

[features]
default = ["rocksdb"]
Expand Down
2 changes: 0 additions & 2 deletions service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ fn staging_testnet_config_genesis() -> polkadot::GenesisConfig {
)).collect::<Vec<_>>(),
}),
staking: Some(polkadot::StakingConfig {
current_era: 0,
validator_count: 50,
minimum_validator_count: 4,
stakers: initial_authorities
Expand Down Expand Up @@ -325,7 +324,6 @@ pub fn testnet_genesis(
)).collect::<Vec<_>>(),
}),
staking: Some(polkadot::StakingConfig {
current_era: 0,
minimum_validator_count: 1,
validator_count: 2,
stakers: initial_authorities.iter()
Expand Down
Loading

0 comments on commit 0218b0c

Please sign in to comment.