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

Remove Default bound for AccountId #10403

Merged
merged 52 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
d3af49f
Remove Default for AccountId
gavofyork Dec 2, 2021
f6827f1
More removals of default
gavofyork Dec 2, 2021
d397c5d
Update frame/authorship/src/lib.rs
gavofyork Dec 2, 2021
c446fff
Update frame/authorship/src/lib.rs
gavofyork Dec 2, 2021
19023db
Update frame/authorship/src/lib.rs
gavofyork Dec 2, 2021
80df1fb
Update frame/authorship/src/lib.rs
gavofyork Dec 2, 2021
2cbe13a
More work
gavofyork Dec 2, 2021
0930529
More work
gavofyork Dec 2, 2021
016a1ee
Remove old code
gavofyork Dec 2, 2021
594deb9
More work
gavofyork Dec 2, 2021
daa2942
pallet-asset-tx-payment
gavofyork Dec 2, 2021
0f270da
tips
gavofyork Dec 2, 2021
393ed87
sc-consensus-babe
gavofyork Dec 2, 2021
7169d84
sc-finality-grandpa
gavofyork Dec 2, 2021
a853bcc
sc-consensus-babe-rpc
gavofyork Dec 2, 2021
4cb42ff
sc-cli
gavofyork Dec 2, 2021
2a04445
make npos crates accept non-default account (#10420)
kianenigma Dec 4, 2021
452651c
more work
gavofyork Dec 4, 2021
227f360
more work
gavofyork Dec 4, 2021
345c87b
Tests build
gavofyork Dec 6, 2021
c12d8cf
Fix imonline tests
gavofyork Dec 7, 2021
2cfd1d0
Formatting
gavofyork Dec 7, 2021
b537356
Merge branch 'master' into gav-no-default-accountid
gavofyork Dec 7, 2021
f5758f1
Fixes
gavofyork Dec 7, 2021
9965af3
Merge branch 'gav-no-default-accountid' of github.com:paritytech/subs…
gavofyork Dec 7, 2021
3dc3969
Fixes
gavofyork Dec 7, 2021
b7fe115
Merge remote-tracking branch 'origin/master' into gav-no-default-acco…
gavofyork Dec 9, 2021
c9c7ba7
Fix bench
kianenigma Dec 9, 2021
ea520fa
Fixes
gavofyork Dec 9, 2021
b694599
Fixes
gavofyork Dec 9, 2021
97ec65a
Fixes
gavofyork Dec 10, 2021
b9c1e17
Fixes
gavofyork Dec 10, 2021
ddfbfa9
Fixes
gavofyork Dec 10, 2021
2316103
Formatting
gavofyork Dec 10, 2021
d302551
Fixes
gavofyork Dec 10, 2021
915bf1c
Formatting
gavofyork Dec 10, 2021
cfb1418
Fixes
gavofyork Dec 10, 2021
ed72cad
Formatting
gavofyork Dec 10, 2021
6e1b9e7
Fixes
gavofyork Dec 10, 2021
5fab98c
Formatting
gavofyork Dec 10, 2021
8eccc1d
Merge remote-tracking branch 'origin/master' into gav-no-default-acco…
gavofyork Dec 11, 2021
67492d1
Fixes
gavofyork Dec 11, 2021
b465b2d
Formatting
gavofyork Dec 11, 2021
26053ee
Merge branch 'master' into gav-no-default-accountid
gavofyork Dec 11, 2021
87351bb
Update client/keystore/src/local.rs
gavofyork Dec 12, 2021
f7939bb
Update client/finality-grandpa/src/lib.rs
gavofyork Dec 12, 2021
5e157c9
Update client/keystore/src/local.rs
gavofyork Dec 12, 2021
3557e13
Update client/keystore/src/local.rs
gavofyork Dec 12, 2021
c147de9
Update frame/staking/src/lib.rs
gavofyork Dec 12, 2021
fa596c1
Update frame/staking/src/lib.rs
gavofyork Dec 12, 2021
aa7ac28
Update primitives/runtime/src/traits.rs
gavofyork Dec 12, 2021
175596a
Formatting
gavofyork Dec 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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::{Pair, Public, ByteArray};
use sp_inherents::CreateInherentDataProviders;
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::{Pair, Public, ByteArray};
use sp_runtime::{traits::Header, DigestItem};

/// BABE verification parameters
Expand Down
19 changes: 11 additions & 8 deletions client/keystore/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ 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::{CryptoTypePublicPair, ExposeSecret, KeyTypeId, Pair as PairT, ByteArray, SecretString},
sr25519::{Pair as Sr25519Pair, Public as Sr25519Public},
Encode,
};
Expand Down Expand Up @@ -189,7 +189,8 @@ 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 key - Invalid size".into()))?;
gavofyork marked this conversation as resolved.
Show resolved Hide resolved
let key_pair = self
.0
.read()
Expand All @@ -198,7 +199,8 @@ 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 key - Invalid size".into()))?;
gavofyork marked this conversation as resolved.
Show resolved Hide resolved
let key_pair = self
.0
.read()
Expand All @@ -207,7 +209,8 @@ 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 key - Invalid size".into()))?;
gavofyork marked this conversation as resolved.
Show resolved Hide resolved
let key_pair = self
.0
.read()
Expand All @@ -223,7 +226,7 @@ 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()
}

