From 932745f21e309c4e67ea5a5c5a901971ebc3ff0c Mon Sep 17 00:00:00 2001 From: claravanstaden Date: Fri, 15 Dec 2023 08:13:13 +0200 Subject: [PATCH] upstream changes --- .../pallets/ethereum-beacon-client/Cargo.toml | 78 ++++++++++--------- .../ethereum-beacon-client/fuzz/Cargo.toml | 6 +- .../ethereum-beacon-client/src/config/mod.rs | 2 +- .../pallets/ethereum-beacon-client/src/lib.rs | 12 +-- .../ethereum-beacon-client/src/mock.rs | 2 + parachain/pallets/inbound-queue/Cargo.toml | 72 ++++++++++------- .../src/benchmarking/fixtures.rs | 6 +- .../inbound-queue/src/benchmarking/mod.rs | 19 ++--- parachain/pallets/inbound-queue/src/mock.rs | 7 +- parachain/pallets/outbound-queue/Cargo.toml | 60 ++++++++------ .../outbound-queue/merkle-tree/Cargo.toml | 18 ++--- .../outbound-queue/merkle-tree/src/lib.rs | 12 +-- .../outbound-queue/runtime-api/Cargo.toml | 14 ++-- .../outbound-queue/runtime-api/src/lib.rs | 2 +- parachain/pallets/outbound-queue/src/mock.rs | 10 ++- parachain/pallets/outbound-queue/src/test.rs | 22 +++--- parachain/pallets/system/Cargo.toml | 26 +++++-- .../pallets/system/runtime-api/Cargo.toml | 4 +- parachain/pallets/system/src/benchmarking.rs | 2 +- parachain/pallets/system/src/mock.rs | 5 +- parachain/pallets/system/src/tests.rs | 4 +- parachain/primitives/beacon/Cargo.toml | 47 +++++------ .../primitives/beacon/src/merkle_proof.rs | 10 +-- parachain/primitives/beacon/src/types.rs | 15 ++-- parachain/primitives/core/Cargo.toml | 39 ++++++---- parachain/primitives/core/src/outbound.rs | 2 +- parachain/primitives/core/src/pricing.rs | 2 +- parachain/primitives/ethereum/Cargo.toml | 24 +++--- parachain/primitives/ethereum/src/header.rs | 39 ++++++---- parachain/primitives/ethereum/src/mpt.rs | 2 +- parachain/primitives/router/Cargo.toml | 47 ++++++----- .../primitives/router/src/inbound/mod.rs | 4 +- .../primitives/router/src/inbound/tests.rs | 2 +- .../primitives/router/src/outbound/tests.rs | 2 +- parachain/runtime/rococo-common/Cargo.toml | 13 ++-- parachain/runtime/runtime-common/Cargo.toml | 27 ++++--- parachain/runtime/tests/Cargo.toml | 56 +++++++------ 37 files changed, 400 insertions(+), 314 deletions(-) diff --git a/parachain/pallets/ethereum-beacon-client/Cargo.toml b/parachain/pallets/ethereum-beacon-client/Cargo.toml index 7effb65f82..596b0ac3fa 100644 --- a/parachain/pallets/ethereum-beacon-client/Cargo.toml +++ b/parachain/pallets/ethereum-beacon-client/Cargo.toml @@ -13,10 +13,10 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] serde = { version = "1.0.188", optional = true } serde_json = { version = "1.0.96", optional = true } -codec = { version = "3.6.1", package = "parity-scale-codec", default-features = false, features = [ "derive" ] } -scale-info = { version = "2.9.0", default-features = false, features = [ "derive" ] } -ssz_rs = { version="0.9.0", default-features = false } -ssz_rs_derive = { version="0.9.0", default-features = false } +codec = { version = "3.6.1", package = "parity-scale-codec", default-features = false, features = ["derive"] } +scale-info = { version = "2.9.0", default-features = false, features = ["derive"] } +ssz_rs = { version = "0.9.0", default-features = false } +ssz_rs_derive = { version = "0.9.0", default-features = false } byte-slice-cast = { version = "1.2.1", default-features = false } rlp = { version = "0.5.2", default-features = false } hex-literal = { version = "0.4.1", optional = true } @@ -49,40 +49,48 @@ serde = "1.0.188" [features] default = ["std"] fuzzing = [ - "sp-io", - "pallet-timestamp", - "serde", - "serde_json", - "hex-literal" + "hex-literal", + "pallet-timestamp", + "serde", + "serde_json", + "sp-io", ] std = [ - "serde", - "codec/std", - "scale-info/std", - "frame-support/std", - "frame-system/std", - 'frame-benchmarking/std', - "sp-core/std", - "sp-runtime/std", - "sp-std/std", - "sp-io/std", - "snowbridge-core/std", - "snowbridge-ethereum/std", - "primitives/std", - "ssz_rs/std", - "byte-slice-cast/std", - "bp-runtime/std", - "byte-slice-cast/std", - "rlp/std", - "log/std", - "pallet-timestamp/std", + "bp-runtime/std", + "byte-slice-cast/std", + "byte-slice-cast/std", + "codec/std", + "frame-support/std", + "frame-system/std", + "log/std", + "pallet-timestamp/std", + "primitives/std", + "rlp/std", + "scale-info/std", + "serde", + "snowbridge-core/std", + "snowbridge-ethereum/std", + "sp-core/std", + "sp-io/std", + "sp-runtime/std", + "sp-std/std", + "ssz_rs/std", + 'frame-benchmarking/std', ] runtime-benchmarks = [ - "beacon-spec-mainnet", - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "hex-literal", - "snowbridge-core/runtime-benchmarks", + "beacon-spec-mainnet", + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "hex-literal", + "pallet-timestamp?/runtime-benchmarks", + "snowbridge-core/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", +] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", + "pallet-timestamp?/try-runtime", + "sp-runtime/try-runtime", ] beacon-spec-mainnet = [] diff --git a/parachain/pallets/ethereum-beacon-client/fuzz/Cargo.toml b/parachain/pallets/ethereum-beacon-client/fuzz/Cargo.toml index b4c62962da..822cfc1873 100644 --- a/parachain/pallets/ethereum-beacon-client/fuzz/Cargo.toml +++ b/parachain/pallets/ethereum-beacon-client/fuzz/Cargo.toml @@ -8,10 +8,10 @@ edition = "2021" cargo-fuzz = true [dependencies] -libfuzzer-sys = { version = "0.4", features = [ "arbitrary-derive" ]} +libfuzzer-sys = { version = "0.4", features = ["arbitrary-derive"] } arbitrary = { version = "1", optional = true, features = ["derive"] } -snowbridge-ethereum-beacon-client = {path = "..", features = [ "fuzzing" ]} -snowbridge-beacon-primitives= {path = "../../../primitives/beacon"} +snowbridge-ethereum-beacon-client = { path = "..", features = ["fuzzing"] } +snowbridge-beacon-primitives = { path = "../../../primitives/beacon" } hex-literal = "0.4.1" sp-core = { path = "../../../../polkadot-sdk/substrate/primitives/core", default-features = false } diff --git a/parachain/pallets/ethereum-beacon-client/src/config/mod.rs b/parachain/pallets/ethereum-beacon-client/src/config/mod.rs index f15dc5f0b0..6b959ebfec 100644 --- a/parachain/pallets/ethereum-beacon-client/src/config/mod.rs +++ b/parachain/pallets/ethereum-beacon-client/src/config/mod.rs @@ -47,7 +47,7 @@ pub const MAX_FEE_RECIPIENT_SIZE: usize = 20; pub const MAX_BRANCH_PROOF_SIZE: usize = 20; /// DomainType('0x07000000') -/// https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/beacon-chain.md#domain-types +/// pub const DOMAIN_SYNC_COMMITTEE: [u8; 4] = [7, 0, 0, 0]; pub const PUBKEY_SIZE: usize = 48; diff --git a/parachain/pallets/ethereum-beacon-client/src/lib.rs b/parachain/pallets/ethereum-beacon-client/src/lib.rs index 11de3ce9b4..fdda200251 100644 --- a/parachain/pallets/ethereum-beacon-client/src/lib.rs +++ b/parachain/pallets/ethereum-beacon-client/src/lib.rs @@ -356,7 +356,7 @@ pub mod pallet { Ok(()) } - /// References and strictly follows https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md#validate_light_client_update + /// References and strictly follows /// Verifies that provided next sync committee is valid through a series of checks /// (including checking that a sync committee period isn't skipped and that the header is /// signed by the current sync committee. @@ -468,7 +468,7 @@ pub mod pallet { Self::validators_root(), update.signature_slot, )?; - // Improvement here per https://eth2book.info/capella/part2/building_blocks/signatures/#sync-aggregates + // Improvement here per // suggested start from the full set aggregate_pubkey then subtracting the absolute // minority that did not participate. fast_aggregate_verify( @@ -482,7 +482,7 @@ pub mod pallet { Ok(()) } - /// Reference and strictly follows https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md#apply_light_client_update + /// Reference and strictly follows fn store_validators_root(validators_root: H256) { >::set(validators_root); } /// Returns the domain for the domain_type and fork_version. The domain is used to /// distinguish between the different players in the chain (see DomainTypes - /// https://eth2book.info/capella/part3/config/constants/#domain-types) and to ensure we are + /// ) and to ensure we are /// addressing the correct chain. - /// https://eth2book.info/capella/part3/helper/misc/#compute_domain + /// pub(super) fn compute_domain( domain_type: Vec, fork_version: ForkVersion, diff --git a/parachain/pallets/ethereum-beacon-client/src/mock.rs b/parachain/pallets/ethereum-beacon-client/src/mock.rs index 1addccf790..aeeb7debd9 100644 --- a/parachain/pallets/ethereum-beacon-client/src/mock.rs +++ b/parachain/pallets/ethereum-beacon-client/src/mock.rs @@ -41,6 +41,7 @@ pub mod minimal { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; @@ -209,6 +210,7 @@ pub mod mainnet { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; diff --git a/parachain/pallets/inbound-queue/Cargo.toml b/parachain/pallets/inbound-queue/Cargo.toml index 688d392499..a8b5011da3 100644 --- a/parachain/pallets/inbound-queue/Cargo.toml +++ b/parachain/pallets/inbound-queue/Cargo.toml @@ -11,8 +11,8 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] serde = { version = "1.0.188", optional = true } -codec = { version = "3.6.1", package = "parity-scale-codec", default-features = false, features = [ "derive" ] } -scale-info = { version = "2.9.0", default-features = false, features = [ "derive" ] } +codec = { version = "3.6.1", package = "parity-scale-codec", default-features = false, features = ["derive"] } +scale-info = { version = "2.9.0", default-features = false, features = ["derive"] } hex-literal = { version = "0.4.1", optional = true } log = { version = "0.4.20", default-features = false } alloy-primitives = { version = "0.4.2", default-features = false, features = ["rlp"] } @@ -47,34 +47,46 @@ hex-literal = { version = "0.4.1" } [features] default = ["std"] std = [ - "serde", - "log/std", - "codec/std", - "scale-info/std", - "alloy-primitives/std", - "alloy-sol-types/std", - "alloy-rlp/std", - "frame-support/std", - "frame-system/std", - "pallet-balances/std", - "frame-benchmarking/std", - "sp-core/std", - "sp-runtime/std", - "sp-std/std", - "sp-io/std", - "num-traits/std", - "snowbridge-core/std", - "snowbridge-ethereum/std", - "snowbridge-router-primitives/std", - "xcm/std", - "xcm-builder/std", + "alloy-primitives/std", + "alloy-rlp/std", + "alloy-sol-types/std", + "codec/std", + "frame-benchmarking/std", + "frame-support/std", + "frame-system/std", + "log/std", + "num-traits/std", + "pallet-balances/std", + "scale-info/std", + "serde", + "snowbridge-core/std", + "snowbridge-ethereum/std", + "snowbridge-router-primitives/std", + "sp-core/std", + "sp-io/std", + "sp-runtime/std", + "sp-std/std", + "xcm-builder/std", + "xcm/std", ] runtime-benchmarks = [ - "snowbridge-core/runtime-benchmarks", - "frame-benchmarking", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "hex-literal", - "snowbridge-beacon-primitives", - "xcm-builder/runtime-benchmarks", + "frame-benchmarking", + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "hex-literal", + "pallet-balances/runtime-benchmarks", + "snowbridge-beacon-primitives", + "snowbridge-core/runtime-benchmarks", + "snowbridge-ethereum-beacon-client/runtime-benchmarks", + "snowbridge-router-primitives/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", + "xcm-builder/runtime-benchmarks", +] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", + "pallet-balances/try-runtime", + "snowbridge-ethereum-beacon-client/try-runtime", + "sp-runtime/try-runtime", ] diff --git a/parachain/pallets/inbound-queue/src/benchmarking/fixtures.rs b/parachain/pallets/inbound-queue/src/benchmarking/fixtures.rs index 4f2382d072..de2e12ad08 100644 --- a/parachain/pallets/inbound-queue/src/benchmarking/fixtures.rs +++ b/parachain/pallets/inbound-queue/src/benchmarking/fixtures.rs @@ -4,12 +4,12 @@ use snowbridge_core::inbound::{Log, Message, Proof}; use sp_std::vec; pub struct InboundQueueTest { - pub execution_header: CompactExecutionHeader, - pub message: Message, + pub execution_header: CompactExecutionHeader, + pub message: Message, } pub fn make_create_message() -> InboundQueueTest { - InboundQueueTest{ + InboundQueueTest{ execution_header: CompactExecutionHeader{ parent_hash: hex!("b5608f0af7c3b6fe5c593772fc25436b8d6549eb236adb0855c6ad33e0004e04").into(), block_number: 115, diff --git a/parachain/pallets/inbound-queue/src/benchmarking/mod.rs b/parachain/pallets/inbound-queue/src/benchmarking/mod.rs index 93a99a2ec8..0763832558 100644 --- a/parachain/pallets/inbound-queue/src/benchmarking/mod.rs +++ b/parachain/pallets/inbound-queue/src/benchmarking/mod.rs @@ -7,7 +7,6 @@ use super::*; use crate::Pallet as InboundQueue; use frame_benchmarking::v2::*; use frame_system::RawOrigin; -use sp_std::vec; #[benchmarks] mod benchmarks { @@ -28,23 +27,17 @@ mod benchmarks { let sovereign_account = sibling_sovereign_account::(1000u32.into()); let minimum_balance = T::Token::minimum_balance(); - let minimum_balance_u32: u32 = minimum_balance - .try_into() - .unwrap_or_else(|_| panic!("unable to cast minimum balance to u32")); - - // Make sure the sovereign balance is enough. This is a funny number, because - // in some cases the minimum balance is really high, in other cases very low. - // e.g. on bridgehub the minimum balance is 33333, on test it is 1. So this equation makes - // it is at least twice the minimum balance (so as to satisfy the minimum balance - // requirement, and then some (in case the minimum balance is very low, even lower - // than the relayer reward fee). - let sovereign_balance = (minimum_balance_u32 * 2) + 5000; // So that the receiving account exists let _ = T::Token::mint_into(&caller, minimum_balance.into()); // Fund the sovereign account (parachain sovereign account) so it can transfer a reward // fee to the caller account - let _ = T::Token::mint_into(&sovereign_account, sovereign_balance.into()); + let _ = T::Token::mint_into( + &sovereign_account, + 3_000_000_000_000u128 + .try_into() + .unwrap_or_else(|_| panic!("unable to cast sovereign account balance")), + ); #[block] { diff --git a/parachain/pallets/inbound-queue/src/mock.rs b/parachain/pallets/inbound-queue/src/mock.rs index a7435db602..7353c4d866 100644 --- a/parachain/pallets/inbound-queue/src/mock.rs +++ b/parachain/pallets/inbound-queue/src/mock.rs @@ -52,6 +52,7 @@ impl frame_system::Config for Test { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = AccountId; @@ -178,7 +179,7 @@ parameter_types! { pub Parameters: PricingParameters = PricingParameters { exchange_rate: FixedU128::from_rational(1, 400), fee_per_gas: gwei(20), - rewards: Rewards { local: 1 * DOT, remote: meth(1) } + rewards: Rewards { local: DOT, remote: meth(1) } }; } @@ -195,7 +196,7 @@ impl StaticLookup for MockChannelLookup { { return None } - Some(Channel { agent_id: H256::zero().into(), para_id: ASSET_HUB_PARAID.into() }) + Some(Channel { agent_id: H256::zero(), para_id: ASSET_HUB_PARAID.into() }) } } @@ -251,7 +252,7 @@ pub fn setup() { pub fn new_tester() -> sp_io::TestExternalities { let storage = frame_system::GenesisConfig::::default().build_storage().unwrap(); let mut ext: sp_io::TestExternalities = storage.into(); - ext.execute_with(|| setup()); + ext.execute_with(setup); ext } diff --git a/parachain/pallets/outbound-queue/Cargo.toml b/parachain/pallets/outbound-queue/Cargo.toml index 5706a955cb..578f6bf87b 100644 --- a/parachain/pallets/outbound-queue/Cargo.toml +++ b/parachain/pallets/outbound-queue/Cargo.toml @@ -10,9 +10,9 @@ repository = "https://github.com/Snowfork/snowbridge" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -serde = { version = "1.0.188", features = ["derive", "alloc"], default-features = false } -codec = { version = "3.6.1", package = "parity-scale-codec", default-features = false, features = [ "derive" ] } -scale-info = { version = "2.9.0", default-features = false, features = [ "derive" ] } +serde = { version = "1.0.188", features = ["alloc", "derive"], default-features = false } +codec = { version = "3.6.1", package = "parity-scale-codec", default-features = false, features = ["derive"] } +scale-info = { version = "2.9.0", default-features = false, features = ["derive"] } hex-literal = { version = "0.4.1", optional = true } frame-benchmarking = { path = "../../../polkadot-sdk/substrate/frame/benchmarking", default-features = false, optional = true} @@ -40,28 +40,38 @@ hex-literal = { version = "0.4.1" } [features] default = ["std"] std = [ - "serde/std", - "codec/std", - "scale-info/std", - "frame-support/std", - "frame-system/std", - "frame-benchmarking/std", - "sp-core/std", - "sp-runtime/std", - "sp-arithmetic/std", - "sp-std/std", - "sp-io/std", - "snowbridge-core/std", - "snowbridge-outbound-queue-merkle-tree/std", - "ethabi/std", - "xcm/std", - "bridge-hub-common/std", + "bridge-hub-common/std", + "codec/std", + "ethabi/std", + "frame-benchmarking/std", + "frame-support/std", + "frame-system/std", + "pallet-message-queue/std", + "scale-info/std", + "serde/std", + "snowbridge-core/std", + "snowbridge-outbound-queue-merkle-tree/std", + "sp-arithmetic/std", + "sp-core/std", + "sp-io/std", + "sp-runtime/std", + "sp-std/std", + "xcm/std", ] runtime-benchmarks = [ - "snowbridge-core/runtime-benchmarks", - "frame-benchmarking", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "hex-literal", - "bridge-hub-common/runtime-benchmarks", + "bridge-hub-common/runtime-benchmarks", + "frame-benchmarking", + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "hex-literal", + "pallet-message-queue/runtime-benchmarks", + "snowbridge-core/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", +] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", + "pallet-message-queue/try-runtime", + "sp-runtime/try-runtime", ] diff --git a/parachain/pallets/outbound-queue/merkle-tree/Cargo.toml b/parachain/pallets/outbound-queue/merkle-tree/Cargo.toml index b791c096f8..3366c7db64 100644 --- a/parachain/pallets/outbound-queue/merkle-tree/Cargo.toml +++ b/parachain/pallets/outbound-queue/merkle-tree/Cargo.toml @@ -3,15 +3,15 @@ name = "snowbridge-outbound-queue-merkle-tree" description = "Snowbridge Outbound Queue Merkle Tree" version = "0.1.1" edition = "2021" -authors = [ "Snowfork " ] +authors = ["Snowfork "] repository = "https://github.com/Snowfork/snowbridge" [package.metadata.docs.rs] -targets = [ "x86_64-unknown-linux-gnu" ] +targets = ["x86_64-unknown-linux-gnu"] [dependencies] -codec = { version = "3.1.5", package = "parity-scale-codec", default-features = false, features = [ "derive" ] } -scale-info = { version = "2.7.0", default-features = false, features = [ "derive" ] } +codec = { version = "3.1.5", package = "parity-scale-codec", default-features = false, features = ["derive"] } +scale-info = { version = "2.7.0", default-features = false, features = ["derive"] } sp-core = { path = "../../../../polkadot-sdk/substrate/primitives/core", default-features = false } sp-runtime = { path = "../../../../polkadot-sdk/substrate/primitives/runtime", default-features = false } @@ -23,10 +23,10 @@ hex = "0.4" array-bytes = "4.1" [features] -default = [ "std" ] +default = ["std"] std = [ - "codec/std", - "scale-info/std", - "sp-core/std", - "sp-runtime/std", + "codec/std", + "scale-info/std", + "sp-core/std", + "sp-runtime/std", ] diff --git a/parachain/pallets/outbound-queue/merkle-tree/src/lib.rs b/parachain/pallets/outbound-queue/merkle-tree/src/lib.rs index ad1f6d719d..2695988b2c 100644 --- a/parachain/pallets/outbound-queue/merkle-tree/src/lib.rs +++ b/parachain/pallets/outbound-queue/merkle-tree/src/lib.rs @@ -11,7 +11,7 @@ //! compilation targets. //! //! Merkle Tree is constructed from arbitrary-length leaves, that are initially hashed using the -//! same [Hasher] as the inner nodes. +//! same `\[`Hasher`\]` as the inner nodes. //! Inner nodes are created by concatenating child hashes and hashing again. The implementation //! does not perform any sorting of the input data (leaves) nor when inner nodes are created. //! @@ -329,7 +329,7 @@ mod tests { use sp_runtime::traits::Keccak256; fn make_leaves(count: u64) -> Vec { - (0..count).into_iter().map(|i| keccak_256(&i.to_le_bytes()).into()).collect() + (0..count).map(|i| keccak_256(&i.to_le_bytes()).into()).collect() } #[test] @@ -343,7 +343,7 @@ mod tests { // then assert_eq!( - hex::encode(&out), + hex::encode(out), "0000000000000000000000000000000000000000000000000000000000000000" ); } @@ -359,7 +359,7 @@ mod tests { // then assert_eq!( - hex::encode(&out), + hex::encode(out), "011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce" ); } @@ -375,7 +375,7 @@ mod tests { // then assert_eq!( - hex::encode(&out), + hex::encode(out), "e497bd1c13b13a60af56fa0d2703517c232fde213ad20d2c3dd60735c6604512" ); } @@ -385,7 +385,7 @@ mod tests { let _ = env_logger::try_init(); let test = |root, data: Vec| { assert_eq!( - array_bytes::bytes2hex("", &merkle_root::(data.into_iter()).as_ref()), + array_bytes::bytes2hex("", merkle_root::(data.into_iter()).as_ref()), root ); }; diff --git a/parachain/pallets/outbound-queue/runtime-api/Cargo.toml b/parachain/pallets/outbound-queue/runtime-api/Cargo.toml index 4b45ae8d83..f61c524e33 100644 --- a/parachain/pallets/outbound-queue/runtime-api/Cargo.toml +++ b/parachain/pallets/outbound-queue/runtime-api/Cargo.toml @@ -2,14 +2,14 @@ name = "snowbridge-outbound-queue-runtime-api" version = "0.1.0" edition = "2021" -authors = [ "Snowfork " ] +authors = ["Snowfork "] repository = "https://github.com/Snowfork/snowbridge" [package.metadata.docs.rs] -targets = [ "x86_64-unknown-linux-gnu" ] +targets = ["x86_64-unknown-linux-gnu"] [dependencies] -codec = { version = "3.1.5", package = "parity-scale-codec", features = [ "derive" ], default-features = false } +codec = { version = "3.1.5", package = "parity-scale-codec", features = ["derive"], default-features = false } sp-core = { path = "../../../../polkadot-sdk/substrate/primitives/core", default-features = false } sp-std = { path = "../../../../polkadot-sdk/substrate/primitives/std", default-features = false } sp-api = { path = "../../../../polkadot-sdk/substrate/primitives/api", default-features = false} @@ -22,11 +22,11 @@ snowbridge-core = { path = "../../../primitives/core", default-features = false default = ["std"] std = [ "codec/std", - "sp-core/std", + "frame-support/std", + "snowbridge-core/std", + "snowbridge-outbound-queue-merkle-tree/std", "sp-api/std", + "sp-core/std", "sp-std/std", - "frame-support/std", "xcm/std", - "snowbridge-outbound-queue-merkle-tree/std", - "snowbridge-core/std", ] diff --git a/parachain/pallets/outbound-queue/runtime-api/src/lib.rs b/parachain/pallets/outbound-queue/runtime-api/src/lib.rs index dc2c8501d0..51f46a7b49 100644 --- a/parachain/pallets/outbound-queue/runtime-api/src/lib.rs +++ b/parachain/pallets/outbound-queue/runtime-api/src/lib.rs @@ -11,7 +11,7 @@ sp_api::decl_runtime_apis! { { /// Generate a merkle proof for a committed message identified by `leaf_index`. /// The merkle root is stored in the block header as a - /// [`sp_runtime::generic::DigestItem::Other`] + /// `\[`sp_runtime::generic::DigestItem::Other`\]` fn prove_message(leaf_index: u64) -> Option; /// Calculate the delivery fee for `message` diff --git a/parachain/pallets/outbound-queue/src/mock.rs b/parachain/pallets/outbound-queue/src/mock.rs index cf6c4c5899..cf012bb9e9 100644 --- a/parachain/pallets/outbound-queue/src/mock.rs +++ b/parachain/pallets/outbound-queue/src/mock.rs @@ -19,6 +19,7 @@ use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup, Keccak256}, AccountId32, BuildStorage, FixedU128, }; +use sp_std::marker::PhantomData; type Block = frame_system::mocking::MockBlock; type AccountId = AccountId32; @@ -42,6 +43,7 @@ impl frame_system::Config for Test { type BlockLength = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = AccountId; @@ -85,7 +87,7 @@ parameter_types! { pub Parameters: PricingParameters = PricingParameters { exchange_rate: FixedU128::from_rational(1, 400), fee_per_gas: gwei(20), - rewards: Rewards { local: 1 * DOT, remote: meth(1) } + rewards: Rewards { local: DOT, remote: meth(1) } }; } @@ -112,7 +114,7 @@ fn setup() { pub fn new_tester() -> sp_io::TestExternalities { let storage = frame_system::GenesisConfig::::default().build_storage().unwrap(); let mut ext: sp_io::TestExternalities = storage.into(); - ext.execute_with(|| setup()); + ext.execute_with(setup); ext } @@ -136,6 +138,8 @@ pub fn mock_governance_message() -> Message where T: Config, { + let _marker = PhantomData::; // for clippy + Message { id: None, channel_id: PRIMARY_GOVERNANCE_CHANNEL, @@ -152,6 +156,8 @@ pub fn mock_invalid_governance_message() -> Message where T: Config, { + let _marker = PhantomData::; // for clippy + Message { id: None, channel_id: PRIMARY_GOVERNANCE_CHANNEL, diff --git a/parachain/pallets/outbound-queue/src/test.rs b/parachain/pallets/outbound-queue/src/test.rs index 9bdc636495..77fa7e92f0 100644 --- a/parachain/pallets/outbound-queue/src/test.rs +++ b/parachain/pallets/outbound-queue/src/test.rs @@ -54,7 +54,7 @@ fn submit_message_fail_too_large() { fn convert_from_ether_decimals() { assert_eq!( OutboundQueue::convert_from_ether_decimals(1_000_000_000_000_000_000), - 100_000_000_000_0 + 1_000_000_000_000 ); } @@ -78,7 +78,7 @@ fn process_message_yields_on_max_messages_per_block() { } let channel_id: ChannelId = ParaId::from(1000).into(); - let origin = AggregateMessageOrigin::Snowbridge(channel_id.into()); + let origin = AggregateMessageOrigin::Snowbridge(channel_id); let message = QueuedMessage { id: Default::default(), channel_id, @@ -93,7 +93,7 @@ fn process_message_yields_on_max_messages_per_block() { let mut meter = WeightMeter::new(); assert_noop!( - OutboundQueue::process_message(&message.as_slice(), origin, &mut meter, &mut [0u8; 32]), + OutboundQueue::process_message(message.as_slice(), origin, &mut meter, &mut [0u8; 32]), ProcessMessageError::Yield ); }) @@ -104,11 +104,11 @@ fn process_message_fails_on_overweight_message() { new_tester().execute_with(|| { let sibling_id = 1000; let channel_id: ChannelId = ParaId::from(sibling_id).into(); - let origin = AggregateMessageOrigin::Snowbridge(channel_id.into()); + let origin = AggregateMessageOrigin::Snowbridge(channel_id); let message = mock_message(sibling_id).encode(); let mut meter = WeightMeter::with_limit(Weight::from_parts(1, 1)); assert_noop!( - OutboundQueue::process_message(&message.as_slice(), origin, &mut meter, &mut [0u8; 32]), + OutboundQueue::process_message(message.as_slice(), origin, &mut meter, &mut [0u8; 32]), ProcessMessageError::Overweight(::WeightInfo::do_process_message()) ); }) @@ -155,7 +155,7 @@ fn governance_message_does_not_get_the_chance_to_processed_in_same_block_when_co OutboundQueue::deliver(ticket).unwrap(); } - let footprint = MessageQueue::footprint(Snowbridge(sibling_channel_id.into())); + let footprint = MessageQueue::footprint(Snowbridge(sibling_channel_id)); assert_eq!(footprint.storage.count, (max_messages) as u64); let message = mock_governance_message::(); @@ -167,11 +167,11 @@ fn governance_message_does_not_get_the_chance_to_processed_in_same_block_when_co run_to_end_of_next_block(); // first process 20 messages from sibling channel - let footprint = MessageQueue::footprint(Snowbridge(sibling_channel_id.into())); + let footprint = MessageQueue::footprint(Snowbridge(sibling_channel_id)); assert_eq!(footprint.storage.count, 40 - 20); // and governance message does not have the chance to execute in same block - let footprint = MessageQueue::footprint(Snowbridge(PRIMARY_GOVERNANCE_CHANNEL.into())); + let footprint = MessageQueue::footprint(Snowbridge(PRIMARY_GOVERNANCE_CHANNEL)); assert_eq!(footprint.storage.count, 1); // move to next block @@ -179,17 +179,17 @@ fn governance_message_does_not_get_the_chance_to_processed_in_same_block_when_co run_to_end_of_next_block(); // now governance message get executed in this block - let footprint = MessageQueue::footprint(Snowbridge(PRIMARY_GOVERNANCE_CHANNEL.into())); + let footprint = MessageQueue::footprint(Snowbridge(PRIMARY_GOVERNANCE_CHANNEL)); assert_eq!(footprint.storage.count, 0); // and this time process 19 messages from sibling channel so we have 1 message left - let footprint = MessageQueue::footprint(Snowbridge(sibling_channel_id.into())); + let footprint = MessageQueue::footprint(Snowbridge(sibling_channel_id)); assert_eq!(footprint.storage.count, 1); // move to the next block, the last 1 message from sibling channel get executed ServiceWeight::set(Some(Weight::MAX)); run_to_end_of_next_block(); - let footprint = MessageQueue::footprint(Snowbridge(sibling_channel_id.into())); + let footprint = MessageQueue::footprint(Snowbridge(sibling_channel_id)); assert_eq!(footprint.storage.count, 0); }); } diff --git a/parachain/pallets/system/Cargo.toml b/parachain/pallets/system/Cargo.toml index 6a190e5e3e..938f915296 100644 --- a/parachain/pallets/system/Cargo.toml +++ b/parachain/pallets/system/Cargo.toml @@ -44,23 +44,39 @@ snowbridge-outbound-queue = { path = "../outbound-queue" } default = ["std"] std = [ "codec/std", + "ethabi/std", "frame-benchmarking?/std", "frame-support/std", "frame-system/std", + "log/std", "scale-info/std", + "snowbridge-core/std", "sp-core/std", - "sp-std/std", "sp-io/std", "sp-runtime/std", - "xcm/std", + "sp-std/std", "xcm-builder/std", "xcm-executor/std", - "ethabi/std", - "snowbridge-core/std" + "xcm/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-message-queue/runtime-benchmarks", + "polkadot-primitives/runtime-benchmarks", + "snowbridge-core/runtime-benchmarks", + "snowbridge-outbound-queue/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", "xcm-executor/runtime-benchmarks", ] -try-runtime = ["frame-support/try-runtime"] +try-runtime = [ + "frame-support/try-runtime", + "frame-system/try-runtime", + "pallet-balances/try-runtime", + "pallet-message-queue/try-runtime", + "snowbridge-outbound-queue/try-runtime", + "sp-runtime/try-runtime", +] diff --git a/parachain/pallets/system/runtime-api/Cargo.toml b/parachain/pallets/system/runtime-api/Cargo.toml index 9bd092209a..ef1d94fc74 100644 --- a/parachain/pallets/system/runtime-api/Cargo.toml +++ b/parachain/pallets/system/runtime-api/Cargo.toml @@ -22,9 +22,9 @@ snowbridge-core = { path = "../../../primitives/core", default-features = false default = ["std"] std = [ "codec/std", - "sp-core/std", + "snowbridge-core/std", "sp-api/std", + "sp-core/std", "sp-std/std", "xcm/std", - "snowbridge-core/std", ] diff --git a/parachain/pallets/system/src/benchmarking.rs b/parachain/pallets/system/src/benchmarking.rs index e0962d81e0..0c940b0322 100644 --- a/parachain/pallets/system/src/benchmarking.rs +++ b/parachain/pallets/system/src/benchmarking.rs @@ -12,7 +12,7 @@ use sp_runtime::SaturatedConversion; use xcm::prelude::*; fn fund_sovereign_account(para_id: ParaId) -> Result<(), BenchmarkError> { - let amount: BalanceOf = (1_000_000_000_000_u64).saturated_into::().saturated_into(); + let amount: BalanceOf = (10_000_000_000_000_u64).saturated_into::().saturated_into(); let sovereign_account = sibling_sovereign_account::(para_id); T::Token::mint_into(&sovereign_account, amount)?; Ok(()) diff --git a/parachain/pallets/system/src/mock.rs b/parachain/pallets/system/src/mock.rs index 2dc5e05f25..604348b9f3 100644 --- a/parachain/pallets/system/src/mock.rs +++ b/parachain/pallets/system/src/mock.rs @@ -103,6 +103,7 @@ impl frame_system::Config for Test { type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = AccountId; @@ -202,7 +203,7 @@ parameter_types! { pub Parameters: PricingParameters = PricingParameters { exchange_rate: FixedU128::from_rational(1, 400), fee_per_gas: gwei(20), - rewards: Rewards { local: 1 * DOT, remote: meth(1) } + rewards: Rewards { local: DOT, remote: meth(1) } }; pub const InboundDeliveryCost: u128 = 1_000_000_000; @@ -243,7 +244,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { .unwrap(); let mut ext: sp_io::TestExternalities = storage.into(); - let initial_amount = InitialFunding::get().into(); + let initial_amount = InitialFunding::get(); let test_para_id = TestParaId::get(); let sovereign_account = sibling_sovereign_account::(test_para_id.into()); let treasury_account = TreasuryAccount::get(); diff --git a/parachain/pallets/system/src/tests.rs b/parachain/pallets/system/src/tests.rs index 18b536e9fc..761924aa0a 100644 --- a/parachain/pallets/system/src/tests.rs +++ b/parachain/pallets/system/src/tests.rs @@ -571,10 +571,10 @@ fn charge_fee_for_create_agent() { // and treasury_balance increased let treasury_balance = Balances::balance(&TreasuryAccount::get()); - assert_eq!(treasury_balance > InitialFunding::get(), true); + assert!(treasury_balance > InitialFunding::get()); // (sovereign_balance + treasury_balance) keeps the same - assert_eq!(sovereign_balance + treasury_balance, (InitialFunding::get() * 2) as u128); + assert_eq!(sovereign_balance + treasury_balance, { InitialFunding::get() * 2 }); }); } diff --git a/parachain/primitives/beacon/Cargo.toml b/parachain/primitives/beacon/Cargo.toml index c28f332e97..0961d33ae2 100644 --- a/parachain/primitives/beacon/Cargo.toml +++ b/parachain/primitives/beacon/Cargo.toml @@ -11,20 +11,20 @@ codec = { package = "parity-scale-codec", version = "3.6.1", default-features = scale-info = { version = "2.9.0", default-features = false, features = ["derive"] } rlp = { version = "0.5", default-features = false } -frame-support = { path = "../../../polkadot-sdk/substrate/frame/support", default-features = false } -frame-system = { path = "../../../polkadot-sdk/substrate/frame/system", default-features = false } -sp-runtime = { path = "../../../polkadot-sdk/substrate/primitives/runtime", default-features = false } -sp-core = { path = "../../../polkadot-sdk/substrate/primitives/core", default-features = false } -sp-std = { path = "../../../polkadot-sdk/substrate/primitives/std", default-features = false } -sp-io = { path = "../../../polkadot-sdk/substrate/primitives/io", default-features = false } +frame-support = { path = "../../../../../substrate/frame/support", default-features = false } +frame-system = { path = "../../../../../substrate/frame/system", default-features = false } +sp-runtime = { path = "../../../../../substrate/primitives/runtime", default-features = false } +sp-core = { path = "../../../../../substrate/primitives/core", default-features = false } +sp-std = { path = "../../../../../substrate/primitives/std", default-features = false } +sp-io = { path = "../../../../../substrate/primitives/io", default-features = false } -ssz_rs = { version="0.9.0", default-features = false } -ssz_rs_derive = { version="0.9.0", default-features = false } +ssz_rs = { version = "0.9.0", default-features = false } +ssz_rs_derive = { version = "0.9.0", default-features = false } byte-slice-cast = { version = "1.2.1", default-features = false } snowbridge-ethereum = { path = "../../primitives/ethereum", default-features = false } static_assertions = { version = "1.1.0" } -milagro_bls = { git = "https://github.com/snowfork/milagro_bls", default-features = false, rev="a6d66e4eb89015e352fb1c9f7b661ecdbb5b2176"} +milagro_bls = { git = "https://github.com/snowfork/milagro_bls", default-features = false, rev = "a6d66e4eb89015e352fb1c9f7b661ecdbb5b2176" } [dev-dependencies] hex-literal = { version = "0.4.1" } @@ -32,18 +32,19 @@ hex-literal = { version = "0.4.1" } [features] default = ["std"] std = [ - "serde", - "codec/std", - "scale-info/std", - "frame-support/std", - "frame-system/std", - "sp-std/std", - "sp-core/std", - "sp-runtime/std", - "sp-io/std", - "rlp/std", - "snowbridge-ethereum/std", - "ssz_rs/std", - "byte-slice-cast/std", - "milagro_bls/std", + "byte-slice-cast/std", + "codec/std", + "frame-support/std", + "frame-system/std", + "hex/std", + "milagro_bls/std", + "rlp/std", + "scale-info/std", + "serde", + "snowbridge-ethereum/std", + "sp-core/std", + "sp-io/std", + "sp-runtime/std", + "sp-std/std", + "ssz_rs/std", ] diff --git a/parachain/primitives/beacon/src/merkle_proof.rs b/parachain/primitives/beacon/src/merkle_proof.rs index 4f8cd83f5f..a6ee6e9452 100644 --- a/parachain/primitives/beacon/src/merkle_proof.rs +++ b/parachain/primitives/beacon/src/merkle_proof.rs @@ -3,8 +3,8 @@ use sp_core::H256; use sp_io::hashing::sha2_256; -/// Specified by https://github.com/ethereum/consensus-specs/blob/fe9c1a8cbf0c2da8a4f349efdcd77dd7ac8445c4/specs/phase0/beacon-chain.md?plain=1#L742 -/// with improvements from https://github.com/ethereum/consensus-specs/blob/dev/ssz/merkle-proofs.md +/// Specified by +/// with improvements from pub fn verify_merkle_branch( leaf: H256, branch: &[H256], @@ -39,17 +39,17 @@ fn compute_merkle_root(leaf: H256, proof: &[H256], index: usize) -> H256 { value.into() } -/// Spec: https://github.com/ethereum/consensus-specs/blob/fe9c1a8cbf0c2da8a4f349efdcd77dd7ac8445c4/ssz/merkle-proofs.md#get_generalized_index_bit +/// Spec: fn generalized_index_bit(index: usize, position: usize) -> bool { index & (1 << position) > 0 } -/// Spec: https://github.com/ethereum/consensus-specs/blob/fe9c1a8cbf0c2da8a4f349efdcd77dd7ac8445c4/specs/altair/light-client/sync-protocol.md#get_subtree_index +/// Spec: pub const fn subtree_index(generalized_index: usize) -> usize { generalized_index % (1 << generalized_index_length(generalized_index)) } -/// Spec: https://github.com/ethereum/consensus-specs/blob/fe9c1a8cbf0c2da8a4f349efdcd77dd7ac8445c4/ssz/merkle-proofs.md#get_generalized_index_length +/// Spec: pub const fn generalized_index_length(generalized_index: usize) -> usize { match generalized_index.checked_ilog2() { Some(v) => v as usize, diff --git a/parachain/primitives/beacon/src/types.rs b/parachain/primitives/beacon/src/types.rs index c0e45c0661..f893551d9d 100644 --- a/parachain/primitives/beacon/src/types.rs +++ b/parachain/primitives/beacon/src/types.rs @@ -303,7 +303,7 @@ impl } /// ExecutionPayloadHeader -/// https://github.com/ethereum/annotated-spec/blob/master/capella/beacon-chain.md#executionpayloadheader +/// #[derive( Default, Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, )] @@ -436,11 +436,10 @@ mod tests { #[test] pub fn test_hash_fork_data() { let hash_root = ForkData { - current_version: hex!("83f38a34").into(), + current_version: hex!("83f38a34"), genesis_validators_root: hex!( "22370bbbb358800f5711a10ea9845284272d8493bed0348cab87b8ab1e127930" - ) - .into(), + ), } .hash_tree_root(); @@ -470,7 +469,7 @@ mod tests { #[test] pub fn test_hash_sync_aggregate() { let hash_root = SyncAggregate::<512, 64>{ - sync_committee_bits: hex!("cefffffefffffff767fffbedffffeffffeeffdffffdebffffff7f7dbdf7fffdffffbffcfffdff79dfffbbfefff2ffffff7ddeff7ffffc98ff7fbfffffffffff7").into(), + sync_committee_bits: hex!("cefffffefffffff767fffbedffffeffffeeffdffffdebffffff7f7dbdf7fffdffffbffcfffdff79dfffbbfefff2ffffff7ddeff7ffffc98ff7fbfffffffffff7"), sync_committee_signature: hex!("8af1a8577bba419fe054ee49b16ed28e081dda6d3ba41651634685e890992a0b675e20f8d9f2ec137fe9eb50e838aa6117f9f5410e2e1024c4b4f0e098e55144843ce90b7acde52fe7b94f2a1037342c951dc59f501c92acf7ed944cb6d2b5f7").into(), }.hash_tree_root(); @@ -489,14 +488,14 @@ mod tests { fee_recipient: hex!("f97e180c050e5ab072211ad2c213eb5aee4df134").into(), state_root: hex!("564fa064c2a324c2b5978d7fdfc5d4224d4f421a45388af1ed405a399c845dff").into(), receipts_root: hex!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").into(), - logs_bloom: hex!("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").to_vec().try_into().expect("logs bloom is too long"), + logs_bloom: hex!("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").to_vec(), prev_randao: hex!("6bf538bdfbdf1c96ff528726a40658a91d0bda0f1351448c4c4f3604db2a0ccf").into(), block_number: 477434, gas_limit: 8154925, gas_used: 0, timestamp: 1652816940, - extra_data: vec![].try_into().expect("extra data field is too long"), - base_fee_per_gas: U256::from(7 as i16), + extra_data: vec![], + base_fee_per_gas: U256::from(7_i16), block_hash: hex!("cd8df91b4503adb8f2f1c7a4f60e07a1f1a2cbdfa2a95bceba581f3ff65c1968").into(), transactions_root: hex!("7ffe241ea60187fdb0187bfa22de35d1f9bed7ab061d9401fd47e34a54fbede1").into(), withdrawals_root: hex!("28ba1834a3a7b657460ce79fa3a1d909ab8828fd557659d4d0554a9bdbc0ec30").into(), diff --git a/parachain/primitives/core/Cargo.toml b/parachain/primitives/core/Cargo.toml index fd5747613b..a3426fd5e7 100644 --- a/parachain/primitives/core/Cargo.toml +++ b/parachain/primitives/core/Cargo.toml @@ -5,9 +5,9 @@ authors = ["Snowfork "] edition = "2021" [dependencies] -serde = { version = "1.0.188", optional = true, features = [ "derive", "alloc" ], default-features = false } +serde = { version = "1.0.188", optional = true, features = ["alloc", "derive"], default-features = false } codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false } -scale-info = { version = "2.9.0", default-features = false, features = [ "derive" ] } +scale-info = { version = "2.9.0", default-features = false, features = ["derive"] } hex-literal = { version = "0.4.1" } polkadot-parachain-primitives = { path = "../../../polkadot-sdk/polkadot/parachain", default-features = false } @@ -32,22 +32,27 @@ hex = { version = "0.4.3" } [features] default = ["std"] std = [ - "serde/std", - "codec/std", - "scale-info/std", - "frame-support/std", - "frame-system/std", - "polkadot-parachain-primitives/std", - "sp-std/std", - "sp-io/std", - "sp-core/std", - "sp-runtime/std", - "snowbridge-beacon-primitives/std", - "xcm/std", - "ethabi/std", - "xcm-builder/std", + "codec/std", + "ethabi/std", + "frame-support/std", + "frame-system/std", + "polkadot-parachain-primitives/std", + "scale-info/std", + "serde/std", + "snowbridge-beacon-primitives/std", + "sp-arithmetic/std", + "sp-core/std", + "sp-io/std", + "sp-runtime/std", + "sp-std/std", + "xcm-builder/std", + "xcm/std", ] serde = ["dep:serde", "scale-info/serde"] runtime-benchmarks = [ - "xcm-builder/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "polkadot-parachain-primitives/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", + "xcm-builder/runtime-benchmarks", ] diff --git a/parachain/primitives/core/src/outbound.rs b/parachain/primitives/core/src/outbound.rs index 4aeadae8b9..1595931c69 100644 --- a/parachain/primitives/core/src/outbound.rs +++ b/parachain/primitives/core/src/outbound.rs @@ -37,7 +37,7 @@ mod v1 { use sp_core::{RuntimeDebug, H160, H256, U256}; use sp_std::{borrow::ToOwned, vec, vec::Vec}; - /// A message which can be accepted by implementations of [`SendMessage`] + /// A message which can be accepted by implementations of `/[`SendMessage`\]` #[derive(Encode, Decode, TypeInfo, Clone, RuntimeDebug)] #[cfg_attr(feature = "std", derive(PartialEq))] pub struct Message { diff --git a/parachain/primitives/core/src/pricing.rs b/parachain/primitives/core/src/pricing.rs index 2e30a25b14..33aeda6d15 100644 --- a/parachain/primitives/core/src/pricing.rs +++ b/parachain/primitives/core/src/pricing.rs @@ -47,7 +47,7 @@ where } } -/// Holder for fixed point number implemented in https://github.com/PaulRBerg/prb-math +/// Holder for fixed point number implemented in #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo)] #[cfg_attr(feature = "std", derive(PartialEq))] pub struct UD60x18(U256); diff --git a/parachain/primitives/ethereum/Cargo.toml b/parachain/primitives/ethereum/Cargo.toml index 832a7bffe0..08d7bb8987 100644 --- a/parachain/primitives/ethereum/Cargo.toml +++ b/parachain/primitives/ethereum/Cargo.toml @@ -1,16 +1,16 @@ [package] name = "snowbridge-ethereum" version = "0.1.0" -authors = [ "Snowfork " ] +authors = ["Snowfork "] edition = "2021" [dependencies] -serde = { version = "1.0.188", optional = true, features = [ "derive" ] } -serde-big-array = { version = "0.3.2", optional = true, features = [ "const-generics" ] } -codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = [ "derive" ] } -scale-info = { version = "2.9.0", default-features = false, features = [ "derive" ] } +serde = { version = "1.0.188", optional = true, features = ["derive"] } +serde-big-array = { version = "0.3.2", optional = true, features = ["const-generics"] } +codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] } +scale-info = { version = "2.9.0", default-features = false, features = ["derive"] } ethbloom = { version = "0.13.0", default-features = false } -ethereum-types = { version = "0.14.1", default-features = false, features = [ "codec", "rlp", "serialize" ] } +ethereum-types = { version = "0.14.1", default-features = false, features = ["codec", "rlp", "serialize"] } hex = { package = "rustc-hex", version = "2.1.0", default-features = false } hex-literal = { version = "0.4.1", default-features = false } parity-bytes = { version = "0.1.2", default-features = false } @@ -21,7 +21,7 @@ sp-std = { path = "../../../polkadot-sdk/substrate/primitives/std", default-feat sp-core = { path = "../../../polkadot-sdk/substrate/primitives/core", default-features = false } sp-runtime = { path = "../../../polkadot-sdk/substrate/primitives/runtime", default-features = false } -ethabi = { git = "https://github.com/snowfork/ethabi-decode.git", package = "ethabi-decode", branch="master", default-features = false } +ethabi = { git = "https://github.com/snowfork/ethabi-decode.git", package = "ethabi-decode", branch = "master", default-features = false } [dev-dependencies] wasm-bindgen-test = "0.3.19" @@ -29,21 +29,21 @@ rand = "0.8.5" serde_json = "1.0.96" [features] -default = [ "std" ] +default = ["std"] expensive_tests = [] std = [ - "serde", - "serde-big-array", "codec/std", - "scale-info/std", "ethabi/std", "ethbloom/std", "ethereum-types/std", "hex/std", "parity-bytes/std", "rlp/std", + "scale-info/std", + "serde", + "serde-big-array", "sp-core/std", "sp-io/std", "sp-runtime/std", - "sp-std/std" + "sp-std/std", ] diff --git a/parachain/primitives/ethereum/src/header.rs b/parachain/primitives/ethereum/src/header.rs index 2dad41ac24..f0b51f8c79 100644 --- a/parachain/primitives/ethereum/src/header.rs +++ b/parachain/primitives/ethereum/src/header.rs @@ -147,7 +147,7 @@ impl Header { /// Returns header RLP with or without seals. /// For EIP-1559 baseFee addition refer to: - /// https://github.com/openethereum/openethereum/blob/193b25a22d5ff07759c6431129e95235510516f9/crates/ethcore/types/src/header.rs#L341 + /// fn rlp(&self, with_seal: bool) -> Bytes { let mut s = RlpStream::new(); @@ -285,7 +285,7 @@ mod tests { #[test] fn header_compute_hash_pow() { - // https://etherscan.io/block/11090290 + // let nonce = hex!("6935bbe7b63c4f8e").to_vec(); let mix_hash = hex!("be3adfb0087be62b28b716e2cdf3c79329df5caa04c9eee035d35b5d52102815").to_vec(); @@ -324,11 +324,14 @@ mod tests { let nonce: H64 = hex!("6935bbe7b63c4f8e").into(); let mix_hash: H256 = hex!("be3adfb0087be62b28b716e2cdf3c79329df5caa04c9eee035d35b5d52102815").into(); - let mut header: Header = Default::default(); - header.seal = vec![ - rlp::encode(&mix_hash.0.to_vec()).to_vec(), - rlp::encode(&nonce.0.to_vec()).to_vec(), - ]; + let header = Header { + seal: vec![ + rlp::encode(&mix_hash.0.to_vec()).to_vec(), + rlp::encode(&nonce.0.to_vec()).to_vec(), + ], + ..Default::default() + }; + assert_eq!(header.nonce().unwrap(), nonce); assert_eq!(header.mix_hash().unwrap(), mix_hash); } @@ -338,8 +341,10 @@ mod tests { let nonce = hex!("696935bbe7b63c4f8e").to_vec(); let mix_hash = hex!("bebe3adfb0087be62b28b716e2cdf3c79329df5caa04c9eee035d35b5d52102815").to_vec(); - let mut header: Header = Default::default(); - header.seal = vec![rlp::encode(&mix_hash).to_vec(), rlp::encode(&nonce).to_vec()]; + let mut header = Header { + seal: vec![rlp::encode(&mix_hash).to_vec(), rlp::encode(&nonce).to_vec()], + ..Default::default() + }; assert_eq!(header.nonce(), None); assert_eq!(header.mix_hash(), None); @@ -350,9 +355,11 @@ mod tests { #[test] fn header_check_receipt_proof() { - let mut header: Header = Default::default(); - header.receipts_root = - hex!("fd5e397a84884641f53c496804f24b5276cbb8c5c9cfc2342246be8e3ce5ad02").into(); + let header = Header { + receipts_root: hex!("fd5e397a84884641f53c496804f24b5276cbb8c5c9cfc2342246be8e3ce5ad02") + .into(), + ..Default::default() + }; // Valid proof let proof_receipt5 = vec!( @@ -388,9 +395,11 @@ mod tests { #[test] fn header_check_receipt_proof_with_intermediate_short_node() { - let mut header: Header = Default::default(); - header.receipts_root = - hex!("d128e3a57142d2bf15bc0cbcac7ad54f40750d571b5c3097e425882c10c9ba66").into(); + let header = Header { + receipts_root: hex!("d128e3a57142d2bf15bc0cbcac7ad54f40750d571b5c3097e425882c10c9ba66") + .into(), + ..Default::default() + }; let proof_receipt263 = vec![ hex!("f90131a00d3cb8d3f57ac1c0e12918a2ebe0cafed8c273577b9dd73e7ed1079b403ef494a0678b9835b834f8a287c0dd33a8fca9146e456ca688555ed4ec1361a2180b778da0fe42da181a46677a043b3d9d4b8bb05a6a17b7b5c010c17e7c1d31cfb7c4f911a0c89f0e2c53241cdb578e1f2b4caf6ba36e00500bdc57fecd66b84a6a58394c19a086c3c1fae5a0575940b5d38e111c469d07883106c26856f3ef608469a2081f13a06c5992ff00aab6226a70a032fd2f571ba22f797321f45e2daa73020d638d21b0a050861e9503ef68728f6c90a44f7fe1bceb2a9bdab6957bbe7136166bd849561ea006aa6eaca8a07e57176e9aa41e6a09edfb7678d1a112404e0ec779d7e567e82ea0bb0b430d303ba21b0af11c487b8a218bd75db54c98940b3f11bad8ff47cad3ef8080808080808080").to_vec(), diff --git a/parachain/primitives/ethereum/src/mpt.rs b/parachain/primitives/ethereum/src/mpt.rs index 9a88b2afa7..9a2dae486d 100644 --- a/parachain/primitives/ethereum/src/mpt.rs +++ b/parachain/primitives/ethereum/src/mpt.rs @@ -126,7 +126,7 @@ mod tests { // key + item value let node: ShortNode = rlp::decode(RAW_PROOF[2]).unwrap(); assert_eq!(node.key, vec![32]); - assert!(node.value.len() > 0); + assert!(!node.value.is_empty()); // key + item hash let node: ShortNode = rlp::decode(&hex!( diff --git a/parachain/primitives/router/Cargo.toml b/parachain/primitives/router/Cargo.toml index 056a33d2ca..e6a8cfc58a 100644 --- a/parachain/primitives/router/Cargo.toml +++ b/parachain/primitives/router/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "snowbridge-router-primitives" version = "0.1.1" -authors = [ "Snowfork " ] +authors = ["Snowfork "] edition = "2021" [dependencies] -serde = { version = "1.0.188", optional = true, features = [ "derive" ] } +serde = { version = "1.0.188", optional = true, features = ["derive"] } codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false } -scale-info = { version = "2.9.0", default-features = false, features = [ "derive" ] } +scale-info = { version = "2.9.0", default-features = false, features = ["derive"] } log = { version = "0.4.20", default-features = false } frame-support = { path = "../../../polkadot-sdk/substrate/frame/support", default-features = false } @@ -25,30 +25,35 @@ snowbridge-core = { path = "../../primitives/core", default-features = false } ethabi = { git = "https://github.com/Snowfork/ethabi-decode.git", package = "ethabi-decode", branch = "master", default-features = false } -hex-literal = { version = "0.4.1" } +hex-literal = { version = "0.4.1" } [dev-dependencies] hex = { package = "rustc-hex", version = "2.1.0" } [features] -default = [ "std" ] +default = ["std"] std = [ - "serde", - "codec/std", - "scale-info/std", - "frame-support/std", - "frame-system/std", - "sp-core/std", - "sp-io/std", - "sp-runtime/std", - "sp-std/std", - "xcm/std", - "xcm-builder/std", - "xcm-executor/std", - "snowbridge-core/std", - "ethabi/std", - "log/std", + "codec/std", + "ethabi/std", + "frame-support/std", + "frame-system/std", + "log/std", + "scale-info/std", + "serde", + "snowbridge-core/std", + "sp-core/std", + "sp-io/std", + "sp-runtime/std", + "sp-std/std", + "xcm-builder/std", + "xcm-executor/std", + "xcm/std", ] runtime-benchmarks = [ - "snowbridge-core/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "snowbridge-core/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", + "xcm-builder/runtime-benchmarks", + "xcm-executor/runtime-benchmarks", ] diff --git a/parachain/primitives/router/src/inbound/mod.rs b/parachain/primitives/router/src/inbound/mod.rs index 398c2bf639..6065a62fbd 100644 --- a/parachain/primitives/router/src/inbound/mod.rs +++ b/parachain/primitives/router/src/inbound/mod.rs @@ -69,7 +69,7 @@ pub enum Destination { AccountId32 { id: [u8; 32] }, /// The funds will deposited into the sovereign account of destination parachain `para_id` on /// AssetHub, Account `id` on the destination parachain will receive the funds via a - /// reserve-backed transfer. See https://github.com/paritytech/xcm-format#depositreserveasset + /// reserve-backed transfer. See ForeignAccountId32 { para_id: u32, id: [u8; 32], @@ -78,7 +78,7 @@ pub enum Destination { }, /// The funds will deposited into the sovereign account of destination parachain `para_id` on /// AssetHub, Account `id` on the destination parachain will receive the funds via a - /// reserve-backed transfer. See https://github.com/paritytech/xcm-format#depositreserveasset + /// reserve-backed transfer. See ForeignAccountId20 { para_id: u32, id: [u8; 20], diff --git a/parachain/primitives/router/src/inbound/tests.rs b/parachain/primitives/router/src/inbound/tests.rs index fb5c83de3f..176784f3e0 100644 --- a/parachain/primitives/router/src/inbound/tests.rs +++ b/parachain/primitives/router/src/inbound/tests.rs @@ -10,7 +10,7 @@ const NETWORK: NetworkId = Ethereum { chain_id: 11155111 }; const SS58_FORMAT: u16 = 2; const EXPECTED_SOVEREIGN_KEY: [u8; 32] = hex!("ce796ae65569a670d0c1cc1ac12515a3ce21b5fbf729d63d7b289baad070139d"); -const EXPECTED_SOVEREIGN_ADDRESS: &'static str = "HF3T62xRQvoCCowYamEQweEyWbD5yt4mkET8UkNWxfMbvJE"; +const EXPECTED_SOVEREIGN_ADDRESS: &str = "HF3T62xRQvoCCowYamEQweEyWbD5yt4mkET8UkNWxfMbvJE"; parameter_types! { pub EthereumNetwork: NetworkId = NETWORK; diff --git a/parachain/primitives/router/src/outbound/tests.rs b/parachain/primitives/router/src/outbound/tests.rs index 0b24a6d4d3..f64ad8698c 100644 --- a/parachain/primitives/router/src/outbound/tests.rs +++ b/parachain/primitives/router/src/outbound/tests.rs @@ -579,7 +579,7 @@ fn xcm_converter_with_different_fee_asset_fails() { let asset_location = X1(AccountKey20 { network: None, key: token_address }).into(); let fee_asset = MultiAsset { - id: Concrete(MultiLocation { parents: 0, interior: Here.into() }), + id: Concrete(MultiLocation { parents: 0, interior: Here }), fun: Fungible(1000), }; diff --git a/parachain/runtime/rococo-common/Cargo.toml b/parachain/runtime/rococo-common/Cargo.toml index c221cd31e1..dede998645 100644 --- a/parachain/runtime/rococo-common/Cargo.toml +++ b/parachain/runtime/rococo-common/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "snowbridge-rococo-common" version = "0.0.1" -authors = [ "Snowfork " ] +authors = ["Snowfork "] edition = "2021" [dependencies] @@ -13,9 +13,12 @@ xcm = { package = "staging-xcm", path = "../../../polkadot-sdk/polkadot/xcm", de [dev-dependencies] [features] -default = [ "std" ] +default = ["std"] std = [ - "frame-support/std", - "xcm/std", + "frame-support/std", + "log/std", + "xcm/std", +] +runtime-benchmarks = [ + "frame-support/runtime-benchmarks", ] -runtime-benchmarks = [] diff --git a/parachain/runtime/runtime-common/Cargo.toml b/parachain/runtime/runtime-common/Cargo.toml index 1d7c9c711c..9182ef2590 100644 --- a/parachain/runtime/runtime-common/Cargo.toml +++ b/parachain/runtime/runtime-common/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "snowbridge-runtime-common" version = "0.1.1" -authors = [ "Snowfork " ] +authors = ["Snowfork "] edition = "2021" [dependencies] @@ -19,18 +19,21 @@ snowbridge-core = { path = "../../primitives/core", default-features = false } [dev-dependencies] [features] -default = [ "std" ] +default = ["std"] std = [ - "frame-support/std", - "frame-system/std", - "sp-arithmetic/std", - "snowbridge-core/std", - "xcm-builder/std", - "xcm-executor/std", - "xcm/std", + "frame-support/std", + "frame-system/std", + "log/std", + "snowbridge-core/std", + "sp-arithmetic/std", + "xcm-builder/std", + "xcm-executor/std", + "xcm/std", ] runtime-benchmarks = [ - "snowbridge-core/runtime-benchmarks", - "xcm-builder/runtime-benchmarks", - "xcm-executor/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "snowbridge-core/runtime-benchmarks", + "xcm-builder/runtime-benchmarks", + "xcm-executor/runtime-benchmarks", ] diff --git a/parachain/runtime/tests/Cargo.toml b/parachain/runtime/tests/Cargo.toml index 6804e917df..da2c1025fc 100644 --- a/parachain/runtime/tests/Cargo.toml +++ b/parachain/runtime/tests/Cargo.toml @@ -93,6 +93,9 @@ sp-keyring = { path = "../../../polkadot-sdk/substrate/primitives/keyring" } [features] default = ["std"] std = [ + "asset-hub-rococo-runtime/std", + "assets-common/std", + "bridge-hub-rococo-runtime/std", "codec/std", "cumulus-pallet-aura-ext/std", "cumulus-pallet-dmp-queue/std", @@ -102,10 +105,6 @@ std = [ "cumulus-pallet-xcmp-queue/std", "cumulus-primitives-core/std", "cumulus-primitives-utility/std", - "bridge-hub-rococo-runtime/std", - "asset-hub-rococo-runtime/std", - "assets-common/std", - "parachains-runtimes-test-utils/std", "frame-benchmarking/std", "frame-executive/std", "frame-support/std", @@ -118,8 +117,8 @@ std = [ "pallet-authorship/std", "pallet-balances/std", "pallet-collator-selection/std", - "pallet-multisig/std", "pallet-message-queue/std", + "pallet-multisig/std", "pallet-session/std", "pallet-timestamp/std", "pallet-transaction-payment-rpc-runtime-api/std", @@ -129,12 +128,22 @@ std = [ "pallet-xcm/std", "parachain-info/std", "parachains-common/std", + "parachains-runtimes-test-utils/std", "polkadot-core-primitives/std", "polkadot-parachain-primitives/std", "polkadot-runtime-common/std", "rococo-runtime-constants/std", "scale-info/std", "serde", + "snowbridge-beacon-primitives/std", + "snowbridge-core/std", + "snowbridge-ethereum-beacon-client/std", + "snowbridge-inbound-queue/std", + "snowbridge-outbound-queue-runtime-api/std", + "snowbridge-outbound-queue/std", + "snowbridge-router-primitives/std", + "snowbridge-system-runtime-api/std", + "snowbridge-system/std", "sp-api/std", "sp-block-builder/std", "sp-consensus-aura/std", @@ -152,31 +161,26 @@ std = [ "xcm-builder/std", "xcm-executor/std", "xcm/std", - "snowbridge-core/std", - "snowbridge-router-primitives/std", - "snowbridge-beacon-primitives/std", - "snowbridge-ethereum-beacon-client/std", - "snowbridge-inbound-queue/std", - "snowbridge-outbound-queue/std", - "snowbridge-outbound-queue-runtime-api/std", - "snowbridge-system/std", - "snowbridge-system-runtime-api/std", ] runtime-benchmarks = [ + "asset-hub-rococo-runtime/runtime-benchmarks", + "assets-common/runtime-benchmarks", + "bridge-hub-rococo-runtime/runtime-benchmarks", + "bridge-runtime-common/runtime-benchmarks", + "cumulus-pallet-dmp-queue/runtime-benchmarks", "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", + "cumulus-primitives-core/runtime-benchmarks", "cumulus-primitives-utility/runtime-benchmarks", - "bridge-hub-rococo-runtime/runtime-benchmarks", - "asset-hub-rococo-runtime/runtime-benchmarks", - "assets-common/runtime-benchmarks", "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system-benchmarking/runtime-benchmarks", "frame-system/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", + "pallet-message-queue/runtime-benchmarks", "pallet-multisig/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-utility/runtime-benchmarks", @@ -185,17 +189,20 @@ runtime-benchmarks = [ "parachains-common/runtime-benchmarks", "polkadot-parachain-primitives/runtime-benchmarks", "polkadot-runtime-common/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", - "xcm-builder/runtime-benchmarks", - "xcm-executor/runtime-benchmarks", "snowbridge-core/runtime-benchmarks", - "snowbridge-system/runtime-benchmarks", + "snowbridge-ethereum-beacon-client/runtime-benchmarks", "snowbridge-inbound-queue/runtime-benchmarks", "snowbridge-outbound-queue/runtime-benchmarks", - "snowbridge-ethereum-beacon-client/runtime-benchmarks", + "snowbridge-router-primitives/runtime-benchmarks", + "snowbridge-system/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", + "xcm-builder/runtime-benchmarks", + "xcm-executor/runtime-benchmarks", ] try-runtime = [ + "asset-hub-rococo-runtime/try-runtime", + "bridge-hub-rococo-runtime/try-runtime", "cumulus-pallet-aura-ext/try-runtime", "cumulus-pallet-dmp-queue/try-runtime", "cumulus-pallet-parachain-system/try-runtime", @@ -209,6 +216,7 @@ try-runtime = [ "pallet-authorship/try-runtime", "pallet-balances/try-runtime", "pallet-collator-selection/try-runtime", + "pallet-message-queue/try-runtime", "pallet-multisig/try-runtime", "pallet-session/try-runtime", "pallet-timestamp/try-runtime", @@ -217,6 +225,10 @@ try-runtime = [ "pallet-xcm/try-runtime", "parachain-info/try-runtime", "polkadot-runtime-common/try-runtime", + "snowbridge-ethereum-beacon-client/try-runtime", + "snowbridge-inbound-queue/try-runtime", + "snowbridge-outbound-queue/try-runtime", + "snowbridge-system/try-runtime", "sp-runtime/try-runtime", ] beacon-spec-mainnet = [