Skip to content

Commit

Permalink
Upgrade to v0.9.37 (#23)
Browse files Browse the repository at this point in the history
* Upgrade to v0.9.37
* Add `try-runtime` & bump versions
  • Loading branch information
MiguelDD1 committed Feb 20, 2023
1 parent 4c32cbe commit 7ba247c
Show file tree
Hide file tree
Showing 12 changed files with 762 additions and 361 deletions.
899 changes: 633 additions & 266 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ members = [
"primitives/nomad/merkle",
]
[patch.crates-io]
# Substrate (polkadot-v0.9.33).
sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.33" }
sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.33" }
sp-std = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.33" }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.33" }
sp-trie = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.33" }
sp-runtime-interface = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.33" }
sp-weights = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.33" }
frame-support = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.33" }
# Substrate (polkadot-v0.9.37).
sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-std = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-trie = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-runtime-interface = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-weights = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
frame-support = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
4 changes: 2 additions & 2 deletions kate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kate"
version = "0.6.0"
version = "0.6.1"
authors = ["Denis Ermolin <denis.ermolin@matic.network>"]
edition = "2021"

Expand All @@ -24,7 +24,7 @@ rand_chacha = { version = "0.3", default-features = false, optional = true }
rand_core = { version = "0.6", default-features = false }
rayon = { version = "1.5.2", optional = true }
serde = { version = "1.0.121", optional = true, features = ["derive"] }
sp-core = { version = "6.0.0", default-features = false }
sp-core = { version = "7.0.0", default-features = false }
sp-std = { version = "4.0.0", default-features = false }
static_assertions = "1.1.0"

Expand Down
17 changes: 10 additions & 7 deletions primitives/avail/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "da-primitives"
version = "0.4.2"
version = "0.4.3"
authors = []
edition = "2018"

Expand All @@ -13,18 +13,18 @@ serde_json = { version = "1.0", optional = true }
thiserror-no-std = "2.0.2"

# Substrate
beefy-merkle-tree = { git = "https://github.com/paritytech/substrate.git/", branch = "polkadot-v0.9.33", default-features = false }
beefy-merkle-tree = { git = "https://github.com/paritytech/substrate.git/", branch = "polkadot-v0.9.37", default-features = false }
codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
frame-support = { version = "4.0.0-dev", default-features = false }
hash256-std-hasher = { version = "0.15.2", default-features = false }
parity-util-mem = { version = "0.12.0", default-features = false, features = ["primitive-types"] }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
sp-core = { version = "6.0.0", default-features = false }
sp-io = { version = "6.0.0", default-features = false }
sp-runtime = { version = "6.0.0", default-features = false }
sp-runtime-interface = { version = "6.0.0", default-features = false }
sp-core = { version = "7.0.0", default-features = false }
sp-io = { version = "7.0.0", default-features = false }
sp-runtime = { version = "7.0.0", default-features = false }
sp-runtime-interface = { version = "7.0.0", default-features = false }
sp-std = { version = "4.0.0", default-features = false }
sp-trie = { version = "6.0.0", default-features = false }
sp-trie = { version = "7.0.0", default-features = false }

[dev-dependencies]
hex-literal = "0.3.4"
Expand All @@ -51,3 +51,6 @@ std = [
]

header-backward-compatibility-test = []
try-runtime = [
"sp-runtime/try-runtime",
]
98 changes: 65 additions & 33 deletions primitives/avail/src/asdr/app_unchecked_extrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ use frame_support::{
dispatch::{DispatchInfo, GetDispatchInfo},
traits::ExtrinsicCall,
};
#[cfg(feature = "std")]
use parity_util_mem::{MallocSizeOf, MallocSizeOfOps};
use scale_info::{build::Fields, meta_type, Path, StaticTypeInfo, Type, TypeInfo, TypeParameter};
use sp_io::hashing::blake2_256;
use sp_runtime::{
Expand All @@ -43,8 +41,12 @@ use sp_std::{

use crate::asdr::{AppId, GetAppId};

/// Current version of the [`AppUncheckedExtrinsic`] format.
const EXTRINSIC_VERSION: u8 = 4;
/// Current version of the [`UncheckedExtrinsic`] encoded format.
///
/// This version needs to be bumped if the encoded representation changes.
/// It ensures that if the representation is changed and the format is not known,
/// the decoding fails.
const EXTRINSIC_FORMAT_VERSION: u8 = 4;

/// A extrinsic right from the external world. This is unchecked and so
/// can contain a signature.
Expand Down Expand Up @@ -95,17 +97,6 @@ where
}
}

#[cfg(feature = "std")]
impl<Address, Call, Signature, Extra> MallocSizeOf
for AppUncheckedExtrinsic<Address, Call, Signature, Extra>
where
Extra: SignedExtension,
{
fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {
0
}
}

