Skip to content

Commit

Permalink
Remove Default bound for AccountId (paritytech#10403)
Browse files Browse the repository at this point in the history
* 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 (paritytech#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>
  • Loading branch information
4 people authored and grishasobol committed Mar 28, 2022
1 parent bd22194 commit 8a888b1
Show file tree
Hide file tree
Showing 118 changed files with 998 additions and 4,181 deletions.
16 changes: 1 addition & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ members = [
"frame/contracts/rpc/runtime-api",
"frame/democracy",
"frame/try-runtime",
"frame/elections",
"frame/election-provider-multi-phase",
"frame/election-provider-support",
"frame/examples/basic",
Expand Down
2 changes: 1 addition & 1 deletion bin/node-template/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ fn testnet_genesis(
},
sudo: SudoConfig {
// Assign network admin rights.
key: root_key,
key: Some(root_key),
},
transaction_payment: Default::default(),
}
Expand Down
2 changes: 1 addition & 1 deletion bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ pub fn testnet_genesis(
.collect(),
phantom: Default::default(),
},
sudo: SudoConfig { key: root_key },
sudo: SudoConfig { key: Some(root_key) },
babe: BabeConfig {
authorities: vec![],
epoch_config: Some(node_runtime::BABE_GENESIS_EPOCH_CONFIG),
Expand Down
1 change: 1 addition & 0 deletions bin/node/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ sp-application-crypto = { version = "4.0.0-dev", path = "../../../primitives/app
sp-consensus-babe = { version = "0.10.0-dev", path = "../../../primitives/consensus/babe" }
sp-runtime = { version = "4.0.0-dev", path = "../../../primitives/runtime" }
sp-externalities = { version = "0.10.0", path = "../../../primitives/externalities" }
sp-keyring = { version = "4.0.0-dev", path = "../../../primitives/keyring" }
wat = "1.0"
futures = "0.3.9"

Expand Down
16 changes: 9 additions & 7 deletions bin/node/executor/tests/submit_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use frame_system::offchain::{SendSignedTransaction, Signer, SubmitTransaction};
use node_runtime::{Executive, Indices, Runtime, UncheckedExtrinsic};
use sp_application_crypto::AppKey;
use sp_core::offchain::{testing::TestTransactionPoolExt, TransactionPoolExt};
use sp_keyring::sr25519::Keyring::Alice;
use sp_keystore::{testing::KeyStore, KeystoreExt, SyncCryptoStore};
use std::sync::Arc;

Expand All @@ -33,7 +34,8 @@ fn should_submit_unsigned_transaction() {
t.register_extension(TransactionPoolExt::new(pool));

t.execute_with(|| {
let signature = Default::default();
let signature =
pallet_im_online::sr25519::AuthoritySignature::try_from(vec![0; 64]).unwrap();
let heartbeat_data = pallet_im_online::Heartbeat {
block_number: 1,
network_state: Default::default(),
Expand Down Expand Up @@ -85,7 +87,7 @@ fn should_submit_signed_transaction() {
let results =
Signer::<Runtime, TestAuthorityId>::all_accounts().send_signed_transaction(|_| {
pallet_balances::Call::transfer {
dest: Default::default(),
dest: Alice.to_account_id().into(),
value: Default::default(),
}
});
Expand Down Expand Up @@ -122,7 +124,7 @@ fn should_submit_signed_twice_from_the_same_account() {
let result =
Signer::<Runtime, TestAuthorityId>::any_account().send_signed_transaction(|_| {
pallet_balances::Call::transfer {
dest: Default::default(),
dest: Alice.to_account_id().into(),
value: Default::default(),
}
});
Expand All @@ -134,7 +136,7 @@ fn should_submit_signed_twice_from_the_same_account() {
let result =
Signer::<Runtime, TestAuthorityId>::any_account().send_signed_transaction(|_| {
pallet_balances::Call::transfer {
dest: Default::default(),
dest: Alice.to_account_id().into(),
value: Default::default(),
}
});
Expand Down Expand Up @@ -172,7 +174,7 @@ fn should_submit_signed_twice_from_all_accounts() {
t.execute_with(|| {
let results = Signer::<Runtime, TestAuthorityId>::all_accounts()
.send_signed_transaction(|_| {
pallet_balances::Call::transfer { dest: Default::default(), value: Default::default() }
pallet_balances::Call::transfer { dest: Alice.to_account_id().into(), value: Default::default() }
});

let len = results.len();
Expand All @@ -183,7 +185,7 @@ fn should_submit_signed_twice_from_all_accounts() {
// submit another one from the same account. The nonce should be incremented.
let results = Signer::<Runtime, TestAuthorityId>::all_accounts()
.send_signed_transaction(|_| {
pallet_balances::Call::transfer { dest: Default::default(), value: Default::default() }
pallet_balances::Call::transfer { dest: Alice.to_account_id().into(), value: Default::default() }
});

let len = results.len();
Expand Down Expand Up @@ -237,7 +239,7 @@ fn submitted_transaction_should_be_valid() {
let results =
Signer::<Runtime, TestAuthorityId>::all_accounts().send_signed_transaction(|_| {
pallet_balances::Call::transfer {
dest: Default::default(),
dest: Alice.to_account_id().into(),
value: Default::default(),
}
});
Expand Down
11 changes: 7 additions & 4 deletions bin/node/runtime/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ use pallet_asset_tx_payment::HandleCredit;
pub struct Author;
impl OnUnbalanced<NegativeImbalance> for Author {
fn on_nonzero_unbalanced(amount: NegativeImbalance) {
Balances::resolve_creating(&Authorship::author(), amount);
if let Some(author) = Authorship::author() {
Balances::resolve_creating(&author, amount);
}
}
}

Expand All @@ -36,9 +38,10 @@ impl OnUnbalanced<NegativeImbalance> for Author {
pub struct CreditToBlockAuthor;
impl HandleCredit<AccountId, Assets> for CreditToBlockAuthor {
fn handle_credit(credit: CreditOf<AccountId, Assets>) {
let author = pallet_authorship::Pallet::<Runtime>::author();
// Drop the result which will trigger the `OnDrop` of the imbalance in case of error.
let _ = Assets::resolve(&author, credit);
if let Some(author) = pallet_authorship::Pallet::<Runtime>::author() {
// Drop the result which will trigger the `OnDrop` of the imbalance in case of error.
let _ = Assets::resolve(&author, credit);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1835,8 +1835,8 @@ mod tests {
fn call_size() {
let size = core::mem::size_of::<Call>();
assert!(
size <= 200,
"size of Call {} is more than 200 bytes: some calls have too big arguments, use Box to reduce the
size <= 208,
"size of Call {} is more than 208 bytes: some calls have too big arguments, use Box to reduce the
size of Call.
If the limit is too strong, maybe consider increase the limit to 300.",
size,
Expand Down
6 changes: 3 additions & 3 deletions bin/node/testing/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ pub fn config_endowed(code: Option<&[u8]>, extra_endowed: Vec<AccountId>) -> Gen
balances: BalancesConfig { balances: endowed },
session: SessionConfig {
keys: vec![
(dave(), alice(), to_session_keys(&Ed25519Keyring::Alice, &Sr25519Keyring::Alice)),
(eve(), bob(), to_session_keys(&Ed25519Keyring::Bob, &Sr25519Keyring::Bob)),
(alice(), dave(), to_session_keys(&Ed25519Keyring::Alice, &Sr25519Keyring::Alice)),
(bob(), eve(), to_session_keys(&Ed25519Keyring::Bob, &Sr25519Keyring::Bob)),
(
ferdie(),
charlie(),
ferdie(),
to_session_keys(&Ed25519Keyring::Charlie, &Sr25519Keyring::Charlie),
),
],
Expand Down
2 changes: 1 addition & 1 deletion bin/utils/chain-spec-builder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use structopt::StructOpt;
use node_cli::chain_spec::{self, AccountId};
use sc_keystore::LocalKeystore;
use sp_core::{
crypto::{Public, Ss58Codec},
crypto::{ByteArray, Ss58Codec},
sr25519,
};
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
Expand Down
8 changes: 4 additions & 4 deletions client/basic-authorship/src/basic_authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ mod tests {
amount: Default::default(),
nonce,
from: AccountKeyring::Alice.into(),
to: Default::default(),
to: AccountKeyring::Bob.into(),
}
.into_signed_tx()
}
Expand All @@ -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 }
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion client/cli/src/commands/insert_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion client/cli/src/commands/inspect_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
15 changes: 5 additions & 10 deletions client/cli/src/commands/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)?
};
Expand Down
12 changes: 5 additions & 7 deletions client/cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions client/cli/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {}",
Expand Down
2 changes: 1 addition & 1 deletion client/consensus/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
2 changes: 1 addition & 1 deletion client/consensus/babe/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion client/consensus/babe/src/authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion client/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
2 changes: 1 addition & 1 deletion client/consensus/babe/src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions client/finality-grandpa/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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()
}
Expand Down Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 8a888b1

Please sign in to comment.