style: Migrate to stable-only rustfmt configuration
- Remove nightly-only features from .rustfmt.toml and vendor/ss58-registry/rustfmt.toml - Removed features: imports_granularity, wrap_comments, comment_width, reorder_impl_items, spaces_around_ranges, binop_separator, match_arm_blocks, trailing_semicolon, trailing_comma - Format all 898 affected files with stable rustfmt - Ensures long-term reliability without nightly toolchain dependency
This commit is contained in:
@@ -221,8 +221,9 @@ fn generate_runtime_decls(decls: &[ItemTrait]) -> Result<TokenStream> {
|
||||
);
|
||||
|
||||
let err2 = match found_attributes.get(&API_VERSION_ATTRIBUTE) {
|
||||
Some(attr) =>
|
||||
Error::new(attr.span(), "Trait version is set here."),
|
||||
Some(attr) => {
|
||||
Error::new(attr.span(), "Trait version is set here.")
|
||||
},
|
||||
None => Error::new(
|
||||
decl_span,
|
||||
"Trait version is not set so it is implicitly equal to 1.",
|
||||
@@ -676,12 +677,13 @@ impl<'ast> Visit<'ast> for CheckTraitDecl {
|
||||
|
||||
fn visit_generic_param(&mut self, input: &'ast GenericParam) {
|
||||
match input {
|
||||
GenericParam::Type(ty) if ty.ident == BLOCK_GENERIC_IDENT =>
|
||||
GenericParam::Type(ty) if ty.ident == BLOCK_GENERIC_IDENT => {
|
||||
self.errors.push(Error::new(
|
||||
input.span(),
|
||||
"`Block: BlockT` generic parameter will be added automatically by the \
|
||||
`decl_runtime_apis!` macro!",
|
||||
)),
|
||||
))
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
|
||||
|
||||
@@ -213,7 +213,10 @@ fn get_at_param_name(
|
||||
let ptype_and_borrows = param_types_and_borrows.remove(0);
|
||||
let span = ptype_and_borrows.1.span();
|
||||
if ptype_and_borrows.1 {
|
||||
return Err(Error::new(span, "`Hash` needs to be taken by value and not by reference!"));
|
||||
return Err(Error::new(
|
||||
span,
|
||||
"`Hash` needs to be taken by value and not by reference!",
|
||||
));
|
||||
}
|
||||
|
||||
let name = param_names.remove(0);
|
||||
@@ -378,7 +381,7 @@ fn generate_runtime_api_impls(impls: &[ItemImpl]) -> Result<GeneratedRuntimeApiI
|
||||
let block_type = extract_block_type_from_trait_path(impl_trait_path)?;
|
||||
|
||||
self_ty = match self_ty.take() {
|
||||
Some(self_ty) =>
|
||||
Some(self_ty) => {
|
||||
if self_ty == impl_.self_ty {
|
||||
Some(self_ty)
|
||||
} else {
|
||||
@@ -390,12 +393,13 @@ fn generate_runtime_api_impls(impls: &[ItemImpl]) -> Result<GeneratedRuntimeApiI
|
||||
error.combine(Error::new(self_ty.span(), "First self type found here"));
|
||||
|
||||
return Err(error);
|
||||
},
|
||||
}
|
||||
},
|
||||
None => Some(impl_.self_ty.clone()),
|
||||
};
|
||||
|
||||
global_block_type = match global_block_type.take() {
|
||||
Some(global_block_type) =>
|
||||
Some(global_block_type) => {
|
||||
if global_block_type == *block_type {
|
||||
Some(global_block_type)
|
||||
} else {
|
||||
@@ -410,7 +414,8 @@ fn generate_runtime_api_impls(impls: &[ItemImpl]) -> Result<GeneratedRuntimeApiI
|
||||
));
|
||||
|
||||
return Err(error);
|
||||
},
|
||||
}
|
||||
},
|
||||
None => Some(block_type.clone()),
|
||||
};
|
||||
|
||||
|
||||
@@ -146,12 +146,14 @@ pub fn extract_parameter_names_types_and_borrows(
|
||||
let name = sanitize_pattern((*arg.pat).clone(), &mut generated_pattern_counter);
|
||||
result.push((name, ty, borrow));
|
||||
},
|
||||
FnArg::Receiver(_) if matches!(allow_self, AllowSelfRefInParameters::No) =>
|
||||
return Err(Error::new(input.span(), "`self` parameter not supported!")),
|
||||
FnArg::Receiver(recv) =>
|
||||
FnArg::Receiver(_) if matches!(allow_self, AllowSelfRefInParameters::No) => {
|
||||
return Err(Error::new(input.span(), "`self` parameter not supported!"))
|
||||
},
|
||||
FnArg::Receiver(recv) => {
|
||||
if recv.mutability.is_some() || recv.reference.is_none() {
|
||||
return Err(Error::new(recv.span(), "Only `&self` is supported!"));
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,8 +188,9 @@ pub fn extract_block_type_from_trait_path(trait_: &Path) -> Result<&TypePath> {
|
||||
let span = trait_.segments.last().as_ref().unwrap().span();
|
||||
Err(Error::new(span, "Missing `Block` generic parameter."))
|
||||
},
|
||||
PathArguments::Parenthesized(_) =>
|
||||
Err(Error::new(generics.arguments.span(), "Unexpected parentheses in path!")),
|
||||
PathArguments::Parenthesized(_) => {
|
||||
Err(Error::new(generics.arguments.span(), "Unexpected parentheses in path!"))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,8 +76,8 @@ fn main() {
|
||||
let a = FixedI64::saturating_from_rational(2, 5);
|
||||
let b = a.saturating_mul_acc_int(x);
|
||||
let xx = FixedI64::saturating_from_integer(x);
|
||||
let d = a.saturating_mul(xx).saturating_add(xx).into_inner() as i128 /
|
||||
FixedI64::accuracy() as i128;
|
||||
let d = a.saturating_mul(xx).saturating_add(xx).into_inner() as i128
|
||||
/ FixedI64::accuracy() as i128;
|
||||
assert_eq!(b, d);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -74,19 +74,21 @@ where
|
||||
fn round(f: Fraction, r: Rounding) -> Fraction {
|
||||
match r {
|
||||
Up => f.ceil(),
|
||||
NearestPrefUp =>
|
||||
NearestPrefUp => {
|
||||
if f.fract() < Fraction::from(0.5) {
|
||||
f.floor()
|
||||
} else {
|
||||
f.ceil()
|
||||
},
|
||||
}
|
||||
},
|
||||
Down => f.floor(),
|
||||
NearestPrefDown =>
|
||||
NearestPrefDown => {
|
||||
if f.fract() > Fraction::from(0.5) {
|
||||
f.ceil()
|
||||
} else {
|
||||
f.floor()
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,19 +74,21 @@ where
|
||||
fn round(f: Fraction, r: Rounding) -> Fraction {
|
||||
match r {
|
||||
Up => f.ceil(),
|
||||
NearestPrefUp =>
|
||||
NearestPrefUp => {
|
||||
if f.fract() < Fraction::from(0.5) {
|
||||
f.floor()
|
||||
} else {
|
||||
f.ceil()
|
||||
},
|
||||
}
|
||||
},
|
||||
Down => f.floor(),
|
||||
NearestPrefDown =>
|
||||
NearestPrefDown => {
|
||||
if f.fract() > Fraction::from(0.5) {
|
||||
f.ceil()
|
||||
} else {
|
||||
f.floor()
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -273,9 +273,9 @@ impl BigUint {
|
||||
let mut k = 0;
|
||||
for i in 0..m {
|
||||
// PROOF: (B−1) × (B−1) + (B−1) + (B−1) = B^2 −1 < B^2. addition is safe.
|
||||
let t = mul_single(self.get(j), other.get(i)) +
|
||||
Double::from(w.get(i + j)) +
|
||||
Double::from(k);
|
||||
let t = mul_single(self.get(j), other.get(i))
|
||||
+ Double::from(w.get(i + j))
|
||||
+ Double::from(k);
|
||||
w.set(i + j, (t % B) as Single);
|
||||
// PROOF: (B^2 - 1) / B < B. conversion is safe.
|
||||
k = (t / B) as Single;
|
||||
|
||||
@@ -490,10 +490,12 @@ impl Rounding {
|
||||
match (rounding, negative) {
|
||||
(Low, true) | (Major, _) | (High, false) => Up,
|
||||
(High, true) | (Minor, _) | (Low, false) => Down,
|
||||
(NearestPrefMajor, _) | (NearestPrefHigh, false) | (NearestPrefLow, true) =>
|
||||
NearestPrefUp,
|
||||
(NearestPrefMinor, _) | (NearestPrefLow, false) | (NearestPrefHigh, true) =>
|
||||
NearestPrefDown,
|
||||
(NearestPrefMajor, _) | (NearestPrefHigh, false) | (NearestPrefLow, true) => {
|
||||
NearestPrefUp
|
||||
},
|
||||
(NearestPrefMinor, _) | (NearestPrefLow, false) | (NearestPrefHigh, true) => {
|
||||
NearestPrefDown
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,8 +311,8 @@ where
|
||||
|
||||
// both headers must be targeting the same slot and it must
|
||||
// be the same as the one in the proof.
|
||||
if proof.slot != first_pre_digest.slot() ||
|
||||
first_pre_digest.slot() != second_pre_digest.slot()
|
||||
if proof.slot != first_pre_digest.slot()
|
||||
|| first_pre_digest.slot() != second_pre_digest.slot()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -153,9 +153,9 @@ impl<TBlockNumber, TSignature> SignedCommitment<TBlockNumber, TSignature> {
|
||||
TAuthorityId: RuntimeAppPublic<Signature = TSignature> + BeefyAuthorityId<MsgHash>,
|
||||
MsgHash: Hash,
|
||||
{
|
||||
if self.signatures.len() != validator_set.len() ||
|
||||
self.commitment.validator_set_id != validator_set.id() ||
|
||||
self.commitment.block_number != target_number
|
||||
if self.signatures.len() != validator_set.len()
|
||||
|| self.commitment.validator_set_id != validator_set.id()
|
||||
|| self.commitment.block_number != target_number
|
||||
{
|
||||
return Err(0);
|
||||
}
|
||||
|
||||
@@ -405,10 +405,10 @@ where
|
||||
// have different validator set ids,
|
||||
// or both votes have the same commitment,
|
||||
// --> the equivocation is invalid.
|
||||
if first.id != second.id ||
|
||||
first.commitment.block_number != second.commitment.block_number ||
|
||||
first.commitment.validator_set_id != second.commitment.validator_set_id ||
|
||||
first.commitment.payload == second.commitment.payload
|
||||
if first.id != second.id
|
||||
|| first.commitment.block_number != second.commitment.block_number
|
||||
|| first.commitment.validator_set_id != second.commitment.validator_set_id
|
||||
|| first.commitment.payload == second.commitment.payload
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -355,8 +355,8 @@ where
|
||||
macro_rules! check {
|
||||
( $equivocation:expr, $message:expr ) => {
|
||||
// if both votes have the same target the equivocation is invalid.
|
||||
if $equivocation.first.0.target_hash == $equivocation.second.0.target_hash &&
|
||||
$equivocation.first.0.target_number == $equivocation.second.0.target_number
|
||||
if $equivocation.first.0.target_hash == $equivocation.second.0.target_hash
|
||||
&& $equivocation.first.0.target_number == $equivocation.second.0.target_number
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -391,9 +391,9 @@ pub mod ring_vrf {
|
||||
const OVERHEAD_SIZE: usize = 16;
|
||||
const G2_POINTS_NUM: usize = 2;
|
||||
let g1_points_num = ark_vrf::ring::pcs_domain_size::<BandersnatchSuite>(ring_size);
|
||||
OVERHEAD_SIZE +
|
||||
g1_points_num * G1_POINT_UNCOMPRESSED_SIZE +
|
||||
G2_POINTS_NUM * G2_POINT_UNCOMPRESSED_SIZE
|
||||
OVERHEAD_SIZE
|
||||
+ g1_points_num * G1_POINT_UNCOMPRESSED_SIZE
|
||||
+ G2_POINTS_NUM * G2_POINT_UNCOMPRESSED_SIZE
|
||||
}
|
||||
|
||||
/// [`RingVerifierKey`] serialized size.
|
||||
|
||||
@@ -121,8 +121,8 @@ pub const SIGNATURE_SERIALIZED_SIZE: usize =
|
||||
<DoubleSignature<TinyBLS381> as SerializableToBytes>::SERIALIZED_BYTES_SIZE;
|
||||
|
||||
/// Signature serialized size (for back cert) + Nugget BLS PoP size
|
||||
pub const PROOF_OF_POSSESSION_SERIALIZED_SIZE: usize = SIGNATURE_SERIALIZED_SIZE +
|
||||
<NuggetBLSnCPPoP<TinyBLS381> as SerializableToBytes>::SERIALIZED_BYTES_SIZE;
|
||||
pub const PROOF_OF_POSSESSION_SERIALIZED_SIZE: usize = SIGNATURE_SERIALIZED_SIZE
|
||||
+ <NuggetBLSnCPPoP<TinyBLS381> as SerializableToBytes>::SERIALIZED_BYTES_SIZE;
|
||||
|
||||
/// A secret seed.
|
||||
///
|
||||
|
||||
@@ -1299,14 +1299,16 @@ mod tests {
|
||||
password,
|
||||
path: path.into_iter().chain(path_iter).collect(),
|
||||
},
|
||||
TestPair::GeneratedFromPhrase { phrase, password } =>
|
||||
TestPair::Standard { phrase, password, path: path_iter.collect() },
|
||||
x =>
|
||||
TestPair::GeneratedFromPhrase { phrase, password } => {
|
||||
TestPair::Standard { phrase, password, path: path_iter.collect() }
|
||||
},
|
||||
x => {
|
||||
if path_iter.count() == 0 {
|
||||
x
|
||||
} else {
|
||||
return Err(DeriveError::SoftKeyInPath);
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
None,
|
||||
))
|
||||
|
||||
@@ -75,13 +75,14 @@ impl OffchainStorage for InMemOffchainStorage {
|
||||
let key = prefix.iter().chain(key).cloned().collect();
|
||||
|
||||
match self.storage.entry(key) {
|
||||
Entry::Vacant(entry) =>
|
||||
Entry::Vacant(entry) => {
|
||||
if old_value.is_none() {
|
||||
entry.insert(new_value.to_vec());
|
||||
true
|
||||
} else {
|
||||
false
|
||||
},
|
||||
}
|
||||
},
|
||||
Entry::Occupied(ref mut entry) if Some(entry.get().as_slice()) == old_value => {
|
||||
entry.insert(new_value.to_vec());
|
||||
true
|
||||
@@ -161,8 +162,9 @@ impl<Storage: OffchainStorage> DbExternalities for OffchainDb<Storage> {
|
||||
"CAS",
|
||||
);
|
||||
match kind {
|
||||
StorageKind::PERSISTENT =>
|
||||
self.persistent.compare_and_set(STORAGE_PREFIX, key, old_value, new_value),
|
||||
StorageKind::PERSISTENT => {
|
||||
self.persistent.compare_and_set(STORAGE_PREFIX, key, old_value, new_value)
|
||||
},
|
||||
StorageKind::LOCAL => unavailable_yet(LOCAL_DB),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,8 +80,9 @@ impl TestPersistentOffchainDB {
|
||||
let mut me = self.persistent.write();
|
||||
for ((_prefix, key), value_operation) in changes {
|
||||
match value_operation {
|
||||
OffchainOverlayedChange::SetValue(val) =>
|
||||
me.set(Self::PREFIX, key.as_slice(), val.as_slice()),
|
||||
OffchainOverlayedChange::SetValue(val) => {
|
||||
me.set(Self::PREFIX, key.as_slice(), val.as_slice())
|
||||
},
|
||||
OffchainOverlayedChange::Remove => me.remove(Self::PREFIX, key.as_slice()),
|
||||
}
|
||||
}
|
||||
@@ -381,10 +382,12 @@ impl offchain::DbExternalities for TestOffchainExt {
|
||||
) -> bool {
|
||||
let mut state = self.0.write();
|
||||
match kind {
|
||||
StorageKind::LOCAL =>
|
||||
state.local_storage.compare_and_set(b"", key, old_value, new_value),
|
||||
StorageKind::PERSISTENT =>
|
||||
state.persistent_storage.compare_and_set(b"", key, old_value, new_value),
|
||||
StorageKind::LOCAL => {
|
||||
state.local_storage.compare_and_set(b"", key, old_value, new_value)
|
||||
},
|
||||
StorageKind::PERSISTENT => {
|
||||
state.persistent_storage.compare_and_set(b"", key, old_value, new_value)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -520,25 +520,34 @@ pub mod vrf {
|
||||
NotMarkedSchnorrkel => "Signature error: `NotMarkedSchnorrkel`".into(),
|
||||
BytesLengthError { .. } => "Signature error: `BytesLengthError`".into(),
|
||||
InvalidKey => "Signature error: `InvalidKey`".into(),
|
||||
MuSigAbsent { musig_stage: Commitment } =>
|
||||
"Signature error: `MuSigAbsent` at stage `Commitment`".into(),
|
||||
MuSigAbsent { musig_stage: Reveal } =>
|
||||
"Signature error: `MuSigAbsent` at stage `Reveal`".into(),
|
||||
MuSigAbsent { musig_stage: Cosignature } =>
|
||||
"Signature error: `MuSigAbsent` at stage `Commitment`".into(),
|
||||
MuSigInconsistent { musig_stage: Commitment, duplicate: true } =>
|
||||
"Signature error: `MuSigInconsistent` at stage `Commitment` on duplicate".into(),
|
||||
MuSigInconsistent { musig_stage: Commitment, duplicate: false } =>
|
||||
"Signature error: `MuSigInconsistent` at stage `Commitment` on not duplicate".into(),
|
||||
MuSigInconsistent { musig_stage: Reveal, duplicate: true } =>
|
||||
"Signature error: `MuSigInconsistent` at stage `Reveal` on duplicate".into(),
|
||||
MuSigInconsistent { musig_stage: Reveal, duplicate: false } =>
|
||||
"Signature error: `MuSigInconsistent` at stage `Reveal` on not duplicate".into(),
|
||||
MuSigInconsistent { musig_stage: Cosignature, duplicate: true } =>
|
||||
"Signature error: `MuSigInconsistent` at stage `Cosignature` on duplicate".into(),
|
||||
MuSigInconsistent { musig_stage: Cosignature, duplicate: false } =>
|
||||
MuSigAbsent { musig_stage: Commitment } => {
|
||||
"Signature error: `MuSigAbsent` at stage `Commitment`".into()
|
||||
},
|
||||
MuSigAbsent { musig_stage: Reveal } => {
|
||||
"Signature error: `MuSigAbsent` at stage `Reveal`".into()
|
||||
},
|
||||
MuSigAbsent { musig_stage: Cosignature } => {
|
||||
"Signature error: `MuSigAbsent` at stage `Commitment`".into()
|
||||
},
|
||||
MuSigInconsistent { musig_stage: Commitment, duplicate: true } => {
|
||||
"Signature error: `MuSigInconsistent` at stage `Commitment` on duplicate".into()
|
||||
},
|
||||
MuSigInconsistent { musig_stage: Commitment, duplicate: false } => {
|
||||
"Signature error: `MuSigInconsistent` at stage `Commitment` on not duplicate".into()
|
||||
},
|
||||
MuSigInconsistent { musig_stage: Reveal, duplicate: true } => {
|
||||
"Signature error: `MuSigInconsistent` at stage `Reveal` on duplicate".into()
|
||||
},
|
||||
MuSigInconsistent { musig_stage: Reveal, duplicate: false } => {
|
||||
"Signature error: `MuSigInconsistent` at stage `Reveal` on not duplicate".into()
|
||||
},
|
||||
MuSigInconsistent { musig_stage: Cosignature, duplicate: true } => {
|
||||
"Signature error: `MuSigInconsistent` at stage `Cosignature` on duplicate".into()
|
||||
},
|
||||
MuSigInconsistent { musig_stage: Cosignature, duplicate: false } => {
|
||||
"Signature error: `MuSigInconsistent` at stage `Cosignature` on not duplicate"
|
||||
.into(),
|
||||
.into()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,17 +48,19 @@ impl Parse for InputBytes {
|
||||
syn::Expr::Lit(lit) => match &lit.lit {
|
||||
syn::Lit::Int(b) => bytes.push(b.base10_parse()?),
|
||||
syn::Lit::Byte(b) => bytes.push(b.value()),
|
||||
_ =>
|
||||
_ => {
|
||||
return Err(syn::Error::new(
|
||||
input.span(),
|
||||
"Expected array of u8 elements.".to_string(),
|
||||
)),
|
||||
))
|
||||
},
|
||||
},
|
||||
_ =>
|
||||
_ => {
|
||||
return Err(syn::Error::new(
|
||||
input.span(),
|
||||
"Expected array of u8 elements.".to_string(),
|
||||
)),
|
||||
))
|
||||
},
|
||||
}
|
||||
}
|
||||
return Ok(InputBytes(bytes));
|
||||
|
||||
@@ -179,8 +179,9 @@ mod implementation {
|
||||
name_str,
|
||||
Fields::new(f.named.iter(), Some(syn::Token!(self)(Span::call_site()))),
|
||||
),
|
||||
syn::Fields::Unnamed(ref f) =>
|
||||
derive_fields(name_str, Fields::new(f.unnamed.iter(), None)),
|
||||
syn::Fields::Unnamed(ref f) => {
|
||||
derive_fields(name_str, Fields::new(f.unnamed.iter(), None))
|
||||
},
|
||||
syn::Fields::Unit => derive_fields(name_str, Fields::Indexed { indices: vec![] }),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,9 +367,9 @@ impl CheckInherentsResult {
|
||||
#[cfg(feature = "std")]
|
||||
impl PartialEq for CheckInherentsResult {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.fatal_error == other.fatal_error &&
|
||||
self.okay == other.okay &&
|
||||
self.errors.data == other.errors.data
|
||||
self.fatal_error == other.fatal_error
|
||||
&& self.okay == other.okay
|
||||
&& self.errors.data == other.errors.data
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -205,10 +205,12 @@ impl From<EnumDeprecationInfoIR> for EnumDeprecationInfo {
|
||||
impl From<VariantDeprecationInfoIR> for VariantDeprecationInfo {
|
||||
fn from(ir: VariantDeprecationInfoIR) -> Self {
|
||||
match ir {
|
||||
VariantDeprecationInfoIR::DeprecatedWithoutNote =>
|
||||
VariantDeprecationInfo::DeprecatedWithoutNote,
|
||||
VariantDeprecationInfoIR::Deprecated { note, since } =>
|
||||
VariantDeprecationInfo::Deprecated { note, since },
|
||||
VariantDeprecationInfoIR::DeprecatedWithoutNote => {
|
||||
VariantDeprecationInfo::DeprecatedWithoutNote
|
||||
},
|
||||
VariantDeprecationInfoIR::Deprecated { note, since } => {
|
||||
VariantDeprecationInfo::Deprecated { note, since }
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,10 +219,12 @@ impl From<ItemDeprecationInfoIR> for ItemDeprecationInfo {
|
||||
fn from(ir: ItemDeprecationInfoIR) -> Self {
|
||||
match ir {
|
||||
ItemDeprecationInfoIR::NotDeprecated => ItemDeprecationInfo::NotDeprecated,
|
||||
ItemDeprecationInfoIR::DeprecatedWithoutNote =>
|
||||
ItemDeprecationInfo::DeprecatedWithoutNote,
|
||||
ItemDeprecationInfoIR::Deprecated { note, since } =>
|
||||
ItemDeprecationInfo::Deprecated { note, since },
|
||||
ItemDeprecationInfoIR::DeprecatedWithoutNote => {
|
||||
ItemDeprecationInfo::DeprecatedWithoutNote
|
||||
},
|
||||
ItemDeprecationInfoIR::Deprecated { note, since } => {
|
||||
ItemDeprecationInfo::Deprecated { note, since }
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,10 +158,12 @@ pub fn generate_random_npos_result(
|
||||
|
||||
(
|
||||
match election_type {
|
||||
ElectionType::Phragmen(conf) =>
|
||||
seq_phragmen(to_elect, candidates.clone(), voters.clone(), conf).unwrap(),
|
||||
ElectionType::Phragmms(conf) =>
|
||||
phragmms(to_elect, candidates.clone(), voters.clone(), conf).unwrap(),
|
||||
ElectionType::Phragmen(conf) => {
|
||||
seq_phragmen(to_elect, candidates.clone(), voters.clone(), conf).unwrap()
|
||||
},
|
||||
ElectionType::Phragmms(conf) => {
|
||||
phragmms(to_elect, candidates.clone(), voters.clone(), conf).unwrap()
|
||||
},
|
||||
},
|
||||
candidates,
|
||||
voters,
|
||||
|
||||
@@ -86,9 +86,9 @@ fn main() {
|
||||
// The only guarantee of balancing is such that the first and third element of the
|
||||
// score cannot decrease.
|
||||
assert!(
|
||||
balanced_score.minimal_stake >= unbalanced_score.minimal_stake &&
|
||||
balanced_score.sum_stake == unbalanced_score.sum_stake &&
|
||||
balanced_score.sum_stake_squared <= unbalanced_score.sum_stake_squared
|
||||
balanced_score.minimal_stake >= unbalanced_score.minimal_stake
|
||||
&& balanced_score.sum_stake == unbalanced_score.sum_stake
|
||||
&& balanced_score.sum_stake_squared <= unbalanced_score.sum_stake_squared
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -85,9 +85,9 @@ fn main() {
|
||||
// The only guarantee of balancing is such that the first and third element of the score
|
||||
// cannot decrease.
|
||||
assert!(
|
||||
balanced_score.minimal_stake >= unbalanced_score.minimal_stake &&
|
||||
balanced_score.sum_stake == unbalanced_score.sum_stake &&
|
||||
balanced_score.sum_stake_squared <= unbalanced_score.sum_stake_squared
|
||||
balanced_score.minimal_stake >= unbalanced_score.minimal_stake
|
||||
&& balanced_score.sum_stake == unbalanced_score.sum_stake
|
||||
&& balanced_score.sum_stake_squared <= unbalanced_score.sum_stake_squared
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -51,8 +51,8 @@ pub fn standard_threshold(
|
||||
) -> Threshold {
|
||||
weights
|
||||
.into_iter()
|
||||
.fold(Threshold::zero(), |acc, elem| acc.saturating_add(elem)) /
|
||||
committee_size.max(1) as Threshold
|
||||
.fold(Threshold::zero(), |acc, elem| acc.saturating_add(elem))
|
||||
/ committee_size.max(1) as Threshold
|
||||
}
|
||||
|
||||
/// Check a solution to be PJR.
|
||||
|
||||
+3
-2
@@ -467,14 +467,15 @@ fn generate_wasm_interface_signature_for_host_function(sig: &Signature) -> Resul
|
||||
/// Generate the variable name that stores the FFI value.
|
||||
fn generate_ffi_value_var_name(pat: &Pat) -> Result<Ident> {
|
||||
match pat {
|
||||
Pat::Ident(pat_ident) =>
|
||||
Pat::Ident(pat_ident) => {
|
||||
if let Some(by_ref) = pat_ident.by_ref {
|
||||
Err(Error::new(by_ref.span(), "`ref` not supported!"))
|
||||
} else if let Some(sub_pattern) = &pat_ident.subpat {
|
||||
Err(Error::new(sub_pattern.0.span(), "Not supported!"))
|
||||
} else {
|
||||
Ok(Ident::new(&format!("{}_ffi_value", pat_ident.ident), Span::call_site()))
|
||||
},
|
||||
}
|
||||
},
|
||||
_ => Err(Error::new(pat.span(), "Not supported as variable name!")),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,8 +128,8 @@ impl RuntimeInterfaceFunctionSet {
|
||||
|
||||
self.versions
|
||||
.insert(version.version, RuntimeInterfaceFunction::new(trait_item)?);
|
||||
if self.latest_version_to_call.map_or(true, |v| v < version.version) &&
|
||||
version.is_callable()
|
||||
if self.latest_version_to_call.map_or(true, |v| v < version.version)
|
||||
&& version.is_callable()
|
||||
{
|
||||
self.latest_version_to_call = Some(version.version);
|
||||
}
|
||||
@@ -360,9 +360,10 @@ pub fn host_inner_return_ty(ty: &syn::ReturnType) -> syn::ReturnType {
|
||||
let crate_ = generate_crate_access();
|
||||
match ty {
|
||||
syn::ReturnType::Default => syn::ReturnType::Default,
|
||||
syn::ReturnType::Type(ref arrow, ref ty) =>
|
||||
syn::ReturnType::Type(ref arrow, ref ty) => {
|
||||
syn::parse2::<syn::ReturnType>(quote! { #arrow <#ty as #crate_::RIType>::Inner })
|
||||
.expect("parsing doesn't fail"),
|
||||
.expect("parsing doesn't fail")
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -147,8 +147,9 @@ impl<AccountId, Call: Dispatchable, Extension: TransactionExtension<Call>>
|
||||
pub fn extension_weight(&self) -> Weight {
|
||||
match &self.format {
|
||||
ExtrinsicFormat::Bare => Weight::zero(),
|
||||
ExtrinsicFormat::Signed(_, ext) | ExtrinsicFormat::General(_, ext) =>
|
||||
ext.weight(&self.function),
|
||||
ExtrinsicFormat::Signed(_, ext) | ExtrinsicFormat::General(_, ext) => {
|
||||
ext.weight(&self.function)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,11 +356,13 @@ impl<'a> DigestItemRef<'a> {
|
||||
/// return the opaque data it contains.
|
||||
pub fn try_as_raw(&self, id: OpaqueDigestItemId) -> Option<&'a [u8]> {
|
||||
match (id, self) {
|
||||
(OpaqueDigestItemId::Consensus(w), &Self::Consensus(v, s)) |
|
||||
(OpaqueDigestItemId::Seal(w), &Self::Seal(v, s)) |
|
||||
(OpaqueDigestItemId::PreRuntime(w), &Self::PreRuntime(v, s))
|
||||
(OpaqueDigestItemId::Consensus(w), &Self::Consensus(v, s))
|
||||
| (OpaqueDigestItemId::Seal(w), &Self::Seal(v, s))
|
||||
| (OpaqueDigestItemId::PreRuntime(w), &Self::PreRuntime(v, s))
|
||||
if v == w =>
|
||||
Some(s),
|
||||
{
|
||||
Some(s)
|
||||
},
|
||||
(OpaqueDigestItemId::Other, &Self::Other(s)) => Some(s),
|
||||
_ => None,
|
||||
}
|
||||
@@ -445,14 +447,18 @@ mod tests {
|
||||
let check = |digest_item_type: DigestItemType| {
|
||||
let (variant_name, digest_item) = match digest_item_type {
|
||||
DigestItemType::Other => ("Other", DigestItem::Other(Default::default())),
|
||||
DigestItemType::Consensus =>
|
||||
("Consensus", DigestItem::Consensus(Default::default(), Default::default())),
|
||||
DigestItemType::Seal =>
|
||||
("Seal", DigestItem::Seal(Default::default(), Default::default())),
|
||||
DigestItemType::PreRuntime =>
|
||||
("PreRuntime", DigestItem::PreRuntime(Default::default(), Default::default())),
|
||||
DigestItemType::RuntimeEnvironmentUpdated =>
|
||||
("RuntimeEnvironmentUpdated", DigestItem::RuntimeEnvironmentUpdated),
|
||||
DigestItemType::Consensus => {
|
||||
("Consensus", DigestItem::Consensus(Default::default(), Default::default()))
|
||||
},
|
||||
DigestItemType::Seal => {
|
||||
("Seal", DigestItem::Seal(Default::default(), Default::default()))
|
||||
},
|
||||
DigestItemType::PreRuntime => {
|
||||
("PreRuntime", DigestItem::PreRuntime(Default::default(), Default::default()))
|
||||
},
|
||||
DigestItemType::RuntimeEnvironmentUpdated => {
|
||||
("RuntimeEnvironmentUpdated", DigestItem::RuntimeEnvironmentUpdated)
|
||||
},
|
||||
};
|
||||
let encoded = digest_item.encode();
|
||||
let variant = variants
|
||||
|
||||
@@ -105,8 +105,8 @@ impl Encode for Era {
|
||||
Self::Immortal => output.push_byte(0),
|
||||
Self::Mortal(period, phase) => {
|
||||
let quantize_factor = (*period as u64 >> 12).max(1);
|
||||
let encoded = (period.trailing_zeros() - 1).clamp(1, 15) as u16 |
|
||||
((phase / quantize_factor) << 4) as u16;
|
||||
let encoded = (period.trailing_zeros() - 1).clamp(1, 15) as u16
|
||||
| ((phase / quantize_factor) << 4) as u16;
|
||||
encoded.encode_to(output);
|
||||
},
|
||||
}
|
||||
|
||||
@@ -421,8 +421,9 @@ where
|
||||
format: ExtrinsicFormat::General(extension_version, tx_ext),
|
||||
function: self.function,
|
||||
},
|
||||
Preamble::Bare(_) =>
|
||||
CheckedExtrinsic { format: ExtrinsicFormat::Bare, function: self.function },
|
||||
Preamble::Bare(_) => {
|
||||
CheckedExtrinsic { format: ExtrinsicFormat::Bare, function: self.function }
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -443,8 +444,9 @@ where
|
||||
format: ExtrinsicFormat::General(extension_version, tx_ext),
|
||||
function: self.function,
|
||||
},
|
||||
Preamble::Bare(_) =>
|
||||
CheckedExtrinsic { format: ExtrinsicFormat::Bare, function: self.function },
|
||||
Preamble::Bare(_) => {
|
||||
CheckedExtrinsic { format: ExtrinsicFormat::Bare, function: self.function }
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -529,8 +529,8 @@ impl Verify for AnySignature {
|
||||
let msg = msg.get();
|
||||
sr25519::Signature::try_from(self.0.as_fixed_bytes().as_ref())
|
||||
.map(|s| s.verify(msg, signer))
|
||||
.unwrap_or(false) ||
|
||||
ed25519::Signature::try_from(self.0.as_fixed_bytes().as_ref())
|
||||
.unwrap_or(false)
|
||||
|| ed25519::Signature::try_from(self.0.as_fixed_bytes().as_ref())
|
||||
.map(|s| match ed25519::Public::from_slice(signer.as_ref()) {
|
||||
Err(()) => false,
|
||||
Ok(signer) => s.verify(msg, &signer),
|
||||
@@ -693,8 +693,9 @@ impl DispatchError {
|
||||
/// Return the same error but without the attached message.
|
||||
pub fn stripped(self) -> Self {
|
||||
match self {
|
||||
DispatchError::Module(ModuleError { index, error, message: Some(_) }) =>
|
||||
DispatchError::Module(ModuleError { index, error, message: None }),
|
||||
DispatchError::Module(ModuleError { index, error, message: Some(_) }) => {
|
||||
DispatchError::Module(ModuleError { index, error, message: None })
|
||||
},
|
||||
m => m,
|
||||
}
|
||||
}
|
||||
@@ -770,8 +771,9 @@ impl From<TokenError> for &'static str {
|
||||
TokenError::UnknownAsset => "The asset in question is unknown",
|
||||
TokenError::Frozen => "Funds exist but are frozen",
|
||||
TokenError::Unsupported => "Operation is not supported by the asset",
|
||||
TokenError::CannotCreateHold =>
|
||||
"Account cannot be created for recording amount on hold",
|
||||
TokenError::CannotCreateHold => {
|
||||
"Account cannot be created for recording amount on hold"
|
||||
},
|
||||
TokenError::NotExpendable => "Account that is desired to remain would die",
|
||||
TokenError::Blocked => "Account cannot receive the assets",
|
||||
}
|
||||
@@ -973,8 +975,8 @@ pub fn verify_encoded_lazy<V: Verify, T: codec::Encode>(
|
||||
macro_rules! assert_eq_error_rate {
|
||||
($x:expr, $y:expr, $error:expr $(,)?) => {
|
||||
assert!(
|
||||
($x >= $crate::Saturating::saturating_sub($y, $error)) &&
|
||||
($x <= $crate::Saturating::saturating_add($y, $error)),
|
||||
($x >= $crate::Saturating::saturating_sub($y, $error))
|
||||
&& ($x <= $crate::Saturating::saturating_add($y, $error)),
|
||||
"{:?} != {:?} (with error rate {:?})",
|
||||
$x,
|
||||
$y,
|
||||
|
||||
@@ -222,8 +222,8 @@ impl<B: BlockNumberProvider> Lockable for BlockAndTime<B> {
|
||||
type Deadline = BlockAndTimeDeadline<B>;
|
||||
|
||||
fn deadline(&self) -> Self::Deadline {
|
||||
let block_number = <B as BlockNumberProvider>::current_block_number() +
|
||||
self.expiration_block_number_offset.into();
|
||||
let block_number = <B as BlockNumberProvider>::current_block_number()
|
||||
+ self.expiration_block_number_offset.into();
|
||||
BlockAndTimeDeadline {
|
||||
timestamp: offchain::timestamp().add(self.expiration_duration),
|
||||
block_number,
|
||||
@@ -231,8 +231,8 @@ impl<B: BlockNumberProvider> Lockable for BlockAndTime<B> {
|
||||
}
|
||||
|
||||
fn has_expired(deadline: &Self::Deadline) -> bool {
|
||||
offchain::timestamp() > deadline.timestamp &&
|
||||
<B as BlockNumberProvider>::current_block_number() > deadline.block_number
|
||||
offchain::timestamp() > deadline.timestamp
|
||||
&& <B as BlockNumberProvider>::current_block_number() > deadline.block_number
|
||||
}
|
||||
|
||||
fn snooze(deadline: &Self::Deadline) {
|
||||
|
||||
@@ -107,8 +107,9 @@ impl From<TrieError> for &'static str {
|
||||
match e {
|
||||
TrieError::InvalidStateRoot => "The state root is not in the database.",
|
||||
TrieError::IncompleteDatabase => "A trie item was not found in the database.",
|
||||
TrieError::ValueAtIncompleteKey =>
|
||||
"A value was found with a key that is not byte-aligned.",
|
||||
TrieError::ValueAtIncompleteKey => {
|
||||
"A value was found with a key that is not byte-aligned."
|
||||
},
|
||||
TrieError::DecoderError => "A corrupt trie item was encountered.",
|
||||
TrieError::InvalidHash => "The hash does not match the expected value.",
|
||||
TrieError::DuplicateKey => "The proof contains duplicate keys.",
|
||||
|
||||
+3
-2
@@ -115,8 +115,9 @@ where
|
||||
source,
|
||||
) {
|
||||
// After validation, some origin must have been authorized.
|
||||
Ok((_, _, origin)) if !origin.is_transaction_authorized() =>
|
||||
Err(InvalidTransaction::UnknownOrigin.into()),
|
||||
Ok((_, _, origin)) if !origin.is_transaction_authorized() => {
|
||||
Err(InvalidTransaction::UnknownOrigin.into())
|
||||
},
|
||||
res => res,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,18 +109,23 @@ impl From<InvalidTransaction> for &'static str {
|
||||
InvalidTransaction::BadProof => "Transaction has a bad signature",
|
||||
InvalidTransaction::AncientBirthBlock => "Transaction has an ancient birth block",
|
||||
InvalidTransaction::ExhaustsResources => "Transaction would exhaust the block limits",
|
||||
InvalidTransaction::Payment =>
|
||||
"Inability to pay some fees (e.g. account balance too low)",
|
||||
InvalidTransaction::BadMandatory =>
|
||||
"A call was labelled as mandatory, but resulted in an Error.",
|
||||
InvalidTransaction::MandatoryValidation =>
|
||||
"Transaction dispatch is mandatory; transactions must not be validated.",
|
||||
InvalidTransaction::Payment => {
|
||||
"Inability to pay some fees (e.g. account balance too low)"
|
||||
},
|
||||
InvalidTransaction::BadMandatory => {
|
||||
"A call was labelled as mandatory, but resulted in an Error."
|
||||
},
|
||||
InvalidTransaction::MandatoryValidation => {
|
||||
"Transaction dispatch is mandatory; transactions must not be validated."
|
||||
},
|
||||
InvalidTransaction::Custom(_) => "InvalidTransaction custom error",
|
||||
InvalidTransaction::BadSigner => "Invalid signing address",
|
||||
InvalidTransaction::IndeterminateImplicit =>
|
||||
"The implicit data was unable to be calculated",
|
||||
InvalidTransaction::UnknownOrigin =>
|
||||
"The transaction extension did not authorize any origin",
|
||||
InvalidTransaction::IndeterminateImplicit => {
|
||||
"The implicit data was unable to be calculated"
|
||||
},
|
||||
InvalidTransaction::UnknownOrigin => {
|
||||
"The transaction extension did not authorize any origin"
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,10 +145,12 @@ pub enum UnknownTransaction {
|
||||
impl From<UnknownTransaction> for &'static str {
|
||||
fn from(unknown: UnknownTransaction) -> &'static str {
|
||||
match unknown {
|
||||
UnknownTransaction::CannotLookup =>
|
||||
"Could not lookup information required to validate the transaction",
|
||||
UnknownTransaction::NoUnsignedValidator =>
|
||||
"Could not find an unsigned validator for the unsigned transaction",
|
||||
UnknownTransaction::CannotLookup => {
|
||||
"Could not lookup information required to validate the transaction"
|
||||
},
|
||||
UnknownTransaction::NoUnsignedValidator => {
|
||||
"Could not find an unsigned validator for the unsigned transaction"
|
||||
},
|
||||
UnknownTransaction::Custom(_) => "UnknownTransaction custom error",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,13 +127,14 @@ impl PartialEq for BasicExternalities {
|
||||
self.overlay
|
||||
.changes()
|
||||
.map(|(k, v)| (k, v.value_ref().materialize()))
|
||||
.collect::<BTreeMap<_, _>>() ==
|
||||
other
|
||||
.collect::<BTreeMap<_, _>>()
|
||||
== other
|
||||
.overlay
|
||||
.changes()
|
||||
.map(|(k, v)| (k, v.value_ref().materialize()))
|
||||
.collect::<BTreeMap<_, _>>() &&
|
||||
self.overlay
|
||||
.collect::<BTreeMap<_, _>>()
|
||||
&& self
|
||||
.overlay
|
||||
.children()
|
||||
.map(|(iter, i)| {
|
||||
(
|
||||
@@ -142,8 +143,8 @@ impl PartialEq for BasicExternalities {
|
||||
.collect::<BTreeMap<_, _>>(),
|
||||
)
|
||||
})
|
||||
.collect::<BTreeMap<_, _>>() ==
|
||||
other
|
||||
.collect::<BTreeMap<_, _>>()
|
||||
== other
|
||||
.overlay
|
||||
.children()
|
||||
.map(|(iter, i)| {
|
||||
|
||||
@@ -626,8 +626,9 @@ mod execution {
|
||||
let storage_key = PrefixedStorageKey::new_ref(storage_key);
|
||||
(
|
||||
Some(match ChildType::from_prefixed_key(storage_key) {
|
||||
Some((ChildType::ParentKeyId, storage_key)) =>
|
||||
ChildInfo::new_default(storage_key),
|
||||
Some((ChildType::ParentKeyId, storage_key)) => {
|
||||
ChildInfo::new_default(storage_key)
|
||||
},
|
||||
None => return Err(Box::new("Invalid range start child trie key.")),
|
||||
}),
|
||||
2,
|
||||
@@ -650,8 +651,8 @@ mod execution {
|
||||
while let Some(item) = iter.next() {
|
||||
let (key, value) = item.map_err(|e| Box::new(e) as Box<dyn Error>)?;
|
||||
|
||||
if depth < MAX_NESTED_TRIE_DEPTH &&
|
||||
pezsp_core::storage::well_known_keys::is_child_storage_key(key.as_slice())
|
||||
if depth < MAX_NESTED_TRIE_DEPTH
|
||||
&& pezsp_core::storage::well_known_keys::is_child_storage_key(key.as_slice())
|
||||
{
|
||||
count += 1;
|
||||
// do not add two child trie with same root
|
||||
@@ -1025,8 +1026,9 @@ mod execution {
|
||||
let storage_key = PrefixedStorageKey::new_ref(storage_key);
|
||||
(
|
||||
Some(match ChildType::from_prefixed_key(storage_key) {
|
||||
Some((ChildType::ParentKeyId, storage_key)) =>
|
||||
ChildInfo::new_default(storage_key),
|
||||
Some((ChildType::ParentKeyId, storage_key)) => {
|
||||
ChildInfo::new_default(storage_key)
|
||||
},
|
||||
None => return Err(Box::new("Invalid range start child trie key.")),
|
||||
}),
|
||||
2,
|
||||
@@ -1057,8 +1059,8 @@ mod execution {
|
||||
let (key, value) = item.map_err(|e| Box::new(e) as Box<dyn Error>)?;
|
||||
values.push((key.to_vec(), value.to_vec()));
|
||||
|
||||
if depth < MAX_NESTED_TRIE_DEPTH &&
|
||||
pezsp_core::storage::well_known_keys::is_child_storage_key(key.as_slice())
|
||||
if depth < MAX_NESTED_TRIE_DEPTH
|
||||
&& pezsp_core::storage::well_known_keys::is_child_storage_key(key.as_slice())
|
||||
{
|
||||
// Do not add two chid trie with same root.
|
||||
if !child_roots.contains(value.as_slice()) {
|
||||
|
||||
@@ -654,8 +654,8 @@ impl<K: Ord + Hash + Clone, V> OverlayedMap<K, V> {
|
||||
|
||||
fn close_transaction_offchain(&mut self, rollback: bool) -> Result<(), NoOpenTransaction> {
|
||||
// runtime is not allowed to close transactions started by the client
|
||||
if matches!(self.execution_mode, ExecutionMode::Runtime) &&
|
||||
!self.has_open_runtime_transactions()
|
||||
if matches!(self.execution_mode, ExecutionMode::Runtime)
|
||||
&& !self.has_open_runtime_transactions()
|
||||
{
|
||||
return Err(NoOpenTransaction);
|
||||
}
|
||||
@@ -725,8 +725,8 @@ impl OverlayedChangeSet {
|
||||
|
||||
fn close_transaction(&mut self, rollback: bool) -> Result<(), NoOpenTransaction> {
|
||||
// runtime is not allowed to close transactions started by the client
|
||||
if matches!(self.execution_mode, ExecutionMode::Runtime) &&
|
||||
!self.has_open_runtime_transactions()
|
||||
if matches!(self.execution_mode, ExecutionMode::Runtime)
|
||||
&& !self.has_open_runtime_transactions()
|
||||
{
|
||||
return Err(NoOpenTransaction);
|
||||
}
|
||||
|
||||
@@ -1015,8 +1015,8 @@ pub mod tests {
|
||||
.storage_root(iter::once((&b"new-key"[..], Some(&b"new-value"[..]))), state_version);
|
||||
assert!(!tx.drain().is_empty());
|
||||
assert!(
|
||||
new_root !=
|
||||
test_trie(state_version, None, None)
|
||||
new_root
|
||||
!= test_trie(state_version, None, None)
|
||||
.storage_root(iter::empty(), state_version)
|
||||
.0
|
||||
);
|
||||
|
||||
@@ -128,8 +128,8 @@ where
|
||||
None
|
||||
},
|
||||
Some(Err(error)) => {
|
||||
if matches!(*error, TrieError::IncompleteDatabase(_)) &&
|
||||
self.stop_on_incomplete_database
|
||||
if matches!(*error, TrieError::IncompleteDatabase(_))
|
||||
&& self.stop_on_incomplete_database
|
||||
{
|
||||
self.state = IterState::FinishedIncomplete;
|
||||
None
|
||||
@@ -681,7 +681,7 @@ where
|
||||
self.with_recorder_and_cache_for_storage_root(Some(child_root), |recorder, cache| {
|
||||
let mut eph = Ephemeral::new(self.backend_storage(), &mut write_overlay);
|
||||
match match state_version {
|
||||
StateVersion::V0 =>
|
||||
StateVersion::V0 => {
|
||||
child_delta_trie_root::<pezsp_trie::LayoutV0<H>, _, _, _, _, _, _>(
|
||||
child_info.keyspace(),
|
||||
&mut eph,
|
||||
@@ -689,8 +689,9 @@ where
|
||||
delta,
|
||||
recorder,
|
||||
cache,
|
||||
),
|
||||
StateVersion::V1 =>
|
||||
)
|
||||
},
|
||||
StateVersion::V1 => {
|
||||
child_delta_trie_root::<pezsp_trie::LayoutV1<H>, _, _, _, _, _, _>(
|
||||
child_info.keyspace(),
|
||||
&mut eph,
|
||||
@@ -698,7 +699,8 @@ where
|
||||
delta,
|
||||
recorder,
|
||||
cache,
|
||||
),
|
||||
)
|
||||
},
|
||||
} {
|
||||
Ok(ret) => (Some(ret), ret),
|
||||
Err(e) => {
|
||||
|
||||
@@ -134,8 +134,9 @@ impl Proof {
|
||||
match self {
|
||||
Proof::Sr25519 { signer, .. } => *signer,
|
||||
Proof::Ed25519 { signer, .. } => *signer,
|
||||
Proof::Secp256k1Ecdsa { signer, .. } =>
|
||||
<pezsp_runtime::traits::BlakeTwo256 as pezsp_core::Hasher>::hash(signer).into(),
|
||||
Proof::Secp256k1Ecdsa { signer, .. } => {
|
||||
<pezsp_runtime::traits::BlakeTwo256 as pezsp_core::Hasher>::hash(signer).into()
|
||||
},
|
||||
Proof::OnChain { who, .. } => *who,
|
||||
}
|
||||
}
|
||||
@@ -477,12 +478,12 @@ impl Statement {
|
||||
fn encoded(&self, for_signing: bool) -> Vec<u8> {
|
||||
// Encoding matches that of Vec<Field>. Basically this just means accepting that there
|
||||
// will be a prefix of vector length.
|
||||
let num_fields = if !for_signing && self.proof.is_some() { 1 } else { 0 } +
|
||||
if self.decryption_key.is_some() { 1 } else { 0 } +
|
||||
if self.priority.is_some() { 1 } else { 0 } +
|
||||
if self.channel.is_some() { 1 } else { 0 } +
|
||||
if self.data.is_some() { 1 } else { 0 } +
|
||||
self.num_topics as u32;
|
||||
let num_fields = if !for_signing && self.proof.is_some() { 1 } else { 0 }
|
||||
+ if self.decryption_key.is_some() { 1 } else { 0 }
|
||||
+ if self.priority.is_some() { 1 } else { 0 }
|
||||
+ if self.channel.is_some() { 1 } else { 0 }
|
||||
+ if self.data.is_some() { 1 } else { 0 }
|
||||
+ self.num_topics as u32;
|
||||
|
||||
let mut output = Vec::new();
|
||||
// When encoding signature payload, the length prefix is omitted.
|
||||
|
||||
@@ -298,8 +298,9 @@ impl ChildInfo {
|
||||
/// this trie.
|
||||
pub fn prefixed_storage_key(&self) -> PrefixedStorageKey {
|
||||
match self {
|
||||
ChildInfo::ParentKeyId(ChildTrieParentKeyId { data }) =>
|
||||
ChildType::ParentKeyId.new_prefixed_key(data.as_slice()),
|
||||
ChildInfo::ParentKeyId(ChildTrieParentKeyId { data }) => {
|
||||
ChildType::ParentKeyId.new_prefixed_key(data.as_slice())
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,9 +58,9 @@ impl<H: Hash> AccessedNodesTracker<H> {
|
||||
impl<H: Hash + Ord> TrieRecorder<H> for AccessedNodesTracker<H> {
|
||||
fn record(&mut self, access: TrieAccess<H>) {
|
||||
match access {
|
||||
TrieAccess::NodeOwned { hash, .. } |
|
||||
TrieAccess::EncodedNode { hash, .. } |
|
||||
TrieAccess::Value { hash, .. } => {
|
||||
TrieAccess::NodeOwned { hash, .. }
|
||||
| TrieAccess::EncodedNode { hash, .. }
|
||||
| TrieAccess::Value { hash, .. } => {
|
||||
self.recorder.insert(hash);
|
||||
},
|
||||
_ => {},
|
||||
|
||||
+3
-2
@@ -654,13 +654,14 @@ impl<H: Hasher> ValueCache<'_, H> {
|
||||
stats.local_fetch_attempts.fetch_add(1, Ordering::Relaxed);
|
||||
|
||||
match self {
|
||||
Self::Fresh(map) =>
|
||||
Self::Fresh(map) => {
|
||||
if let Some(value) = map.get(key) {
|
||||
stats.local_hits.fetch_add(1, Ordering::Relaxed);
|
||||
Some(value)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
}
|
||||
},
|
||||
Self::ForStorageRoot {
|
||||
local_value_cache,
|
||||
shared_value_cache_access,
|
||||
|
||||
+2
-2
@@ -410,8 +410,8 @@ where
|
||||
H: AsRef<[u8]>,
|
||||
{
|
||||
fn eq(&self, rhs: &ValueCacheKey<H>) -> bool {
|
||||
self.storage_root.as_ref() == rhs.storage_root.as_ref() &&
|
||||
self.storage_key == &*rhs.storage_key
|
||||
self.storage_root.as_ref() == rhs.storage_root.as_ref()
|
||||
&& self.storage_key == &*rhs.storage_key
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -231,12 +231,15 @@ where
|
||||
) -> Vec<u8> {
|
||||
let contains_hash = matches!(&value, Some(Value::Node(..)));
|
||||
let mut output = match (&value, contains_hash) {
|
||||
(&None, _) =>
|
||||
partial_from_iterator_encode(partial, number_nibble, NodeKind::BranchNoValue),
|
||||
(_, false) =>
|
||||
partial_from_iterator_encode(partial, number_nibble, NodeKind::BranchWithValue),
|
||||
(_, true) =>
|
||||
partial_from_iterator_encode(partial, number_nibble, NodeKind::HashedValueBranch),
|
||||
(&None, _) => {
|
||||
partial_from_iterator_encode(partial, number_nibble, NodeKind::BranchNoValue)
|
||||
},
|
||||
(_, false) => {
|
||||
partial_from_iterator_encode(partial, number_nibble, NodeKind::BranchWithValue)
|
||||
},
|
||||
(_, true) => {
|
||||
partial_from_iterator_encode(partial, number_nibble, NodeKind::HashedValueBranch)
|
||||
},
|
||||
};
|
||||
|
||||
let bitmap_index = output.len();
|
||||
@@ -287,10 +290,12 @@ fn partial_from_iterator_encode<I: Iterator<Item = u8>>(
|
||||
NodeKind::Leaf => NodeHeader::Leaf(nibble_count).encode_to(&mut output),
|
||||
NodeKind::BranchWithValue => NodeHeader::Branch(true, nibble_count).encode_to(&mut output),
|
||||
NodeKind::BranchNoValue => NodeHeader::Branch(false, nibble_count).encode_to(&mut output),
|
||||
NodeKind::HashedValueLeaf =>
|
||||
NodeHeader::HashedValueLeaf(nibble_count).encode_to(&mut output),
|
||||
NodeKind::HashedValueBranch =>
|
||||
NodeHeader::HashedValueBranch(nibble_count).encode_to(&mut output),
|
||||
NodeKind::HashedValueLeaf => {
|
||||
NodeHeader::HashedValueLeaf(nibble_count).encode_to(&mut output)
|
||||
},
|
||||
NodeKind::HashedValueBranch => {
|
||||
NodeHeader::HashedValueBranch(nibble_count).encode_to(&mut output)
|
||||
},
|
||||
};
|
||||
output.extend(partial);
|
||||
output
|
||||
|
||||
@@ -54,16 +54,18 @@ impl Encode for NodeHeader {
|
||||
fn encode_to<T: Output + ?Sized>(&self, output: &mut T) {
|
||||
match self {
|
||||
NodeHeader::Null => output.push_byte(trie_constants::EMPTY_TRIE),
|
||||
NodeHeader::Branch(true, nibble_count) =>
|
||||
encode_size_and_prefix(*nibble_count, trie_constants::BRANCH_WITH_MASK, 2, output),
|
||||
NodeHeader::Branch(true, nibble_count) => {
|
||||
encode_size_and_prefix(*nibble_count, trie_constants::BRANCH_WITH_MASK, 2, output)
|
||||
},
|
||||
NodeHeader::Branch(false, nibble_count) => encode_size_and_prefix(
|
||||
*nibble_count,
|
||||
trie_constants::BRANCH_WITHOUT_MASK,
|
||||
2,
|
||||
output,
|
||||
),
|
||||
NodeHeader::Leaf(nibble_count) =>
|
||||
encode_size_and_prefix(*nibble_count, trie_constants::LEAF_PREFIX_MASK, 2, output),
|
||||
NodeHeader::Leaf(nibble_count) => {
|
||||
encode_size_and_prefix(*nibble_count, trie_constants::LEAF_PREFIX_MASK, 2, output)
|
||||
},
|
||||
NodeHeader::HashedValueBranch(nibble_count) => encode_size_and_prefix(
|
||||
*nibble_count,
|
||||
trie_constants::ALT_HASHING_BRANCH_WITH_MASK,
|
||||
@@ -90,10 +92,12 @@ impl Decode for NodeHeader {
|
||||
}
|
||||
match i & (0b11 << 6) {
|
||||
trie_constants::LEAF_PREFIX_MASK => Ok(NodeHeader::Leaf(decode_size(i, input, 2)?)),
|
||||
trie_constants::BRANCH_WITH_MASK =>
|
||||
Ok(NodeHeader::Branch(true, decode_size(i, input, 2)?)),
|
||||
trie_constants::BRANCH_WITHOUT_MASK =>
|
||||
Ok(NodeHeader::Branch(false, decode_size(i, input, 2)?)),
|
||||
trie_constants::BRANCH_WITH_MASK => {
|
||||
Ok(NodeHeader::Branch(true, decode_size(i, input, 2)?))
|
||||
},
|
||||
trie_constants::BRANCH_WITHOUT_MASK => {
|
||||
Ok(NodeHeader::Branch(false, decode_size(i, input, 2)?))
|
||||
},
|
||||
trie_constants::EMPTY_TRIE => {
|
||||
if i & (0b111 << 5) == trie_constants::ALT_HASHING_LEAF_PREFIX_MASK {
|
||||
Ok(NodeHeader::HashedValueLeaf(decode_size(i, input, 3)?))
|
||||
|
||||
@@ -57,14 +57,18 @@ fn fuse_nibbles_node(nibbles: &[u8], kind: NodeKind) -> impl Iterator<Item = u8>
|
||||
let size = nibbles.len();
|
||||
let iter_start = match kind {
|
||||
NodeKind::Leaf => size_and_prefix_iterator(size, trie_constants::LEAF_PREFIX_MASK, 2),
|
||||
NodeKind::BranchNoValue =>
|
||||
size_and_prefix_iterator(size, trie_constants::BRANCH_WITHOUT_MASK, 2),
|
||||
NodeKind::BranchWithValue =>
|
||||
size_and_prefix_iterator(size, trie_constants::BRANCH_WITH_MASK, 2),
|
||||
NodeKind::HashedValueLeaf =>
|
||||
size_and_prefix_iterator(size, trie_constants::ALT_HASHING_LEAF_PREFIX_MASK, 3),
|
||||
NodeKind::HashedValueBranch =>
|
||||
size_and_prefix_iterator(size, trie_constants::ALT_HASHING_BRANCH_WITH_MASK, 4),
|
||||
NodeKind::BranchNoValue => {
|
||||
size_and_prefix_iterator(size, trie_constants::BRANCH_WITHOUT_MASK, 2)
|
||||
},
|
||||
NodeKind::BranchWithValue => {
|
||||
size_and_prefix_iterator(size, trie_constants::BRANCH_WITH_MASK, 2)
|
||||
},
|
||||
NodeKind::HashedValueLeaf => {
|
||||
size_and_prefix_iterator(size, trie_constants::ALT_HASHING_LEAF_PREFIX_MASK, 3)
|
||||
},
|
||||
NodeKind::HashedValueBranch => {
|
||||
size_and_prefix_iterator(size, trie_constants::ALT_HASHING_BRANCH_WITH_MASK, 4)
|
||||
},
|
||||
};
|
||||
iter_start
|
||||
.chain(if nibbles.len() % 2 == 1 { Some(nibbles[0]) } else { None })
|
||||
|
||||
@@ -88,8 +88,12 @@ impl ParseRuntimeVersion {
|
||||
fn parse_expr(init_expr: &Expr) -> Result<(ParseRuntimeVersion, Vec<Warning>)> {
|
||||
let init_expr = match init_expr {
|
||||
Expr::Struct(ref e) => e,
|
||||
_ =>
|
||||
return Err(Error::new(init_expr.span(), "expected a struct initializer expression")),
|
||||
_ => {
|
||||
return Err(Error::new(
|
||||
init_expr.span(),
|
||||
"expected a struct initializer expression",
|
||||
))
|
||||
},
|
||||
};
|
||||
|
||||
let mut parsed = ParseRuntimeVersion::default();
|
||||
@@ -103,8 +107,9 @@ impl ParseRuntimeVersion {
|
||||
fn parse_field_value(&mut self, field_value: &FieldValue) -> Result<Vec<Warning>> {
|
||||
let field_name = match field_value.member {
|
||||
syn::Member::Named(ref ident) => ident,
|
||||
syn::Member::Unnamed(_) =>
|
||||
return Err(Error::new(field_value.span(), "only named members must be used")),
|
||||
syn::Member::Unnamed(_) => {
|
||||
return Err(Error::new(field_value.span(), "only named members must be used"))
|
||||
},
|
||||
};
|
||||
|
||||
fn parse_once<T>(
|
||||
@@ -160,11 +165,12 @@ impl ParseRuntimeVersion {
|
||||
fn parse_num_literal(expr: &Expr) -> Result<u32> {
|
||||
let lit = match *expr {
|
||||
Expr::Lit(ExprLit { lit: Lit::Int(ref lit), .. }) => lit,
|
||||
_ =>
|
||||
_ => {
|
||||
return Err(Error::new(
|
||||
expr.span(),
|
||||
"only numeric literals (e.g. `10`) are supported here",
|
||||
)),
|
||||
))
|
||||
},
|
||||
};
|
||||
lit.base10_parse::<u32>()
|
||||
}
|
||||
@@ -172,11 +178,12 @@ impl ParseRuntimeVersion {
|
||||
fn parse_num_literal_u8(expr: &Expr) -> Result<u8> {
|
||||
let lit = match *expr {
|
||||
Expr::Lit(ExprLit { lit: Lit::Int(ref lit), .. }) => lit,
|
||||
_ =>
|
||||
_ => {
|
||||
return Err(Error::new(
|
||||
expr.span(),
|
||||
"only numeric literals (e.g. `10`) are supported here",
|
||||
)),
|
||||
))
|
||||
},
|
||||
};
|
||||
lit.base10_parse::<u8>()
|
||||
}
|
||||
|
||||
@@ -376,43 +376,48 @@ impl<'de> serde::Deserialize<'de> for RuntimeVersion {
|
||||
{
|
||||
let spec_name = match seq.next_element()? {
|
||||
Some(spec_name) => spec_name,
|
||||
None =>
|
||||
None => {
|
||||
return Err(serde::de::Error::invalid_length(
|
||||
0usize,
|
||||
&"struct RuntimeVersion with 8 elements",
|
||||
)),
|
||||
))
|
||||
},
|
||||
};
|
||||
let impl_name = match seq.next_element()? {
|
||||
Some(impl_name) => impl_name,
|
||||
None =>
|
||||
None => {
|
||||
return Err(serde::de::Error::invalid_length(
|
||||
1usize,
|
||||
&"struct RuntimeVersion with 8 elements",
|
||||
)),
|
||||
))
|
||||
},
|
||||
};
|
||||
let authoring_version = match seq.next_element()? {
|
||||
Some(authoring_version) => authoring_version,
|
||||
None =>
|
||||
None => {
|
||||
return Err(serde::de::Error::invalid_length(
|
||||
2usize,
|
||||
&"struct RuntimeVersion with 8 elements",
|
||||
)),
|
||||
))
|
||||
},
|
||||
};
|
||||
let spec_version = match seq.next_element()? {
|
||||
Some(spec_version) => spec_version,
|
||||
None =>
|
||||
None => {
|
||||
return Err(serde::de::Error::invalid_length(
|
||||
3usize,
|
||||
&"struct RuntimeVersion with 8 elements",
|
||||
)),
|
||||
))
|
||||
},
|
||||
};
|
||||
let impl_version = match seq.next_element()? {
|
||||
Some(impl_version) => impl_version,
|
||||
None =>
|
||||
None => {
|
||||
return Err(serde::de::Error::invalid_length(
|
||||
4usize,
|
||||
&"struct RuntimeVersion with 8 elements",
|
||||
)),
|
||||
))
|
||||
},
|
||||
};
|
||||
let apis = match {
|
||||
struct DeserializeWith<'de> {
|
||||
@@ -436,27 +441,30 @@ impl<'de> serde::Deserialize<'de> for RuntimeVersion {
|
||||
seq.next_element::<DeserializeWith<'de>>()?.map(|wrap| wrap.value)
|
||||
} {
|
||||
Some(apis) => apis,
|
||||
None =>
|
||||
None => {
|
||||
return Err(serde::de::Error::invalid_length(
|
||||
5usize,
|
||||
&"struct RuntimeVersion with 8 elements",
|
||||
)),
|
||||
))
|
||||
},
|
||||
};
|
||||
let transaction_version = match seq.next_element()? {
|
||||
Some(transaction_version) => transaction_version,
|
||||
None =>
|
||||
None => {
|
||||
return Err(serde::de::Error::invalid_length(
|
||||
6usize,
|
||||
&"struct RuntimeVersion with 8 elements",
|
||||
)),
|
||||
))
|
||||
},
|
||||
};
|
||||
let system_version = match seq.next_element()? {
|
||||
Some(system_version) => system_version,
|
||||
None =>
|
||||
None => {
|
||||
return Err(serde::de::Error::invalid_length(
|
||||
7usize,
|
||||
&"struct RuntimeVersion with 8 elements",
|
||||
)),
|
||||
))
|
||||
},
|
||||
};
|
||||
Ok(RuntimeVersion {
|
||||
spec_name,
|
||||
@@ -528,7 +536,9 @@ impl<'de> serde::Deserialize<'de> for RuntimeVersion {
|
||||
},
|
||||
Field::Apis => {
|
||||
if apis.is_some() {
|
||||
return Err(<A::Error as serde::de::Error>::duplicate_field("apis"));
|
||||
return Err(<A::Error as serde::de::Error>::duplicate_field(
|
||||
"apis",
|
||||
));
|
||||
}
|
||||
apis = Some({
|
||||
struct DeserializeWith<'de> {
|
||||
@@ -558,7 +568,7 @@ impl<'de> serde::Deserialize<'de> for RuntimeVersion {
|
||||
}
|
||||
transaction_version = Some(map.next_value()?);
|
||||
},
|
||||
Field::SystemVersion =>
|
||||
Field::SystemVersion => {
|
||||
if let Some(system_version) = system_version {
|
||||
let new_value = map.next_value::<u8>()?;
|
||||
if system_version != new_value {
|
||||
@@ -572,7 +582,8 @@ impl<'de> serde::Deserialize<'de> for RuntimeVersion {
|
||||
}
|
||||
} else {
|
||||
system_version = Some(map.next_value()?);
|
||||
},
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
map.next_value::<serde::de::IgnoredAny>()?;
|
||||
},
|
||||
@@ -700,9 +711,9 @@ pub fn core_version_from_apis(apis: &ApisVec) -> Option<u32> {
|
||||
impl RuntimeVersion {
|
||||
/// Check if this version matches other version for calling into runtime.
|
||||
pub fn can_call_with(&self, other: &RuntimeVersion) -> bool {
|
||||
self.spec_version == other.spec_version &&
|
||||
self.spec_name == other.spec_name &&
|
||||
self.authoring_version == other.authoring_version
|
||||
self.spec_version == other.spec_version
|
||||
&& self.spec_name == other.spec_name
|
||||
&& self.authoring_version == other.authoring_version
|
||||
}
|
||||
|
||||
/// Check if the given api with `api_id` is implemented and the version passes the given
|
||||
@@ -766,8 +777,8 @@ impl NativeVersion {
|
||||
"`spec_name` does not match `{}` vs `{}`",
|
||||
self.runtime_version.spec_name, other.spec_name,
|
||||
))
|
||||
} else if self.runtime_version.authoring_version != other.authoring_version &&
|
||||
!self.can_author_with.contains(&other.authoring_version)
|
||||
} else if self.runtime_version.authoring_version != other.authoring_version
|
||||
&& !self.can_author_with.contains(&other.authoring_version)
|
||||
{
|
||||
Err(format!(
|
||||
"`authoring_version` does not match `{version}` vs `{other_version}` and \
|
||||
|
||||
Reference in New Issue
Block a user