impl<Address, Call, Signature, Extra: SignedExtension>
AppUncheckedExtrinsic<Address, Call, Signature, Extra>
{
Expand All @@ -130,6 +121,7 @@ impl<Address, Call, Signature, Extra: SignedExtension> Extrinsic
for AppUncheckedExtrinsic<Address, Call, Signature, Extra>
{
type Call = Call;

type SignaturePayload = (Address, Signature, Extra);

fn is_signed(&self) -> Option<bool> {
Expand Down Expand Up @@ -188,16 +180,37 @@ where
},
})
}

#[cfg(feature = "try-runtime")]
fn unchecked_into_checked_i_know_what_i_am_doing(
self,
lookup: &Lookup,
) -> Result<Self::Checked, TransactionValidityError> {
Ok(match self.signature {
Some((signed, _, extra)) => {
let signed = lookup.lookup(signed)?;
let raw_payload = SignedPayload::new(self.function, extra)?;
let (function, extra, _) = raw_payload.deconstruct();
CheckedExtrinsic {
signed: Some((signed, extra)),
function,
}
},
None => CheckedExtrinsic {
signed: None,
function: self.function,
},
})
}
}

impl<Address, Call, Signature, Extra> ExtrinsicMetadata
for AppUncheckedExtrinsic<Address, Call, Signature, Extra>
where
Extra: SignedExtension,
{
const VERSION: u8 = EXTRINSIC_FORMAT_VERSION;
type SignedExtensions = Extra;

const VERSION: u8 = EXTRINSIC_VERSION;
}

