mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-18 01:21:01 +00:00
Apply some clippy lints (#11154)
* Apply some clippy hints * Revert clippy ci changes * Update client/cli/src/commands/generate.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/cli/src/commands/inspect_key.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/db/src/bench.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/db/src/bench.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/service/src/client/block_rules.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/service/src/client/block_rules.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/network/src/transactions.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/network/src/protocol.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Revert due to missing `or_default` function. * Fix compilation and simplify code * Undo change that corrupts benchmark. * fix clippy * Update client/service/test/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/state-db/src/noncanonical.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/state-db/src/noncanonical.rs remove leftovers! * Update client/tracing/src/logging/directives.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update utils/fork-tree/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * added needed ref * Update frame/referenda/src/benchmarking.rs * Simplify byte-vec creation * let's just not overlap the ranges * Correction * cargo fmt * Update utils/frame/benchmarking-cli/src/shared/stats.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update utils/frame/benchmarking-cli/src/pallet/command.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update utils/frame/benchmarking-cli/src/pallet/command.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Giles Cope <gilescope@gmail.com>
This commit is contained in:
committed by
GitHub
parent
a990473cf9
commit
b581604aa7
@@ -188,7 +188,7 @@ fn generate_native_call_generators(decl: &ItemTrait) -> Result<TokenStream> {
|
||||
|
||||
// Generate a native call generator for each function of the given trait.
|
||||
for fn_ in fns {
|
||||
let params = extract_parameter_names_types_and_borrows(&fn_, AllowSelfRefInParameters::No)?;
|
||||
let params = extract_parameter_names_types_and_borrows(fn_, AllowSelfRefInParameters::No)?;
|
||||
let trait_fn_name = &fn_.ident;
|
||||
let function_name_str = fn_.ident.to_string();
|
||||
let fn_name = generate_native_call_generator_fn_name(&fn_.ident);
|
||||
@@ -336,7 +336,7 @@ fn generate_call_api_at_calls(decl: &ItemTrait) -> Result<TokenStream> {
|
||||
// Generate a native call generator for each function of the given trait.
|
||||
for (attrs, fn_) in fns {
|
||||
let trait_name = &decl.ident;
|
||||
let trait_fn_name = prefix_function_with_trait(&trait_name, &fn_.ident);
|
||||
let trait_fn_name = prefix_function_with_trait(trait_name, &fn_.ident);
|
||||
let fn_name = generate_call_api_at_fn_name(&fn_.ident);
|
||||
|
||||
let attrs = remove_supported_attributes(&mut attrs.clone());
|
||||
@@ -360,7 +360,7 @@ fn generate_call_api_at_calls(decl: &ItemTrait) -> Result<TokenStream> {
|
||||
let mut renames = Vec::new();
|
||||
if let Some((_, a)) = attrs.iter().find(|a| a.0 == &RENAMED_ATTRIBUTE) {
|
||||
let (old_name, version) = parse_renamed_attribute(a)?;
|
||||
renames.push((version, prefix_function_with_trait(&trait_name, &old_name)));
|
||||
renames.push((version, prefix_function_with_trait(trait_name, &old_name)));
|
||||
}
|
||||
|
||||
renames.sort_by(|l, r| r.cmp(l));
|
||||
@@ -582,7 +582,7 @@ impl<'a> ToClientSideDecl<'a> {
|
||||
Vec::new()
|
||||
},
|
||||
};
|
||||
let name = generate_method_runtime_api_impl_name(&self.trait_, &method.sig.ident);
|
||||
let name = generate_method_runtime_api_impl_name(self.trait_, &method.sig.ident);
|
||||
let block_id = self.block_id;
|
||||
let crate_ = self.crate_;
|
||||
|
||||
@@ -619,9 +619,9 @@ impl<'a> ToClientSideDecl<'a> {
|
||||
let params2 = params.clone();
|
||||
let ret_type = return_type_extract_type(&method.sig.output);
|
||||
|
||||
fold_fn_decl_for_client_side(&mut method.sig, &self.block_id, &self.crate_);
|
||||
fold_fn_decl_for_client_side(&mut method.sig, self.block_id, self.crate_);
|
||||
|
||||
let name_impl = generate_method_runtime_api_impl_name(&self.trait_, &method.sig.ident);
|
||||
let name_impl = generate_method_runtime_api_impl_name(self.trait_, &method.sig.ident);
|
||||
let crate_ = self.crate_;
|
||||
|
||||
let found_attributes = remove_supported_attributes(&mut method.attrs);
|
||||
@@ -630,7 +630,7 @@ impl<'a> ToClientSideDecl<'a> {
|
||||
let (native_handling, param_tuple) = match get_changed_in(&found_attributes) {
|
||||
Ok(Some(version)) => {
|
||||
// Make sure that the `changed_in` version is at least the current `api_version`.
|
||||
if get_api_version(&self.found_attributes).ok() < Some(version) {
|
||||
if get_api_version(self.found_attributes).ok() < Some(version) {
|
||||
self.errors.push(
|
||||
Error::new(
|
||||
method.span(),
|
||||
@@ -972,7 +972,7 @@ pub fn decl_runtime_apis_impl(input: proc_macro::TokenStream) -> proc_macro::Tok
|
||||
}
|
||||
|
||||
fn decl_runtime_apis_impl_inner(api_decls: &[ItemTrait]) -> Result<TokenStream> {
|
||||
check_trait_decls(&api_decls)?;
|
||||
check_trait_decls(api_decls)?;
|
||||
|
||||
let hidden_includes = generate_hidden_includes(HIDDEN_INCLUDES_ID);
|
||||
let runtime_decls = generate_runtime_decls(api_decls)?;
|
||||
|
||||
@@ -491,7 +491,7 @@ impl<'a> Fold for ApiRuntimeImplToApiRuntimeApiImpl<'a> {
|
||||
};
|
||||
|
||||
input.sig.ident =
|
||||
generate_method_runtime_api_impl_name(&self.impl_trait, &input.sig.ident);
|
||||
generate_method_runtime_api_impl_name(self.impl_trait, &input.sig.ident);
|
||||
let ret_type = return_type_extract_type(&input.sig.output);
|
||||
|
||||
// Generate the correct return type.
|
||||
@@ -593,7 +593,7 @@ fn generate_api_impl_for_runtime_api(impls: &[ItemImpl]) -> Result<TokenStream>
|
||||
let mut result = Vec::with_capacity(impls.len());
|
||||
|
||||
for impl_ in impls {
|
||||
let impl_trait_path = extract_impl_trait(&impl_, RequireQualifiedTraitPath::Yes)?;
|
||||
let impl_trait_path = extract_impl_trait(impl_, RequireQualifiedTraitPath::Yes)?;
|
||||
let impl_trait = &impl_trait_path
|
||||
.segments
|
||||
.last()
|
||||
@@ -634,7 +634,7 @@ fn generate_runtime_api_versions(impls: &[ItemImpl]) -> Result<TokenStream> {
|
||||
|
||||
for impl_ in impls {
|
||||
let mut path = extend_with_runtime_decl_path(
|
||||
extract_impl_trait(&impl_, RequireQualifiedTraitPath::Yes)?.clone(),
|
||||
extract_impl_trait(impl_, RequireQualifiedTraitPath::Yes)?.clone(),
|
||||
);
|
||||
// Remove the trait
|
||||
let trait_ = path
|
||||
@@ -723,7 +723,7 @@ fn impl_runtime_apis_impl_inner(api_impls: &[ItemImpl]) -> Result<TokenStream> {
|
||||
|
||||
// Filters all attributes except the cfg ones.
|
||||
fn filter_cfg_attrs(attrs: &[Attribute]) -> Vec<Attribute> {
|
||||
attrs.into_iter().filter(|a| a.path.is_ident("cfg")).cloned().collect()
|
||||
attrs.iter().filter(|a| a.path.is_ident("cfg")).cloned().collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -283,7 +283,7 @@ impl<'a> Fold for FoldRuntimeApiImpl<'a> {
|
||||
};
|
||||
|
||||
input.sig.ident =
|
||||
generate_method_runtime_api_impl_name(&self.impl_trait, &input.sig.ident);
|
||||
generate_method_runtime_api_impl_name(self.impl_trait, &input.sig.ident);
|
||||
|
||||
// When using advanced, the user needs to declare the correct return type on its own,
|
||||
// otherwise do it for the user.
|
||||
@@ -350,7 +350,7 @@ fn generate_runtime_api_impls(impls: &[ItemImpl]) -> Result<GeneratedRuntimeApiI
|
||||
let mut self_ty: Option<Box<Type>> = None;
|
||||
|
||||
for impl_ in impls {
|
||||
let impl_trait_path = extract_impl_trait(&impl_, RequireQualifiedTraitPath::No)?;
|
||||
let impl_trait_path = extract_impl_trait(impl_, RequireQualifiedTraitPath::No)?;
|
||||
let impl_trait = &impl_trait_path
|
||||
.segments
|
||||
.last()
|
||||
|
||||
@@ -61,12 +61,11 @@ pub fn generate_crate_access(unique_id: &'static str) -> TokenStream {
|
||||
let mod_name = generate_hidden_includes_mod_name(unique_id);
|
||||
quote!( self::#mod_name::sp_api )
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Generates the name of the module that contains the trait declaration for the runtime.
|
||||
pub fn generate_runtime_mod_name_for_trait(trait_: &Ident) -> Ident {
|
||||
Ident::new(&format!("runtime_decl_for_{}", trait_.to_string()), Span::call_site())
|
||||
Ident::new(&format!("runtime_decl_for_{}", trait_), Span::call_site())
|
||||
}
|
||||
|
||||
/// Generates a name for a method that needs to be implemented in the runtime for the client side.
|
||||
@@ -169,17 +168,17 @@ pub fn extract_parameter_names_types_and_borrows(
|
||||
|
||||
/// Generates the name for the native call generator function.
|
||||
pub fn generate_native_call_generator_fn_name(fn_name: &Ident) -> Ident {
|
||||
Ident::new(&format!("{}_native_call_generator", fn_name.to_string()), Span::call_site())
|
||||
Ident::new(&format!("{}_native_call_generator", fn_name), Span::call_site())
|
||||
}
|
||||
|
||||
/// Generates the name for the call api at function.
|
||||
pub fn generate_call_api_at_fn_name(fn_name: &Ident) -> Ident {
|
||||
Ident::new(&format!("{}_call_api_at", fn_name.to_string()), Span::call_site())
|
||||
Ident::new(&format!("{}_call_api_at", fn_name), Span::call_site())
|
||||
}
|
||||
|
||||
/// Prefix the given function with the trait name.
|
||||
pub fn prefix_function_with_trait<F: ToString>(trait_: &Ident, function: &F) -> String {
|
||||
format!("{}_{}", trait_.to_string(), function.to_string())
|
||||
format!("{}_{}", trait_, function.to_string())
|
||||
}
|
||||
|
||||
/// Extract all types that appear in signatures in the given `ImplItem`'s.
|
||||
@@ -250,10 +249,7 @@ pub enum RequireQualifiedTraitPath {
|
||||
}
|
||||
|
||||
/// Extract the trait that is implemented by the given `ItemImpl`.
|
||||
pub fn extract_impl_trait<'a>(
|
||||
impl_: &'a ItemImpl,
|
||||
require: RequireQualifiedTraitPath,
|
||||
) -> Result<&'a Path> {
|
||||
pub fn extract_impl_trait(impl_: &ItemImpl, require: RequireQualifiedTraitPath) -> Result<&Path> {
|
||||
impl_
|
||||
.trait_
|
||||
.as_ref()
|
||||
|
||||
@@ -422,7 +422,7 @@ pub trait ConstructRuntimeApi<Block: BlockT, C: CallApiAt<Block>> {
|
||||
type RuntimeApi: ApiExt<Block>;
|
||||
|
||||
/// Construct an instance of the runtime api.
|
||||
fn construct_runtime_api<'a>(call: &'a C) -> ApiRef<'a, Self::RuntimeApi>;
|
||||
fn construct_runtime_api(call: &C) -> ApiRef<Self::RuntimeApi>;
|
||||
}
|
||||
|
||||
/// Init the [`RuntimeLogger`](sp_runtime::runtime_logger::RuntimeLogger).
|
||||
@@ -554,12 +554,11 @@ pub trait CallApiAt<Block: BlockT> {
|
||||
/// Calls the given api function with the given encoded arguments at the given block and returns
|
||||
/// the encoded result.
|
||||
fn call_api_at<
|
||||
'a,
|
||||
R: Encode + Decode + PartialEq,
|
||||
NC: FnOnce() -> result::Result<R, ApiError> + UnwindSafe,
|
||||
>(
|
||||
&self,
|
||||
params: CallApiAtParams<'a, Block, NC, Self::StateBackend>,
|
||||
params: CallApiAtParams<Block, NC, Self::StateBackend>,
|
||||
) -> Result<NativeOrEncoded<R>, ApiError>;
|
||||
|
||||
/// Returns the runtime version at the given block.
|
||||
@@ -604,7 +603,7 @@ pub trait ProvideRuntimeApi<Block: BlockT> {
|
||||
/// call to an api function, will `commit` its changes to an internal buffer. Otherwise,
|
||||
/// the modifications will be `discarded`. The modifications will not be applied to the
|
||||
/// storage, even on a `commit`.
|
||||
fn runtime_api<'a>(&'a self) -> ApiRef<'a, Self::Api>;
|
||||
fn runtime_api(&self) -> ApiRef<Self::Api>;
|
||||
}
|
||||
|
||||
/// Something that provides information about a runtime api.
|
||||
|
||||
@@ -53,7 +53,7 @@ impl RuntimePublic for Public {
|
||||
}
|
||||
|
||||
fn verify<M: AsRef<[u8]>>(&self, msg: &M, signature: &Self::Signature) -> bool {
|
||||
sp_io::crypto::ecdsa_verify(&signature, msg.as_ref(), self)
|
||||
sp_io::crypto::ecdsa_verify(signature, msg.as_ref(), self)
|
||||
}
|
||||
|
||||
fn to_raw_vec(&self) -> Vec<u8> {
|
||||
|
||||
@@ -53,7 +53,7 @@ impl RuntimePublic for Public {
|
||||
}
|
||||
|
||||
fn verify<M: AsRef<[u8]>>(&self, msg: &M, signature: &Self::Signature) -> bool {
|
||||
sp_io::crypto::ed25519_verify(&signature, msg.as_ref(), self)
|
||||
sp_io::crypto::ed25519_verify(signature, msg.as_ref(), self)
|
||||
}
|
||||
|
||||
fn to_raw_vec(&self) -> Vec<u8> {
|
||||
|
||||
@@ -53,7 +53,7 @@ impl RuntimePublic for Public {
|
||||
}
|
||||
|
||||
fn verify<M: AsRef<[u8]>>(&self, msg: &M, signature: &Self::Signature) -> bool {
|
||||
sp_io::crypto::sr25519_verify(&signature, msg.as_ref(), self)
|
||||
sp_io::crypto::sr25519_verify(signature, msg.as_ref(), self)
|
||||
}
|
||||
|
||||
fn to_raw_vec(&self) -> Vec<u8> {
|
||||
|
||||
@@ -41,19 +41,19 @@ fn bench_op<F: Fn(&BigUint, &BigUint)>(c: &mut Criterion, name: &str, op: F) {
|
||||
|
||||
fn bench_addition(c: &mut Criterion) {
|
||||
bench_op(c, "addition", |a, b| {
|
||||
let _ = a.clone().add(&b);
|
||||
let _ = a.clone().add(b);
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_subtraction(c: &mut Criterion) {
|
||||
bench_op(c, "subtraction", |a, b| {
|
||||
let _ = a.clone().sub(&b);
|
||||
let _ = a.clone().sub(b);
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_multiplication(c: &mut Criterion) {
|
||||
bench_op(c, "multiplication", |a, b| {
|
||||
let _ = a.clone().mul(&b);
|
||||
let _ = a.clone().mul(b);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ fn main() {
|
||||
loop {
|
||||
fuzz!(|data: (Vec<Ty>, Ty)| {
|
||||
let (data, norm) = data;
|
||||
if data.len() == 0 {
|
||||
if data.is_empty() {
|
||||
return
|
||||
}
|
||||
let pre_sum: u128 = data.iter().map(|x| *x as u128).sum();
|
||||
@@ -44,16 +44,14 @@ fn main() {
|
||||
// error cases.
|
||||
if pre_sum > sum_limit || data.len() > len_limit {
|
||||
assert!(normalized.is_err())
|
||||
} else {
|
||||
if let Ok(normalized) = normalized {
|
||||
// if sum goes beyond u128, panic.
|
||||
let sum: u128 = normalized.iter().map(|x| *x as u128).sum();
|
||||
} else if let Ok(normalized) = normalized {
|
||||
// if sum goes beyond u128, panic.
|
||||
let sum: u128 = normalized.iter().map(|x| *x as u128).sum();
|
||||
|
||||
// if this function returns Ok(), then it will ALWAYS be accurate.
|
||||
assert_eq!(sum, norm as u128, "sums don't match {:?}, {}", normalized, norm);
|
||||
} else {
|
||||
panic!("Should have returned Ok for input = {:?}, target = {:?}", data, norm);
|
||||
}
|
||||
// if this function returns Ok(), then it will ALWAYS be accurate.
|
||||
assert_eq!(sum, norm as u128, "sums don't match {:?}, {}", normalized, norm);
|
||||
} else {
|
||||
panic!("Should have returned Ok for input = {:?}, target = {:?}", data, norm);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ where
|
||||
fn tcmp(&self, other: &T, threshold: T) -> Ordering {
|
||||
// early exit.
|
||||
if threshold.is_zero() {
|
||||
return self.cmp(&other)
|
||||
return self.cmp(other)
|
||||
}
|
||||
|
||||
let upper_bound = other.saturating_add(threshold);
|
||||
@@ -73,7 +73,7 @@ where
|
||||
|
||||
if upper_bound <= lower_bound {
|
||||
// defensive only. Can never happen.
|
||||
self.cmp(&other)
|
||||
self.cmp(other)
|
||||
} else {
|
||||
// upper_bound is guaranteed now to be bigger than lower.
|
||||
match (self.cmp(&lower_bound), self.cmp(&upper_bound)) {
|
||||
@@ -113,10 +113,7 @@ impl_normalize_for_numeric!(u8, u16, u32, u64, u128);
|
||||
|
||||
impl<P: PerThing> Normalizable<P> for Vec<P> {
|
||||
fn normalize(&self, targeted_sum: P) -> Result<Vec<P>, &'static str> {
|
||||
let uppers = self
|
||||
.iter()
|
||||
.map(|p| <UpperOf<P>>::from(p.clone().deconstruct()))
|
||||
.collect::<Vec<_>>();
|
||||
let uppers = self.iter().map(|p| <UpperOf<P>>::from(p.deconstruct())).collect::<Vec<_>>();
|
||||
|
||||
let normalized =
|
||||
normalize(uppers.as_ref(), <UpperOf<P>>::from(targeted_sum.deconstruct()))?;
|
||||
|
||||
@@ -63,14 +63,14 @@ impl Ord for RationalInfinite {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
// handle some edge cases.
|
||||
if self.d() == other.d() {
|
||||
self.n().cmp(&other.n())
|
||||
self.n().cmp(other.n())
|
||||
} else if self.d().is_zero() {
|
||||
Ordering::Greater
|
||||
} else if other.d().is_zero() {
|
||||
Ordering::Less
|
||||
} else {
|
||||
// (a/b) cmp (c/d) => (a*d) cmp (c*b)
|
||||
self.n().clone().mul(&other.d()).cmp(&other.n().clone().mul(&self.d()))
|
||||
self.n().clone().mul(other.d()).cmp(&other.n().clone().mul(self.d()))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -272,6 +272,7 @@ impl PartialEq for Rational128 {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{helpers_128bit::*, *};
|
||||
use static_assertions::const_assert;
|
||||
|
||||
const MAX128: u128 = u128::MAX;
|
||||
const MAX64: u128 = u64::MAX as u128;
|
||||
@@ -349,8 +350,8 @@ mod tests {
|
||||
r(1_000_000_000, MAX64).lcm(&r(7_000_000_000, MAX64 - 1)),
|
||||
Ok(340282366920938463408034375210639556610),
|
||||
);
|
||||
assert!(340282366920938463408034375210639556610 < MAX128);
|
||||
assert!(340282366920938463408034375210639556610 == MAX64 * (MAX64 - 1));
|
||||
const_assert!(340282366920938463408034375210639556610 < MAX128);
|
||||
const_assert!(340282366920938463408034375210639556610 == MAX64 * (MAX64 - 1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -184,7 +184,7 @@ pub trait Backend<Block: BlockT>:
|
||||
if let Some(max_number) = maybe_max_number {
|
||||
loop {
|
||||
let current_header = self
|
||||
.header(BlockId::Hash(current_hash.clone()))?
|
||||
.header(BlockId::Hash(current_hash))?
|
||||
.ok_or_else(|| Error::MissingHeader(current_hash.to_string()))?;
|
||||
|
||||
if current_header.number() <= &max_number {
|
||||
@@ -204,7 +204,7 @@ pub trait Backend<Block: BlockT>:
|
||||
}
|
||||
|
||||
let current_header = self
|
||||
.header(BlockId::Hash(current_hash.clone()))?
|
||||
.header(BlockId::Hash(current_hash))?
|
||||
.ok_or_else(|| Error::MissingHeader(current_hash.to_string()))?;
|
||||
|
||||
// stop search in this chain once we go below the target's block number
|
||||
|
||||
@@ -275,11 +275,11 @@ pub struct CachedHeaderMetadata<Block: BlockT> {
|
||||
impl<Block: BlockT> From<&Block::Header> for CachedHeaderMetadata<Block> {
|
||||
fn from(header: &Block::Header) -> Self {
|
||||
CachedHeaderMetadata {
|
||||
hash: header.hash().clone(),
|
||||
number: header.number().clone(),
|
||||
parent: header.parent_hash().clone(),
|
||||
state_root: header.state_root().clone(),
|
||||
ancestor: header.parent_hash().clone(),
|
||||
hash: header.hash(),
|
||||
number: *header.number(),
|
||||
parent: *header.parent_hash(),
|
||||
state_root: *header.state_root(),
|
||||
ancestor: *header.parent_hash(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ pub fn evaluate_initial<Block: BlockT>(
|
||||
parent_number: <<Block as BlockT>::Header as HeaderT>::Number,
|
||||
) -> Result<()> {
|
||||
let encoded = Encode::encode(proposal);
|
||||
let proposal = Block::decode(&mut &encoded[..]).map_err(|e| Error::BadProposalFormat(e))?;
|
||||
let proposal = Block::decode(&mut &encoded[..]).map_err(Error::BadProposalFormat)?;
|
||||
|
||||
if *parent_hash != *proposal.header().parent_hash() {
|
||||
return Err(Error::WrongParentHash {
|
||||
|
||||
@@ -169,7 +169,7 @@ impl ProofRecording for EnableProofRecording {
|
||||
const ENABLED: bool = true;
|
||||
|
||||
fn into_proof(proof: Option<StorageProof>) -> Result<Self::Proof, NoProofRecorded> {
|
||||
proof.ok_or_else(|| NoProofRecorded)
|
||||
proof.ok_or(NoProofRecorded)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ fn bench_hash_128_dyn_size(c: &mut Criterion) {
|
||||
fn bench_ed25519(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("ed25519");
|
||||
|
||||
for msg_size in vec![32, 1024, 1024 * 1024] {
|
||||
for &msg_size in &[32, 1024, 1024 * 1024] {
|
||||
let msg = (0..msg_size).map(|_| rand::random::<u8>()).collect::<Vec<_>>();
|
||||
let key = sp_core::ed25519::Pair::generate().0;
|
||||
group.bench_function(BenchmarkId::new("signing", format!("{}", msg_size)), |b| {
|
||||
@@ -87,7 +87,7 @@ fn bench_ed25519(c: &mut Criterion) {
|
||||
});
|
||||
}
|
||||
|
||||
for msg_size in vec![32, 1024, 1024 * 1024] {
|
||||
for &msg_size in &[32, 1024, 1024 * 1024] {
|
||||
let msg = (0..msg_size).map(|_| rand::random::<u8>()).collect::<Vec<_>>();
|
||||
let key = sp_core::ed25519::Pair::generate().0;
|
||||
let sig = key.sign(&msg);
|
||||
@@ -103,7 +103,7 @@ fn bench_ed25519(c: &mut Criterion) {
|
||||
fn bench_sr25519(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("sr25519");
|
||||
|
||||
for msg_size in vec![32, 1024, 1024 * 1024] {
|
||||
for &msg_size in &[32, 1024, 1024 * 1024] {
|
||||
let msg = (0..msg_size).map(|_| rand::random::<u8>()).collect::<Vec<_>>();
|
||||
let key = sp_core::sr25519::Pair::generate().0;
|
||||
group.bench_function(BenchmarkId::new("signing", format!("{}", msg_size)), |b| {
|
||||
@@ -111,7 +111,7 @@ fn bench_sr25519(c: &mut Criterion) {
|
||||
});
|
||||
}
|
||||
|
||||
for msg_size in vec![32, 1024, 1024 * 1024] {
|
||||
for &msg_size in &[32, 1024, 1024 * 1024] {
|
||||
let msg = (0..msg_size).map(|_| rand::random::<u8>()).collect::<Vec<_>>();
|
||||
let key = sp_core::sr25519::Pair::generate().0;
|
||||
let sig = key.sign(&msg);
|
||||
@@ -127,7 +127,7 @@ fn bench_sr25519(c: &mut Criterion) {
|
||||
fn bench_ecdsa(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("ecdsa");
|
||||
|
||||
for msg_size in vec![32, 1024, 1024 * 1024] {
|
||||
for &msg_size in &[32, 1024, 1024 * 1024] {
|
||||
let msg = (0..msg_size).map(|_| rand::random::<u8>()).collect::<Vec<_>>();
|
||||
let key = sp_core::ecdsa::Pair::generate().0;
|
||||
group.bench_function(BenchmarkId::new("signing", format!("{}", msg_size)), |b| {
|
||||
@@ -135,7 +135,7 @@ fn bench_ecdsa(c: &mut Criterion) {
|
||||
});
|
||||
}
|
||||
|
||||
for msg_size in vec![32, 1024, 1024 * 1024] {
|
||||
for &msg_size in &[32, 1024, 1024 * 1024] {
|
||||
let msg = (0..msg_size).map(|_| rand::random::<u8>()).collect::<Vec<_>>();
|
||||
let key = sp_core::ecdsa::Pair::generate().0;
|
||||
let sig = key.sign(&msg);
|
||||
|
||||
@@ -26,7 +26,7 @@ pub(super) struct MultipleInputBytes(pub Vec<Vec<u8>>);
|
||||
|
||||
impl MultipleInputBytes {
|
||||
pub(super) fn concatenated(mut self) -> Vec<u8> {
|
||||
if self.0.len() == 0 {
|
||||
if self.0.is_empty() {
|
||||
Vec::new()
|
||||
} else {
|
||||
let mut result = core::mem::take(&mut self.0[0]);
|
||||
|
||||
@@ -1172,7 +1172,7 @@ mod tests {
|
||||
impl ByteArray for TestPublic {
|
||||
const LEN: usize = 0;
|
||||
fn from_slice(bytes: &[u8]) -> Result<Self, ()> {
|
||||
if bytes.len() == 0 {
|
||||
if bytes.is_empty() {
|
||||
Ok(Self)
|
||||
} else {
|
||||
Err(())
|
||||
|
||||
@@ -364,7 +364,7 @@ impl From<RecoverableSignature> for Signature {
|
||||
/// Derive a single hard junction.
|
||||
#[cfg(feature = "full_crypto")]
|
||||
fn derive_hard_junction(secret_seed: &Seed, cc: &[u8; 32]) -> Seed {
|
||||
("Secp256k1HDKD", secret_seed, cc).using_encoded(|data| sp_core_hashing::blake2_256(data))
|
||||
("Secp256k1HDKD", secret_seed, cc).using_encoded(sp_core_hashing::blake2_256)
|
||||
}
|
||||
|
||||
/// An error when deriving a key.
|
||||
@@ -763,12 +763,12 @@ mod test {
|
||||
set_default_ss58_version(Ss58AddressFormat::custom(200));
|
||||
// custom addr encoded by version 200
|
||||
let addr = "4pbsSkWcBaYoFHrKJZp5fDVUKbqSYD9dhZZGvpp3vQ5ysVs5ybV";
|
||||
Public::from_ss58check(&addr).unwrap();
|
||||
Public::from_ss58check(addr).unwrap();
|
||||
|
||||
set_default_ss58_version(default_format);
|
||||
// set current ss58 version to default version
|
||||
let addr = "KWAfgC2aRG5UVD6CpbPQXCx4YZZUhvWqqAJE6qcYc9Rtr6g5C";
|
||||
Public::from_ss58check(&addr).unwrap();
|
||||
Public::from_ss58check(addr).unwrap();
|
||||
|
||||
println!("CUSTOM_FORMAT_SUCCESSFUL");
|
||||
} else {
|
||||
|
||||
@@ -397,7 +397,7 @@ impl From<&Public> for CryptoTypePublicPair {
|
||||
/// Derive a single hard junction.
|
||||
#[cfg(feature = "full_crypto")]
|
||||
fn derive_hard_junction(secret_seed: &Seed, cc: &[u8; 32]) -> Seed {
|
||||
("Ed25519HDKD", secret_seed, cc).using_encoded(|data| sp_core_hashing::blake2_256(data))
|
||||
("Ed25519HDKD", secret_seed, cc).using_encoded(sp_core_hashing::blake2_256)
|
||||
}
|
||||
|
||||
/// An error when deriving a key.
|
||||
|
||||
@@ -69,13 +69,13 @@ impl AsBytesRef for &[u8] {
|
||||
|
||||
impl AsBytesRef for [u8] {
|
||||
fn as_bytes_ref(&self) -> &[u8] {
|
||||
&self
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsBytesRef for sp_std::vec::Vec<u8> {
|
||||
fn as_bytes_ref(&self) -> &[u8] {
|
||||
&self
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -67,10 +67,9 @@ mod implementation {
|
||||
/// Derive the inner implementation of `Debug::fmt` function.
|
||||
pub fn derive(name_str: &str, data: &Data) -> TokenStream {
|
||||
match *data {
|
||||
Data::Struct(ref s) => derive_struct(&name_str, &s.fields),
|
||||
Data::Union(ref u) =>
|
||||
derive_fields(&name_str, Fields::new(u.fields.named.iter(), None)),
|
||||
Data::Enum(ref e) => derive_enum(&name_str, &e),
|
||||
Data::Struct(ref s) => derive_struct(name_str, &s.fields),
|
||||
Data::Union(ref u) => derive_fields(name_str, Fields::new(u.fields.named.iter(), None)),
|
||||
Data::Enum(ref e) => derive_enum(name_str, e),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -174,9 +174,7 @@ impl Extensions {
|
||||
}
|
||||
|
||||
/// Returns a mutable iterator over all extensions.
|
||||
pub fn iter_mut<'a>(
|
||||
&'a mut self,
|
||||
) -> impl Iterator<Item = (&'a TypeId, &'a mut Box<dyn Extension>)> {
|
||||
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&TypeId, &mut Box<dyn Extension>)> {
|
||||
self.extensions.iter_mut()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ pub const GRANDPA_ENGINE_ID: ConsensusEngineId = *b"FRNK";
|
||||
|
||||
/// The storage key for the current set of weighted Grandpa authorities.
|
||||
/// The value stored is an encoded VersionedAuthorityList.
|
||||
pub const GRANDPA_AUTHORITIES_KEY: &'static [u8] = b":grandpa_authorities";
|
||||
pub const GRANDPA_AUTHORITIES_KEY: &[u8] = b":grandpa_authorities";
|
||||
|
||||
/// The weight of an authority.
|
||||
pub type AuthorityWeight = u64;
|
||||
|
||||
@@ -220,7 +220,7 @@ pub trait Storage {
|
||||
|
||||
/// Get the next key in storage after the given one in lexicographic order.
|
||||
fn next_key(&mut self, key: &[u8]) -> Option<Vec<u8>> {
|
||||
self.next_storage_key(&key)
|
||||
self.next_storage_key(key)
|
||||
}
|
||||
|
||||
/// Start a new nested transaction.
|
||||
@@ -629,7 +629,7 @@ pub trait Crypto {
|
||||
///
|
||||
/// Returns the public key.
|
||||
fn ed25519_generate(&mut self, id: KeyTypeId, seed: Option<Vec<u8>>) -> ed25519::Public {
|
||||
let seed = seed.as_ref().map(|s| std::str::from_utf8(&s).expect("Seed is valid utf8!"));
|
||||
let seed = seed.as_ref().map(|s| std::str::from_utf8(s).expect("Seed is valid utf8!"));
|
||||
let keystore = &***self
|
||||
.extension::<KeystoreExt>()
|
||||
.expect("No `keystore` associated for the current context!");
|
||||
@@ -678,7 +678,7 @@ pub trait Crypto {
|
||||
pub_key: &ed25519::Public,
|
||||
) -> bool {
|
||||
self.extension::<VerificationExt>()
|
||||
.map(|extension| extension.push_ed25519(sig.clone(), pub_key.clone(), msg.to_vec()))
|
||||
.map(|extension| extension.push_ed25519(sig.clone(), *pub_key, msg.to_vec()))
|
||||
.unwrap_or_else(|| ed25519_verify(sig, msg, pub_key))
|
||||
}
|
||||
|
||||
@@ -705,7 +705,7 @@ pub trait Crypto {
|
||||
pub_key: &sr25519::Public,
|
||||
) -> bool {
|
||||
self.extension::<VerificationExt>()
|
||||
.map(|extension| extension.push_sr25519(sig.clone(), pub_key.clone(), msg.to_vec()))
|
||||
.map(|extension| extension.push_sr25519(sig.clone(), *pub_key, msg.to_vec()))
|
||||
.unwrap_or_else(|| sr25519_verify(sig, msg, pub_key))
|
||||
}
|
||||
|
||||
@@ -753,7 +753,7 @@ pub trait Crypto {
|
||||
///
|
||||
/// Returns the public key.
|
||||
fn sr25519_generate(&mut self, id: KeyTypeId, seed: Option<Vec<u8>>) -> sr25519::Public {
|
||||
let seed = seed.as_ref().map(|s| std::str::from_utf8(&s).expect("Seed is valid utf8!"));
|
||||
let seed = seed.as_ref().map(|s| std::str::from_utf8(s).expect("Seed is valid utf8!"));
|
||||
let keystore = &***self
|
||||
.extension::<KeystoreExt>()
|
||||
.expect("No `keystore` associated for the current context!");
|
||||
@@ -803,7 +803,7 @@ pub trait Crypto {
|
||||
///
|
||||
/// Returns the public key.
|
||||
fn ecdsa_generate(&mut self, id: KeyTypeId, seed: Option<Vec<u8>>) -> ecdsa::Public {
|
||||
let seed = seed.as_ref().map(|s| std::str::from_utf8(&s).expect("Seed is valid utf8!"));
|
||||
let seed = seed.as_ref().map(|s| std::str::from_utf8(s).expect("Seed is valid utf8!"));
|
||||
let keystore = &***self
|
||||
.extension::<KeystoreExt>()
|
||||
.expect("No `keystore` associated for the current context!");
|
||||
@@ -888,7 +888,7 @@ pub trait Crypto {
|
||||
pub_key: &ecdsa::Public,
|
||||
) -> bool {
|
||||
self.extension::<VerificationExt>()
|
||||
.map(|extension| extension.push_ecdsa(sig.clone(), pub_key.clone(), msg.to_vec()))
|
||||
.map(|extension| extension.push_ecdsa(sig.clone(), *pub_key, msg.to_vec()))
|
||||
.unwrap_or_else(|| ecdsa_verify(sig, msg, pub_key))
|
||||
}
|
||||
|
||||
@@ -1504,14 +1504,7 @@ pub trait Sandbox {
|
||||
state_ptr: Pointer<u8>,
|
||||
) -> u32 {
|
||||
self.sandbox()
|
||||
.invoke(
|
||||
instance_idx,
|
||||
&function,
|
||||
&args,
|
||||
return_val_ptr,
|
||||
return_val_len,
|
||||
state_ptr.into(),
|
||||
)
|
||||
.invoke(instance_idx, function, args, return_val_ptr, return_val_len, state_ptr.into())
|
||||
.expect("Failed to invoke function with sandbox")
|
||||
}
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ lazy_static! {
|
||||
|
||||
impl From<Keyring> for Public {
|
||||
fn from(k: Keyring) -> Self {
|
||||
(*PUBLIC_KEYS).get(&k).unwrap().clone()
|
||||
*(*PUBLIC_KEYS).get(&k).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -168,7 +168,7 @@ impl From<Keyring> for AccountId32 {
|
||||
|
||||
impl From<Keyring> for Public {
|
||||
fn from(k: Keyring) -> Self {
|
||||
(*PUBLIC_KEYS).get(&k).unwrap().clone()
|
||||
*(*PUBLIC_KEYS).get(&k).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -316,7 +316,7 @@ impl SyncCryptoStore for KeyStore {
|
||||
fn has_keys(&self, public_keys: &[(Vec<u8>, KeyTypeId)]) -> bool {
|
||||
public_keys
|
||||
.iter()
|
||||
.all(|(k, t)| self.keys.read().get(&t).and_then(|s| s.get(k)).is_some())
|
||||
.all(|(k, t)| self.keys.read().get(t).and_then(|s| s.get(k)).is_some())
|
||||
}
|
||||
|
||||
fn supported_keys(
|
||||
|
||||
@@ -231,7 +231,7 @@ impl<H: traits::Hash, L: FullLeaf> DataOrHash<H, L> {
|
||||
pub fn hash(&self) -> H::Output {
|
||||
match *self {
|
||||
Self::Data(ref leaf) => leaf.using_encoded(<H as traits::Hash>::hash, true),
|
||||
Self::Hash(ref hash) => hash.clone(),
|
||||
Self::Hash(ref hash) => *hash,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ pub fn generate_random_npos_inputs(
|
||||
|
||||
let mut chosen_candidates = Vec::with_capacity(n_candidates_chosen);
|
||||
chosen_candidates.extend(candidates.choose_multiple(&mut rng, n_candidates_chosen));
|
||||
chosen_candidates.sort();
|
||||
chosen_candidates.sort_unstable();
|
||||
voters.push((id, vote_weight, chosen_candidates));
|
||||
}
|
||||
|
||||
|
||||
@@ -53,11 +53,9 @@ fn main() {
|
||||
let stake_of = |who: &AccountId| -> VoteWeight { *stake_of_tree.get(who).unwrap() };
|
||||
|
||||
let unbalanced_score = {
|
||||
let staked = assignment_ratio_to_staked_normalized(
|
||||
unbalanced.assignments.clone(),
|
||||
&stake_of,
|
||||
)
|
||||
.unwrap();
|
||||
let staked =
|
||||
assignment_ratio_to_staked_normalized(unbalanced.assignments, &stake_of)
|
||||
.unwrap();
|
||||
let score = to_supports(staked.as_ref()).evaluate();
|
||||
|
||||
if score.minimal_stake == 0 {
|
||||
@@ -72,11 +70,9 @@ fn main() {
|
||||
seq_phragmen(to_elect, candidates, voters, Some((iterations, 0))).unwrap();
|
||||
|
||||
let balanced_score = {
|
||||
let staked = assignment_ratio_to_staked_normalized(
|
||||
balanced.assignments.clone(),
|
||||
&stake_of,
|
||||
)
|
||||
.unwrap();
|
||||
let staked =
|
||||
assignment_ratio_to_staked_normalized(balanced.assignments, &stake_of)
|
||||
.unwrap();
|
||||
to_supports(staked.as_ref()).evaluate()
|
||||
};
|
||||
|
||||
|
||||
@@ -53,11 +53,9 @@ fn main() {
|
||||
let stake_of = |who: &AccountId| -> VoteWeight { *stake_of_tree.get(who).unwrap() };
|
||||
|
||||
let unbalanced_score = {
|
||||
let staked = assignment_ratio_to_staked_normalized(
|
||||
unbalanced.assignments.clone(),
|
||||
&stake_of,
|
||||
)
|
||||
.unwrap();
|
||||
let staked =
|
||||
assignment_ratio_to_staked_normalized(unbalanced.assignments, &stake_of)
|
||||
.unwrap();
|
||||
let score = to_supports(&staked).evaluate();
|
||||
|
||||
if score.minimal_stake == 0 {
|
||||
@@ -72,8 +70,7 @@ fn main() {
|
||||
|
||||
let balanced_score = {
|
||||
let staked =
|
||||
assignment_ratio_to_staked_normalized(balanced.assignments.clone(), &stake_of)
|
||||
.unwrap();
|
||||
assignment_ratio_to_staked_normalized(balanced.assignments, &stake_of).unwrap();
|
||||
to_supports(staked.as_ref()).evaluate()
|
||||
};
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ fn reduce_and_compare(assignment: &Vec<StakedAssignment<AccountId>>, winners: &V
|
||||
let n = assignment.len() as u32;
|
||||
let m = winners.len() as u32;
|
||||
|
||||
let edges_before = assignment_len(&assignment);
|
||||
let edges_before = assignment_len(assignment);
|
||||
let num_changed = reduce(&mut altered_assignment);
|
||||
let edges_after = edges_before - num_changed;
|
||||
|
||||
|
||||
@@ -49,13 +49,9 @@ where
|
||||
for<'r> FS: Fn(&'r A) -> VoteWeight,
|
||||
{
|
||||
let mut staked = assignment_ratio_to_staked(ratio, &stake_of);
|
||||
staked
|
||||
.iter_mut()
|
||||
.map(|a| {
|
||||
a.try_normalize(stake_of(&a.who).into())
|
||||
.map_err(|err| Error::ArithmeticError(err))
|
||||
})
|
||||
.collect::<Result<_, _>>()?;
|
||||
staked.iter_mut().try_for_each(|a| {
|
||||
a.try_normalize(stake_of(&a.who).into()).map_err(Error::ArithmeticError)
|
||||
})?;
|
||||
Ok(staked)
|
||||
}
|
||||
|
||||
@@ -74,7 +70,7 @@ pub fn assignment_staked_to_ratio_normalized<A: IdentifierT, P: PerThing128>(
|
||||
) -> Result<Vec<Assignment<A, P>>, Error> {
|
||||
let mut ratio = staked.into_iter().map(|a| a.into_assignment()).collect::<Vec<_>>();
|
||||
for assignment in ratio.iter_mut() {
|
||||
assignment.try_normalize().map_err(|err| Error::ArithmeticError(err))?;
|
||||
assignment.try_normalize().map_err(Error::ArithmeticError)?;
|
||||
}
|
||||
Ok(ratio)
|
||||
}
|
||||
|
||||
@@ -456,8 +456,8 @@ pub fn to_support_map<AccountId: IdentifierT>(
|
||||
let mut supports = <BTreeMap<AccountId, Support<AccountId>>>::new();
|
||||
|
||||
// build support struct.
|
||||
for StakedAssignment { who, distribution } in assignments.into_iter() {
|
||||
for (c, weight_extended) in distribution.into_iter() {
|
||||
for StakedAssignment { who, distribution } in assignments.iter() {
|
||||
for (c, weight_extended) in distribution.iter() {
|
||||
let mut support = supports.entry(c.clone()).or_default();
|
||||
support.total = support.total.saturating_add(*weight_extended);
|
||||
support.voters.push((who.clone(), *weight_extended));
|
||||
|
||||
@@ -97,8 +97,7 @@ pub fn seq_phragmen<AccountId: IdentifierT, P: PerThing128>(
|
||||
voters.into_iter().filter_map(|v| v.into_assignment()).collect::<Vec<_>>();
|
||||
let _ = assignments
|
||||
.iter_mut()
|
||||
.map(|a| a.try_normalize().map_err(|e| crate::Error::ArithmeticError(e)))
|
||||
.collect::<Result<(), _>>()?;
|
||||
.try_for_each(|a| a.try_normalize().map_err(crate::Error::ArithmeticError))?;
|
||||
let winners = winners
|
||||
.into_iter()
|
||||
.map(|w_ptr| (w_ptr.borrow().who.clone(), w_ptr.borrow().backed_stake))
|
||||
@@ -200,7 +199,7 @@ pub fn seq_phragmen_core<AccountId: IdentifierT>(
|
||||
// edge of all candidates that eventually have a non-zero weight must be elected.
|
||||
debug_assert!(voter.edges.iter().all(|e| e.candidate.borrow().elected));
|
||||
// inc budget to sum the budget.
|
||||
voter.try_normalize_elected().map_err(|e| crate::Error::ArithmeticError(e))?;
|
||||
voter.try_normalize_elected().map_err(crate::Error::ArithmeticError)?;
|
||||
}
|
||||
|
||||
Ok((candidates, voters))
|
||||
|
||||
@@ -70,9 +70,8 @@ pub fn phragmms<AccountId: IdentifierT, P: PerThing128>(
|
||||
voters.into_iter().filter_map(|v| v.into_assignment()).collect::<Vec<_>>();
|
||||
let _ = assignments
|
||||
.iter_mut()
|
||||
.map(|a| a.try_normalize())
|
||||
.collect::<Result<(), _>>()
|
||||
.map_err(|e| crate::Error::ArithmeticError(e))?;
|
||||
.try_for_each(|a| a.try_normalize())
|
||||
.map_err(crate::Error::ArithmeticError)?;
|
||||
let winners = winners
|
||||
.into_iter()
|
||||
.map(|w_ptr| (w_ptr.borrow().who.clone(), w_ptr.borrow().backed_stake))
|
||||
@@ -157,16 +156,14 @@ pub(crate) fn calculate_max_score<AccountId: IdentifierT, P: PerThing>(
|
||||
// `RationalInfinite` as the score type does not introduce significant overhead. Then we
|
||||
// can switch the score type to `RationalInfinite` and ensure compatibility with any
|
||||
// crazy token scale.
|
||||
let score_n = candidate
|
||||
.approval_stake
|
||||
.checked_mul(one)
|
||||
.unwrap_or_else(|| Bounded::max_value());
|
||||
let score_n =
|
||||
candidate.approval_stake.checked_mul(one).unwrap_or_else(Bounded::max_value);
|
||||
candidate.score = Rational128::from(score_n, score_d);
|
||||
|
||||
// check if we have a new winner.
|
||||
if !candidate.elected && candidate.score > best_score {
|
||||
best_score = candidate.score;
|
||||
best_candidate = Some(Rc::clone(&c_ptr));
|
||||
best_candidate = Some(Rc::clone(c_ptr));
|
||||
}
|
||||
} else {
|
||||
candidate.score = Rational128::zero();
|
||||
|
||||
@@ -212,7 +212,7 @@ fn validate_pjr_challenge_core<AccountId: IdentifierT>(
|
||||
None => return false,
|
||||
Some(candidate) => candidate.clone(),
|
||||
};
|
||||
pre_score(candidate, &voters, threshold) >= threshold
|
||||
pre_score(candidate, voters, threshold) >= threshold
|
||||
}
|
||||
|
||||
/// Convert the data types that the user runtime has into ones that can be used by this module.
|
||||
@@ -351,7 +351,7 @@ fn pre_score<AccountId: IdentifierT>(
|
||||
debug_assert!(!unelected.borrow().elected);
|
||||
voters
|
||||
.iter()
|
||||
.filter(|ref v| v.votes_for(&unelected.borrow().who))
|
||||
.filter(|v| v.votes_for(&unelected.borrow().who))
|
||||
.fold(Zero::zero(), |acc: ExtendedBalance, voter| acc.saturating_add(slack(voter, t)))
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ fn merge<A: IdentifierT>(voter_root_path: Vec<NodeRef<A>>, target_root_path: Vec
|
||||
shorter_path
|
||||
.iter()
|
||||
.zip(shorter_path.iter().skip(1))
|
||||
.for_each(|(voter, next)| Node::set_parent_of(&next, &voter));
|
||||
.for_each(|(voter, next)| Node::set_parent_of(next, voter));
|
||||
Node::set_parent_of(&shorter_path[0], &longer_path[0]);
|
||||
}
|
||||
|
||||
@@ -524,12 +524,10 @@ fn reduce_all<A: IdentifierT>(assignments: &mut Vec<StakedAssignment<A>>) -> u32
|
||||
} else {
|
||||
ass.distribution[idx].1.saturating_sub(min_value)
|
||||
}
|
||||
} else if start_operation_add {
|
||||
ass.distribution[idx].1.saturating_sub(min_value)
|
||||
} else {
|
||||
if start_operation_add {
|
||||
ass.distribution[idx].1.saturating_sub(min_value)
|
||||
} else {
|
||||
ass.distribution[idx].1.saturating_add(min_value)
|
||||
}
|
||||
ass.distribution[idx].1.saturating_add(min_value)
|
||||
};
|
||||
|
||||
if next_value.is_zero() {
|
||||
@@ -569,12 +567,10 @@ fn reduce_all<A: IdentifierT>(assignments: &mut Vec<StakedAssignment<A>>) -> u32
|
||||
} else {
|
||||
ass.distribution[idx].1.saturating_add(min_value)
|
||||
}
|
||||
} else if start_operation_add {
|
||||
ass.distribution[idx].1.saturating_add(min_value)
|
||||
} else {
|
||||
if start_operation_add {
|
||||
ass.distribution[idx].1.saturating_add(min_value)
|
||||
} else {
|
||||
ass.distribution[idx].1.saturating_sub(min_value)
|
||||
}
|
||||
ass.distribution[idx].1.saturating_sub(min_value)
|
||||
};
|
||||
|
||||
if next_value.is_zero() {
|
||||
|
||||
@@ -158,7 +158,7 @@ fn panic_hook(info: &PanicInfo, report_url: &str, version: &str) {
|
||||
},
|
||||
};
|
||||
|
||||
let msg = strip_control_codes(&msg);
|
||||
let msg = strip_control_codes(msg);
|
||||
|
||||
let thread = thread::current();
|
||||
let name = thread.name().unwrap_or("<unnamed>");
|
||||
@@ -167,13 +167,13 @@ fn panic_hook(info: &PanicInfo, report_url: &str, version: &str) {
|
||||
|
||||
let mut stderr = io::stderr();
|
||||
|
||||
let _ = writeln!(stderr, "");
|
||||
let _ = writeln!(stderr);
|
||||
let _ = writeln!(stderr, "====================");
|
||||
let _ = writeln!(stderr, "");
|
||||
let _ = writeln!(stderr);
|
||||
let _ = writeln!(stderr, "Version: {}", version);
|
||||
let _ = writeln!(stderr, "");
|
||||
let _ = writeln!(stderr);
|
||||
let _ = writeln!(stderr, "{:?}", backtrace);
|
||||
let _ = writeln!(stderr, "");
|
||||
let _ = writeln!(stderr);
|
||||
let _ = writeln!(stderr, "Thread '{}' panicked at '{}', {}:{}", name, msg, file, line);
|
||||
|
||||
let _ = writeln!(stderr, ABOUT_PANIC!(), report_url);
|
||||
|
||||
@@ -79,7 +79,7 @@ pub fn derive_impl(input: DeriveInput) -> Result<TokenStream> {
|
||||
///
|
||||
/// Returns an error if the number of variants is greater than `256`, the given `data` is not an
|
||||
/// enum or a variant is not an unit.
|
||||
fn get_enum_field_idents<'a>(data: &'a Data) -> Result<impl Iterator<Item = Result<&'a Ident>>> {
|
||||
fn get_enum_field_idents(data: &Data) -> Result<impl Iterator<Item = Result<&Ident>>> {
|
||||
match data {
|
||||
Data::Enum(d) =>
|
||||
if d.variants.len() <= 256 {
|
||||
|
||||
@@ -65,13 +65,11 @@ impl RuntimeInterfaceFunction {
|
||||
}
|
||||
});
|
||||
|
||||
if should_trap_on_return {
|
||||
if !matches!(item.sig.output, syn::ReturnType::Default) {
|
||||
return Err(Error::new(
|
||||
item.sig.ident.span(),
|
||||
"Methods marked as #[trap_on_return] cannot return anything",
|
||||
))
|
||||
}
|
||||
if should_trap_on_return && !matches!(item.sig.output, syn::ReturnType::Default) {
|
||||
return Err(Error::new(
|
||||
item.sig.ident.span(),
|
||||
"Methods marked as #[trap_on_return] cannot return anything",
|
||||
))
|
||||
}
|
||||
|
||||
Ok(Self { item, should_trap_on_return })
|
||||
@@ -212,7 +210,7 @@ pub fn create_function_ident_with_version(name: &Ident, version: u32) -> Ident {
|
||||
}
|
||||
|
||||
/// Returns the function arguments of the given `Signature`, minus any `self` arguments.
|
||||
pub fn get_function_arguments<'a>(sig: &'a Signature) -> impl Iterator<Item = PatType> + 'a {
|
||||
pub fn get_function_arguments(sig: &Signature) -> impl Iterator<Item = PatType> + '_ {
|
||||
sig.inputs
|
||||
.iter()
|
||||
.filter_map(|a| match a {
|
||||
@@ -234,20 +232,20 @@ pub fn get_function_arguments<'a>(sig: &'a Signature) -> impl Iterator<Item = Pa
|
||||
}
|
||||
|
||||
/// Returns the function argument names of the given `Signature`, minus any `self`.
|
||||
pub fn get_function_argument_names<'a>(sig: &'a Signature) -> impl Iterator<Item = Box<Pat>> + 'a {
|
||||
pub fn get_function_argument_names(sig: &Signature) -> impl Iterator<Item = Box<Pat>> + '_ {
|
||||
get_function_arguments(sig).map(|pt| pt.pat)
|
||||
}
|
||||
|
||||
/// Returns the function argument types of the given `Signature`, minus any `Self` type.
|
||||
pub fn get_function_argument_types<'a>(sig: &'a Signature) -> impl Iterator<Item = Box<Type>> + 'a {
|
||||
pub fn get_function_argument_types(sig: &Signature) -> impl Iterator<Item = Box<Type>> + '_ {
|
||||
get_function_arguments(sig).map(|pt| pt.ty)
|
||||
}
|
||||
|
||||
/// Returns the function argument types, minus any `Self` type. If any of the arguments
|
||||
/// is a reference, the underlying type without the ref is returned.
|
||||
pub fn get_function_argument_types_without_ref<'a>(
|
||||
sig: &'a Signature,
|
||||
) -> impl Iterator<Item = Box<Type>> + 'a {
|
||||
pub fn get_function_argument_types_without_ref(
|
||||
sig: &Signature,
|
||||
) -> impl Iterator<Item = Box<Type>> + '_ {
|
||||
get_function_arguments(sig).map(|pt| pt.ty).map(|ty| match *ty {
|
||||
Type::Reference(type_ref) => type_ref.elem,
|
||||
_ => ty,
|
||||
@@ -256,9 +254,9 @@ pub fn get_function_argument_types_without_ref<'a>(
|
||||
|
||||
/// Returns the function argument names and types, minus any `self`. If any of the arguments
|
||||
/// is a reference, the underlying type without the ref is returned.
|
||||
pub fn get_function_argument_names_and_types_without_ref<'a>(
|
||||
sig: &'a Signature,
|
||||
) -> impl Iterator<Item = (Box<Pat>, Box<Type>)> + 'a {
|
||||
pub fn get_function_argument_names_and_types_without_ref(
|
||||
sig: &Signature,
|
||||
) -> impl Iterator<Item = (Box<Pat>, Box<Type>)> + '_ {
|
||||
get_function_arguments(sig).map(|pt| match *pt.ty {
|
||||
Type::Reference(type_ref) => (pt.pat, type_ref.elem),
|
||||
_ => (pt.pat, pt.ty),
|
||||
@@ -267,9 +265,9 @@ pub fn get_function_argument_names_and_types_without_ref<'a>(
|
||||
|
||||
/// Returns the `&`/`&mut` for all function argument types, minus the `self` arg. If a function
|
||||
/// argument is not a reference, `None` is returned.
|
||||
pub fn get_function_argument_types_ref_and_mut<'a>(
|
||||
sig: &'a Signature,
|
||||
) -> impl Iterator<Item = Option<(token::And, Option<token::Mut>)>> + 'a {
|
||||
pub fn get_function_argument_types_ref_and_mut(
|
||||
sig: &Signature,
|
||||
) -> impl Iterator<Item = Option<(token::And, Option<token::Mut>)>> + '_ {
|
||||
get_function_arguments(sig).map(|pt| pt.ty).map(|ty| match *ty {
|
||||
Type::Reference(type_ref) => Some((type_ref.and_token, type_ref.mutability)),
|
||||
_ => None,
|
||||
@@ -277,7 +275,7 @@ pub fn get_function_argument_types_ref_and_mut<'a>(
|
||||
}
|
||||
|
||||
/// Returns an iterator over all trait methods for the given trait definition.
|
||||
fn get_trait_methods<'a>(trait_def: &'a ItemTrait) -> impl Iterator<Item = &'a TraitItemMethod> {
|
||||
fn get_trait_methods(trait_def: &ItemTrait) -> impl Iterator<Item = &TraitItemMethod> {
|
||||
trait_def.items.iter().filter_map(|i| match i {
|
||||
TraitItem::Method(ref method) => Some(method),
|
||||
_ => None,
|
||||
|
||||
@@ -321,7 +321,7 @@ impl<'a> DigestItemRef<'a> {
|
||||
/// Cast this digest item into `PreRuntime`
|
||||
pub fn as_pre_runtime(&self) -> Option<(ConsensusEngineId, &'a [u8])> {
|
||||
match *self {
|
||||
Self::PreRuntime(consensus_engine_id, ref data) => Some((*consensus_engine_id, data)),
|
||||
Self::PreRuntime(consensus_engine_id, data) => Some((*consensus_engine_id, data)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -329,7 +329,7 @@ impl<'a> DigestItemRef<'a> {
|
||||
/// Cast this digest item into `Consensus`
|
||||
pub fn as_consensus(&self) -> Option<(ConsensusEngineId, &'a [u8])> {
|
||||
match *self {
|
||||
Self::Consensus(consensus_engine_id, ref data) => Some((*consensus_engine_id, data)),
|
||||
Self::Consensus(consensus_engine_id, data) => Some((*consensus_engine_id, data)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -337,7 +337,7 @@ impl<'a> DigestItemRef<'a> {
|
||||
/// Cast this digest item into `Seal`
|
||||
pub fn as_seal(&self) -> Option<(ConsensusEngineId, &'a [u8])> {
|
||||
match *self {
|
||||
Self::Seal(consensus_engine_id, ref data) => Some((*consensus_engine_id, data)),
|
||||
Self::Seal(consensus_engine_id, data) => Some((*consensus_engine_id, data)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -345,7 +345,7 @@ impl<'a> DigestItemRef<'a> {
|
||||
/// Cast this digest item into `PreRuntime`
|
||||
pub fn as_other(&self) -> Option<&'a [u8]> {
|
||||
match *self {
|
||||
Self::Other(ref data) => Some(data),
|
||||
Self::Other(data) => Some(data),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -452,7 +452,7 @@ impl Headers {
|
||||
let raw = name.as_bytes();
|
||||
for &(ref key, ref val) in &self.raw {
|
||||
if &**key == raw {
|
||||
return str::from_utf8(&val).ok()
|
||||
return str::from_utf8(val).ok()
|
||||
}
|
||||
}
|
||||
None
|
||||
|
||||
@@ -134,7 +134,7 @@ impl Lockable for Time {
|
||||
|
||||
fn snooze(deadline: &Self::Deadline) {
|
||||
let now = offchain::timestamp();
|
||||
let remainder: Duration = now.diff(&deadline);
|
||||
let remainder: Duration = now.diff(deadline);
|
||||
// do not snooze the full duration, but instead snooze max 100ms
|
||||
// it might get unlocked in another thread
|
||||
use core::cmp::{max, min};
|
||||
|
||||
@@ -98,8 +98,8 @@ impl std::ops::Deref for RuntimeString {
|
||||
|
||||
fn deref(&self) -> &str {
|
||||
match self {
|
||||
Self::Borrowed(val) => &val,
|
||||
Self::Owned(val) => &val,
|
||||
Self::Borrowed(val) => val,
|
||||
Self::Owned(val) => val,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ where
|
||||
use sp_application_crypto::IsWrappedBy;
|
||||
let inner: &S = self.as_ref();
|
||||
let inner_pubkey =
|
||||
<<T as AppKey>::Public as sp_application_crypto::AppPublic>::Generic::from_ref(&signer);
|
||||
<<T as AppKey>::Public as sp_application_crypto::AppPublic>::Generic::from_ref(signer);
|
||||
Verify::verify(inner, msg, inner_pubkey)
|
||||
}
|
||||
}
|
||||
@@ -1284,7 +1284,7 @@ impl<T: Encode + Decode, Id: Encode + Decode + TypeId> AccountIdConversion<T> fo
|
||||
|
||||
fn try_from_sub_account<S: Decode>(x: &T) -> Option<(Self, S)> {
|
||||
x.using_encoded(|d| {
|
||||
if &d[0..4] != Id::TYPE_ID {
|
||||
if d[0..4] != Id::TYPE_ID {
|
||||
return None
|
||||
}
|
||||
let mut cursor = &d[4..];
|
||||
|
||||
@@ -266,7 +266,7 @@ impl<T> super::SandboxInstance<T> for Instance<T> {
|
||||
|
||||
let mut externals =
|
||||
GuestExternals { state, defined_host_functions: &self.defined_host_functions };
|
||||
let result = self.instance.invoke_export(&name, &args, &mut externals);
|
||||
let result = self.instance.invoke_export(name, &args, &mut externals);
|
||||
|
||||
match result {
|
||||
Ok(None) => Ok(ReturnValue::Unit),
|
||||
|
||||
@@ -197,7 +197,7 @@ pub trait Backend<H: Hasher>: sp_std::fmt::Debug {
|
||||
// child first
|
||||
for (child_info, child_delta) in child_deltas {
|
||||
let (child_root, empty, child_txs) =
|
||||
self.child_storage_root(&child_info, child_delta, state_version);
|
||||
self.child_storage_root(child_info, child_delta, state_version);
|
||||
let prefixed_storage_key = child_info.prefixed_storage_key();
|
||||
txs.consolidate(child_txs);
|
||||
if empty {
|
||||
@@ -311,7 +311,7 @@ pub struct BackendRuntimeCode<'a, B, H> {
|
||||
impl<'a, B: Backend<H>, H: Hasher> sp_core::traits::FetchRuntimeCode
|
||||
for BackendRuntimeCode<'a, B, H>
|
||||
{
|
||||
fn fetch_runtime_code<'b>(&'b self) -> Option<std::borrow::Cow<'b, [u8]>> {
|
||||
fn fetch_runtime_code(&self) -> Option<std::borrow::Cow<[u8]>> {
|
||||
self.backend
|
||||
.storage(sp_core::storage::well_known_keys::CODE)
|
||||
.ok()
|
||||
|
||||
@@ -288,7 +288,7 @@ impl Externalities for BasicExternalities {
|
||||
let empty_hash = empty_child_trie_root::<LayoutV1<Blake2Hasher>>();
|
||||
for (prefixed_storage_key, child_info) in prefixed_keys {
|
||||
let child_root = self.child_storage_root(&child_info, state_version);
|
||||
if &empty_hash[..] == &child_root[..] {
|
||||
if empty_hash[..] == child_root[..] {
|
||||
top.remove(prefixed_storage_key.as_slice());
|
||||
} else {
|
||||
top.insert(prefixed_storage_key.into_inner(), child_root);
|
||||
|
||||
@@ -316,8 +316,8 @@ where
|
||||
match (&next_backend_key, overlay_changes.peek()) {
|
||||
(_, None) => next_backend_key,
|
||||
(Some(_), Some(_)) => {
|
||||
while let Some(overlay_key) = overlay_changes.next() {
|
||||
let cmp = next_backend_key.as_deref().map(|v| v.cmp(&overlay_key.0));
|
||||
for overlay_key in overlay_changes {
|
||||
let cmp = next_backend_key.as_deref().map(|v| v.cmp(overlay_key.0));
|
||||
|
||||
// If `backend_key` is less than the `overlay_key`, we found out next key.
|
||||
if cmp == Some(Ordering::Less) {
|
||||
@@ -332,7 +332,7 @@ where
|
||||
// this key.
|
||||
next_backend_key = self
|
||||
.backend
|
||||
.next_storage_key(&overlay_key.0)
|
||||
.next_storage_key(overlay_key.0)
|
||||
.expect(EXT_NOT_ALLOWED_TO_FAIL);
|
||||
}
|
||||
}
|
||||
@@ -357,8 +357,8 @@ where
|
||||
match (&next_backend_key, overlay_changes.peek()) {
|
||||
(_, None) => next_backend_key,
|
||||
(Some(_), Some(_)) => {
|
||||
while let Some(overlay_key) = overlay_changes.next() {
|
||||
let cmp = next_backend_key.as_deref().map(|v| v.cmp(&overlay_key.0));
|
||||
for overlay_key in overlay_changes {
|
||||
let cmp = next_backend_key.as_deref().map(|v| v.cmp(overlay_key.0));
|
||||
|
||||
// If `backend_key` is less than the `overlay_key`, we found out next key.
|
||||
if cmp == Some(Ordering::Less) {
|
||||
@@ -373,7 +373,7 @@ where
|
||||
// this key.
|
||||
next_backend_key = self
|
||||
.backend
|
||||
.next_child_storage_key(child_info, &overlay_key.0)
|
||||
.next_child_storage_key(child_info, overlay_key.0)
|
||||
.expect(EXT_NOT_ALLOWED_TO_FAIL);
|
||||
}
|
||||
}
|
||||
@@ -546,7 +546,7 @@ where
|
||||
.storage(prefixed_storage_key.as_slice())
|
||||
.and_then(|k| Decode::decode(&mut &k[..]).ok())
|
||||
// V1 is equivalent to V0 on empty root.
|
||||
.unwrap_or_else(|| empty_child_trie_root::<LayoutV1<H>>());
|
||||
.unwrap_or_else(empty_child_trie_root::<LayoutV1<H>>);
|
||||
trace!(
|
||||
target: "state",
|
||||
method = "ChildStorageRoot",
|
||||
@@ -593,7 +593,7 @@ where
|
||||
.storage(prefixed_storage_key.as_slice())
|
||||
.and_then(|k| Decode::decode(&mut &k[..]).ok())
|
||||
// V1 is equivalent to V0 on empty root.
|
||||
.unwrap_or_else(|| empty_child_trie_root::<LayoutV1<H>>());
|
||||
.unwrap_or_else(empty_child_trie_root::<LayoutV1<H>>);
|
||||
|
||||
trace!(
|
||||
target: "state",
|
||||
|
||||
@@ -94,7 +94,7 @@ where
|
||||
H::Out: Codec + Ord,
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
TrieBackend::new(self.backend_storage().clone(), self.root().clone())
|
||||
TrieBackend::new(self.backend_storage().clone(), *self.root())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -644,7 +644,7 @@ mod execution {
|
||||
H::Out: Ord + 'static + codec::Codec,
|
||||
Spawn: SpawnNamed + Send + 'static,
|
||||
{
|
||||
let trie_backend = create_proof_check_backend::<H>(root.into(), proof)?;
|
||||
let trie_backend = create_proof_check_backend::<H>(root, proof)?;
|
||||
execution_proof_check_on_trie_backend::<_, _, _>(
|
||||
&trie_backend,
|
||||
overlay,
|
||||
@@ -791,7 +791,7 @@ mod execution {
|
||||
self.0.last().and_then(|s| s.key_values.last().map(|kv| kv.0.clone()));
|
||||
|
||||
if let Some(child_last) = child_last {
|
||||
if last.len() == 0 {
|
||||
if last.is_empty() {
|
||||
if let Some(top_last) = top_last {
|
||||
last.push(top_last)
|
||||
} else {
|
||||
@@ -866,7 +866,7 @@ mod execution {
|
||||
.storage(&storage_key)
|
||||
.map_err(|e| Box::new(e) as Box<dyn Error>)?
|
||||
{
|
||||
child_roots.insert(state_root.clone());
|
||||
child_roots.insert(state_root);
|
||||
} else {
|
||||
return Err(Box::new("Invalid range start child trie key."))
|
||||
}
|
||||
@@ -880,7 +880,7 @@ mod execution {
|
||||
let (child_info, depth) = if let Some(storage_key) = child_key.as_ref() {
|
||||
let storage_key = PrefixedStorageKey::new_ref(storage_key);
|
||||
(
|
||||
Some(match ChildType::from_prefixed_key(&storage_key) {
|
||||
Some(match ChildType::from_prefixed_key(storage_key) {
|
||||
Some((ChildType::ParentKeyId, storage_key)) =>
|
||||
ChildInfo::new_default(storage_key),
|
||||
None => return Err(Box::new("Invalid range start child trie key.")),
|
||||
@@ -900,15 +900,15 @@ mod execution {
|
||||
None,
|
||||
start_at_ref,
|
||||
|key, value| {
|
||||
if first {
|
||||
if start_at_ref
|
||||
if first &&
|
||||
start_at_ref
|
||||
.as_ref()
|
||||
.map(|start| &key.as_slice() > start)
|
||||
.unwrap_or(true)
|
||||
{
|
||||
first = false;
|
||||
}
|
||||
{
|
||||
first = false;
|
||||
}
|
||||
|
||||
if first {
|
||||
true
|
||||
} else if depth < MAX_NESTED_TRIE_DEPTH &&
|
||||
@@ -938,12 +938,10 @@ mod execution {
|
||||
if switch_child_key.is_none() {
|
||||
if depth == 1 {
|
||||
break
|
||||
} else if completed {
|
||||
start_at = child_key.take();
|
||||
} else {
|
||||
if completed {
|
||||
start_at = child_key.take();
|
||||
} else {
|
||||
break
|
||||
}
|
||||
break
|
||||
}
|
||||
} else {
|
||||
child_key = switch_child_key;
|
||||
@@ -1269,7 +1267,7 @@ mod execution {
|
||||
|
||||
let storage_key = PrefixedStorageKey::new_ref(storage_key);
|
||||
(
|
||||
Some(match ChildType::from_prefixed_key(&storage_key) {
|
||||
Some(match ChildType::from_prefixed_key(storage_key) {
|
||||
Some((ChildType::ParentKeyId, storage_key)) =>
|
||||
ChildInfo::new_default(storage_key),
|
||||
None => return Err(Box::new("Invalid range start child trie key.")),
|
||||
@@ -1294,15 +1292,15 @@ mod execution {
|
||||
None,
|
||||
start_at_ref,
|
||||
|key, value| {
|
||||
if first {
|
||||
if start_at_ref
|
||||
if first &&
|
||||
start_at_ref
|
||||
.as_ref()
|
||||
.map(|start| &key.as_slice() > start)
|
||||
.unwrap_or(true)
|
||||
{
|
||||
first = false;
|
||||
}
|
||||
{
|
||||
first = false;
|
||||
}
|
||||
|
||||
if !first {
|
||||
values.push((key.to_vec(), value.to_vec()));
|
||||
}
|
||||
@@ -1390,7 +1388,7 @@ mod tests {
|
||||
let using_native = use_native && self.native_available;
|
||||
match (using_native, self.native_succeeds, self.fallback_succeeds, native_call) {
|
||||
(true, true, _, Some(call)) => {
|
||||
let res = sp_externalities::set_and_run_with_externalities(ext, || call());
|
||||
let res = sp_externalities::set_and_run_with_externalities(ext, call);
|
||||
(res.map(NativeOrEncoded::Native).map_err(|_| 0), true)
|
||||
},
|
||||
(true, true, _, None) | (false, _, true, None) => (
|
||||
@@ -1584,13 +1582,13 @@ mod tests {
|
||||
.map(|(k, v)| (k.clone(), v.value().cloned()))
|
||||
.collect::<HashMap<_, _>>(),
|
||||
map![
|
||||
b"abc".to_vec() => None.into(),
|
||||
b"abb".to_vec() => None.into(),
|
||||
b"aba".to_vec() => None.into(),
|
||||
b"abd".to_vec() => None.into(),
|
||||
b"abc".to_vec() => None,
|
||||
b"abb".to_vec() => None,
|
||||
b"aba".to_vec() => None,
|
||||
b"abd".to_vec() => None,
|
||||
|
||||
b"bab".to_vec() => Some(b"228".to_vec()).into(),
|
||||
b"bbd".to_vec() => Some(b"42".to_vec()).into()
|
||||
b"bab".to_vec() => Some(b"228".to_vec()),
|
||||
b"bbd".to_vec() => Some(b"42".to_vec())
|
||||
],
|
||||
);
|
||||
|
||||
@@ -1608,12 +1606,12 @@ mod tests {
|
||||
.map(|(k, v)| (k.clone(), v.value().cloned()))
|
||||
.collect::<HashMap<_, _>>(),
|
||||
map![
|
||||
b"abb".to_vec() => None.into(),
|
||||
b"aba".to_vec() => None.into(),
|
||||
b"abd".to_vec() => None.into(),
|
||||
b"abb".to_vec() => None,
|
||||
b"aba".to_vec() => None,
|
||||
b"abd".to_vec() => None,
|
||||
|
||||
b"bab".to_vec() => Some(b"228".to_vec()).into(),
|
||||
b"bbd".to_vec() => Some(b"42".to_vec()).into()
|
||||
b"bab".to_vec() => Some(b"228".to_vec()),
|
||||
b"bbd".to_vec() => Some(b"42".to_vec())
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -1647,15 +1645,15 @@ mod tests {
|
||||
overlay
|
||||
.children()
|
||||
.flat_map(|(iter, _child_info)| iter)
|
||||
.map(|(k, v)| (k.clone(), v.value().clone()))
|
||||
.map(|(k, v)| (k.clone(), v.value()))
|
||||
.collect::<BTreeMap<_, _>>(),
|
||||
map![
|
||||
b"1".to_vec() => None.into(),
|
||||
b"2".to_vec() => None.into(),
|
||||
b"3".to_vec() => None.into(),
|
||||
b"4".to_vec() => None.into(),
|
||||
b"a".to_vec() => None.into(),
|
||||
b"b".to_vec() => None.into(),
|
||||
b"1".to_vec() => None,
|
||||
b"2".to_vec() => None,
|
||||
b"3".to_vec() => None,
|
||||
b"4".to_vec() => None,
|
||||
b"a".to_vec() => None,
|
||||
b"b".to_vec() => None,
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -1796,7 +1794,7 @@ mod tests {
|
||||
|
||||
fn test_compact(remote_proof: StorageProof, remote_root: &sp_core::H256) -> StorageProof {
|
||||
let compact_remote_proof =
|
||||
remote_proof.into_compact_proof::<BlakeTwo256>(remote_root.clone()).unwrap();
|
||||
remote_proof.into_compact_proof::<BlakeTwo256>(*remote_root).unwrap();
|
||||
compact_remote_proof
|
||||
.to_storage_proof::<BlakeTwo256>(Some(remote_root))
|
||||
.unwrap()
|
||||
@@ -1823,8 +1821,7 @@ mod tests {
|
||||
read_proof_check::<BlakeTwo256, _>(remote_root, remote_proof.clone(), &[b"value2"])
|
||||
.unwrap();
|
||||
let local_result2 =
|
||||
read_proof_check::<BlakeTwo256, _>(remote_root, remote_proof.clone(), &[&[0xff]])
|
||||
.is_ok();
|
||||
read_proof_check::<BlakeTwo256, _>(remote_root, remote_proof, &[&[0xff]]).is_ok();
|
||||
// check that results are correct
|
||||
assert_eq!(
|
||||
local_result1.into_iter().collect::<Vec<_>>(),
|
||||
@@ -1852,7 +1849,7 @@ mod tests {
|
||||
.unwrap();
|
||||
let local_result3 = read_child_proof_check::<BlakeTwo256, _>(
|
||||
remote_root,
|
||||
remote_proof.clone(),
|
||||
remote_proof,
|
||||
missing_child_info,
|
||||
&[b"dummy"],
|
||||
)
|
||||
@@ -1899,7 +1896,7 @@ mod tests {
|
||||
|
||||
let trie: InMemoryBackend<BlakeTwo256> =
|
||||
(storage.clone(), StateVersion::default()).into();
|
||||
let trie_root = trie.root().clone();
|
||||
let trie_root = trie.root();
|
||||
let backend = crate::ProvingBackend::new(&trie);
|
||||
let mut queries = Vec::new();
|
||||
for c in 0..(5 + nb_child_trie / 2) {
|
||||
@@ -1948,7 +1945,7 @@ mod tests {
|
||||
let storage_proof = backend.extract_proof();
|
||||
let remote_proof = test_compact(storage_proof, &trie_root);
|
||||
let proof_check =
|
||||
create_proof_check_backend::<BlakeTwo256>(trie_root, remote_proof).unwrap();
|
||||
create_proof_check_backend::<BlakeTwo256>(*trie_root, remote_proof).unwrap();
|
||||
|
||||
for (child_info, key, expected) in queries {
|
||||
assert_eq!(
|
||||
@@ -1998,15 +1995,9 @@ mod tests {
|
||||
prove_range_read_with_size(remote_backend, None, None, 50000, Some(&[])).unwrap();
|
||||
assert_eq!(proof.clone().into_memory_db::<BlakeTwo256>().drain().len(), 11);
|
||||
assert_eq!(count, 132);
|
||||
let (results, completed) = read_range_proof_check::<BlakeTwo256>(
|
||||
remote_root,
|
||||
proof.clone(),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
let (results, completed) =
|
||||
read_range_proof_check::<BlakeTwo256>(remote_root, proof, None, None, None, None)
|
||||
.unwrap();
|
||||
assert_eq!(results.len() as u32, count);
|
||||
assert_eq!(completed, true);
|
||||
}
|
||||
@@ -2041,11 +2032,11 @@ mod tests {
|
||||
remote_proof
|
||||
};
|
||||
|
||||
let remote_proof = check_proof(mdb.clone(), root.clone(), state_version);
|
||||
let remote_proof = check_proof(mdb.clone(), root, state_version);
|
||||
// check full values in proof
|
||||
assert!(remote_proof.encode().len() > 1_100);
|
||||
assert!(remote_proof.encoded_size() > 1_100);
|
||||
let root1 = root.clone();
|
||||
let root1 = root;
|
||||
|
||||
// do switch
|
||||
state_version = StateVersion::V1;
|
||||
@@ -2057,9 +2048,9 @@ mod tests {
|
||||
trie.insert(b"foo", vec![1u8; 1000].as_slice()) // inner hash
|
||||
.expect("insert failed");
|
||||
}
|
||||
let root3 = root.clone();
|
||||
let root3 = root;
|
||||
assert!(root1 != root3);
|
||||
let remote_proof = check_proof(mdb.clone(), root.clone(), state_version);
|
||||
let remote_proof = check_proof(mdb.clone(), root, state_version);
|
||||
// nodes foo is replaced by its hashed value form.
|
||||
assert!(remote_proof.encode().len() < 1000);
|
||||
assert!(remote_proof.encoded_size() < 1000);
|
||||
@@ -2159,7 +2150,7 @@ mod tests {
|
||||
let remote_proof = test_compact(remote_proof, &remote_root);
|
||||
let local_result1 = read_child_proof_check::<BlakeTwo256, _>(
|
||||
remote_root,
|
||||
remote_proof.clone(),
|
||||
remote_proof,
|
||||
&child_info1,
|
||||
&[b"key1"],
|
||||
)
|
||||
|
||||
@@ -513,7 +513,7 @@ impl OverlayedChanges {
|
||||
pub fn drain_storage_changes<B: Backend<H>, H: Hasher>(
|
||||
&mut self,
|
||||
backend: &B,
|
||||
mut cache: &mut StorageTransactionCache<B::Transaction, H>,
|
||||
cache: &mut StorageTransactionCache<B::Transaction, H>,
|
||||
state_version: StateVersion,
|
||||
) -> Result<StorageChanges<B::Transaction, H>, DefaultError>
|
||||
where
|
||||
@@ -521,7 +521,7 @@ impl OverlayedChanges {
|
||||
{
|
||||
// If the transaction does not exist, we generate it.
|
||||
if cache.transaction.is_none() {
|
||||
self.storage_root(backend, &mut cache, state_version);
|
||||
self.storage_root(backend, cache, state_version);
|
||||
}
|
||||
|
||||
let (transaction, transaction_storage_root) = cache
|
||||
|
||||
@@ -42,7 +42,7 @@ impl OffchainOverlayedChanges {
|
||||
}
|
||||
|
||||
/// Iterate over all key value pairs by reference.
|
||||
pub fn iter<'a>(&'a self) -> impl Iterator<Item = OffchainOverlayedChangesItem<'a>> {
|
||||
pub fn iter(&self) -> impl Iterator<Item = OffchainOverlayedChangesItem> {
|
||||
self.0.changes().map(|kv| (kv.0, kv.1.value_ref()))
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ where
|
||||
.storage(storage_key)?
|
||||
.and_then(|r| Decode::decode(&mut &r[..]).ok())
|
||||
// V1 is equivalent to V0 on empty trie
|
||||
.unwrap_or_else(|| empty_child_trie_root::<LayoutV1<H>>());
|
||||
.unwrap_or_else(empty_child_trie_root::<LayoutV1<H>>);
|
||||
|
||||
let mut read_overlay = S::Overlay::default();
|
||||
let eph = Ephemeral::new(self.backend.backend_storage(), &mut read_overlay);
|
||||
@@ -88,7 +88,7 @@ where
|
||||
read_child_trie_value_with::<LayoutV1<H>, _, _>(
|
||||
child_info.keyspace(),
|
||||
&eph,
|
||||
&root.as_ref(),
|
||||
root.as_ref(),
|
||||
key,
|
||||
&mut *self.proof_recorder,
|
||||
)
|
||||
@@ -203,7 +203,7 @@ where
|
||||
proof_recorder: ProofRecorder<H::Out>,
|
||||
) -> Self {
|
||||
let essence = backend.essence();
|
||||
let root = essence.root().clone();
|
||||
let root = *essence.root();
|
||||
let recorder = ProofRecorderBackend { backend: essence.backend_storage(), proof_recorder };
|
||||
ProvingBackend(TrieBackend::new(recorder, root))
|
||||
}
|
||||
@@ -238,7 +238,7 @@ impl<'a, S: 'a + TrieBackendStorage<H>, H: 'a + Hasher> TrieBackendStorage<H>
|
||||
}
|
||||
|
||||
let backend_value = self.backend.get(key, prefix)?;
|
||||
self.proof_recorder.record(key.clone(), backend_value.clone());
|
||||
self.proof_recorder.record(*key, backend_value.clone());
|
||||
Ok(backend_value)
|
||||
}
|
||||
}
|
||||
@@ -395,9 +395,9 @@ mod tests {
|
||||
use sp_runtime::traits::BlakeTwo256;
|
||||
use sp_trie::PrefixedMemoryDB;
|
||||
|
||||
fn test_proving<'a>(
|
||||
trie_backend: &'a TrieBackend<PrefixedMemoryDB<BlakeTwo256>, BlakeTwo256>,
|
||||
) -> ProvingBackend<'a, PrefixedMemoryDB<BlakeTwo256>, BlakeTwo256> {
|
||||
fn test_proving(
|
||||
trie_backend: &TrieBackend<PrefixedMemoryDB<BlakeTwo256>, BlakeTwo256>,
|
||||
) -> ProvingBackend<PrefixedMemoryDB<BlakeTwo256>, BlakeTwo256> {
|
||||
ProvingBackend::new(trie_backend)
|
||||
}
|
||||
|
||||
@@ -474,7 +474,6 @@ mod tests {
|
||||
let trie_root = trie.storage_root(std::iter::empty(), state_version).0;
|
||||
assert_eq!(in_memory_root, trie_root);
|
||||
value_range
|
||||
.clone()
|
||||
.for_each(|i| assert_eq!(trie.storage(&[i]).unwrap().unwrap(), vec![i; size_content]));
|
||||
|
||||
let proving = ProvingBackend::new(trie);
|
||||
@@ -482,8 +481,7 @@ mod tests {
|
||||
|
||||
let proof = proving.extract_proof();
|
||||
|
||||
let proof_check =
|
||||
create_proof_check_backend::<BlakeTwo256>(in_memory_root.into(), proof).unwrap();
|
||||
let proof_check = create_proof_check_backend::<BlakeTwo256>(in_memory_root, proof).unwrap();
|
||||
assert_eq!(proof_check.storage(&[42]).unwrap().unwrap(), vec![42; size_content]);
|
||||
}
|
||||
|
||||
@@ -530,8 +528,7 @@ mod tests {
|
||||
|
||||
let proof = proving.extract_proof();
|
||||
|
||||
let proof_check =
|
||||
create_proof_check_backend::<BlakeTwo256>(in_memory_root.into(), proof).unwrap();
|
||||
let proof_check = create_proof_check_backend::<BlakeTwo256>(in_memory_root, proof).unwrap();
|
||||
assert!(proof_check.storage(&[0]).is_err());
|
||||
assert_eq!(proof_check.storage(&[42]).unwrap().unwrap(), vec![42]);
|
||||
// note that it is include in root because proof close
|
||||
@@ -542,8 +539,7 @@ mod tests {
|
||||
assert_eq!(proving.child_storage(child_info_1, &[64]), Ok(Some(vec![64])));
|
||||
|
||||
let proof = proving.extract_proof();
|
||||
let proof_check =
|
||||
create_proof_check_backend::<BlakeTwo256>(in_memory_root.into(), proof).unwrap();
|
||||
let proof_check = create_proof_check_backend::<BlakeTwo256>(in_memory_root, proof).unwrap();
|
||||
assert_eq!(proof_check.child_storage(child_info_1, &[64]).unwrap().unwrap(), vec![64]);
|
||||
}
|
||||
|
||||
|
||||
@@ -521,7 +521,7 @@ where
|
||||
Ok(None) => default_root,
|
||||
Err(e) => {
|
||||
warn!(target: "trie", "Failed to read child storage root: {}", e);
|
||||
default_root.clone()
|
||||
default_root
|
||||
},
|
||||
};
|
||||
|
||||
@@ -580,16 +580,12 @@ impl<'a, S: 'a + TrieBackendStorage<H>, H: Hasher> hash_db::HashDB<H, DBValue>
|
||||
for Ephemeral<'a, S, H>
|
||||
{
|
||||
fn get(&self, key: &H::Out, prefix: Prefix) -> Option<DBValue> {
|
||||
match HashDB::get(self.overlay, key, prefix) {
|
||||
Some(val) => Some(val),
|
||||
None => match self.storage.get(&key, prefix) {
|
||||
Ok(x) => x,
|
||||
Err(e) => {
|
||||
warn!(target: "trie", "Failed to read from DB: {}", e);
|
||||
None
|
||||
},
|
||||
},
|
||||
}
|
||||
HashDB::get(self.overlay, key, prefix).or_else(|| {
|
||||
self.storage.get(key, prefix).unwrap_or_else(|e| {
|
||||
warn!(target: "trie", "Failed to read from DB: {}", e);
|
||||
None
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn contains(&self, key: &H::Out, prefix: Prefix) -> bool {
|
||||
@@ -664,7 +660,7 @@ impl<S: TrieBackendStorage<H>, H: Hasher> HashDB<H, DBValue> for TrieBackendEsse
|
||||
if *key == self.empty {
|
||||
return Some([0u8].to_vec())
|
||||
}
|
||||
match self.storage.get(&key, prefix) {
|
||||
match self.storage.get(key, prefix) {
|
||||
Ok(x) => x,
|
||||
Err(e) => {
|
||||
warn!(target: "trie", "Failed to read from DB: {}", e);
|
||||
|
||||
@@ -189,21 +189,21 @@ pub mod well_known_keys {
|
||||
/// Wasm code of the runtime.
|
||||
///
|
||||
/// Stored as a raw byte vector. Required by substrate.
|
||||
pub const CODE: &'static [u8] = b":code";
|
||||
pub const CODE: &[u8] = b":code";
|
||||
|
||||
/// Number of wasm linear memory pages required for execution of the runtime.
|
||||
///
|
||||
/// The type of this value is encoded `u64`.
|
||||
pub const HEAP_PAGES: &'static [u8] = b":heappages";
|
||||
pub const HEAP_PAGES: &[u8] = b":heappages";
|
||||
|
||||
/// Current extrinsic index (u32) is stored under this key.
|
||||
pub const EXTRINSIC_INDEX: &'static [u8] = b":extrinsic_index";
|
||||
pub const EXTRINSIC_INDEX: &[u8] = b":extrinsic_index";
|
||||
|
||||
/// Prefix of child storage keys.
|
||||
pub const CHILD_STORAGE_KEY_PREFIX: &'static [u8] = b":child_storage:";
|
||||
pub const CHILD_STORAGE_KEY_PREFIX: &[u8] = b":child_storage:";
|
||||
|
||||
/// Prefix of the default child storage keys in the top trie.
|
||||
pub const DEFAULT_CHILD_STORAGE_KEY_PREFIX: &'static [u8] = b":child_storage:default:";
|
||||
pub const DEFAULT_CHILD_STORAGE_KEY_PREFIX: &[u8] = b":child_storage:default:";
|
||||
|
||||
/// Whether a key is a default child storage key.
|
||||
///
|
||||
@@ -359,7 +359,7 @@ impl ChildType {
|
||||
fn do_prefix_key(&self, key: &mut Vec<u8>) {
|
||||
let parent_prefix = self.parent_prefix();
|
||||
let key_len = key.len();
|
||||
if parent_prefix.len() > 0 {
|
||||
if !parent_prefix.is_empty() {
|
||||
key.resize(key_len + parent_prefix.len(), 0);
|
||||
key.copy_within(..key_len, parent_prefix.len());
|
||||
key[..parent_prefix.len()].copy_from_slice(parent_prefix);
|
||||
|
||||
@@ -639,7 +639,7 @@ mod std_features {
|
||||
|
||||
tracing::span::Span::child_of(
|
||||
a.parent_id.map(tracing_core::span::Id::from_u64),
|
||||
&metadata,
|
||||
metadata,
|
||||
&tracing::valueset! { metadata.fields(), target, name, file, line, module_path, ?params },
|
||||
)
|
||||
}
|
||||
@@ -658,7 +658,7 @@ mod std_features {
|
||||
|
||||
tracing_core::Event::child_of(
|
||||
self.parent_id.map(tracing_core::span::Id::from_u64),
|
||||
&metadata,
|
||||
metadata,
|
||||
&tracing::valueset! { metadata.fields(), target, name, file, line, module_path, ?params },
|
||||
)
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ pub mod registration {
|
||||
B: BlockT,
|
||||
C: IndexedBody<B>,
|
||||
{
|
||||
let parent_number = client.number(parent.clone())?.unwrap_or(Zero::zero());
|
||||
let parent_number = client.number(*parent)?.unwrap_or(Zero::zero());
|
||||
let number = parent_number
|
||||
.saturating_add(One::one())
|
||||
.saturating_sub(DEFAULT_STORAGE_PERIOD.into());
|
||||
@@ -214,10 +214,10 @@ pub mod registration {
|
||||
trie.commit();
|
||||
}
|
||||
if target_chunk.is_some() && target_root == Default::default() {
|
||||
target_root = transaction_root.clone();
|
||||
target_root = transaction_root;
|
||||
chunk_proof = sp_trie::generate_trie_proof::<TrieLayout, _, _, _>(
|
||||
&db,
|
||||
transaction_root.clone(),
|
||||
transaction_root,
|
||||
&[target_chunk_key.clone()],
|
||||
)
|
||||
.map_err(|e| Error::Application(Box::new(e)))?;
|
||||
|
||||
@@ -555,7 +555,7 @@ mod tests {
|
||||
for (x, y) in input.iter().rev() {
|
||||
t.insert(x, y).unwrap();
|
||||
}
|
||||
t.root().clone()
|
||||
*t.root()
|
||||
};
|
||||
assert_eq!(closed_form, persistent);
|
||||
}
|
||||
@@ -571,7 +571,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
{
|
||||
let t = TrieDB::<T>::new(&mut memdb, &root).unwrap();
|
||||
let t = TrieDB::<T>::new(&memdb, &root).unwrap();
|
||||
assert_eq!(
|
||||
input.iter().map(|(i, j)| (i.to_vec(), j.to_vec())).collect::<Vec<_>>(),
|
||||
t.iter()
|
||||
@@ -752,7 +752,7 @@ mod tests {
|
||||
memtrie.commit();
|
||||
if *memtrie.root() != real {
|
||||
println!("TRIE MISMATCH");
|
||||
println!("");
|
||||
println!();
|
||||
println!("{:?} vs {:?}", memtrie.root(), real);
|
||||
for i in &x {
|
||||
println!("{:#x?} -> {:#x?}", i.0, i.1);
|
||||
@@ -764,7 +764,7 @@ mod tests {
|
||||
let hashed_null_node = hashed_null_node::<L>();
|
||||
if *memtrie.root() != hashed_null_node {
|
||||
println!("- TRIE MISMATCH");
|
||||
println!("");
|
||||
println!();
|
||||
println!("{:?} vs {:?}", memtrie.root(), hashed_null_node);
|
||||
for i in &x {
|
||||
println!("{:#x?} -> {:#x?}", i.0, i.1);
|
||||
|
||||
@@ -71,7 +71,7 @@ where
|
||||
// Only check root if expected root is passed as argument.
|
||||
if let Some(expected_root) = expected_root {
|
||||
if expected_root != &top_root {
|
||||
return Err(Error::RootMismatch(top_root.clone(), expected_root.clone()))
|
||||
return Err(Error::RootMismatch(top_root, *expected_root))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ fn branch_node_bit_mask(has_children: impl Iterator<Item = bool>) -> (u8, u8) {
|
||||
}
|
||||
|
||||
/// Create a leaf/branch node, encoding a number of nibbles.
|
||||
fn fuse_nibbles_node<'a>(nibbles: &'a [u8], kind: NodeKind) -> impl Iterator<Item = u8> + 'a {
|
||||
fn fuse_nibbles_node(nibbles: &[u8], kind: NodeKind) -> impl Iterator<Item = u8> + '_ {
|
||||
let size = sp_std::cmp::min(trie_constants::NIBBLE_SIZE_BOUND, nibbles.len());
|
||||
|
||||
let iter_start = match kind {
|
||||
|
||||
@@ -105,7 +105,7 @@ impl ParseRuntimeVersion {
|
||||
parser: impl FnOnce(&Expr) -> Result<T>,
|
||||
) -> Result<()> {
|
||||
if value.is_some() {
|
||||
return Err(Error::new(field.span(), "field is already initialized before"))
|
||||
Err(Error::new(field.span(), "field is already initialized before"))
|
||||
} else {
|
||||
*value = Some(parser(&field.expr)?);
|
||||
Ok(())
|
||||
|
||||
@@ -73,7 +73,7 @@ impl From<Signature> for wasmi::Signature {
|
||||
impl From<&wasmi::Signature> for Signature {
|
||||
fn from(sig: &wasmi::Signature) -> Self {
|
||||
Signature::new(
|
||||
sig.params().into_iter().copied().map(Into::into).collect::<Vec<_>>(),
|
||||
sig.params().iter().copied().map(Into::into).collect::<Vec<_>>(),
|
||||
sig.return_type().map(Into::into),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user