From a7954aa86bcd3de29180a231d2e2503f13f0570c Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Thu, 14 Dec 2023 16:11:46 +0200 Subject: [PATCH 1/2] add gateway to storage --- Cargo.lock | 147 +----------------- .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 4 +- .../bridge-hub-rococo/src/xcm_config.rs | 10 +- .../bridge-hub-rococo/tests/tests.rs | 22 ++- 4 files changed, 28 insertions(+), 155 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 18424c32793c..9fdab2cb0a0b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2941,16 +2941,6 @@ dependencies = [ "windows-sys 0.45.0", ] -[[package]] -name = "console_error_panic_hook" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" -dependencies = [ - "cfg-if", - "wasm-bindgen", -] - [[package]] name = "const-hex" version = "1.10.0" @@ -4924,7 +4914,7 @@ dependencies = [ [[package]] name = "ethabi-decode" version = "1.4.0" -source = "git+https://github.com/snowfork/ethabi-decode.git?branch=master#7d215837b626650bd9a076821e57ad488101301f" +source = "git+https://github.com/Snowfork/ethabi-decode.git?branch=master#7d215837b626650bd9a076821e57ad488101301f" dependencies = [ "ethereum-types", "tiny-keccak", @@ -16455,12 +16445,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "scoped-tls" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" - [[package]] name = "scopeguard" version = "1.2.0" @@ -17136,7 +17120,6 @@ dependencies = [ "frame-support", "frame-system", "hex", - "hex-literal", "milagro_bls", "parity-scale-codec", "rlp", @@ -17159,7 +17142,6 @@ dependencies = [ "ethabi-decode", "frame-support", "frame-system", - "hex", "hex-literal", "parity-scale-codec", "polkadot-parachain-primitives", @@ -17185,18 +17167,15 @@ dependencies = [ "hex-literal", "parity-bytes", "parity-scale-codec", - "rand 0.8.5", "rlp", "rustc-hex", "scale-info", "serde", "serde-big-array", - "serde_json", "sp-core", "sp-io", "sp-runtime", "sp-std 8.0.0", - "wasm-bindgen-test", ] [[package]] @@ -17212,17 +17191,14 @@ dependencies = [ "log", "pallet-timestamp", "parity-scale-codec", - "rand 0.8.5", "rlp", "scale-info", "serde", - "serde_json", "snowbridge-beacon-primitives", "snowbridge-core", "snowbridge-ethereum", "sp-core", "sp-io", - "sp-keyring", "sp-runtime", "sp-std 8.0.0", "ssz_rs", @@ -17250,11 +17226,9 @@ dependencies = [ "snowbridge-beacon-primitives", "snowbridge-core", "snowbridge-ethereum", - "snowbridge-ethereum-beacon-client", "snowbridge-router-primitives", "sp-core", "sp-io", - "sp-keyring", "sp-runtime", "sp-std 8.0.0", "staging-xcm", @@ -17271,7 +17245,6 @@ dependencies = [ "frame-support", "frame-system", "hex-literal", - "pallet-message-queue", "parity-scale-codec", "scale-info", "serde", @@ -17280,7 +17253,6 @@ dependencies = [ "sp-arithmetic", "sp-core", "sp-io", - "sp-keyring", "sp-runtime", "sp-std 8.0.0", "staging-xcm", @@ -17290,10 +17262,6 @@ dependencies = [ name = "snowbridge-outbound-queue-merkle-tree" version = "0.1.1" dependencies = [ - "array-bytes 4.2.0", - "env_logger 0.9.3", - "hex", - "hex-literal", "parity-scale-codec", "scale-info", "sp-core", @@ -17333,7 +17301,6 @@ dependencies = [ "hex-literal", "log", "parity-scale-codec", - "rustc-hex", "scale-info", "serde", "snowbridge-core", @@ -17360,86 +17327,6 @@ dependencies = [ "staging-xcm-executor", ] -[[package]] -name = "snowbridge-runtime-tests" -version = "0.1.0" -dependencies = [ - "asset-hub-rococo-runtime", - "assets-common", - "bridge-hub-rococo-runtime", - "bridge-hub-test-utils", - "bridge-runtime-common", - "cumulus-pallet-aura-ext", - "cumulus-pallet-dmp-queue", - "cumulus-pallet-parachain-system", - "cumulus-pallet-session-benchmarking", - "cumulus-pallet-xcm", - "cumulus-pallet-xcmp-queue", - "cumulus-primitives-core", - "cumulus-primitives-utility", - "frame-benchmarking", - "frame-executive", - "frame-support", - "frame-system", - "frame-system-benchmarking", - "frame-system-rpc-runtime-api", - "frame-try-runtime", - "hex-literal", - "log", - "pallet-aura", - "pallet-authorship", - "pallet-balances", - "pallet-collator-selection", - "pallet-message-queue", - "pallet-multisig", - "pallet-session", - "pallet-timestamp", - "pallet-transaction-payment", - "pallet-transaction-payment-rpc-runtime-api", - "pallet-utility", - "pallet-xcm", - "pallet-xcm-benchmarks", - "parachains-common", - "parachains-runtimes-test-utils", - "parity-scale-codec", - "polkadot-core-primitives", - "polkadot-parachain-primitives", - "polkadot-runtime-common", - "rococo-runtime-constants", - "scale-info", - "serde", - "smallvec", - "snowbridge-beacon-primitives", - "snowbridge-core", - "snowbridge-ethereum-beacon-client", - "snowbridge-inbound-queue", - "snowbridge-outbound-queue", - "snowbridge-outbound-queue-runtime-api", - "snowbridge-router-primitives", - "snowbridge-system", - "snowbridge-system-runtime-api", - "sp-api", - "sp-block-builder", - "sp-consensus-aura", - "sp-core", - "sp-genesis-builder", - "sp-inherents", - "sp-io", - "sp-keyring", - "sp-offchain", - "sp-runtime", - "sp-session", - "sp-std 8.0.0", - "sp-storage 13.0.0", - "sp-transaction-pool", - "sp-version", - "staging-parachain-info", - "staging-xcm", - "staging-xcm-builder", - "staging-xcm-executor", - "static_assertions", -] - [[package]] name = "snowbridge-system" version = "0.1.1" @@ -17448,19 +17335,12 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", - "hex", - "hex-literal", "log", - "pallet-balances", - "pallet-message-queue", "parity-scale-codec", - "polkadot-primitives", "scale-info", "snowbridge-core", - "snowbridge-outbound-queue", "sp-core", "sp-io", - "sp-keyring", "sp-runtime", "sp-std 8.0.0", "staging-xcm", @@ -20572,31 +20452,6 @@ version = "0.2.89" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" -[[package]] -name = "wasm-bindgen-test" -version = "0.3.39" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cf9242c0d27999b831eae4767b2a146feb0b27d332d553e605864acd2afd403" -dependencies = [ - "console_error_panic_hook", - "js-sys", - "scoped-tls", - "wasm-bindgen", - "wasm-bindgen-futures", - "wasm-bindgen-test-macro", -] - -[[package]] -name = "wasm-bindgen-test-macro" -version = "0.3.39" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "794645f5408c9a039fd09f4d113cdfb2e7eba5ff1956b07bcf701cf4b394fe89" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.41", -] - [[package]] name = "wasm-encoder" version = "0.38.1" diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 8544a6c9b842..d7885e33b916 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -490,7 +490,7 @@ impl pallet_utility::Config for Runtime { parameter_types! { pub const Reward: u128 = 10; - pub const GatewayAddress: H160 = H160(hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39")); + pub storage EthereumGatewayAddress: H160 = H160(hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39")); pub const CreateAssetCall: [u8;2] = [53, 0]; pub const CreateAssetDeposit: u128 = (UNITS / 10) + EXISTENTIAL_DEPOSIT; pub const InboundQueuePalletInstance: u8 = snowbridge_rococo_common::INBOUND_QUEUE_MESSAGES_PALLET_INDEX; @@ -517,7 +517,7 @@ impl snowbridge_inbound_queue::Config for Runtime { #[cfg(feature = "runtime-benchmarks")] type XcmSender = DoNothingRouter; type ChannelLookup = EthereumSystem; - type GatewayAddress = GatewayAddress; + type GatewayAddress = EthereumGatewayAddress; #[cfg(feature = "runtime-benchmarks")] type Helper = Runtime; type MessageConverter = MessageToXcm< diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs index ab1574bf6f59..4c3450b4414c 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs @@ -26,6 +26,7 @@ use crate::{ }, bridge_to_bulletin_config::WithRococoBulletinMessagesInstance, bridge_to_westend_config::WithBridgeHubWestendMessagesInstance, + EthereumGatewayAddress, }; use bp_messages::LaneId; use bp_relayers::{PayRewardFromAccount, RewardsAccountOwner, RewardsAccountParams}; @@ -160,10 +161,11 @@ impl Contains for SafeCallFilter { // Allow to change dedicated storage items (called by governance-like) match call { RuntimeCall::System(frame_system::Call::set_storage { items }) - if items.iter().all(|(k, _)| { - k.eq(&DeliveryRewardInBalance::key()) | - k.eq(&RequiredStakeForStakeAndSlash::key()) - }) => + if items.iter().all(|(k, _)| { + k.eq(&DeliveryRewardInBalance::key()) | + k.eq(&RequiredStakeForStakeAndSlash::key()) | + k.eq(&EthereumGatewayAddress::key()) + }) => return true, _ => (), }; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/tests.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/tests.rs index 0ba5fb37aef0..eda09db396f9 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/tests.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/tests.rs @@ -20,13 +20,14 @@ use bp_polkadot_core::Signature; use bridge_hub_rococo_runtime::{ bridge_common_config, bridge_to_bulletin_config, bridge_to_westend_config, xcm_config::{RelayNetwork, TokenLocation, XcmConfig}, - AllPalletsWithoutSystem, BridgeRejectObsoleteHeadersAndMessages, Executive, ExistentialDeposit, - ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, SessionKeys, - SignedExtra, TransactionPayment, UncheckedExtrinsic, + AllPalletsWithoutSystem, BridgeRejectObsoleteHeadersAndMessages, EthereumGatewayAddress, + Executive, ExistentialDeposit, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, + RuntimeEvent, SessionKeys, SignedExtra, TransactionPayment, UncheckedExtrinsic, }; use codec::{Decode, Encode}; use frame_support::{dispatch::GetDispatchInfo, parameter_types, traits::ConstU8}; use parachains_common::{rococo::fee::WeightToFee, AccountId, AuraId, Balance}; +use sp_core::H160; use sp_keyring::AccountKeyring::Alice; use sp_runtime::{ generic::{Era, SignedPayload}, @@ -182,6 +183,21 @@ mod bridge_hub_westend_tests { >(collator_session_keys(), bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID) } + #[test] + fn change_ethereum_gateway_by_governance_works() { + bridge_hub_test_utils::test_cases::change_storage_constant_by_governance_works::< + Runtime, + EthereumGatewayAddress, + H160, + >( + collator_session_keys(), + bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID, + Box::new(|call| RuntimeCall::System(call).encode()), + || (EthereumGatewayAddress::key().to_vec(), EthereumGatewayAddress::get()), + |_| H160::default(), + ) + } + #[test] fn change_delivery_reward_by_governance_works() { bridge_hub_test_utils::test_cases::change_storage_constant_by_governance_works::< From a6e6647937057bba0118ebfb8a7ba30d08b5d23f Mon Sep 17 00:00:00 2001 From: Alistair Singh Date: Fri, 15 Dec 2023 01:45:03 +0200 Subject: [PATCH 2/2] fix benchmarks --- .../runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index d7885e33b916..8d679ce3c0c6 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -488,9 +488,18 @@ impl pallet_utility::Config for Runtime { // Ethereum Bridge +#[cfg(not(feature = "runtime-benchmarks"))] +parameter_types! { + pub storage EthereumGatewayAddress: H160 = H160::zero(); +} + +#[cfg(feature = "runtime-benchmarks")] parameter_types! { - pub const Reward: u128 = 10; pub storage EthereumGatewayAddress: H160 = H160(hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39")); +} + +parameter_types! { + pub const Reward: u128 = 10; pub const CreateAssetCall: [u8;2] = [53, 0]; pub const CreateAssetDeposit: u128 = (UNITS / 10) + EXISTENTIAL_DEPOSIT; pub const InboundQueuePalletInstance: u8 = snowbridge_rococo_common::INBOUND_QUEUE_MESSAGES_PALLET_INDEX;