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

Commit 39397ab

Browse files
authored
Backport of Substrate update (#515)
* Update Substrate (#514) * Update Substrate * Attempt a fix * Update substrate again * Fix compilation * update substrate add support for sentry * Fixes tests * Actually update substrate
1 parent 775a6d5 commit 39397ab

File tree

6 files changed

+170
-172
lines changed

6 files changed

+170
-172
lines changed

Cargo.lock

Lines changed: 138 additions & 141 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub use service::{
3434
};
3535

3636
pub use cli::{VersionInfo, IntoExit, NoCustom};
37-
pub use cli::error;
37+
pub use cli::{display_role, error};
3838

3939
/// Abstraction over an executor that lets you spawn tasks in the background.
4040
pub type TaskExecutor = Arc<dyn futures::future::Executor<Box<dyn Future<Item = (), Error = ()> + Send>> + Send + Sync>;
@@ -98,7 +98,7 @@ pub fn run<W>(worker: W, version: cli::VersionInfo) -> error::Result<()> where
9898
info!(" by {}, 2017-2019", version.author);
9999
info!("Chain specification: {}", config.chain_spec.name());
100100
info!("Node name: {}", config.name);
101-
info!("Roles: {:?}", config.roles);
101+
info!("Roles: {}", display_role(&config));
102102
config.custom = worker.configuration();
103103
let runtime = Runtime::new().map_err(|e| format!("{:?}", e))?;
104104
match config.roles {

runtime/src/lib.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,14 @@ use client::{
4040
runtime_api as client_api, impl_runtime_apis,
4141
};
4242
use sr_primitives::{
43-
create_runtime_str, generic, impl_opaque_keys, key_types,
43+
create_runtime_str, generic, impl_opaque_keys,
4444
ApplyResult, Permill, Perbill, RuntimeDebug,
4545
transaction_validity::{TransactionValidity, InvalidTransaction, TransactionValidityError},
4646
weights::{Weight, DispatchInfo}, curve::PiecewiseLinear,
47-
traits::{BlakeTwo256, Block as BlockT, StaticLookup, SignedExtension},
47+
traits::{BlakeTwo256, Block as BlockT, StaticLookup, SignedExtension, OpaqueKeys},
4848
};
4949
use version::RuntimeVersion;
5050
use grandpa::{AuthorityId as GrandpaId, fg_primitives};
51-
use babe_primitives::{AuthorityId as BabeId};
5251
#[cfg(any(feature = "std", test))]
5352
use version::NativeVersion;
5453
use substrate_primitives::OpaqueMetadata;
@@ -256,35 +255,22 @@ parameter_types! {
256255
pub const Offset: BlockNumber = 0;
257256
}
258257

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

281267
parameter_types! {
282268
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(17);
283269
}
284270

285271
impl session::Trait for Runtime {
286272
type OnSessionEnding = Staking;
287-
type SessionHandler = SessionHandlers;
273+
type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
288274
type ShouldEndSession = Babe;
289275
type Event = Event;
290276
type Keys = SessionKeys;

runtime/src/parachains.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,10 @@ impl<T: Trait> Module<T> {
842842
*/
843843
}
844844

845+
impl<T: Trait> sr_primitives::BoundToRuntimeAppPublic for Module<T> {
846+
type Public = ValidatorId;
847+
}
848+
845849
impl<T: Trait> session::OneSessionHandler<T::AccountId> for Module<T> {
846850
type Key = ValidatorId;
847851

@@ -902,13 +906,14 @@ mod tests {
902906
use substrate_primitives::{H256, Blake2Hasher};
903907
use substrate_trie::NodeCodec;
904908
use sr_primitives::{
905-
Perbill,
909+
Perbill, curve::PiecewiseLinear, testing::{UintAuthorityId, Header},
906910
traits::{BlakeTwo256, IdentityLookup, OnInitialize, OnFinalize},
907-
testing::{UintAuthorityId, Header},
908-
curve::PiecewiseLinear,
909911
};
910912
use primitives::{
911-
parachain::{CandidateReceipt, HeadData, ValidityAttestation, ValidatorId, Info as ParaInfo, Scheduling},
913+
parachain::{
914+
CandidateReceipt, HeadData, ValidityAttestation, ValidatorId, Info as ParaInfo,
915+
Scheduling,
916+
},
912917
BlockNumber,
913918
};
914919
use crate::constants::time::*;
@@ -940,6 +945,7 @@ mod tests {
940945
pub const MaximumBlockLength: u32 = 4 * 1024 * 1024;
941946
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
942947
}
948+
943949
impl system::Trait for Test {
944950
type Origin = Origin;
945951
type Call = Call;
@@ -968,7 +974,7 @@ mod tests {
968974
type OnSessionEnding = ();
969975
type Keys = UintAuthorityId;
970976
type ShouldEndSession = session::PeriodicSessions<Period, Offset>;
971-
type SessionHandler = ();
977+
type SessionHandler = session::TestSessionHandler;
972978
type Event = ();
973979
type SelectInitialValidators = staking::Module<Self>;
974980
type ValidatorId = u64;

runtime/src/registrar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ mod tests {
688688
type OnSessionEnding = ();
689689
type Keys = UintAuthorityId;
690690
type ShouldEndSession = session::PeriodicSessions<Period, Offset>;
691-
type SessionHandler = ();
691+
type SessionHandler = session::TestSessionHandler;
692692
type Event = ();
693693
type SelectInitialValidators = ();
694694
type ValidatorId = u64;

service/src/lib.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
150150
let disable_grandpa = config.disable_grandpa;
151151
let name = config.name.clone();
152152

153+
// sentry nodes announce themselves as authorities to the network
154+
// and should run the same protocols authorities do, but it should
155+
// never actively participate in any consensus process.
156+
let participates_in_consensus = is_authority && !config.sentry_mode;
157+
153158
let (builder, mut import_setup, inherent_data_providers) = new_full_start!(config);
154159

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

207-
if is_authority {
212+
if participates_in_consensus {
208213
let availability_store = {
209214
use std::path::PathBuf;
210215

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

267-
let keystore = if is_authority {
272+
// if the node isn't actively participating in consensus then it doesn't
273+
// need a keystore, regardless of which protocol we use below.
274+
let keystore = if participates_in_consensus {
268275
Some(service.keystore())
269276
} else {
270277
None
@@ -275,7 +282,9 @@ pub fn new_full(config: Configuration<CustomConfiguration, GenesisConfig>)
275282
gossip_duration: Duration::from_millis(333),
276283
justification_period: 512,
277284
name: Some(name),
285+
observer_enabled: false,
278286
keystore,
287+
is_authority,
279288
};
280289

281290
let enable_grandpa = !disable_grandpa;

0 commit comments

Comments
 (0)