From b382462a1746661071adbe0fd0cd5db486e1eda0 Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Mon, 21 Aug 2023 19:06:30 +1000 Subject: [PATCH 1/9] fix try-on-runtime-upgrade return weight (#14793) --- frame/support/src/traits/hooks.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frame/support/src/traits/hooks.rs b/frame/support/src/traits/hooks.rs index e58f836070b75..6163c048e75d8 100644 --- a/frame/support/src/traits/hooks.rs +++ b/frame/support/src/traits/hooks.rs @@ -164,13 +164,13 @@ impl OnRuntimeUpgrade for Tuple { /// that occur. #[cfg(feature = "try-runtime")] fn try_on_runtime_upgrade(checks: bool) -> Result { - let mut weight = Weight::zero(); + let mut cumulative_weight = Weight::zero(); let mut errors = Vec::new(); for_tuples!(#( match Tuple::try_on_runtime_upgrade(checks) { - Ok(weight) => { weight.saturating_add(weight); }, + Ok(weight) => { cumulative_weight.saturating_accrue(weight); }, Err(err) => { errors.push(err); }, } )*); @@ -194,7 +194,7 @@ impl OnRuntimeUpgrade for Tuple { return Err("Detected multiple errors while executing `try_on_runtime_upgrade`, check the logs!".into()) } - Ok(weight) + Ok(cumulative_weight) } /// [`OnRuntimeUpgrade::pre_upgrade`] should not be used on a tuple. From 51695bb7009ea2e0996eb94ab4dfdc643a076702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= <123550+andresilva@users.noreply.github.com> Date: Mon, 21 Aug 2023 15:00:59 +0100 Subject: [PATCH 2/9] bump ed25519-dalek to 2.0 (#14776) * bump ed25519-dalek to 2.0 * sp-statement-store: don't use deprecated SecretKey::new * Remove snow patch --------- Co-authored-by: Sebastian Kunert --- Cargo.lock | 91 +++++++++++++++---------- primitives/io/Cargo.toml | 5 +- primitives/io/src/lib.rs | 4 +- primitives/statement-store/Cargo.toml | 6 +- primitives/statement-store/src/ecies.rs | 6 +- 5 files changed, 65 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6cca0a018ca72..0a9e201290a50 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1894,18 +1894,32 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "4.0.0-rc.1" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d4ba9852b42210c7538b75484f9daa0655e9a3ac04f693747bb0f02cf3cfe16" +checksum = "f711ade317dd348950a9910f81c5947e3d8907ebd2b83f76203ff1807e6a2bc2" dependencies = [ "cfg-if", + "cpufeatures", + "curve25519-dalek-derive", + "digest 0.10.7", "fiat-crypto", - "packed_simd_2", "platforms", + "rustc_version 0.4.0", "subtle", "zeroize", ] +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.18", +] + [[package]] name = "cxx" version = "1.0.95" @@ -2353,6 +2367,16 @@ dependencies = [ "signature 1.6.4", ] +[[package]] +name = "ed25519" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60f6d271ca33075c88028be6f04d502853d63a5ece419d269c15315d4fc1cf1d" +dependencies = [ + "pkcs8 0.10.2", + "signature 2.1.0", +] + [[package]] name = "ed25519-dalek" version = "1.0.1" @@ -2360,13 +2384,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" dependencies = [ "curve25519-dalek 3.2.0", - "ed25519", + "ed25519 1.5.3", "rand 0.7.3", "serde", "sha2 0.9.9", "zeroize", ] +[[package]] +name = "ed25519-dalek" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7277392b266383ef8396db7fdeb1e77b6c52fed775f5df15bb24f35b72156980" +dependencies = [ + "curve25519-dalek 4.0.0", + "ed25519 2.2.2", + "serde", + "sha2 0.10.7", + "zeroize", +] + [[package]] name = "ed25519-zebra" version = "3.1.0" @@ -4364,12 +4401,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "libm" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fc7aa29613bd6a620df431842069224d8bc9011086b1db4c0e0cd47fa03ec9a" - [[package]] name = "libm" version = "0.2.7" @@ -4505,7 +4536,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e2d584751cecb2aabaa56106be6be91338a60a0f4e420cf2af639204f596fc1" dependencies = [ "bs58", - "ed25519-dalek", + "ed25519-dalek 1.0.1", "log", "multiaddr", "multihash", @@ -5951,7 +5982,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ "autocfg", - "libm 0.2.7", + "libm", ] [[package]] @@ -6067,16 +6098,6 @@ dependencies = [ "sha2 0.10.7", ] -[[package]] -name = "packed_simd_2" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1914cd452d8fccd6f9db48147b29fd4ae05bea9dc5d9ad578509f72415de282" -dependencies = [ - "cfg-if", - "libm 0.1.4", -] - [[package]] name = "pallet-alliance" version = "4.0.0-dev" @@ -10921,14 +10942,14 @@ checksum = "5e9f0ab6ef7eb7353d9119c170a436d1bf248eea575ac42d19d12f4e34130831" [[package]] name = "snow" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ccba027ba85743e09d15c03296797cad56395089b832b48b5a5217880f57733" +checksum = "0c9d1425eb528a21de2755c75af4c9b5d57f50a0d4c3b7f1828a4cd03f8ba155" dependencies = [ "aes-gcm 0.9.4", "blake2", "chacha20poly1305", - "curve25519-dalek 4.0.0-rc.1", + "curve25519-dalek 4.0.0", "rand_core 0.6.4", "ring 0.16.20", "rustc_version 0.4.0", @@ -11467,8 +11488,7 @@ name = "sp-io" version = "23.0.0" dependencies = [ "bytes", - "ed25519", - "ed25519-dalek", + "ed25519-dalek 2.0.0", "libsecp256k1", "log", "parity-scale-codec", @@ -11754,8 +11774,8 @@ name = "sp-statement-store" version = "4.0.0-dev" dependencies = [ "aes-gcm 0.10.2", - "curve25519-dalek 3.2.0", - "ed25519-dalek", + "curve25519-dalek 4.0.0", + "ed25519-dalek 2.0.0", "hkdf", "parity-scale-codec", "rand 0.8.5", @@ -11769,7 +11789,7 @@ dependencies = [ "sp-runtime-interface", "sp-std", "thiserror", - "x25519-dalek 2.0.0-pre.1", + "x25519-dalek 2.0.0", ] [[package]] @@ -13529,7 +13549,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624e6333e861ef49095d2d678b76ebf30b06bf37effca845be7e5b87c90071b7" dependencies = [ "downcast-rs", - "libm 0.2.7", + "libm", "num-traits", "paste", ] @@ -13901,7 +13921,7 @@ dependencies = [ "tokio", "webpki 0.21.4", "webrtc-util", - "x25519-dalek 2.0.0-pre.1", + "x25519-dalek 2.0.0", "x509-parser 0.13.2", ] @@ -14299,12 +14319,13 @@ dependencies = [ [[package]] name = "x25519-dalek" -version = "2.0.0-pre.1" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5da623d8af10a62342bcbbb230e33e58a63255a58012f8653c578e54bab48df" +checksum = "fb66477291e7e8d2b0ff1bcb900bf29489a9692816d79874bea351e7a8b6de96" dependencies = [ - "curve25519-dalek 3.2.0", + "curve25519-dalek 4.0.0", "rand_core 0.6.4", + "serde", "zeroize", ] diff --git a/primitives/io/Cargo.toml b/primitives/io/Cargo.toml index 8590778714121..3a9a573456668 100644 --- a/primitives/io/Cargo.toml +++ b/primitives/io/Cargo.toml @@ -33,9 +33,7 @@ tracing = { version = "0.1.29", default-features = false } tracing-core = { version = "0.1.28", default-features = false} # Required for backwards compatibility reason, but only used for verifying when `UseDalekExt` is set. -ed25519-dalek = { version = "1.0.1", default-features = false, optional = true } -# Force the usage of ed25519, this is being used in `ed25519-dalek`. -ed25519 = { version = "1.5.2", optional = true } +ed25519-dalek = { version = "2.0.0", default-features = false, optional = true } [build-dependencies] rustversion = "1.0.6" @@ -58,7 +56,6 @@ std = [ "tracing-core/std", "log", "ed25519-dalek", - "ed25519", "sp-keystore/std" ] diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index 0bc434a2a59fc..ec098a155c9c5 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -825,11 +825,11 @@ pub trait Crypto { { use ed25519_dalek::Verifier; - let Ok(public_key) = ed25519_dalek::PublicKey::from_bytes(&pub_key.0) else { + let Ok(public_key) = ed25519_dalek::VerifyingKey::from_bytes(&pub_key.0) else { return false }; - let Ok(sig) = ed25519_dalek::Signature::from_bytes(&sig.0) else { return false }; + let sig = ed25519_dalek::Signature::from_bytes(&sig.0); public_key.verify(msg, &sig).is_ok() } else { diff --git a/primitives/statement-store/Cargo.toml b/primitives/statement-store/Cargo.toml index c3e620ab22c2d..d5612eaca8c19 100644 --- a/primitives/statement-store/Cargo.toml +++ b/primitives/statement-store/Cargo.toml @@ -25,9 +25,9 @@ sp-externalities = { version = "0.19.0", default-features = false, path = "../ex thiserror = { version = "1.0", optional = true } # ECIES dependencies -ed25519-dalek = { version = "1.0", optional = true } -x25519-dalek = { version = "2.0.0-pre.1", optional = true } -curve25519-dalek = { version = "3.2", optional = true } +ed25519-dalek = { version = "2.0.0", optional = true } +x25519-dalek = { version = "2.0.0", optional = true, features = ["static_secrets"] } +curve25519-dalek = { version = "4.0.0", optional = true } aes-gcm = { version = "0.10", optional = true } hkdf = { version = "0.12.0", optional = true } sha2 = { version = "0.10.7", optional = true } diff --git a/primitives/statement-store/src/ecies.rs b/primitives/statement-store/src/ecies.rs index 4afd583e03c80..80a040fd4c8e0 100644 --- a/primitives/statement-store/src/ecies.rs +++ b/primitives/statement-store/src/ecies.rs @@ -71,7 +71,7 @@ fn kdf(shared_secret: &[u8]) -> [u8; AES_KEY_LEN] { /// Encrypt `plaintext` with the given public x25519 public key. Decryption can be performed with /// the matching secret key. pub fn encrypt_x25519(pk: &PublicKey, plaintext: &[u8]) -> Result, Error> { - let ephemeral_sk = x25519_dalek::StaticSecret::new(OsRng); + let ephemeral_sk = x25519_dalek::StaticSecret::random_from_rng(OsRng); let ephemeral_pk = x25519_dalek::PublicKey::from(&ephemeral_sk); let mut shared_secret = ephemeral_sk.diffie_hellman(pk).to_bytes().to_vec(); @@ -135,7 +135,7 @@ mod test { #[test] fn basic_x25519_encryption() { - let sk = SecretKey::new(OsRng); + let sk = SecretKey::random_from_rng(OsRng); let pk = PublicKey::from(&sk); let plain_message = b"An important secret message"; @@ -159,7 +159,7 @@ mod test { #[test] fn fails_on_bad_data() { - let sk = SecretKey::new(OsRng); + let sk = SecretKey::random_from_rng(OsRng); let pk = PublicKey::from(&sk); let plain_message = b"An important secret message"; From e526f80a91f75a3811059d4ee19b0f190005c5a2 Mon Sep 17 00:00:00 2001 From: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com> Date: Mon, 21 Aug 2023 23:03:38 +0200 Subject: [PATCH 3/9] Make owned_item in MintWitness optional (#14800) Co-authored-by: parity-processbot <> --- frame/nfts/src/lib.rs | 3 ++- frame/nfts/src/tests.rs | 6 +++--- frame/nfts/src/types.rs | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/frame/nfts/src/lib.rs b/frame/nfts/src/lib.rs index 333fe97dd4a1e..92b27432ab215 100644 --- a/frame/nfts/src/lib.rs +++ b/frame/nfts/src/lib.rs @@ -662,7 +662,7 @@ pub mod pallet { /// /// The origin must be Signed and the sender must have sufficient funds free. /// - /// `ItemDeposit` funds of sender are reserved. + /// `CollectionDeposit` funds of sender are reserved. /// /// Parameters: /// - `admin`: The admin of this collection. The admin is the initial address of each @@ -844,6 +844,7 @@ pub mod pallet { MintType::HolderOf(collection_id) => { let MintWitness { owned_item, .. } = witness_data.clone().ok_or(Error::::WitnessRequired)?; + let owned_item = owned_item.ok_or(Error::::BadWitness)?; let owns_item = Account::::contains_key(( &caller, diff --git a/frame/nfts/src/tests.rs b/frame/nfts/src/tests.rs index c94e75d343930..f7879570a4cb7 100644 --- a/frame/nfts/src/tests.rs +++ b/frame/nfts/src/tests.rs @@ -427,7 +427,7 @@ fn mint_should_work() { 1, 42, account(2), - Some(MintWitness { owned_item: 42, ..Default::default() }) + Some(MintWitness { owned_item: Some(42), ..Default::default() }) ), Error::::BadWitness ); @@ -436,7 +436,7 @@ fn mint_should_work() { 1, 42, account(2), - Some(MintWitness { owned_item: 43, ..Default::default() }) + Some(MintWitness { owned_item: Some(43), ..Default::default() }) )); // can't mint twice @@ -446,7 +446,7 @@ fn mint_should_work() { 1, 46, account(2), - Some(MintWitness { owned_item: 43, ..Default::default() }) + Some(MintWitness { owned_item: Some(43), ..Default::default() }) ), Error::::AlreadyClaimed ); diff --git a/frame/nfts/src/types.rs b/frame/nfts/src/types.rs index f083b116fe938..5a9f6ae2f0e21 100644 --- a/frame/nfts/src/types.rs +++ b/frame/nfts/src/types.rs @@ -133,7 +133,7 @@ impl CollectionDetails { #[derive(Clone, Encode, Decode, Default, Eq, PartialEq, RuntimeDebug, TypeInfo)] pub struct MintWitness { /// Provide the id of the item in a required collection. - pub owned_item: ItemId, + pub owned_item: Option, /// The price specified in mint settings. pub mint_price: Option, } From 53d912efdc6fde3155565578eed2a6f73cbb91b4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 22 Aug 2023 09:43:30 +0000 Subject: [PATCH 4/9] Bump comfy-table from 7.0.0 to 7.0.1 (#14798) Bumps [comfy-table](https://github.com/nukesor/comfy-table) from 7.0.0 to 7.0.1. - [Release notes](https://github.com/nukesor/comfy-table/releases) - [Changelog](https://github.com/Nukesor/comfy-table/blob/main/CHANGELOG.md) - [Commits](https://github.com/nukesor/comfy-table/compare/v7.0.0...v7.0.1) --- updated-dependencies: - dependency-name: comfy-table dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: parity-processbot <> --- Cargo.lock | 4 ++-- utils/frame/benchmarking-cli/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0a9e201290a50..98ec87cc4e576 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1440,9 +1440,9 @@ checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] name = "comfy-table" -version = "7.0.0" +version = "7.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9e1f7e5d046697d34b593bdba8ee31f4649366e452a2ccabb3baf3511e503d1" +checksum = "9ab77dbd8adecaf3f0db40581631b995f312a8a5ae3aa9993188bb8f23d83a5b" dependencies = [ "strum", "strum_macros", diff --git a/utils/frame/benchmarking-cli/Cargo.toml b/utils/frame/benchmarking-cli/Cargo.toml index b7970613d1a11..0ebfbc3cdaf31 100644 --- a/utils/frame/benchmarking-cli/Cargo.toml +++ b/utils/frame/benchmarking-cli/Cargo.toml @@ -17,7 +17,7 @@ array-bytes = "6.1" chrono = "0.4" clap = { version = "4.2.5", features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.6.1" } -comfy-table = { version = "7.0.0", default-features = false } +comfy-table = { version = "7.0.1", default-features = false } handlebars = "4.2.2" Inflector = "0.11.4" itertools = "0.10.3" From 8e7c21b9a70c1fdc0d25c5e4d33e53e0db35381b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 22 Aug 2023 13:19:29 +0200 Subject: [PATCH 5/9] Bump cfg-expr from 0.15.2 to 0.15.4 (#14808) Bumps [cfg-expr](https://github.com/EmbarkStudios/cfg-expr) from 0.15.2 to 0.15.4. - [Release notes](https://github.com/EmbarkStudios/cfg-expr/releases) - [Changelog](https://github.com/EmbarkStudios/cfg-expr/blob/main/CHANGELOG.md) - [Commits](https://github.com/EmbarkStudios/cfg-expr/compare/0.15.2...0.15.4) --- updated-dependencies: - dependency-name: cfg-expr dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- frame/support/procedural/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 98ec87cc4e576..6ec53e9be0169 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1189,9 +1189,9 @@ dependencies = [ [[package]] name = "cfg-expr" -version = "0.15.2" +version = "0.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e70d3ad08698a0568b0562f22710fe6bfc1f4a61a367c77d0398c562eadd453a" +checksum = "b40ccee03b5175c18cde8f37e7d2a33bcef6f8ec8f7cc0d81090d1bb380949c9" dependencies = [ "smallvec", ] diff --git a/frame/support/procedural/Cargo.toml b/frame/support/procedural/Cargo.toml index 1d201d5a87fc5..f596713e5f115 100644 --- a/frame/support/procedural/Cargo.toml +++ b/frame/support/procedural/Cargo.toml @@ -17,7 +17,7 @@ proc-macro = true [dependencies] derive-syn-parse = "0.1.5" Inflector = "0.11.4" -cfg-expr = "0.15.1" +cfg-expr = "0.15.4" itertools = "0.10.3" proc-macro2 = "1.0.56" quote = "1.0.28" From e48e8368969d708abe7f200d345d8149ea3950ca Mon Sep 17 00:00:00 2001 From: Muharem Ismailov Date: Wed, 23 Aug 2023 00:37:06 +0200 Subject: [PATCH 6/9] asset-conversion pallet: pool's `AccountId` derivation warn docs (#14811) * pool_id docs * fmt --- frame/asset-conversion/src/lib.rs | 7 ++++++- frame/asset-conversion/src/tests.rs | 6 +++++- frame/asset-conversion/src/types.rs | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/frame/asset-conversion/src/lib.rs b/frame/asset-conversion/src/lib.rs index 3a16ab875c06a..d1d68f3e10fbb 100644 --- a/frame/asset-conversion/src/lib.rs +++ b/frame/asset-conversion/src/lib.rs @@ -147,6 +147,9 @@ pub mod pallet { /// Type that identifies either the native currency or a token class from `Assets`. /// `Ord` is added because of `get_pool_id`. + /// + /// The pool's `AccountId` is derived from this type. Any changes to the type may + /// necessitate a migration. type MultiAssetId: AssetId + Ord + From; /// Type to convert an `AssetId` into `MultiAssetId`. @@ -1193,7 +1196,9 @@ pub mod pallet { () ); } else { - let MultiAssetIdConversionResult::Converted(asset_id) = T::MultiAssetIdConverter::try_convert(asset) else { + let MultiAssetIdConversionResult::Converted(asset_id) = + T::MultiAssetIdConverter::try_convert(asset) + else { return Err(()) }; let minimal = T::Assets::minimum_balance(asset_id); diff --git a/frame/asset-conversion/src/tests.rs b/frame/asset-conversion/src/tests.rs index 80faf5363b011..450a074ec3675 100644 --- a/frame/asset-conversion/src/tests.rs +++ b/frame/asset-conversion/src/tests.rs @@ -66,7 +66,11 @@ fn pool_assets() -> Vec { fn create_tokens(owner: u128, tokens: Vec>) { for token_id in tokens { - let MultiAssetIdConversionResult::Converted(asset_id) = NativeOrAssetIdConverter::try_convert(&token_id) else { unreachable!("invalid token") }; + let MultiAssetIdConversionResult::Converted(asset_id) = + NativeOrAssetIdConverter::try_convert(&token_id) + else { + unreachable!("invalid token") + }; assert_ok!(Assets::force_create(RuntimeOrigin::root(), asset_id, owner, false, 1)); } } diff --git a/frame/asset-conversion/src/types.rs b/frame/asset-conversion/src/types.rs index 7cd9743ff04b8..9c28bd7666b71 100644 --- a/frame/asset-conversion/src/types.rs +++ b/frame/asset-conversion/src/types.rs @@ -21,6 +21,10 @@ use codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use sp_std::{cmp::Ordering, marker::PhantomData}; +/// Pool ID. +/// +/// The pool's `AccountId` is derived from this type. Any changes to the type may necessitate a +/// migration. pub(super) type PoolIdOf = (::MultiAssetId, ::MultiAssetId); /// Stores the lp_token asset id a particular pool has been assigned. From 30998d186cf3f71ea7f6f5eba7a2f02ea16fd3bc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 23 Aug 2023 10:08:08 +0000 Subject: [PATCH 7/9] Bump rustls-webpki from 0.100.1 to 0.100.2 (#14812) Bumps [rustls-webpki](https://github.com/rustls/webpki) from 0.100.1 to 0.100.2. - [Release notes](https://github.com/rustls/webpki/releases) - [Commits](https://github.com/rustls/webpki/compare/v/0.100.1...v/0.100.2) --- updated-dependencies: - dependency-name: rustls-webpki dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6ec53e9be0169..98e8242b337c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9066,9 +9066,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.100.1" +version = "0.100.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6207cd5ed3d8dca7816f8f3725513a34609c0c765bf652b8c3cb4cfd87db46b" +checksum = "e98ff011474fa39949b7e5c0428f9b4937eda7da7848bbb947786b7be0b27dab" dependencies = [ "ring 0.16.20", "untrusted", From a732a9a7153b2be8424199b20e567e6358c25e17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Wed, 23 Aug 2023 13:05:35 +0200 Subject: [PATCH 8/9] contracts: Expose environment types for offchain tooling (#14750) * Expose environment types for offchain tooling * Use EnvironmentType wrapper * Add type impl to test config --------- Co-authored-by: parity-processbot <> --- bin/node/runtime/src/lib.rs | 1 + frame/contracts/src/lib.rs | 47 +++++++++++++++++++++++++++++++++--- frame/contracts/src/tests.rs | 1 + 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 4e1b6d4e8bec0..87ec467dca934 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -1265,6 +1265,7 @@ impl pallet_contracts::Config for Runtime { type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent; #[cfg(feature = "unsafe-debug")] type Debug = (); + type Environment = (); } impl pallet_sudo::Config for Runtime { diff --git a/frame/contracts/src/lib.rs b/frame/contracts/src/lib.rs index a511ac81a73b7..c6a43779ada23 100644 --- a/frame/contracts/src/lib.rs +++ b/frame/contracts/src/lib.rs @@ -103,7 +103,7 @@ pub mod weights; #[cfg(test)] mod tests; use crate::{ - exec::{AccountIdOf, ErrorOrigin, ExecError, Executable, Key, Stack as ExecStack}, + exec::{AccountIdOf, ErrorOrigin, ExecError, Executable, Key, MomentOf, Stack as ExecStack}, gas::GasMeter, storage::{meter::Meter as StorageMeter, ContractInfo, DeletionQueueManager}, wasm::{CodeInfo, WasmBlob}, @@ -122,9 +122,13 @@ use frame_support::{ ConstU32, Contains, Get, Randomness, Time, }, weights::Weight, - BoundedVec, RuntimeDebug, RuntimeDebugNoBound, + BoundedVec, DefaultNoBound, RuntimeDebug, RuntimeDebugNoBound, +}; +use frame_system::{ + ensure_signed, + pallet_prelude::{BlockNumberFor, OriginFor}, + EventRecord, Pallet as System, }; -use frame_system::{ensure_signed, pallet_prelude::OriginFor, EventRecord, Pallet as System}; use pallet_contracts_primitives::{ Code, CodeUploadResult, CodeUploadReturnValue, ContractAccessError, ContractExecResult, ContractInstantiateResult, ContractResult, ExecReturnValue, GetStorageResult, @@ -179,6 +183,36 @@ const SENTINEL: u32 = u32::MAX; /// Example: `RUST_LOG=runtime::contracts=debug my_code --dev` const LOG_TARGET: &str = "runtime::contracts"; +/// Wrapper around `PhantomData` to prevent it being filtered by `scale-info`. +/// +/// `scale-info` filters out `PhantomData` fields because usually we are only interested +/// in sized types. However, when trying to communicate **types** as opposed to **values** +/// we want to have those zero sized types be included. +#[derive(Encode, Decode, DefaultNoBound, TypeInfo)] +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +pub struct EnvironmentType(PhantomData); + +/// List of all runtime configurable types that are used in the communication between +/// `pallet-contracts` and any given contract. +/// +/// Since those types are configurable they can vary between +/// chains all using `pallet-contracts`. Hence we need a mechanism to communicate those types +/// in a way that can be consumed by offchain tooling. +/// +/// This type only exists in order to appear in the metadata where it can be read by +/// offchain tooling. +#[derive(Encode, Decode, DefaultNoBound, TypeInfo)] +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +#[scale_info(skip_type_params(T))] +pub struct Environment { + account_id: EnvironmentType>, + balance: EnvironmentType>, + hash: EnvironmentType<::Hash>, + hasher: EnvironmentType<::Hashing>, + timestamp: EnvironmentType>, + block_number: EnvironmentType>, +} + #[frame_support::pallet] pub mod pallet { use super::*; @@ -360,6 +394,13 @@ pub mod pallet { /// Do **not** use it in a production environment or for benchmarking purposes. #[cfg(feature = "unsafe-debug")] type Debug: unsafe_debug::UnsafeDebug; + + /// Type that bundles together all the runtime configurable interface types. + /// + /// This is not a real config. We just mention the type here as constant so that + /// its type appears in the metadata. Only valid value is `()`. + #[pallet::constant] + type Environment: Get>; } #[pallet::hooks] diff --git a/frame/contracts/src/tests.rs b/frame/contracts/src/tests.rs index 5c8fca43ab746..b421bbf3e3093 100644 --- a/frame/contracts/src/tests.rs +++ b/frame/contracts/src/tests.rs @@ -481,6 +481,7 @@ impl Config for Test { type MaxDelegateDependencies = MaxDelegateDependencies; #[cfg(feature = "unsafe-debug")] type Debug = unsafe_debug::TestDebugger; + type Environment = (); } pub const ALICE: AccountId32 = AccountId32::new([1u8; 32]); From 1631c8e155296fc8a97848a61afe28676113cab2 Mon Sep 17 00:00:00 2001 From: Cem Eliguzel Date: Wed, 23 Aug 2023 15:06:50 +0300 Subject: [PATCH 9/9] return proof size on manually created blocks (for tests only) (#14650) * return proof size on manually created blocks (for tests only) * Fix the build error in the test --------- Co-authored-by: librelois --- client/consensus/manual-seal/src/lib.rs | 18 +++++++++++------- client/consensus/manual-seal/src/rpc.rs | 2 ++ client/consensus/manual-seal/src/seal_block.rs | 10 +++++++--- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/client/consensus/manual-seal/src/lib.rs b/client/consensus/manual-seal/src/lib.rs index c3b891b84e893..1e5db966e66db 100644 --- a/client/consensus/manual-seal/src/lib.rs +++ b/client/consensus/manual-seal/src/lib.rs @@ -173,7 +173,7 @@ pub async fn run_manual_seal( SC: SelectChain + 'static, TP: TransactionPool, CIDP: CreateInherentDataProviders, - P: Send + Sync + 'static, + P: codec::Encode + Send + Sync + 'static, { while let Some(command) = commands_stream.next().await { match command { @@ -231,7 +231,7 @@ pub async fn run_instant_seal( SC: SelectChain + 'static, TP: TransactionPool, CIDP: CreateInherentDataProviders, - P: Send + Sync + 'static, + P: codec::Encode + Send + Sync + 'static, { // instant-seal creates blocks as soon as transactions are imported // into the transaction pool. @@ -281,7 +281,7 @@ pub async fn run_instant_seal_and_finalize( SC: SelectChain + 'static, TP: TransactionPool, CIDP: CreateInherentDataProviders, - P: Send + Sync + 'static, + P: codec::Encode + Send + Sync + 'static, { // Creates and finalizes blocks as soon as transactions are imported // into the transaction pool. @@ -459,7 +459,8 @@ mod tests { needs_justification: false, bad_justification: false, is_new_best: true, - } + }, + proof_size: 0 } ); // assert that there's a new block in the db. @@ -549,7 +550,8 @@ mod tests { needs_justification: false, bad_justification: false, is_new_best: true, - } + }, + proof_size: created_block.proof_size } ); // assert that there's a new block in the db. @@ -625,7 +627,8 @@ mod tests { needs_justification: false, bad_justification: false, is_new_best: true, - } + }, + proof_size: 0 } ); // assert that there's a new block in the db. @@ -711,7 +714,8 @@ mod tests { needs_justification: false, bad_justification: false, is_new_best: true - } + }, + proof_size: 0 } ); diff --git a/client/consensus/manual-seal/src/rpc.rs b/client/consensus/manual-seal/src/rpc.rs index 85abcdc08574b..c0b3af69bedf4 100644 --- a/client/consensus/manual-seal/src/rpc.rs +++ b/client/consensus/manual-seal/src/rpc.rs @@ -97,6 +97,8 @@ pub struct CreatedBlock { pub hash: Hash, /// some extra details about the import operation pub aux: ImportedAux, + /// uncompacted storage proof size (zero mean that there is no proof) + pub proof_size: usize, } impl ManualSeal { diff --git a/client/consensus/manual-seal/src/seal_block.rs b/client/consensus/manual-seal/src/seal_block.rs index 4b6230c3efc3d..716e889ec0395 100644 --- a/client/consensus/manual-seal/src/seal_block.rs +++ b/client/consensus/manual-seal/src/seal_block.rs @@ -83,7 +83,7 @@ pub async fn seal_block( TP: TransactionPool, SC: SelectChain, CIDP: CreateInherentDataProviders, - P: Send + Sync + 'static, + P: codec::Encode + Send + Sync + 'static, { let future = async { if pool.status().ready == 0 && !create_empty { @@ -131,6 +131,7 @@ pub async fn seal_block( let (header, body) = proposal.block.deconstruct(); let proof = proposal.proof; + let proof_size = proof.encoded_size(); let mut params = BlockImportParams::new(BlockOrigin::Own, header.clone()); params.body = Some(body); params.finalized = finalize; @@ -149,8 +150,11 @@ pub async fn seal_block( post_header.digest_mut().logs.extend(params.post_digests.iter().cloned()); match block_import.import_block(params).await? { - ImportResult::Imported(aux) => - Ok(CreatedBlock { hash: ::Header::hash(&post_header), aux }), + ImportResult::Imported(aux) => Ok(CreatedBlock { + hash: ::Header::hash(&post_header), + aux, + proof_size, + }), other => Err(other.into()), } };