Remove Default bound for AccountId (#10403)

* Remove Default for AccountId

* More removals of default

* Update frame/authorship/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update frame/authorship/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update frame/authorship/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update frame/authorship/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* More work

* More work

* Remove old code

* More work

* pallet-asset-tx-payment

* tips

* sc-consensus-babe

* sc-finality-grandpa

* sc-consensus-babe-rpc

* sc-cli

* make npos crates accept non-default account (#10420)

* minimal changes to make npos pallets all work

* make this pesky reduce.rs a bit cleaner

* more work

* more work

* Tests build

* Fix imonline tests

* Formatting

* Fixes

* Fixes

* Fix bench

* Fixes

* Fixes

* Fixes

* Fixes

* Fixes

* Formatting

* Fixes

* Formatting

* Fixes

* Formatting

* Fixes

* Formatting

* Fixes

* Formatting

* Update client/keystore/src/local.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/finality-grandpa/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/keystore/src/local.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/keystore/src/local.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update frame/staking/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update frame/staking/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update primitives/runtime/src/traits.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Formatting

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: kianenigma <kian@parity.io>
This commit is contained in:
Gavin Wood
2021-12-13 15:03:59 +01:00
committed by GitHub
parent a4ccc26e33
commit 1e24e45ea1
118 changed files with 998 additions and 4181 deletions
@@ -179,7 +179,7 @@ mod tests {
report, AuthorityId, FinalityProof, GrandpaJustification, GrandpaJustificationSender,
};
use sp_blockchain::HeaderBackend;
use sp_core::crypto::Public;
use sp_core::crypto::ByteArray;
use sp_keyring::Ed25519Keyring;
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
use substrate_test_runtime_client::{
@@ -196,8 +196,8 @@ mod tests {
}
fn voters() -> HashSet<AuthorityId> {
let voter_id_1 = AuthorityId::from_slice(&[1; 32]);
let voter_id_2 = AuthorityId::from_slice(&[2; 32]);
let voter_id_1 = AuthorityId::from_slice(&[1; 32]).unwrap();
let voter_id_2 = AuthorityId::from_slice(&[2; 32]).unwrap();
vec![voter_id_1, voter_id_2].into_iter().collect()
}
@@ -245,7 +245,7 @@ mod tests {
impl ReportVoterState for TestVoterState {
fn get(&self) -> Option<report::VoterState<AuthorityId>> {
let voter_id_1 = AuthorityId::from_slice(&[1; 32]);
let voter_id_1 = AuthorityId::from_slice(&[1; 32]).unwrap();
let voters_best: HashSet<_> = vec![voter_id_1].into_iter().collect();
let best_round_state = sc_finality_grandpa::report::RoundState {
@@ -753,7 +753,7 @@ impl<N: Ord + Clone> AuthoritySetChanges<N> {
#[cfg(test)]
mod tests {
use super::*;
use sp_core::crypto::Public;
use sp_core::crypto::{ByteArray, UncheckedFrom};
fn static_is_descendent_of<A>(value: bool) -> impl Fn(&A, &A) -> Result<bool, std::io::Error> {
move |_, _| Ok(value)
@@ -768,7 +768,7 @@ mod tests {
#[test]
fn current_limit_filters_min() {
let current_authorities = vec![(AuthorityId::from_slice(&[1; 32]), 1)];
let current_authorities = vec![(AuthorityId::from_slice(&[1; 32]).unwrap(), 1)];
let mut authorities = AuthoritySet {
current_authorities: current_authorities.clone(),
@@ -802,7 +802,7 @@ mod tests {
#[test]
fn changes_iterated_in_pre_order() {
let current_authorities = vec![(AuthorityId::from_slice(&[1; 32]), 1)];
let current_authorities = vec![(AuthorityId::from_slice(&[1; 32]).unwrap(), 1)];
let mut authorities = AuthoritySet {
current_authorities: current_authorities.clone(),
@@ -894,8 +894,8 @@ mod tests {
authority_set_changes: AuthoritySetChanges::empty(),
};
let set_a = vec![(AuthorityId::from_slice(&[1; 32]), 5)];
let set_b = vec![(AuthorityId::from_slice(&[2; 32]), 5)];
let set_a = vec![(AuthorityId::from_slice(&[1; 32]).unwrap(), 5)];
let set_b = vec![(AuthorityId::from_slice(&[2; 32]).unwrap(), 5)];
// two competing changes at the same height on different forks
let change_a = PendingChange {
@@ -977,8 +977,8 @@ mod tests {
authority_set_changes: AuthoritySetChanges::empty(),
};
let set_a = vec![(AuthorityId::from_slice(&[1; 32]), 5)];
let set_c = vec![(AuthorityId::from_slice(&[2; 32]), 5)];
let set_a = vec![(AuthorityId::from_slice(&[1; 32]).unwrap(), 5)];
let set_c = vec![(AuthorityId::from_slice(&[2; 32]).unwrap(), 5)];
// two competing changes at the same height on different forks
let change_a = PendingChange {
@@ -1057,7 +1057,7 @@ mod tests {
authority_set_changes: AuthoritySetChanges::empty(),
};
let set_a = vec![(AuthorityId::from_slice(&[1; 32]), 5)];
let set_a = vec![(AuthorityId::from_slice(&[1; 32]).unwrap(), 5)];
let change_a = PendingChange {
next_authorities: set_a.clone(),
@@ -1128,8 +1128,8 @@ mod tests {
authority_set_changes: AuthoritySetChanges::empty(),
};
let set_a = vec![(AuthorityId::from_slice(&[1; 32]), 5)];
let set_b = vec![(AuthorityId::from_slice(&[2; 32]), 5)];
let set_a = vec![(AuthorityId::from_slice(&[1; 32]).unwrap(), 5)];
let set_b = vec![(AuthorityId::from_slice(&[2; 32]).unwrap(), 5)];
let change_a = PendingChange {
next_authorities: set_a.clone(),
@@ -1228,7 +1228,7 @@ mod tests {
authority_set_changes: AuthoritySetChanges::empty(),
};
let set_a = vec![(AuthorityId::from_slice(&[1; 32]), 5)];
let set_a = vec![(AuthorityId::from_slice(&[1; 32]).unwrap(), 5)];
// we create a forced change with no delay
let change_a = PendingChange {
@@ -1253,7 +1253,7 @@ mod tests {
#[test]
fn forced_changes_blocked_by_standard_changes() {
let set_a = vec![(AuthorityId::from_slice(&[1; 32]), 1)];
let set_a = vec![(AuthorityId::from_slice(&[1; 32]).unwrap(), 1)];
let mut authorities = AuthoritySet {
current_authorities: set_a.clone(),
@@ -1378,7 +1378,7 @@ mod tests {
#[test]
fn next_change_works() {
let current_authorities = vec![(AuthorityId::from_slice(&[1; 32]), 1)];
let current_authorities = vec![(AuthorityId::from_slice(&[1; 32]).unwrap(), 1)];
let mut authorities = AuthoritySet {
current_authorities: current_authorities.clone(),
@@ -1493,8 +1493,10 @@ mod tests {
None,
);
let invalid_authorities_weight =
vec![(AuthorityId::from_slice(&[1; 32]), 5), (AuthorityId::from_slice(&[2; 32]), 0)];
let invalid_authorities_weight = vec![
(AuthorityId::from_slice(&[1; 32]).unwrap(), 5),
(AuthorityId::from_slice(&[2; 32]).unwrap(), 0),
];
// authority weight of zero is invalid
assert_eq!(AuthoritySet::<(), ()>::genesis(invalid_authorities_weight.clone()), None);
@@ -1510,7 +1512,8 @@ mod tests {
);
let mut authority_set =
AuthoritySet::<(), u64>::genesis(vec![(AuthorityId::from_slice(&[1; 32]), 5)]).unwrap();
AuthoritySet::<(), u64>::genesis(vec![(AuthorityId::unchecked_from([1; 32]), 5)])
.unwrap();
let invalid_change_empty_authorities = PendingChange {
next_authorities: vec![],
@@ -1550,7 +1553,7 @@ mod tests {
#[test]
fn cleans_up_stale_forced_changes_when_applying_standard_change() {
let current_authorities = vec![(AuthorityId::from_slice(&[1; 32]), 1)];
let current_authorities = vec![(AuthorityId::from_slice(&[1; 32]).unwrap(), 1)];
let mut authorities = AuthoritySet {
current_authorities: current_authorities.clone(),
@@ -498,15 +498,19 @@ pub(crate) fn load_authorities<B: AuxStore, H: Decode, N: Decode + Clone + Ord>(
#[cfg(test)]
mod test {
use super::*;
use sp_core::H256;
use sp_core::{crypto::UncheckedFrom, H256};
use sp_finality_grandpa::AuthorityId;
use substrate_test_runtime_client;
fn dummy_id() -> AuthorityId {
AuthorityId::unchecked_from([1; 32])
}
#[test]
fn load_decode_from_v0_migrates_data_format() {
let client = substrate_test_runtime_client::new();
let authorities = vec![(AuthorityId::default(), 100)];
let authorities = vec![(dummy_id(), 100)];
let set_id = 3;
let round_number: RoundNumber = 42;
let round_state = RoundState::<H256, u64> {
@@ -595,7 +599,7 @@ mod test {
fn load_decode_from_v1_migrates_data_format() {
let client = substrate_test_runtime_client::new();
let authorities = vec![(AuthorityId::default(), 100)];
let authorities = vec![(dummy_id(), 100)];
let set_id = 3;
let round_number: RoundNumber = 42;
let round_state = RoundState::<H256, u64> {
@@ -688,7 +692,7 @@ mod test {
fn load_decode_from_v2_migrates_data_format() {
let client = substrate_test_runtime_client::new();
let authorities = vec![(AuthorityId::default(), 100)];
let authorities = vec![(dummy_id(), 100)];
let set_id = 3;
{
@@ -1670,7 +1670,7 @@ mod tests {
use sc_network::config::Role;
use sc_network_gossip::Validator as GossipValidatorT;
use sc_network_test::Block;
use sp_core::{crypto::Public, H256};
use sp_core::{crypto::UncheckedFrom, H256};
// some random config (not really needed)
fn config() -> crate::Config {
@@ -1691,7 +1691,7 @@ mod tests {
let base = (H256::zero(), 0);
let voters = vec![(AuthorityId::from_slice(&[1; 32]), 1)];
let voters = vec![(AuthorityId::unchecked_from([1; 32]), 1)];
let voters = AuthoritySet::genesis(voters).unwrap();
let set_state = VoterSetState::live(0, &voters, base);
@@ -1861,7 +1861,7 @@ mod tests {
let (val, _) = GossipValidator::<Block>::new(config(), voter_set_state(), None, None);
let set_id = 1;
let auth = AuthorityId::from_slice(&[1u8; 32]);
let auth = AuthorityId::unchecked_from([1u8; 32]);
let peer = PeerId::random();
val.note_set(SetId(set_id), vec![auth.clone()], |_, _| {});
@@ -1878,8 +1878,8 @@ mod tests {
target_hash: Default::default(),
target_number: 10,
}),
signature: Default::default(),
id: AuthorityId::from_slice(&[2u8; 32]),
signature: UncheckedFrom::unchecked_from([1; 64]),
id: UncheckedFrom::unchecked_from([2u8; 32]),
},
},
);
@@ -1894,7 +1894,7 @@ mod tests {
target_hash: Default::default(),
target_number: 10,
}),
signature: Default::default(),
signature: UncheckedFrom::unchecked_from([1; 64]),
id: auth.clone(),
},
},
@@ -1909,7 +1909,7 @@ mod tests {
let (val, _) = GossipValidator::<Block>::new(config(), voter_set_state(), None, None);
let set_id = 1;
let auth = AuthorityId::from_slice(&[1u8; 32]);
let auth = AuthorityId::unchecked_from([1u8; 32]);
let peer = PeerId::random();
val.note_set(SetId(set_id), vec![auth.clone()], |_, _| {});
@@ -1972,7 +1972,7 @@ mod tests {
let (val, _) = GossipValidator::<Block>::new(config(), set_state.clone(), None, None);
let set_id = 1;
let auth = AuthorityId::from_slice(&[1u8; 32]);
let auth = AuthorityId::unchecked_from([1u8; 32]);
let peer = PeerId::random();
val.note_set(SetId(set_id), vec![auth.clone()], |_, _| {});
@@ -2550,12 +2550,13 @@ mod tests {
fn allow_noting_different_authorities_for_same_set() {
let (val, _) = GossipValidator::<Block>::new(config(), voter_set_state(), None, None);
let a1 = vec![AuthorityId::from_slice(&[0; 32])];
let a1 = vec![UncheckedFrom::unchecked_from([0; 32])];
val.note_set(SetId(1), a1.clone(), |_, _| {});
assert_eq!(val.inner().read().authorities, a1);
let a2 = vec![AuthorityId::from_slice(&[1; 32]), AuthorityId::from_slice(&[2; 32])];
let a2 =
vec![UncheckedFrom::unchecked_from([1; 32]), UncheckedFrom::unchecked_from([2; 32])];
val.note_set(SetId(1), a2.clone(), |_, _| {});
assert_eq!(val.inner().read().authorities, a2);
@@ -155,13 +155,13 @@ fn config() -> crate::Config {
fn voter_set_state() -> SharedVoterSetState<Block> {
use crate::{authorities::AuthoritySet, environment::VoterSetState};
use finality_grandpa::round::State as RoundState;
use sp_core::{crypto::Public, H256};
use sp_core::{crypto::ByteArray, H256};
use sp_finality_grandpa::AuthorityId;
let state = RoundState::genesis((H256::zero(), 0));
let base = state.prevote_ghost.unwrap();
let voters = vec![(AuthorityId::from_slice(&[1; 32]), 1)];
let voters = vec![(AuthorityId::from_slice(&[1; 32]).unwrap(), 1)];
let voters = AuthoritySet::genesis(voters).unwrap();
let set_state = VoterSetState::live(0, &voters, base);
@@ -243,8 +243,8 @@ pub(crate) mod tests {
use sc_block_builder::BlockBuilderProvider;
use sc_client_api::{apply_aux, LockImportRun};
use sp_consensus::BlockOrigin;
use sp_core::crypto::Public;
use sp_finality_grandpa::{AuthorityId, GRANDPA_ENGINE_ID as ID};
use sp_core::crypto::UncheckedFrom;
use sp_finality_grandpa::GRANDPA_ENGINE_ID as ID;
use sp_keyring::Ed25519Keyring;
use substrate_test_runtime_client::{
runtime::{Block, Header, H256},
@@ -350,7 +350,7 @@ pub(crate) mod tests {
// When we can't decode proof from Vec<u8>
check_finality_proof::<Block>(
1,
vec![(AuthorityId::from_slice(&[3u8; 32]), 1u64)],
vec![(UncheckedFrom::unchecked_from([3u8; 32]), 1u64)],
vec![42],
)
.unwrap_err();
@@ -361,7 +361,7 @@ pub(crate) mod tests {
// When decoded proof has zero length
check_finality_proof::<Block>(
1,
vec![(AuthorityId::from_slice(&[3u8; 32]), 1u64)],
vec![(UncheckedFrom::unchecked_from([3u8; 32]), 1u64)],
Vec::<GrandpaJustification<Block>>::new().encode(),
)
.unwrap_err();
@@ -387,7 +387,7 @@ pub(crate) mod tests {
check_finality_proof::<Block>(
1,
vec![(AuthorityId::from_slice(&[3u8; 32]), 1u64)],
vec![(UncheckedFrom::unchecked_from([3u8; 32]), 1u64)],
finality_proof.encode(),
)
.unwrap_err();
+9 -8
View File
@@ -73,7 +73,7 @@ use sp_api::ProvideRuntimeApi;
use sp_application_crypto::AppKey;
use sp_blockchain::{Error as ClientError, HeaderBackend, HeaderMetadata};
use sp_consensus::SelectChain;
use sp_core::crypto::Public;
use sp_core::crypto::ByteArray;
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
use sp_runtime::{
generic::BlockId,
@@ -786,8 +786,8 @@ where
let events = telemetry_on_connect.for_each(move |_| {
let current_authorities = authorities.current_authorities();
let set_id = authorities.set_id();
let authority_id = local_authority_id(&current_authorities, conf.keystore.as_ref())
.unwrap_or_default();
let maybe_authority_id =
local_authority_id(&current_authorities, conf.keystore.as_ref());
let authorities =
current_authorities.iter().map(|(id, _)| id.to_string()).collect::<Vec<_>>();
@@ -801,7 +801,7 @@ where
telemetry;
CONSENSUS_INFO;
"afg.authority_set";
"authority_id" => authority_id.to_string(),
"authority_id" => maybe_authority_id.map_or("".into(), |s| s.to_string()),
"authority_set_id" => ?set_id,
"authorities" => authorities,
);
@@ -940,8 +940,9 @@ where
fn rebuild_voter(&mut self) {
debug!(target: "afg", "{}: Starting new voter with set ID {}", self.env.config.name(), self.env.set_id);
let authority_id = local_authority_id(&self.env.voters, self.env.config.keystore.as_ref())
.unwrap_or_default();
let maybe_authority_id =
local_authority_id(&self.env.voters, self.env.config.keystore.as_ref());
let authority_id = maybe_authority_id.map_or("<unknown>".into(), |s| s.to_string());
telemetry!(
self.telemetry;
@@ -949,7 +950,7 @@ where
"afg.starting_new_voter";
"name" => ?self.env.config.name(),
"set_id" => ?self.env.set_id,
"authority_id" => authority_id.to_string(),
"authority_id" => authority_id,
);
let chain_info = self.env.client.info();
@@ -966,7 +967,7 @@ where
"afg.authority_set";
"number" => ?chain_info.finalized_number,
"hash" => ?chain_info.finalized_hash,
"authority_id" => authority_id.to_string(),
"authority_id" => authority_id,
"authority_set_id" => ?self.env.set_id,
"authorities" => authorities,
);
@@ -1671,7 +1671,7 @@ fn grandpa_environment_doesnt_send_equivocation_reports_for_itself() {
// if we set the equivocation offender to another id for which we don't have
// keys it should work
equivocation.identity = Default::default();
equivocation.identity = TryFrom::try_from(&[1; 32][..]).unwrap();
let equivocation_proof = sp_finality_grandpa::Equivocation::Prevote(equivocation);
assert!(environment.report_equivocation(equivocation_proof).is_ok());
}
@@ -563,6 +563,7 @@ mod tests {
use sc_client_api::BlockImportNotification;
use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedSender};
use sp_consensus::BlockOrigin;
use sp_core::crypto::UncheckedFrom;
use substrate_test_runtime_client::runtime::{Block, Hash, Header};
#[derive(Clone)]
@@ -796,8 +797,8 @@ mod tests {
let h3 = make_header(7);
let signed_prevote = |header: &Header| finality_grandpa::SignedPrevote {
id: Default::default(),
signature: Default::default(),
id: UncheckedFrom::unchecked_from([1; 32]),
signature: UncheckedFrom::unchecked_from([1; 64]),
prevote: finality_grandpa::Prevote {
target_hash: header.hash(),
target_number: *header.number(),
@@ -805,8 +806,8 @@ mod tests {
};
let signed_precommit = |header: &Header| finality_grandpa::SignedPrecommit {
id: Default::default(),
signature: Default::default(),
id: UncheckedFrom::unchecked_from([1; 32]),
signature: UncheckedFrom::unchecked_from([1; 64]),
precommit: finality_grandpa::Precommit {
target_hash: header.hash(),
target_number: *header.number(),
@@ -844,8 +845,8 @@ mod tests {
let h3 = make_header(7);
let signed_prevote = |header: &Header| finality_grandpa::SignedPrevote {
id: Default::default(),
signature: Default::default(),
id: UncheckedFrom::unchecked_from([1; 32]),
signature: UncheckedFrom::unchecked_from([1; 64]),
prevote: finality_grandpa::Prevote {
target_hash: header.hash(),
target_number: *header.number(),
@@ -853,8 +854,8 @@ mod tests {
};
let signed_precommit = |header: &Header| finality_grandpa::SignedPrecommit {
id: Default::default(),
signature: Default::default(),
id: UncheckedFrom::unchecked_from([1; 32]),
signature: UncheckedFrom::unchecked_from([1; 64]),
precommit: finality_grandpa::Precommit {
target_hash: header.hash(),
target_number: *header.number(),