impl<Address, Call, Signature, Extra> GetDispatchInfo
Expand Down Expand Up @@ -294,26 +307,33 @@ where
{
fn decode<I: Input>(input: &mut I) -> Result<Self, Error> {
// This is a little more complicated than usual since the binary format must be compatible
// with substrate's generic `Vec<u8>` type. Basically this just means accepting that there
// will be a prefix of vector length (we don't need
// to use this).
let _length_do_not_remove_me_see_above: Compact<u32> = Decode::decode(input)?;
// with SCALE's generic `Vec<u8>` type. Basically this just means accepting that there
// will be a prefix of vector length.
let expected_length: Compact<u32> = Decode::decode(input)?;
let before_length = input.remaining_len()?;

let version = input.read_byte()?;

let is_signed = version & 0b1000_0000 != 0;
let version = version & 0b0111_1111;
if version != EXTRINSIC_VERSION {
if version != EXTRINSIC_FORMAT_VERSION {
return Err("Invalid transaction version".into());
}

let signature = if is_signed {
Some(Decode::decode(input)?)
} else {
None
};
let signature = is_signed.then(|| Decode::decode(input)).transpose()?;
let function = Decode::decode(input)?;

if let Some((before_length, after_length)) = input
.remaining_len()?
.and_then(|a| before_length.map(|b| (b, a)))
{
let length = before_length.saturating_sub(after_length);

if length != expected_length.0 as usize {
return Err("Invalid length prefix".into());
}
}

Ok(Self {
signature,
function,
Expand All @@ -335,11 +355,11 @@ where
// 1 byte version id.
match self.signature.as_ref() {
Some(s) => {
tmp.push(EXTRINSIC_VERSION | 0b1000_0000);
tmp.push(EXTRINSIC_FORMAT_VERSION | 0b1000_0000);
s.encode_to(&mut tmp);
},
None => {
tmp.push(EXTRINSIC_VERSION & 0b0111_1111);
tmp.push(EXTRINSIC_FORMAT_VERSION & 0b0111_1111);
},
}
self.function.encode_to(&mut tmp);
Expand Down Expand Up @@ -374,7 +394,7 @@ impl<Address: Encode, Signature: Encode, Call: Encode, Extra: SignedExtension> s
where
S: ::serde::Serializer,
{
self.using_encoded(|bytes| sp_core::bytes::serialize(bytes, seq))
self.using_encoded(|bytes| seq.serialize_bytes(bytes))
}
}

Expand Down Expand Up @@ -466,9 +486,7 @@ mod tests {
const TEST_ACCOUNT: TestAccountId = 0;

// NOTE: this is demonstration. One can simply use `()` for testing.
#[derive(
Debug, Encode, Decode, Clone, Eq, PartialEq, Ord, PartialOrd, TypeInfo, MallocSizeOf,
)]
#[derive(Debug, Encode, Decode, Clone, Eq, PartialEq, Ord, PartialOrd, TypeInfo)]
struct TestExtra;
impl SignedExtension for TestExtra {
type AccountId = u64;
Expand Down Expand Up @@ -509,6 +527,20 @@ mod tests {
assert_eq!(Ex::decode(&mut &encoded[..]), Ok(ux));
}

#[test]
fn invalid_length_prefix_is_detected() {
let ux = Ex::new_unsigned(vec![0u8; 0]);
let mut encoded = ux.encode();

let length = Compact::<u32>::decode(&mut &encoded[..]).unwrap();
Compact(length.0 + 10).encode_to(&mut &mut encoded[..1]);

assert_eq!(
Ex::decode(&mut &encoded[..]),
Err("Invalid length prefix".into())
);
}

#[test]
fn signed_codec_should_work() {
let ux = Ex::new_signed(
Expand Down
46 changes: 23 additions & 23 deletions primitives/avail/src/header/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
// This file is part of Substrate.

// Copyright (C) 2017-2022 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Data-Avail implementation of a block header.

use codec::{Codec, Decode, Encode};
#[cfg(feature = "std")]
use parity_util_mem::{MallocSizeOf, MallocSizeOfOps};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_core::{RuntimeDebug, U256};
use sp_runtime::{
traits::{
AtLeast32BitUnsigned, Hash as HashT, Header as HeaderT, MaybeDisplay, MaybeMallocSizeOf,
MaybeSerialize, MaybeSerializeDeserialize, Member, SimpleBitOps,
AtLeast32BitUnsigned, Hash as HashT, Header as HeaderT, MaybeDisplay, MaybeSerialize,
MaybeSerializeDeserialize, Member, SimpleBitOps,
},
Digest,
};
Expand Down Expand Up @@ -119,21 +136,6 @@ impl<N: HeaderBlockNumber, H: HeaderHash> PassBy for Header<N, H> {
type PassBy = PassByCodecImpl<Header<N, H>>;
}

#[cfg(feature = "std")]
impl<N: HeaderBlockNumber, H: HeaderHash> MallocSizeOf for Header<N, H>
where
H::Output: MallocSizeOf,
{
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
self.parent_hash.size_of(ops)
+ self.number.size_of(ops)
+ self.state_root.size_of(ops)
+ self.extrinsics_root.size_of(ops)
+ self.digest.size_of(ops)
+ self.extension.size_of(ops)
}
}

impl<Number, Hash> HeaderT for Header<Number, Hash>
where
Number: Member
Expand All @@ -146,8 +148,7 @@ where
+ Copy
+ Into<U256>
+ TryFrom<U256>
+ sp_std::str::FromStr
+ MaybeMallocSizeOf,
+ sp_std::str::FromStr,
Hash: HashT,
Hash::Output: Default
+ sp_std::hash::Hash
Expand All @@ -158,8 +159,7 @@ where
+ Debug
+ MaybeDisplay
+ SimpleBitOps
+ Codec
+ MaybeMallocSizeOf,
+ Codec,
{
type Hash = <Hash as HashT>::Output;
type Hashing = Hash;
Expand Down
10 changes: 4 additions & 6 deletions primitives/avail/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use codec::{Codec, Decode};
use sp_core::U256;
use sp_runtime::{
traits::{
AtLeast32BitUnsigned, Hash as HashT, MaybeDisplay, MaybeFromStr, MaybeMallocSizeOf,
MaybeSerializeDeserialize, Member, SimpleBitOps,
AtLeast32BitUnsigned, Hash as HashT, MaybeDisplay, MaybeFromStr, MaybeSerializeDeserialize,
Member, SimpleBitOps,
},
Digest,
};
Expand All @@ -20,7 +20,6 @@ pub trait HeaderBlockNumber:
+ MaybeDisplay
+ MaybeFromStr
+ MaybeFromStr
+ MaybeMallocSizeOf
+ StdHash
+ Copy
+ Into<U256>
Expand All @@ -36,7 +35,6 @@ impl<
+ MaybeSerializeDeserialize
+ MaybeDisplay
+ MaybeFromStr
+ MaybeMallocSizeOf
+ StdHash
+ Copy
+ Into<U256>
Expand All @@ -51,8 +49,8 @@ impl<
pub trait HeaderHash: HashT {}
impl<T: HashT> HeaderHash for T {}

pub trait HeaderHashOutput: MaybeDisplay + Decode + MaybeMallocSizeOf + SimpleBitOps + Ord {}
impl<T: MaybeDisplay + Decode + MaybeMallocSizeOf + SimpleBitOps + Ord> HeaderHashOutput for T {}
pub trait HeaderHashOutput: MaybeDisplay + Decode + SimpleBitOps + Ord {}
impl<T: MaybeDisplay + Decode + SimpleBitOps + Ord> HeaderHashOutput for T {}

/// Extended header access
pub trait ExtendedHeader {
Expand Down
Loading

0 comments on commit 7ba247c

Please sign in to comment.