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
@@ -581,7 +581,7 @@ mod tests {
amount: Default::default(),
nonce,
from: AccountKeyring::Alice.into(),
to: Default::default(),
to: AccountKeyring::Bob.into(),
}
.into_signed_tx()
}
@@ -593,7 +593,7 @@ mod tests {
amount: 1,
nonce: 0,
from: pair.public(),
to: Default::default(),
to: AccountKeyring::Bob.into(),
};
let signature = pair.sign(&transfer.encode()).into();
Extrinsic::Transfer { transfer, signature, exhaust_resources_when_not_first: true }
@@ -777,14 +777,14 @@ mod tests {
amount: Default::default(),
nonce: 2,
from: AccountKeyring::Alice.into(),
to: Default::default(),
to: AccountKeyring::Bob.into(),
}.into_resources_exhausting_tx(),
extrinsic(3),
Transfer {
amount: Default::default(),
nonce: 4,
from: AccountKeyring::Alice.into(),
to: Default::default(),
to: AccountKeyring::Bob.into(),
}.into_resources_exhausting_tx(),
extrinsic(5),
extrinsic(6),
@@ -99,7 +99,7 @@ fn to_vec<P: sp_core::Pair>(uri: &str, pass: Option<SecretString>) -> Result<Vec
mod tests {
use super::*;
use sc_service::{ChainSpec, ChainType, GenericChainSpec, NoExtension};
use sp_core::{sr25519::Pair, Pair as _, Public};
use sp_core::{sr25519::Pair, ByteArray, Pair as _};
use structopt::StructOpt;
use tempfile::TempDir;
@@ -156,7 +156,7 @@ fn expect_public_from_phrase<Pair: sp_core::Pair>(
#[cfg(test)]
mod tests {
use super::*;
use sp_core::crypto::{Pair, Public};
use sp_core::crypto::{ByteArray, Pair};
use sp_runtime::traits::IdentifyAccount;
use structopt::StructOpt;
+5 -10
View File
@@ -19,7 +19,7 @@
//! implementation of the `verify` subcommand
use crate::{error, utils, with_crypto_scheme, CryptoSchemeFlag};
use sp_core::{crypto::Ss58Codec, Public};
use sp_core::crypto::{ByteArray, Ss58Codec};
use structopt::StructOpt;
/// The `verify` command
@@ -66,19 +66,14 @@ impl VerifyCmd {
fn verify<Pair>(sig_data: Vec<u8>, message: Vec<u8>, uri: &str) -> error::Result<()>
where
Pair: sp_core::Pair,
Pair::Signature: Default + AsMut<[u8]>,
Pair::Signature: for<'a> std::convert::TryFrom<&'a [u8]>,
{
let mut signature = Pair::Signature::default();
if sig_data.len() != signature.as_ref().len() {
return Err(error::Error::SignatureInvalidLength {
read: sig_data.len(),
expected: signature.as_ref().len(),
})
}
signature.as_mut().copy_from_slice(&sig_data);
let signature =
Pair::Signature::try_from(&sig_data).map_err(|_| error::Error::SignatureFormatInvalid)?;
let pubkey = if let Ok(pubkey_vec) = hex::decode(uri) {
Pair::Public::from_slice(pubkey_vec.as_slice())
.map_err(|_| error::Error::KeyFormatInvalid)?
} else {
Pair::Public::from_string(uri)?
};
+5 -7
View File
@@ -51,13 +51,11 @@ pub enum Error {
#[error("Invalid URI; expecting either a secret URI or a public URI.")]
InvalidUri(crypto::PublicError),
#[error("Signature has an invalid length. Read {read} bytes, expected {expected} bytes")]
SignatureInvalidLength {
/// Amount of signature bytes read.
read: usize,
/// Expected number of signature bytes.
expected: usize,
},
#[error("Signature is an invalid format.")]
SignatureFormatInvalid,
#[error("Key is an invalid format.")]
KeyFormatInvalid,
#[error("Unknown key type, must be a known 4-character sequence")]
KeyTypeInvalid,
+2 -2
View File
@@ -132,7 +132,7 @@ impl<C: SubstrateCli> Runner<C> {
/// 2020-06-03 16:14:21 ✌️ version 2.0.0-rc3-f4940588c-x86_64-linux-gnu
/// 2020-06-03 16:14:21 ❤️ by Parity Technologies <admin@parity.io>, 2017-2020
/// 2020-06-03 16:14:21 📋 Chain specification: Flaming Fir
/// 2020-06-03 16:14:21 🏷 Node name: jolly-rod-7462
/// 2020-06-03 16:14:21 🏷 Node name: jolly-rod-7462
/// 2020-06-03 16:14:21 👤 Role: FULL
/// 2020-06-03 16:14:21 💾 Database: RocksDb at /tmp/c/chains/flamingfir7/db
/// 2020-06-03 16:14:21 ⛓ Native runtime: node-251 (substrate-node-1.tx1.au10)
@@ -199,7 +199,7 @@ pub fn print_node_infos<C: SubstrateCli>(config: &Configuration) {
info!("✌️ version {}", C::impl_version());
info!("❤️ by {}, {}-{}", C::author(), C::copyright_start_year(), Local::today().year());
info!("📋 Chain specification: {}", config.chain_spec.name());
info!("🏷 Node name: {}", config.network.node_name);
info!("🏷 Node name: {}", config.network.node_name);
info!("👤 Role: {}", config.display_role());
info!(
"💾 Database: {} at {}",
+1 -1
View File
@@ -57,7 +57,7 @@ use sp_consensus::{
BlockOrigin, CanAuthorWith, Environment, Error as ConsensusError, Proposer, SelectChain,
};
use sp_consensus_slots::Slot;
use sp_core::crypto::{Pair, Public};
use sp_core::crypto::{ByteArray, Pair, Public};
use sp_inherents::CreateInherentDataProviders;
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
use sp_runtime::{
@@ -30,7 +30,7 @@ use sp_application_crypto::AppKey;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use sp_consensus::{Error as ConsensusError, SelectChain};
use sp_consensus_babe::{digests::PreDigest, AuthorityId, BabeApi as BabeRuntimeApi};
use sp_core::crypto::Public;
use sp_core::crypto::ByteArray;
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
use sp_runtime::traits::{Block as BlockT, Header as _};
use std::{collections::HashMap, sync::Arc};
@@ -27,7 +27,7 @@ use sp_consensus_babe::{
make_transcript, make_transcript_data, AuthorityId, BabeAuthorityWeight, Slot, BABE_VRF_PREFIX,
};
use sp_consensus_vrf::schnorrkel::{VRFOutput, VRFProof};
use sp_core::{blake2_256, crypto::Public, U256};
use sp_core::{blake2_256, crypto::ByteArray, U256};
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
/// Calculates the primary selection threshold for a given authority, taking
+1 -1
View File
@@ -110,7 +110,7 @@ use sp_consensus::{
};
use sp_consensus_babe::inherents::BabeInherentData;
use sp_consensus_slots::Slot;
use sp_core::{crypto::Public, ExecutionContext};
use sp_core::{crypto::ByteArray, ExecutionContext};
use sp_inherents::{CreateInherentDataProviders, InherentData, InherentDataProvider};
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
use sp_runtime::{
@@ -31,7 +31,7 @@ use sp_consensus_babe::{
make_transcript, AuthorityId, AuthorityPair, AuthoritySignature,
};
use sp_consensus_slots::Slot;
use sp_core::{Pair, Public};
use sp_core::{ByteArray, Pair};
use sp_runtime::{traits::Header, DigestItem};
/// BABE verification parameters
@@ -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(),
+30 -9
View File
@@ -21,7 +21,9 @@ use async_trait::async_trait;
use parking_lot::RwLock;
use sp_application_crypto::{ecdsa, ed25519, sr25519, AppKey, AppPair, IsWrappedBy};
use sp_core::{
crypto::{CryptoTypePublicPair, ExposeSecret, KeyTypeId, Pair as PairT, Public, SecretString},
crypto::{
ByteArray, CryptoTypePublicPair, ExposeSecret, KeyTypeId, Pair as PairT, SecretString,
},
sr25519::{Pair as Sr25519Pair, Public as Sr25519Public},
Encode,
};
@@ -189,7 +191,9 @@ impl SyncCryptoStore for LocalKeystore {
) -> std::result::Result<Option<Vec<u8>>, TraitError> {
match key.0 {
ed25519::CRYPTO_ID => {
let pub_key = ed25519::Public::from_slice(key.1.as_slice());
let pub_key = ed25519::Public::from_slice(key.1.as_slice()).map_err(|()| {
TraitError::Other("Corrupted public key - Invalid size".into())
})?;
let key_pair = self
.0
.read()
@@ -198,7 +202,9 @@ impl SyncCryptoStore for LocalKeystore {
key_pair.map(|k| k.sign(msg).encode()).map(Ok).transpose()
},
sr25519::CRYPTO_ID => {
let pub_key = sr25519::Public::from_slice(key.1.as_slice());
let pub_key = sr25519::Public::from_slice(key.1.as_slice()).map_err(|()| {
TraitError::Other("Corrupted public key - Invalid size".into())
})?;
let key_pair = self
.0
.read()
@@ -207,7 +213,9 @@ impl SyncCryptoStore for LocalKeystore {
key_pair.map(|k| k.sign(msg).encode()).map(Ok).transpose()
},
ecdsa::CRYPTO_ID => {
let pub_key = ecdsa::Public::from_slice(key.1.as_slice());
let pub_key = ecdsa::Public::from_slice(key.1.as_slice()).map_err(|()| {
TraitError::Other("Corrupted public key - Invalid size".into())
})?;
let key_pair = self
.0
.read()
@@ -223,7 +231,11 @@ impl SyncCryptoStore for LocalKeystore {
self.0
.read()
.raw_public_keys(key_type)
.map(|v| v.into_iter().map(|k| sr25519::Public::from_slice(k.as_slice())).collect())
.map(|v| {
v.into_iter()
.filter_map(|k| sr25519::Public::from_slice(k.as_slice()).ok())
.collect()
})
.unwrap_or_default()
}
@@ -246,7 +258,11 @@ impl SyncCryptoStore for LocalKeystore {
self.0
.read()
.raw_public_keys(key_type)
.map(|v| v.into_iter().map(|k| ed25519::Public::from_slice(k.as_slice())).collect())
.map(|v| {
v.into_iter()
.filter_map(|k| ed25519::Public::from_slice(k.as_slice()).ok())
.collect()
})
.unwrap_or_default()
}
@@ -269,7 +285,11 @@ impl SyncCryptoStore for LocalKeystore {
self.0
.read()
.raw_public_keys(key_type)
.map(|v| v.into_iter().map(|k| ecdsa::Public::from_slice(k.as_slice())).collect())
.map(|v| {
v.into_iter()
.filter_map(|k| ecdsa::Public::from_slice(k.as_slice()).ok())
.collect()
})
.unwrap_or_default()
}
@@ -561,8 +581,9 @@ mod tests {
}
fn public_keys<Public: AppPublic>(&self) -> Result<Vec<Public>> {
self.raw_public_keys(Public::ID)
.map(|v| v.into_iter().map(|k| Public::from_slice(k.as_slice())).collect())
self.raw_public_keys(Public::ID).map(|v| {
v.into_iter().filter_map(|k| Public::from_slice(k.as_slice()).ok()).collect()
})
}
fn generate<Pair: AppPair>(&mut self) -> Result<Pair> {
+1 -1
View File
@@ -190,7 +190,7 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
let local_peer_id = local_public.clone().to_peer_id();
info!(
target: "sub-libp2p",
"🏷 Local node identity is: {}",
"🏷 Local node identity is: {}",
local_peer_id.to_base58(),
);
+8 -4
View File
@@ -24,7 +24,7 @@ use futures::executor;
use sc_transaction_pool::{BasicPool, FullChainApi};
use sp_core::{
blake2_256,
crypto::{CryptoTypePublicPair, Pair, Public},
crypto::{ByteArray, CryptoTypePublicPair, Pair},
ed25519,
hexdisplay::HexDisplay,
sr25519,
@@ -40,8 +40,12 @@ use substrate_test_runtime_client::{
};
fn uxt(sender: AccountKeyring, nonce: u64) -> Extrinsic {
let tx =
Transfer { amount: Default::default(), nonce, from: sender.into(), to: Default::default() };
let tx = Transfer {
amount: Default::default(),
nonce,
from: sender.into(),
to: AccountKeyring::Bob.into(),
};
tx.into_signed_tx()
}
@@ -133,7 +137,7 @@ fn should_watch_extrinsic() {
amount: 5,
nonce: 0,
from: AccountKeyring::Alice.into(),
to: Default::default(),
to: AccountKeyring::Bob.into(),
};
tx.into_signed_tx()
};
+1 -1
View File
@@ -576,7 +576,7 @@ mod tests {
amount: 5,
nonce: 0,
from: AccountKeyring::Alice.into(),
to: Default::default(),
to: AccountKeyring::Bob.into(),
}
.into_signed_tx();
block_on(pool.submit_one(&BlockId::hash(best.hash()), source, transaction.clone()))
@@ -56,7 +56,7 @@ use syn::{Error, Expr, Ident, ItemFn};
/// 2020-10-16 08:03:14 ✌️ version 2.0.0-47f7d3f2e-x86_64-linux-gnu
/// 2020-10-16 08:03:14 ❤️ by Anonymous, 2017-2020
/// 2020-10-16 08:03:14 📋 Chain specification: Local Testnet
/// 2020-10-16 08:03:14 🏷 Node name: nice-glove-1401
/// 2020-10-16 08:03:14 🏷 Node name: nice-glove-1401
/// 2020-10-16 08:03:14 👤 Role: LIGHT
/// 2020-10-16 08:03:14 💾 Database: RocksDb at /tmp/substrate95w2Dk/chains/local_testnet/db
/// 2020-10-16 08:03:14 ⛓ Native runtime: node-template-1 (node-template-1.tx1.au1)
@@ -64,7 +64,7 @@ use syn::{Error, Expr, Ident, ItemFn};
/// 2020-10-16 08:03:14 [light] Loading GRANDPA authorities from genesis on what appears to be first startup.
/// 2020-10-16 08:03:15 [light] ⏱ Loaded block-time = 6000 milliseconds from genesis on first-launch
/// 2020-10-16 08:03:15 [light] Using default protocol ID "sup" because none is configured in the chain specs
/// 2020-10-16 08:03:15 [light] 🏷 Local node identity is: 12D3KooWHX4rkWT6a6N55Km7ZnvenGdShSKPkzJ3yj9DU5nqDtWR
/// 2020-10-16 08:03:15 [light] 🏷 Local node identity is: 12D3KooWHX4rkWT6a6N55Km7ZnvenGdShSKPkzJ3yj9DU5nqDtWR
/// 2020-10-16 08:03:15 [light] 📦 Highest known block at #0
/// 2020-10-16 08:03:15 [light] 〽️ Prometheus server started at 127.0.0.1:9615
/// 2020-10-16 08:03:15 [light] Listening for new connections on 127.0.0.1:9944.
@@ -90,7 +90,7 @@ use syn::{Error, Expr, Ident, ItemFn};
/// 2020-10-16 08:12:57 ✌️ version 2.0.0-efb9b822a-x86_64-linux-gnu
/// 2020-10-16 08:12:57 ❤️ by Anonymous, 2017-2020
/// 2020-10-16 08:12:57 📋 Chain specification: Local Testnet
/// 2020-10-16 08:12:57 🏷 Node name: open-harbor-1619
/// 2020-10-16 08:12:57 🏷 Node name: open-harbor-1619
/// 2020-10-16 08:12:57 👤 Role: LIGHT
/// 2020-10-16 08:12:57 💾 Database: RocksDb at /tmp/substrate9T9Mtb/chains/local_testnet/db
/// 2020-10-16 08:12:57 ⛓ Native runtime: node-template-1 (node-template-1.tx1.au1)
@@ -98,7 +98,7 @@ use syn::{Error, Expr, Ident, ItemFn};
/// 2020-10-16 08:12:58 [open-harbor-1619] Loading GRANDPA authorities from genesis on what appears to be first startup.
/// 2020-10-16 08:12:58 [open-harbor-1619] ⏱ Loaded block-time = 6000 milliseconds from genesis on first-launch
/// 2020-10-16 08:12:58 [open-harbor-1619] Using default protocol ID "sup" because none is configured in the chain specs
/// 2020-10-16 08:12:58 [open-harbor-1619] 🏷 Local node identity is: 12D3KooWRzmYC8QTK1Pm8Cfvid3skTS4Hn54jc4AUtje8Rqbfgtp
/// 2020-10-16 08:12:58 [open-harbor-1619] 🏷 Local node identity is: 12D3KooWRzmYC8QTK1Pm8Cfvid3skTS4Hn54jc4AUtje8Rqbfgtp
/// 2020-10-16 08:12:58 [open-harbor-1619] 📦 Highest known block at #0
/// 2020-10-16 08:12:58 [open-harbor-1619] 〽️ Prometheus server started at 127.0.0.1:9615
/// 2020-10-16 08:12:58 [open-harbor-1619] Listening for new connections on 127.0.0.1:9944.
@@ -18,7 +18,7 @@
use criterion::{criterion_group, criterion_main, Criterion};
use codec::Encode;
use codec::{Decode, Encode};
use futures::{
executor::block_on,
future::{ready, Ready},
@@ -126,7 +126,8 @@ impl ChainApi for TestApi {
fn uxt(transfer: Transfer) -> Extrinsic {
Extrinsic::Transfer {
transfer,
signature: Default::default(),
signature: Decode::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes())
.expect("infinite input; no dead input space; qed"),
exhaust_resources_when_not_first: false,
}
}
@@ -594,11 +594,8 @@ mod tests {
}
fn uxt(transfer: Transfer) -> Extrinsic {
Extrinsic::Transfer {
transfer,
signature: Default::default(),
exhaust_resources_when_not_first: false,
}
let signature = TryFrom::try_from(&[0; 64][..]).unwrap();
Extrinsic::Transfer { transfer, signature, exhaust_resources_when_not_first: false }
}
fn pool() -> Pool<TestApi> {