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

Commit 55cd07a

Browse files
gavofyorkbkchrkianenigma
authored
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 <[email protected]> * Update frame/authorship/src/lib.rs Co-authored-by: Bastian Köcher <[email protected]> * Update frame/authorship/src/lib.rs Co-authored-by: Bastian Köcher <[email protected]> * Update frame/authorship/src/lib.rs Co-authored-by: Bastian Köcher <[email protected]> * 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 <[email protected]> * Update client/finality-grandpa/src/lib.rs Co-authored-by: Bastian Köcher <[email protected]> * Update client/keystore/src/local.rs Co-authored-by: Bastian Köcher <[email protected]> * Update client/keystore/src/local.rs Co-authored-by: Bastian Köcher <[email protected]> * Update frame/staking/src/lib.rs Co-authored-by: Bastian Köcher <[email protected]> * Update frame/staking/src/lib.rs Co-authored-by: Bastian Köcher <[email protected]> * Update primitives/runtime/src/traits.rs Co-authored-by: Bastian Köcher <[email protected]> * Formatting Co-authored-by: Bastian Köcher <[email protected]> Co-authored-by: Kian Paimani <[email protected]> Co-authored-by: kianenigma <[email protected]>
1 parent b9cafba commit 55cd07a

File tree

118 files changed

+998
-4181
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+998
-4181
lines changed

Cargo.lock

Lines changed: 1 addition & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ members = [
8181
"frame/contracts/rpc/runtime-api",
8282
"frame/democracy",
8383
"frame/try-runtime",
84-
"frame/elections",
8584
"frame/election-provider-multi-phase",
8685
"frame/election-provider-support",
8786
"frame/examples/basic",

bin/node-template/node/src/chain_spec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ fn testnet_genesis(
147147
},
148148
sudo: SudoConfig {
149149
// Assign network admin rights.
150-
key: root_key,
150+
key: Some(root_key),
151151
},
152152
transaction_payment: Default::default(),
153153
}