Expand All @@ -246,7 +249,7 @@ 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()
}

Expand All @@ -269,7 +272,7 @@ 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()
}

Expand Down Expand Up @@ -562,7 +565,7 @@ 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())
.map(|v| v.into_iter().filter_map(|k| Public::from_slice(k.as_slice()).ok()).collect())
}

fn generate<Pair: AppPair>(&mut self) -> Result<Pair> {
Expand Down
23 changes: 12 additions & 11 deletions frame/authorship/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ pub mod pallet {

<DidSetUncles<T>>::put(false);

T::EventHandler::note_author(Self::author());
if let Some(author) = Self::author() {
T::EventHandler::note_author(author);
}

0
}
Expand Down Expand Up @@ -300,19 +302,19 @@ impl<T: Config> Pallet<T> {
///
/// This is safe to invoke in `on_initialize` implementations, as well
/// as afterwards.
pub fn author() -> T::AccountId {
pub fn author() -> Option<T::AccountId> {
gavofyork marked this conversation as resolved.
Show resolved Hide resolved
// Check the memoized storage value.
if let Some(author) = <Author<T>>::get() {
return author
return Some(author)
}

let digest = <frame_system::Pallet<T>>::digest();
let pre_runtime_digests = digest.logs.iter().filter_map(|d| d.as_pre_runtime());
if let Some(author) = T::FindAuthor::find_author(pre_runtime_digests) {
<Author<T>>::put(&author);
gavofyork marked this conversation as resolved.
Show resolved Hide resolved
author
Some(author)
gavofyork marked this conversation as resolved.
Show resolved Hide resolved
} else {
gavofyork marked this conversation as resolved.
Show resolved Hide resolved
Default::default()
None
}
gavofyork marked this conversation as resolved.
Show resolved Hide resolved
}

Expand All @@ -329,14 +331,13 @@ impl<T: Config> Pallet<T> {
UncleEntryItem::InclusionHeight(_) => None,
UncleEntryItem::Uncle(h, _) => Some(h),
});
let author = Self::verify_uncle(&uncle, prev_uncles, &mut acc)?;
let maybe_author = Self::verify_uncle(&uncle, prev_uncles, &mut acc)?;
let hash = uncle.hash();

T::EventHandler::note_uncle(
author.clone().unwrap_or_default(),
now - uncle.number().clone(),
);
uncles.push(UncleEntryItem::Uncle(hash, author));
if let Some(author) = maybe_author.clone() {
T::EventHandler::note_uncle(author, now - uncle.number().clone());
}
uncles.push(UncleEntryItem::Uncle(hash, maybe_author));
}

<Uncles<T>>::put(&uncles);
Expand Down
2 changes: 1 addition & 1 deletion frame/babe/src/equivocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ where
}

fn block_author() -> Option<T::AccountId> {
Some(<pallet_authorship::Pallet<T>>::author())
<pallet_authorship::Pallet<T>>::author()
}
}

Expand Down
6 changes: 3 additions & 3 deletions frame/benchmarking/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,17 +321,17 @@ pub trait BenchmarkingSetup<T, I = ()> {
}

