Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Backport of Substrate update (#515)
Browse files Browse the repository at this point in the history
* Update Substrate (#514)

* Update Substrate

* Attempt a fix

* Update substrate again

* Fix compilation

* update substrate add support for sentry

* Fixes tests

* Actually update substrate
  • Loading branch information
gavofyork authored Oct 29, 2019
1 parent 775a6d5 commit 39397ab
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 172 deletions.
279 changes: 138 additions & 141 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub use service::{
};

pub use cli::{VersionInfo, IntoExit, NoCustom};
pub use cli::error;
pub use cli::{display_role, error};

/// Abstraction over an executor that lets you spawn tasks in the background.
pub type TaskExecutor = Arc<dyn futures::future::Executor<Box<dyn Future<Item = (), Error = ()> + Send>> + Send + Sync>;
Expand Down Expand Up @@ -98,7 +98,7 @@ pub fn run<W>(worker: W, version: cli::VersionInfo) -> error::Result<()> where
info!(" by {}, 2017-2019", version.author);
info!("Chain specification: {}", config.chain_spec.name());
info!("Node name: {}", config.name);
info!("Roles: {:?}", config.roles);
info!("Roles: {}", display_role(&config));
config.custom = worker.configuration();
let runtime = Runtime::new().map_err(|e| format!("{:?}", e))?;
match config.roles {
Expand Down
28 changes: 7 additions & 21 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ use client::{
runtime_api as client_api, impl_runtime_apis,
};
use sr_primitives::{
create_runtime_str, generic, impl_opaque_keys, key_types,
create_runtime_str, generic, impl_opaque_keys,
ApplyResult, Permill, Perbill, RuntimeDebug,
transaction_validity::{TransactionValidity, InvalidTransaction, TransactionValidityError},
weights::{Weight, DispatchInfo}, curve::PiecewiseLinear,
traits::{BlakeTwo256, Block as BlockT, StaticLookup, SignedExtension},
traits::{BlakeTwo256, Block as BlockT, StaticLookup, SignedExtension, OpaqueKeys},
};
use version::RuntimeVersion;
use grandpa::{AuthorityId as GrandpaId, fg_primitives};
use babe_primitives::{AuthorityId as BabeId};
#[cfg(any(feature = "std", test))]
use version::NativeVersion;
use substrate_primitives::OpaqueMetadata;
Expand Down Expand Up @@ -256,35 +255,22 @@ parameter_types! {
pub const Offset: BlockNumber = 0;
}

// !!!!!!!!!!!!!
// WARNING!!!!!! SEE NOTE BELOW BEFORE TOUCHING THIS CODE
// !!!!!!!!!!!!!
type SessionHandlers = (Grandpa, Babe, ImOnline, Parachains);
impl_opaque_keys! {
pub struct SessionKeys {
#[id(key_types::GRANDPA)]
pub grandpa: GrandpaId,
#[id(key_types::BABE)]
pub babe: BabeId,
#[id(key_types::IM_ONLINE)]
pub im_online: ImOnlineId,
#[id(parachain::PARACHAIN_KEY_TYPE_ID)]
pub parachain_validator: parachain::ValidatorId,
pub grandpa: Grandpa,
pub babe: Babe,
pub im_online: ImOnline,
pub parachain_validator: Parachains,
}
}
// NOTE: `SessionHandler` and `SessionKeys` are co-dependent: One key will be used for each handler.
// The number and order of items in `SessionHandler` *MUST* be the same number and order of keys in
// `SessionKeys`.
// TODO: Introduce some structure to tie these together to make it a bit less of a footgun. This
// should be easy, since OneSessionHandler trait provides the `Key` as an associated type. #2858

parameter_types! {
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(17);
}

impl session::Trait for Runtime {
type OnSessionEnding = Staking;
type SessionHandler = SessionHandlers;
type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
type ShouldEndSession = Babe;
type Event = Event;
type Keys = SessionKeys;
Expand Down
16 changes: 11 additions & 5 deletions runtime/src/parachains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,10 @@ impl<T: Trait> Module<T> {
*/
}

impl<T: Trait> sr_primitives::BoundToRuntimeAppPublic for Module<T> {
type Public = ValidatorId;
}

impl<T: Trait> session::OneSessionHandler<T::AccountId> for Module<T> {
type Key = ValidatorId;

Expand Down Expand Up @@ -902,13 +906,14 @@ mod tests {
use substrate_primitives::{H256, Blake2Hasher};
use substrate_trie::NodeCodec;
use sr_primitives::{
Perbill,
Perbill, curve::PiecewiseLinear, testing::{UintAuthorityId, Header},
traits::{BlakeTwo256, IdentityLookup, OnInitialize, OnFinalize},
testing::{UintAuthorityId, Header},
curve::PiecewiseLinear,
};
use primitives::{
parachain::{CandidateReceipt, HeadData, ValidityAttestation, ValidatorId, Info as ParaInfo, Scheduling},
parachain::{
CandidateReceipt, HeadData, ValidityAttestation, ValidatorId, Info as ParaInfo,
Scheduling,
},
BlockNumber,
};
use crate::constants::time::*;
Expand Down Expand Up @@ -940,6 +945,7 @@ mod tests {
pub const MaximumBlockLength: u32 = 4 * 1024 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
}

impl system::Trait for Test {
type Origin = Origin;
type Call = Call;
Expand Down Expand Up @@ -968,7 +974,7 @@ mod tests {
type OnSessionEnding = ();
type Keys = UintAuthorityId;
type ShouldEndSession = session::PeriodicSessions<Period, Offset>;
type SessionHandler = ();
type SessionHandler = session::TestSessionHandler;
type Event = ();
type SelectInitialValidators = staking::Module<Self>;
type ValidatorId = u64;
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ mod tests {
type OnSessionEnding = ();
type Keys = UintAuthorityId;
type ShouldEndSession = session::PeriodicSessions<Period, Offset>;
type SessionHandler = ();
type SessionHandler = session::TestSessionHandler;
type Event = ();
type SelectInitialValidators = ();
type ValidatorId = u64;
Expand Down
13 changes: 11 additions & 2 deletions service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
let disable_grandpa = config.disable_grandpa;
let name = config.name.clone();

// sentry nodes announce themselves as authorities to the network
// and should run the same protocols authorities do, but it should
// never actively participate in any consensus process.
let participates_in_consensus = is_authority && !config.sentry_mode;

let (builder, mut import_setup, inherent_data_providers) = new_full_start!(config);

// Dht event channel from the network to the authority discovery module. Use
Expand Down Expand Up @@ -204,7 +209,7 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
(is_known, client.clone()),
);

if is_authority {
if participates_in_consensus {
let availability_store = {
use std::path::PathBuf;

Expand Down Expand Up @@ -264,7 +269,9 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
service.spawn_essential_task(babe);
}

let keystore = if is_authority {
// if the node isn't actively participating in consensus then it doesn't
// need a keystore, regardless of which protocol we use below.
let keystore = if participates_in_consensus {
Some(service.keystore())
} else {
None
Expand All @@ -275,7 +282,9 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
gossip_duration: Duration::from_millis(333),
justification_period: 512,
name: Some(name),
observer_enabled: false,
keystore,
is_authority,
};

let enable_grandpa = !disable_grandpa;
Expand Down

0 comments on commit 39397ab

Please sign in to comment.