Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 16 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
15 changes: 0 additions & 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 @@ -80,7 +80,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
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
18 changes: 6 additions & 12 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::{Ss58Codec, ByteArray};
use structopt::StructOpt;

/// The `verify` command
Expand Down Expand Up @@ -63,22 +63,16 @@ impl VerifyCmd {
}
}

fn verify<Pair>(sig_data: Vec<u8>, message: Vec<u8>, uri: &str) -> error::Result<()>
where
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
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/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::{Pair, ByteArray};
use sp_runtime::{traits::Header, DigestItem};

/// BABE verification parameters
Expand Down
15 changes: 7 additions & 8 deletions client/finality-grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -763,8 +763,7 @@ 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<_>>();
Expand All @@ -778,7 +777,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,
);
Expand Down Expand Up @@ -917,16 +916,16 @@ 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("".into(), |s| s.to_string());

telemetry!(
self.telemetry;
CONSENSUS_DEBUG;
"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();
Expand All @@ -943,7 +942,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,
);
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()))?;
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()))?;
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()))?;
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
26 changes: 11 additions & 15 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,20 +302,15 @@ 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> {
// 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);
author
} else {
Default::default()
}
T::FindAuthor::find_author(pre_runtime_digests).map(|a| { <Author<T>>::put(&a); a })
}

fn verify_and_import_uncles(new_uncles: Vec<T::Header>) -> dispatch::DispatchResult {
Expand All @@ -329,14 +326,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
8 changes: 5 additions & 3 deletions frame/benchmarking/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use frame_support::{
traits::StorageInfo,
};
use sp_io::hashing::blake2_256;
use sp_runtime::traits::TrailingZeroInput;
use sp_std::{prelude::Box, vec::Vec};
use sp_storage::TrackedStorageKey;

Expand Down Expand Up @@ -321,17 +322,18 @@ 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()
Decode::decode(&mut TrailingZeroInput::new(entropy.as_ref()))
.expect("infinite length input; no invalid inputs for type; qed")
}

/// 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
2 changes: 1 addition & 1 deletion frame/election-provider-multi-phase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ pub mod pallet {
/// affect; we shouldn't need a cryptographically secure hasher.
#[pallet::storage]
pub(crate) type SignedSubmissionsMap<T: Config> =
StorageMap<_, Twox64Concat, u32, SignedSubmissionOf<T>, ValueQuery>;
StorageMap<_, Twox64Concat, u32, SignedSubmissionOf<T>, OptionQuery>;

// `SignedSubmissions` items end here.

Expand Down
Loading