/// Grab an account, seeded by a name and index.
pub fn account<AccountId: Decode + Default>(
pub fn account<AccountId: Decode>(
name: &'static str,
index: u32,
seed: u32,
) -> AccountId {
let entropy = (name, index, seed).using_encoded(blake2_256);
AccountId::decode(&mut &entropy[..]).unwrap_or_default()
AccountId::decode(&mut &entropy[..]).expect("`AccountId` type must be able to decode from any 32 bytes; qed")
gavofyork marked this conversation as resolved.
Show resolved Hide resolved
}

/// This caller account is automatically whitelisted for DB reads/writes by the benchmarking macro.
pub fn whitelisted_caller<AccountId: Decode + Default>() -> AccountId {
pub fn whitelisted_caller<AccountId: Decode>() -> AccountId {
account::<AccountId>("whitelisted_caller", 0, 0)
}

Expand Down
12 changes: 11 additions & 1 deletion frame/elections-phragmen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub enum Renouncing {
}

/// An active voter.
#[derive(Encode, Decode, Clone, Default, RuntimeDebug, PartialEq, TypeInfo)]
#[derive(Encode, Decode, Clone, RuntimeDebug, PartialEq, TypeInfo)]
pub struct Voter<AccountId, Balance> {
/// The members being backed.
pub votes: Vec<AccountId>,
Expand All @@ -159,6 +159,16 @@ pub struct Voter<AccountId, Balance> {
pub deposit: Balance,
}

impl<AccountId, Balance: Default> Default for Voter<AccountId, Balance> {
fn default() -> Self {
Self {
votes: vec![],
stake: Default::default(),
deposit: Default::default(),
}
}
}

/// A holder of a seat as either a member or a runner-up.
#[derive(Encode, Decode, Clone, Default, RuntimeDebug, PartialEq, TypeInfo)]
pub struct SeatHolder<AccountId, Balance> {
Expand Down
8 changes: 5 additions & 3 deletions frame/examples/parallel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ pub struct EnlistedParticipant {

impl EnlistedParticipant {
fn verify(&self, event_id: &[u8]) -> bool {
use sp_core::Public;
use sp_core::ByteArray;
use sp_runtime::traits::Verify;

match sp_core::sr25519::Signature::try_from(&self.signature[..]) {
Ok(signature) => {
let public = sp_core::sr25519::Public::from_slice(self.account.as_ref());
signature.verify(event_id, &public)
match sp_core::sr25519::Public::from_slice(self.account.as_ref()) {
Err(()) => false,
Ok(signer) => signature.verify(event_id, &signer),
}
},
_ => false,
}
Expand Down
2 changes: 1 addition & 1 deletion frame/grandpa/src/equivocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ where
}

fn block_author() -> Option<T::AccountId> {
Some(<pallet_authorship::Pallet<T>>::author())
<pallet_authorship::Pallet<T>>::author()
}
}

Expand Down
2 changes: 1 addition & 1 deletion frame/multisig/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ impl<T: Config> Pallet<T> {
/// NOTE: `who` must be sorted. If it is not, then you'll get the wrong answer.
pub fn multi_account_id(who: &[T::AccountId], threshold: u16) -> T::AccountId {
let entropy = (b"modlpy/utilisuba", who, threshold).using_encoded(blake2_256);
T::AccountId::decode(&mut &entropy[..]).unwrap_or_default()
T::AccountId::decode(&mut &entropy[..]).expect("`AccountId` is never larger than 256 bits; qed")
}

fn operate(
Expand Down
2 changes: 1 addition & 1 deletion frame/proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ impl<T: Config> Pallet<T> {
});
let entropy = (b"modlpy/proxy____", who, height, ext_index, proxy_type, index)
.using_encoded(blake2_256);
T::AccountId::decode(&mut &entropy[..]).unwrap_or_default()
T::AccountId::decode(&mut &entropy[..]).expect("`AccountId` type is never greater than 32 bytes; qed")
}

/// Register a proxy account for the delegator that is able to make calls on its behalf.
Expand Down
15 changes: 9 additions & 6 deletions frame/session/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,9 @@ impl<AId> SessionHandler<AId> for Tuple {
for_tuples!(
#(
let our_keys: Box<dyn Iterator<Item=_>> = Box::new(validators.iter()
.map(|k| (&k.0, k.1.get::<Tuple::Key>(<Tuple::Key as RuntimeAppPublic>::ID)
.unwrap_or_default())));
.filter_map(|k|
(&k.0, k.1.get::<Tuple::Key>(<Tuple::Key as RuntimeAppPublic>::ID)))
);

Tuple::on_genesis_session(our_keys);
)*
Expand All @@ -328,11 +329,13 @@ impl<AId> SessionHandler<AId> for Tuple {
for_tuples!(
#(
let our_keys: Box<dyn Iterator<Item=_>> = Box::new(validators.iter()
.map(|k| (&k.0, k.1.get::<Tuple::Key>(<Tuple::Key as RuntimeAppPublic>::ID)
.unwrap_or_default())));
.filter_map(|k|
(&k.0, k.1.get::<Tuple::Key>(<Tuple::Key as RuntimeAppPublic>::ID)))
);
let queued_keys: Box<dyn Iterator<Item=_>> = Box::new(queued_validators.iter()
.map(|k| (&k.0, k.1.get::<Tuple::Key>(<Tuple::Key as RuntimeAppPublic>::ID)
.unwrap_or_default())));
.filter_map(|k|
(&k.0, k.1.get::<Tuple::Key>(<Tuple::Key as RuntimeAppPublic>::ID)))
);
Tuple::on_new_session(changed, our_keys, queued_keys);
)*
)
Expand Down
4 changes: 3 additions & 1 deletion frame/staking/src/pallet/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,9 @@ where
Self::reward_by_ids(vec![(author, 20)])
}
fn note_uncle(author: T::AccountId, _age: T::BlockNumber) {
Self::reward_by_ids(vec![(<pallet_authorship::Pallet<T>>::author(), 2), (author, 1)])
if let Some(author) = <pallet_authorship::Pallet<T>>::author() {
Self::reward_by_ids(vec![(author, 2), (author, 1)])
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion frame/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2051,7 +2051,7 @@ fn reward_from_authorship_event_handler_works() {
ExtBuilder::default().build_and_execute(|| {
use pallet_authorship::EventHandler;

assert_eq!(<pallet_authorship::Pallet<Test>>::author(), 11);
assert_eq!(<pallet_authorship::Pallet<Test>>::author(), Some(11));

<Pallet<Test>>::note_author(11);
<Pallet<Test>>::note_uncle(21, 1);
Expand Down
8 changes: 5 additions & 3 deletions frame/sudo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,20 +274,22 @@ pub mod pallet {
#[pallet::genesis_config]
pub struct GenesisConfig<T: Config> {
/// The `AccountId` of the sudo key.
pub key: T::AccountId,
pub key: Option<T::AccountId>,
gavofyork marked this conversation as resolved.
Show resolved Hide resolved
}

#[cfg(feature = "std")]
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
Self { key: Default::default() }
Self { key: None }
}
}

#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
fn build(&self) {
<Key<T>>::put(&self.key);
if let Some(ref key) = self.key {
<Key<T>>::put(key);
}
}
}
}
2 changes: 1 addition & 1 deletion frame/support/src/traits/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub trait VerifySeal<Header, Author> {
/// A session handler for specific key type.
pub trait OneSessionHandler<ValidatorId>: BoundToRuntimeAppPublic {
/// The key type expected.
type Key: Decode + Default + RuntimeAppPublic;
type Key: Decode + RuntimeAppPublic;

/// The given validator set will be used for the genesis session.
/// It is guaranteed that the given validator set will also be used
Expand Down
1 change: 0 additions & 1 deletion frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ pub mod pallet {
+ Debug
+ MaybeDisplay
+ Ord
+ Default
+ MaxEncodedLen;

/// Converting trait to take a source type and convert to `AccountId`.
Expand Down
9 changes: 5 additions & 4 deletions frame/transaction-payment/asset-tx-payment/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,11 @@ impl pallet_authorship::Config for Runtime {
pub struct CreditToBlockAuthor;
impl HandleCredit<AccountId, Assets> for CreditToBlockAuthor {
fn handle_credit(credit: CreditOf<AccountId, Assets>) {
let author = pallet_authorship::Pallet::<Runtime>::author();
// What to do in case paying the author fails (e.g. because `fee < min_balance`)
// default: drop the result which will trigger the `OnDrop` of the imbalance.
let _ = <Assets as Balanced<AccountId>>::resolve(&author, credit);
if let Some(author) = pallet_authorship::Pallet::<Runtime>::author() {
// What to do in case paying the author fails (e.g. because `fee < min_balance`)
// default: drop the result which will trigger the `OnDrop` of the imbalance.
let _ = <Assets as Balanced<AccountId>>::resolve(&author, credit);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion primitives/application-crypto/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ impl RuntimePublic for Public {
}

fn to_raw_vec(&self) -> Vec<u8> {
sp_core::crypto::Public::to_raw_vec(self)
sp_core::crypto::ByteArray::to_raw_vec(self)
}
}
2 changes: 1 addition & 1 deletion primitives/application-crypto/src/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ impl RuntimePublic for Public {
}

fn to_raw_vec(&self) -> Vec<u8> {
sp_core::crypto::Public::to_raw_vec(self)
sp_core::crypto::ByteArray::to_raw_vec(self)
}
}
Loading