Skip to content

Commit

Permalink
Merged companions and update Subtrate (paritytech#882)
Browse files Browse the repository at this point in the history
* expunge legacy code from polkadot-network

* mostly rip out old legacy protocol from service

* ensure validation work is spawned by incoming messages

* decouple availabliity store from network logic; clean up data flow

* av_store: test helpers and use futures-abort

* update polkadot-validation to pass n_validators when submitting chunks

* fallible erasure-chunk fetching

* implement `ErasureNetworking` for new network prot

* API for registering availability store in network

* fully integrate new network service into service

* fix validation tests

* scaffolding for porting collator over to new network

* track connected validators' peer IDs and distribute collators' collations

* helper in network for fetching all checked statements

* fix adder-collator

* actually register notifications protocol

* Update service/src/lib.rs

* Make needed changes to service

* Merge two companion PRs.

- paritytech#880
- paritytech#881

* Some effort towards compilation

* Fix

* remove `NetworkSpecialization` references from network

* fix compilation errors in service and collator

* ensure protocol name is valid

* Fixes

* Fix

Co-authored-by: Robert Habermeier <[email protected]>
Co-authored-by: Ashley <[email protected]>
  • Loading branch information
3 people authored and General-Beck committed Mar 19, 2020
1 parent 7fcf651 commit 1b0d03b
Show file tree
Hide file tree
Showing 12 changed files with 382 additions and 324 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ runtime/wasm/target/
.vscode
polkadot.*
.DS_Store
.cargo
549 changes: 292 additions & 257 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ use polkadot_cli::{
ProvideRuntimeApi, AbstractService, ParachainHost, IsKusama,
service::{self, Roles}
};
use polkadot_network::PolkadotProtocol;
pub use polkadot_cli::{VersionInfo, load_spec, service::Configuration};
pub use polkadot_validation::SignedStatement;
pub use polkadot_primitives::parachain::CollatorId;
Expand Down Expand Up @@ -212,7 +211,7 @@ fn build_collator_service<S, P, Extrinsic>(
build_parachain_context: P,
) -> Result<S, polkadot_service::Error>
where
S: AbstractService<Block = service::Block, NetworkSpecialization = PolkadotProtocol>,
S: AbstractService<Block = service::Block>,
sc_client::Client<S::Backend, S::CallExecutor, service::Block, S::RuntimeApi>: ProvideRuntimeApi<Block>,
<sc_client::Client<S::Backend, S::CallExecutor, service::Block, S::RuntimeApi> as ProvideRuntimeApi<Block>>::Api:
RuntimeApiCollection<
Expand Down
27 changes: 9 additions & 18 deletions network/src/legacy/gossip/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
use sp_runtime::traits::{BlakeTwo256, Hash as HashT};
use sp_blockchain::Error as ClientError;
use sc_network::{config::Roles, PeerId, ReputationChange};
use sc_network::{NetworkService as SubstrateNetworkService, specialization::NetworkSpecialization};
use sc_network::NetworkService;
use sc_network_gossip::{
ValidationResult as GossipValidationResult,
ValidatorContext, MessageIntent,
Expand Down Expand Up @@ -266,11 +266,11 @@ pub(crate) fn attestation_topic(parent_hash: Hash) -> Hash {
// NOTE: since RegisteredMessageValidator is meant to be a type-safe proof
// that we've actually done the registration, this should be the only way
// to construct it outside of tests.
pub fn register_validator<C: ChainContext + 'static, S: NetworkSpecialization<Block>>(
service: Arc<SubstrateNetworkService<Block, S, Hash>>,
pub fn register_validator<C: ChainContext + 'static>(
service: Arc<NetworkService<Block, Hash>>,
chain: C,
executor: &impl futures::task::Spawn,
) -> RegisteredMessageValidator<S>
) -> RegisteredMessageValidator
{
let s = service.clone();
let report_handle = Box::new(move |peer: &PeerId, cost_benefit: ReputationChange| {
Expand Down Expand Up @@ -344,25 +344,16 @@ impl NewLeafActions {
/// A registered message validator.
///
/// Create this using `register_validator`.
pub struct RegisteredMessageValidator<S: NetworkSpecialization<Block>> {
#[derive(Clone)]
pub struct RegisteredMessageValidator {
inner: Arc<MessageValidator<dyn ChainContext>>,
// Note: this is always `Some` in real code and `None` in tests.
service: Option<Arc<SubstrateNetworkService<Block, S, Hash>>>,
service: Option<Arc<NetworkService<Block, Hash>>>,
// Note: this is always `Some` in real code and `None` in tests.
gossip_engine: Option<sc_network_gossip::GossipEngine<Block>>,
}

impl<S: NetworkSpecialization<Block>> Clone for RegisteredMessageValidator<S> {
fn clone(&self) -> Self {
RegisteredMessageValidator {
inner: self.inner.clone(),
service: self.service.clone(),
gossip_engine: self.gossip_engine.clone(),
}
}
}

impl<S: NetworkSpecialization<Block>> RegisteredMessageValidator<S> {
impl RegisteredMessageValidator {
/// Register an availabilty store the gossip service can query.
pub(crate) fn register_availability_store(&self, availability_store: av_store::Store) {
self.inner.inner.write().availability_store = Some(availability_store);
Expand Down Expand Up @@ -437,7 +428,7 @@ impl<S: NetworkSpecialization<Block>> RegisteredMessageValidator<S> {
}
}

impl<S: NetworkSpecialization<Block>> GossipService for RegisteredMessageValidator<S> {
impl GossipService for RegisteredMessageValidator {
fn gossip_messages_for(&self, topic: Hash) -> GossipMessageStream {
RegisteredMessageValidator::gossip_messages_for(self, topic)
}
Expand Down
10 changes: 2 additions & 8 deletions network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,8 @@ use polkadot_primitives::{Block, Hash, BlakeTwo256, HashT};
pub mod legacy;
pub mod protocol;

sc_network::construct_simple_protocol! {
/// Stub until https://github.com/paritytech/substrate/pull/4665 is merged
#[derive(Clone)]
pub struct PolkadotProtocol where Block = Block { }
}

/// Specialization of the network service for the polkadot protocol.
pub type PolkadotNetworkService = sc_network::NetworkService<Block, PolkadotProtocol, Hash>;
/// Specialization of the network service for the polkadot block type.
pub type PolkadotNetworkService = sc_network::NetworkService<Block, Hash>;

mod cost {
use sc_network::ReputationChange as Rep;
Expand Down
6 changes: 2 additions & 4 deletions network/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use std::time::Duration;

use super::{cost, benefit, PolkadotNetworkService};
use crate::legacy::collator_pool::Role as CollatorRole;
use crate::legacy::gossip::{GossipMessage, ErasureChunkMessage};
use crate::legacy::gossip::{GossipMessage, ErasureChunkMessage, RegisteredMessageValidator};

/// The current protocol version.
pub const VERSION: u32 = 1;
Expand All @@ -60,7 +60,7 @@ pub const MIN_SUPPORTED_VERSION: u32 = 1;
/// The engine ID of the polkadot network protocol.
pub const POLKADOT_ENGINE_ID: sp_runtime::ConsensusEngineId = *b"dot2";
/// The protocol name.
pub const POLKADOT_PROTOCOL_NAME: &[u8] = b"dot2-proto";
pub const POLKADOT_PROTOCOL_NAME: &[u8] = b"/polkadot/1";

pub use crate::legacy::gossip::ChainContext;

Expand Down Expand Up @@ -305,8 +305,6 @@ struct ConsensusNetworkingInstance {
_drop_signal: exit_future::Signal,
}

type RegisteredMessageValidator = crate::legacy::gossip::RegisteredMessageValidator<crate::PolkadotProtocol>;

/// Protocol configuration.
#[derive(Default)]
pub struct Config {
Expand Down
1 change: 1 addition & 0 deletions parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ serde = { version = "1.0.102", default-features = false, features = [ "derive" ]
rstd = { package = "sp-std", git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
sp-runtime-interface = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
sp-wasm-interface = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", default-features = false }
sp-externalities = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", optional = true }
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", optional = true }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master", optional = true }
Expand Down
17 changes: 11 additions & 6 deletions parachain/src/wasm_executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ use std::any::{TypeId, Any};
use crate::{ValidationParams, ValidationResult, UpwardMessage};
use codec::{Decode, Encode};
use sp_core::storage::{ChildStorageKey, ChildInfo};
use sp_core::traits::CallInWasm;
use sp_wasm_interface::HostFunctions as _;

#[cfg(not(target_os = "unknown"))]
pub use validation_host::{run_worker, EXECUTION_TIMEOUT_SEC};
Expand Down Expand Up @@ -156,15 +158,18 @@ pub fn validate_candidate_internal<E: Externalities + 'static>(
) -> Result<ValidationResult, Error> {
let mut ext = ValidationExternalities(ParachainExt::new(externalities));

let res = sc_executor::call_in_wasm::<HostFunctions>(
"validate_block",
encoded_call_data,
let executor = sc_executor::WasmExecutor::new(
sc_executor::WasmExecutionMethod::Interpreted,
&mut ext,
validation_code,
// TODO: Make sure we don't use more than 1GB: https://github.com/paritytech/polkadot/issues/699
1024,
Some(1024),
HostFunctions::host_functions(),
false,
);
let res = executor.call_in_wasm(
validation_code,
"validate_block",
encoded_call_data,
&mut ext,
)?;

ValidationResult::decode(&mut &res[..]).map_err(|_| Error::BadReturn.into())
Expand Down
2 changes: 2 additions & 0 deletions runtime/common/src/claims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ mod tests {
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
pub const CreationFee: u64 = 0;
pub const MinVestedTransfer: u64 = 0;
}

impl balances::Trait for Test {
Expand All @@ -344,6 +345,7 @@ mod tests {
type Event = ();
type Currency = Balances;
type BlockNumberToBalance = Identity;
type MinVestedTransfer = MinVestedTransfer;
}

parameter_types!{
Expand Down
16 changes: 16 additions & 0 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,16 @@ impl democracy::Trait for Runtime {
type Slash = Treasury;
}

parameter_types! {
pub const CouncilMotionDuration: BlockNumber = 3 * DAYS;
}

type CouncilCollective = collective::Instance1;
impl collective::Trait<CouncilCollective> for Runtime {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
type MotionDuration = CouncilMotionDuration;
}

parameter_types! {
Expand All @@ -367,11 +372,16 @@ impl elections_phragmen::Trait for Runtime {
type TermDuration = TermDuration;
}

parameter_types! {
pub const TechnicalMotionDuration: BlockNumber = 3 * DAYS;
}

type TechnicalCollective = collective::Instance2;
impl collective::Trait<TechnicalCollective> for Runtime {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
type MotionDuration = TechnicalMotionDuration;
}

impl membership::Trait<membership::Instance1> for Runtime {
Expand All @@ -380,6 +390,7 @@ impl membership::Trait<membership::Instance1> for Runtime {
type RemoveOrigin = collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
type SwapOrigin = collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
type ResetOrigin = collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
type PrimeOrigin = collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
type MembershipInitialized = TechnicalCommittee;
type MembershipChanged = TechnicalCommittee;
}
Expand Down Expand Up @@ -599,10 +610,15 @@ impl society::Trait for Runtime {
type ChallengePeriod = ChallengePeriod;
}

parameter_types! {
pub const MinVestedTransfer: Balance = 100 * DOLLARS;
}

impl vesting::Trait for Runtime {
type Event = Event;
type Currency = Balances;
type BlockNumberToBalance = ConvertInto;
type MinVestedTransfer = MinVestedTransfer;
}

construct_runtime! {
Expand Down
16 changes: 16 additions & 0 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,16 @@ impl democracy::Trait for Runtime {
type Slash = Treasury;
}

parameter_types! {
pub const CouncilMotionDuration: BlockNumber = 7 * DAYS;
}

type CouncilCollective = collective::Instance1;
impl collective::Trait<CouncilCollective> for Runtime {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
type MotionDuration = CouncilMotionDuration;
}

parameter_types! {
Expand Down Expand Up @@ -375,11 +380,16 @@ impl elections_phragmen::Trait for Runtime {
type TermDuration = TermDuration;
}

parameter_types! {
pub const TechnicalMotionDuration: BlockNumber = 7 * DAYS;
}

type TechnicalCollective = collective::Instance2;
impl collective::Trait<TechnicalCollective> for Runtime {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
type MotionDuration = TechnicalMotionDuration;
}

impl membership::Trait<membership::Instance1> for Runtime {
Expand All @@ -388,6 +398,7 @@ impl membership::Trait<membership::Instance1> for Runtime {
type RemoveOrigin = collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
type SwapOrigin = collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
type ResetOrigin = collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
type PrimeOrigin = collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
type MembershipInitialized = TechnicalCommittee;
type MembershipChanged = TechnicalCommittee;
}
Expand Down Expand Up @@ -525,10 +536,15 @@ impl claims::Trait for Runtime {
type Prefix = Prefix;
}

parameter_types! {
pub const MinVestedTransfer: Balance = 100 * DOLLARS;
}

impl vesting::Trait for Runtime {
type Event = Event;
type Currency = Balances;
type BlockNumberToBalance = ConvertInto;
type MinVestedTransfer = MinVestedTransfer;
}

impl sudo::Trait for Runtime {
Expand Down
Loading

0 comments on commit 1b0d03b

Please sign in to comment.