bin/node/cli/src/chain_spec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ pub fn testnet_genesis(
338338
.collect(),
339339
phantom: Default::default(),
340340
},
341-
sudo: SudoConfig { key: root_key },
341+
sudo: SudoConfig { key: Some(root_key) },
342342
babe: BabeConfig {
343343
authorities: vec![],
344344
epoch_config: Some(node_runtime::BABE_GENESIS_EPOCH_CONFIG),

bin/node/executor/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ sp-application-crypto = { version = "4.0.0-dev", path = "../../../primitives/app
3838
sp-consensus-babe = { version = "0.10.0-dev", path = "../../../primitives/consensus/babe" }
3939
sp-runtime = { version = "4.0.0-dev", path = "../../../primitives/runtime" }
4040
sp-externalities = { version = "0.10.0", path = "../../../primitives/externalities" }
41+
sp-keyring = { version = "4.0.0-dev", path = "../../../primitives/keyring" }
4142
wat = "1.0"
4243
futures = "0.3.9"
4344

bin/node/executor/tests/submit_transaction.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use frame_system::offchain::{SendSignedTransaction, Signer, SubmitTransaction};
2020
use node_runtime::{Executive, Indices, Runtime, UncheckedExtrinsic};
2121
use sp_application_crypto::AppKey;
2222
use sp_core::offchain::{testing::TestTransactionPoolExt, TransactionPoolExt};
23+
use sp_keyring::sr25519::Keyring::Alice;
2324
use sp_keystore::{testing::KeyStore, KeystoreExt, SyncCryptoStore};
2425
use std::sync::Arc;
2526

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

3536
t.execute_with(|| {
36-
let signature = Default::default();
37+
let signature =
38+
pallet_im_online::sr25519::AuthoritySignature::try_from(vec![0; 64]).unwrap();
3739
let heartbeat_data = pallet_im_online::Heartbeat {
3840
block_number: 1,
3941
network_state: Default::default(),
@@ -85,7 +87,7 @@ fn should_submit_signed_transaction() {
8587
let results =
8688
Signer::<Runtime, TestAuthorityId>::all_accounts().send_signed_transaction(|_| {
8789
pallet_balances::Call::transfer {
88-
dest: Default::default(),
90+
dest: Alice.to_account_id().into(),
8991
value: Default::default(),
9092
}
9193
});
@@ -122,7 +124,7 @@ fn should_submit_signed_twice_from_the_same_account() {
122124
let result =
123125
Signer::<Runtime, TestAuthorityId>::any_account().send_signed_transaction(|_| {
124126
pallet_balances::Call::transfer {
125-
dest: Default::default(),
127+
dest: Alice.to_account_id().into(),
126128
value: Default::default(),
127129
}
128130
});
@@ -134,7 +136,7 @@ fn should_submit_signed_twice_from_the_same_account() {
134136
let result =
135137
Signer::<Runtime, TestAuthorityId>::any_account().send_signed_transaction(|_| {
136138
pallet_balances::Call::transfer {
137-
dest: Default::default(),
139+
dest: Alice.to_account_id().into(),
138140
value: Default::default(),
139141
}
140142
});
@@ -172,7 +174,7 @@ fn should_submit_signed_twice_from_all_accounts() {
172174
t.execute_with(|| {
173175
let results = Signer::<Runtime, TestAuthorityId>::all_accounts()
174176
.send_signed_transaction(|_| {
175-
pallet_balances::Call::transfer { dest: Default::default(), value: Default::default() }
177+
pallet_balances::Call::transfer { dest: Alice.to_account_id().into(), value: Default::default() }
176178
});
177179

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

189191
let len = results.len();
@@ -237,7 +239,7 @@ fn submitted_transaction_should_be_valid() {
237239
let results =
238240
Signer::<Runtime, TestAuthorityId>::all_accounts().send_signed_transaction(|_| {
239241
pallet_balances::Call::transfer {
240-
dest: Default::default(),
242+
dest: Alice.to_account_id().into(),
241243
value: Default::default(),
242244
}
243245
});

bin/node/runtime/src/impls.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ use pallet_asset_tx_payment::HandleCredit;
2727
pub struct Author;
2828
impl OnUnbalanced<NegativeImbalance> for Author {
2929
fn on_nonzero_unbalanced(amount: NegativeImbalance) {
30-
Balances::resolve_creating(&Authorship::author(), amount);
30+
if let Some(author) = Authorship::author() {
31+
Balances::resolve_creating(&author, amount);
32+
}
3133
}
3234
}
3335

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

bin/node/runtime/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,8 +1835,8 @@ mod tests {
18351835
fn call_size() {
18361836
let size = core::mem::size_of::<Call>();
18371837
assert!(
1838-
size <= 200,
1839-
"size of Call {} is more than 200 bytes: some calls have too big arguments, use Box to reduce the
1838+
size <= 208,
1839+
"size of Call {} is more than 208 bytes: some calls have too big arguments, use Box to reduce the
18401840
size of Call.
18411841
If the limit is too strong, maybe consider increase the limit to 300.",
18421842
size,

bin/node/testing/src/genesis.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ pub fn config_endowed(code: Option<&[u8]>, extra_endowed: Vec<AccountId>) -> Gen
5454
balances: BalancesConfig { balances: endowed },
5555
session: SessionConfig {
5656
keys: vec![
57-
(dave(), alice(), to_session_keys(&Ed25519Keyring::Alice, &Sr25519Keyring::Alice)),
58-
(eve(), bob(), to_session_keys(&Ed25519Keyring::Bob, &Sr25519Keyring::Bob)),
57+
(alice(), dave(), to_session_keys(&Ed25519Keyring::Alice, &Sr25519Keyring::Alice)),
58+
(bob(), eve(), to_session_keys(&Ed25519Keyring::Bob, &Sr25519Keyring::Bob)),
5959
(
60-
ferdie(),
6160
charlie(),
61+
ferdie(),
6262
to_session_keys(&Ed25519Keyring::Charlie, &Sr25519Keyring::Charlie),
6363
),
6464
],

bin/utils/chain-spec-builder/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use structopt::StructOpt;
2929
use node_cli::chain_spec::{self, AccountId};
3030
use sc_keystore::LocalKeystore;
3131
use sp_core::{
32-
crypto::{Public, Ss58Codec},
32+
crypto::{ByteArray, Ss58Codec},
3333
sr25519,
3434
};
3535
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};

client/basic-authorship/src/basic_authorship.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ mod tests {
581581
amount: Default::default(),
582582
nonce,
583583
from: AccountKeyring::Alice.into(),
584-
to: Default::default(),
584+
to: AccountKeyring::Bob.into(),
585585
}
586586
.into_signed_tx()
587587
}
@@ -593,7 +593,7 @@ mod tests {
593593
amount: 1,
594594
nonce: 0,
595595
from: pair.public(),
596-
to: Default::default(),
596+
to: AccountKeyring::Bob.into(),
597597
};
598598
let signature = pair.sign(&transfer.encode()).into();
599599
Extrinsic::Transfer { transfer, signature, exhaust_resources_when_not_first: true }
@@ -777,14 +777,14 @@ mod tests {
777777
amount: Default::default(),
778778
nonce: 2,
779779
from: AccountKeyring::Alice.into(),
780-
to: Default::default(),
780+
to: AccountKeyring::Bob.into(),
781781
}.into_resources_exhausting_tx(),
782782
extrinsic(3),
783783
Transfer {
784784
amount: Default::default(),
785785
nonce: 4,
786786
from: AccountKeyring::Alice.into(),
787-
to: Default::default(),
787+
to: AccountKeyring::Bob.into(),
788788
}.into_resources_exhausting_tx(),
789789
extrinsic(5),
790790
extrinsic(6),

client/cli/src/commands/insert_key.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ fn to_vec<P: sp_core::Pair>(uri: &str, pass: Option<SecretString>) -> Result<Vec
9999
mod tests {
100100
use super::*;
101101
use sc_service::{ChainSpec, ChainType, GenericChainSpec, NoExtension};
102-
use sp_core::{sr25519::Pair, Pair as _, Public};
102+
use sp_core::{sr25519::Pair, ByteArray, Pair as _};
103103
use structopt::StructOpt;
104104
use tempfile::TempDir;
105105

client/cli/src/commands/inspect_key.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ fn expect_public_from_phrase<Pair: sp_core::Pair>(
156156
#[cfg(test)]
157157
mod tests {
158158
use super::*;
159-
use sp_core::crypto::{Pair, Public};
159+
use sp_core::crypto::{ByteArray, Pair};
160160
use sp_runtime::traits::IdentifyAccount;
161161
use structopt::StructOpt;
162162

client/cli/src/commands/verify.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//! implementation of the `verify` subcommand
2020
2121
use crate::{error, utils, with_crypto_scheme, CryptoSchemeFlag};
22-
use sp_core::{crypto::Ss58Codec, Public};
22+
use sp_core::crypto::{ByteArray, Ss58Codec};
2323
use structopt::StructOpt;
2424

2525
/// The `verify` command
@@ -66,19 +66,14 @@ impl VerifyCmd {
6666
fn verify<Pair>(sig_data: Vec<u8>, message: Vec<u8>, uri: &str) -> error::Result<()>
6767
where
6868
Pair: sp_core::Pair,
69-
Pair::Signature: Default + AsMut<[u8]>,
69+
Pair::Signature: for<'a> std::convert::TryFrom<&'a [u8]>,
7070
{
71-
let mut signature = Pair::Signature::default();
72-
if sig_data.len() != signature.as_ref().len() {
73-
return Err(error::Error::SignatureInvalidLength {
74-
read: sig_data.len(),
75-
expected: signature.as_ref().len(),
76-
})
77-
}
78-
signature.as_mut().copy_from_slice(&sig_data);
71+
let signature =
72+
Pair::Signature::try_from(&sig_data).map_err(|_| error::Error::SignatureFormatInvalid)?;
7973

8074
let pubkey = if let Ok(pubkey_vec) = hex::decode(uri) {
8175
Pair::Public::from_slice(pubkey_vec.as_slice())
76+
.map_err(|_| error::Error::KeyFormatInvalid)?
8277
} else {
8378
Pair::Public::from_string(uri)?
8479
};

client/cli/src/error.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,11 @@ pub enum Error {
5151
#[error("Invalid URI; expecting either a secret URI or a public URI.")]
5252
InvalidUri(crypto::PublicError),
5353

54-
#[error("Signature has an invalid length. Read {read} bytes, expected {expected} bytes")]
55-
SignatureInvalidLength {
56-
/// Amount of signature bytes read.
57-
read: usize,
58-
/// Expected number of signature bytes.
59-
expected: usize,
60-
},
54+
#[error("Signature is an invalid format.")]
55+
SignatureFormatInvalid,
56+
57+
#[error("Key is an invalid format.")]
58+
KeyFormatInvalid,
6159

6260
#[error("Unknown key type, must be a known 4-character sequence")]
6361
KeyTypeInvalid,

client/cli/src/runner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<C: SubstrateCli> Runner<C> {
132132
/// 2020-06-03 16:14:21 ✌️ version 2.0.0-rc3-f4940588c-x86_64-linux-gnu
133133
/// 2020-06-03 16:14:21 ❤️ by Parity Technologies <[email protected]>, 2017-2020
134134
/// 2020-06-03 16:14:21 📋 Chain specification: Flaming Fir
135-
/// 2020-06-03 16:14:21 🏷 Node name: jolly-rod-7462
135+
/// 2020-06-03 16:14:21 🏷 Node name: jolly-rod-7462
136136
/// 2020-06-03 16:14:21 👤 Role: FULL
137137
/// 2020-06-03 16:14:21 💾 Database: RocksDb at /tmp/c/chains/flamingfir7/db
138138
/// 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) {
199199
info!("✌️ version {}", C::impl_version());
200200
info!("❤️ by {}, {}-{}", C::author(), C::copyright_start_year(), Local::today().year());
201201
info!("📋 Chain specification: {}", config.chain_spec.name());
202-
info!("🏷 Node name: {}", config.network.node_name);
202+
info!("🏷 Node name: {}", config.network.node_name);
203203
info!("👤 Role: {}", config.display_role());
204204
info!(
205205
"💾 Database: {} at {}",

client/consensus/aura/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use sp_consensus::{
5757
BlockOrigin, CanAuthorWith, Environment, Error as ConsensusError, Proposer, SelectChain,
5858
};
5959
use sp_consensus_slots::Slot;
60-
use sp_core::crypto::{Pair, Public};
60+
use sp_core::crypto::{ByteArray, Pair, Public};
6161
use sp_inherents::CreateInherentDataProviders;
6262
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
6363
use sp_runtime::{

client/consensus/babe/rpc/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use sp_application_crypto::AppKey;
3030
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
3131
use sp_consensus::{Error as ConsensusError, SelectChain};
3232
use sp_consensus_babe::{digests::PreDigest, AuthorityId, BabeApi as BabeRuntimeApi};
33-
use sp_core::crypto::Public;
33+
use sp_core::crypto::ByteArray;
3434
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
3535
use sp_runtime::traits::{Block as BlockT, Header as _};
3636
use std::{collections::HashMap, sync::Arc};

client/consensus/babe/src/authorship.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use sp_consensus_babe::{
2727
make_transcript, make_transcript_data, AuthorityId, BabeAuthorityWeight, Slot, BABE_VRF_PREFIX,
2828
};
2929
use sp_consensus_vrf::schnorrkel::{VRFOutput, VRFProof};
30-
use sp_core::{blake2_256, crypto::Public, U256};
30+
use sp_core::{blake2_256, crypto::ByteArray, U256};
3131
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
3232

3333
/// Calculates the primary selection threshold for a given authority, taking

client/consensus/babe/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ use sp_consensus::{
110110
};
111111
use sp_consensus_babe::inherents::BabeInherentData;
112112
use sp_consensus_slots::Slot;
113-
use sp_core::{crypto::Public, ExecutionContext};
113+
use sp_core::{crypto::ByteArray, ExecutionContext};
114114
use sp_inherents::{CreateInherentDataProviders, InherentData, InherentDataProvider};
115115
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
116116
use sp_runtime::{

client/consensus/babe/src/verification.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use sp_consensus_babe::{
3131
make_transcript, AuthorityId, AuthorityPair, AuthoritySignature,
3232
};
3333
use sp_consensus_slots::Slot;
34-
use sp_core::{Pair, Public};
34+
use sp_core::{ByteArray, Pair};
3535
use sp_runtime::{traits::Header, DigestItem};
3636

3737
/// BABE verification parameters

client/finality-grandpa/rpc/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ mod tests {
179179
report, AuthorityId, FinalityProof, GrandpaJustification, GrandpaJustificationSender,
180180
};
181181
use sp_blockchain::HeaderBackend;
182-
use sp_core::crypto::Public;
182+
use sp_core::crypto::ByteArray;
183183
use sp_keyring::Ed25519Keyring;
184184
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
185185
use substrate_test_runtime_client::{
@@ -196,8 +196,8 @@ mod tests {
196196
}
197197

198198
fn voters() -> HashSet<AuthorityId> {
199-
let voter_id_1 = AuthorityId::from_slice(&[1; 32]);
200-
let voter_id_2 = AuthorityId::from_slice(&[2; 32]);
199+
let voter_id_1 = AuthorityId::from_slice(&[1; 32]).unwrap();
200+
let voter_id_2 = AuthorityId::from_slice(&[2; 32]).unwrap();
201201

202202
vec![voter_id_1, voter_id_2].into_iter().collect()
203203
}
@@ -245,7 +245,7 @@ mod tests {
245245

246246
impl ReportVoterState for TestVoterState {
247247
fn get(&self) -> Option<report::VoterState<AuthorityId>> {
248-
let voter_id_1 = AuthorityId::from_slice(&[1; 32]);
248+
let voter_id_1 = AuthorityId::from_slice(&[1; 32]).unwrap();
249249
let voters_best: HashSet<_> = vec![voter_id_1].into_iter().collect();
250250

251251
let best_round_state = sc_finality_grandpa::report::RoundState {

0 commit comments

Comments
 (0)