diff --git a/bridges/modules/relayers/src/lib.rs b/bridges/modules/relayers/src/lib.rs index 738495ff2d55..4069678fbf4e 100644 --- a/bridges/modules/relayers/src/lib.rs +++ b/bridges/modules/relayers/src/lib.rs @@ -439,21 +439,21 @@ pub mod pallet { if value.is_zero() { return Err(Error::::InsufficientFunds.into()); } - let reward_asset = snowbridge_core::location::convert_token_address( - T::EthereumNetwork::get(), - T::WethAddress::get(), - ); let reward_balance: u128 = TryInto::::try_into(value).map_err(|_| Error::::InvalidAmount)?; - let deposit: Asset = (reward_asset, reward_balance).into(); - let asset_hub_fee_asset: Asset = (Location::parent(), T::AssetHubXCMFee::get()).into(); + let reward_location = snowbridge_core::location::convert_token_address( + T::EthereumNetwork::get(), + T::WethAddress::get(), + ); + let reward_asset: Asset = (reward_location.clone(), reward_balance).into(); + let fee_asset: Asset = (reward_location, T::AssetHubXCMFee::get()).into(); let xcm: Xcm<()> = alloc::vec![ DescendOrigin(PalletInstance(T::InboundQueuePalletInstance::get()).into()), UniversalOrigin(GlobalConsensus(T::EthereumNetwork::get())), - ReserveAssetDeposited(deposit.clone().into()), - BuyExecution { fees: asset_hub_fee_asset, weight_limit: Unlimited }, + ReserveAssetDeposited(reward_asset.clone().into()), + BuyExecution { fees: fee_asset, weight_limit: Unlimited }, DepositAsset { assets: AllCounted(1).into(), beneficiary: deposit_location.clone() }, SetAppendix(Xcm(alloc::vec![ RefundSurplus, diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/src/lib.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/src/lib.rs index e92d1c46ccbd..075fd84492e9 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/src/lib.rs @@ -47,8 +47,8 @@ decl_test_parachains! { PolkadotXcm: bridge_hub_westend_runtime::PolkadotXcm, Balances: bridge_hub_westend_runtime::Balances, EthereumSystem: bridge_hub_westend_runtime::EthereumSystem, - EthereumRewards: bridge_hub_westend_runtime::EthereumRewards, EthereumInboundQueue: bridge_hub_westend_runtime::EthereumInboundQueue, + BridgeRelayers: bridge_hub_westend_runtime::BridgeRelayers, } }, } diff --git a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_v2.rs b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_v2.rs index 77b28506a1db..423c764620a1 100644 --- a/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_v2.rs +++ b/cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-westend/src/tests/snowbridge_v2.rs @@ -18,9 +18,7 @@ use hex_literal::hex; use snowbridge_core::rewards::RewardLedger; use snowbridge_router_primitives::inbound::{ v1::{Command, Destination, MessageV1, VersionedMessage}, - GlobalConsensusEthereumConvertsFor, }; -use sp_core::H256; use testnet_parachains_constants::westend::snowbridge::EthereumNetwork; const INITIAL_FUND: u128 = 5_000_000_000_000; @@ -193,23 +191,21 @@ fn claim_rewards_works() { let relayer = BridgeHubWestendSender::get(); let reward_address = AssetHubWestendReceiver::get(); - type EthereumRewards = ::EthereumRewards; - assert_ok!(EthereumRewards::deposit(relayer.clone().into(), 2 * ETH)); + type BridgeRelayers = ::BridgeRelayers; + assert_ok!(BridgeRelayers::deposit(relayer.clone().into(), 2 * ETH)); // Check that the message was sent assert_expected_events!( BridgeHubWestend, vec![ - RuntimeEvent::EthereumRewards(snowbridge_pallet_rewards::Event::RewardDeposited { .. }) => {}, + RuntimeEvent::BridgeRelayers(pallet_bridge_relayers::Event::RewardDeposited { .. }) => {}, ] ); - let message_id = H256::random(); - let result = EthereumRewards::claim( + let relayer_location = Location::new(1, [Parachain(1000), Junction::AccountId32{ id: reward_address.into(), network: None}]); + let result = BridgeRelayers::claim( RuntimeOrigin::signed(relayer.clone()), - reward_address.clone(), - ETH, - message_id, + relayer_location.clone(), ); assert_ok!(result); @@ -217,8 +213,8 @@ fn claim_rewards_works() { assert!( events.iter().any(|event| matches!( event, - RuntimeEvent::EthereumRewards(snowbridge_pallet_rewards::Event::RewardClaimed { account_id, deposit_address, value, message_id: _ }) - if *account_id == relayer && *deposit_address == reward_address && *value == ETH, + RuntimeEvent::BridgeRelayers(pallet_bridge_relayers::Event::RewardClaimed { account_id, deposit_location, value, }) + if *account_id == relayer && *deposit_location == relayer_location && *value > 1 *ETH, )), "RewardClaimed event with correct fields." ); @@ -232,40 +228,3 @@ fn claim_rewards_works() { ); }) } - -#[test] -fn claiming_more_than_accrued_rewards_errors() { - BridgeHubWestend::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - type RuntimeOrigin = ::RuntimeOrigin; - - let relayer = BridgeHubWestendSender::get(); - let reward_address = AssetHubWestendReceiver::get(); - type EthereumRewards = ::EthereumRewards; - assert_ok!(EthereumRewards::deposit(relayer.clone().into(), 2 * ETH)); - - // Check that the message was sent - assert_expected_events!( - BridgeHubWestend, - vec![ - RuntimeEvent::EthereumRewards(snowbridge_pallet_rewards::Event::RewardDeposited { .. }) => {}, - ] - ); - - let message_id = H256::random(); - let result = EthereumRewards::claim( - RuntimeOrigin::signed(relayer.clone()), - reward_address.clone(), - 3 * ETH, - message_id, - ); - assert_err!( - result, - DispatchError::Module(sp_runtime::ModuleError { - index: 86, - error: [1, 0, 0, 0], - message: Some("InsufficientFunds") - }) - ); - }); -} diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_common_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_common_config.rs index 5dca45d326b8..9f4b3233aaa1 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_common_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/bridge_common_config.rs @@ -24,6 +24,12 @@ use super::{weights, AccountId, Balance, Balances, BlockNumber, Runtime, RuntimeEvent}; use bp_parachains::SingleParaStoredHeaderDataBuilder; use frame_support::{parameter_types, traits::ConstU32}; +use testnet_parachains_constants::rococo::snowbridge::EthereumNetwork; +use sp_core::H160; +use crate::xcm_config; +use crate::XcmRouter; +use sp_runtime::traits::ConstU128; +use sp_runtime::traits::ConstU8; parameter_types! { pub const RelayChainHeadersToKeep: u32 = 1024; @@ -83,6 +89,17 @@ impl pallet_bridge_relayers::Config fo >; type WeightInfo = weights::pallet_bridge_relayers::WeightInfo; type LaneId = bp_messages::LegacyLaneId; + type AssetHubParaId = ConstU32; + type EthereumNetwork = EthereumNetwork; + type WethAddress = WethAddress; + #[cfg(not(feature = "runtime-benchmarks"))] + type XcmSender = XcmRouter; + #[cfg(feature = "runtime-benchmarks")] + type XcmSender = DoNothingRouter; + type Token = Balances; + type AssetTransactor = ::AssetTransactor; + type InboundQueuePalletInstance = ConstU8<80>; + type AssetHubXCMFee = ConstU128<1_000_000_000_000>; } /// Allows collect and claim rewards for relayers @@ -105,8 +122,26 @@ impl pallet_bridge_relayers::Config for >; type WeightInfo = weights::pallet_bridge_relayers::WeightInfo; type LaneId = bp_messages::HashedLaneId; + type AssetHubParaId = ConstU32; + type EthereumNetwork = EthereumNetwork; + type WethAddress = WethAddress; + #[cfg(not(feature = "runtime-benchmarks"))] + type XcmSender = XcmRouter; + #[cfg(feature = "runtime-benchmarks")] + type XcmSender = DoNothingRouter; + type Token = Balances; + type AssetTransactor = ::AssetTransactor; + type InboundQueuePalletInstance = ConstU8<80>; + type AssetHubXCMFee = ConstU128<1_000_000_000_000>; } +parameter_types! { + pub WethAddress: H160 = H160(hex_literal::hex!("fff9976782d46cc05630d1f6ebab18b2324d6b14")); +} + +pub const ASSET_HUB_ID: u32 = rococo_runtime_constants::system_parachain::ASSET_HUB_ID; + + /// Add GRANDPA bridge pallet to track Rococo Bulletin chain. pub type BridgeGrandpaRococoBulletinInstance = pallet_bridge_grandpa::Instance4; impl pallet_bridge_grandpa::Config for Runtime { diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/pallet_bridge_relayers.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/pallet_bridge_relayers.rs index b7318361c7d9..f951797537c7 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/pallet_bridge_relayers.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/pallet_bridge_relayers.rs @@ -120,4 +120,13 @@ impl pallet_bridge_relayers::WeightInfo for WeightInfo< .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } + fn claim() -> Weight { + // Proof Size summary in bytes: + // Measured: `80` + // Estimated: `3517` + // Minimum execution time: 44_000_000 picoseconds. + Weight::from_parts(44_000_000, 3517) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/bridge_common_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/bridge_common_config.rs index 0872d0498f85..ae026be7ba92 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/bridge_common_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/bridge_common_config.rs @@ -24,6 +24,13 @@ use super::{weights, AccountId, Balance, Balances, BlockNumber, Runtime, RuntimeEvent}; use bp_messages::LegacyLaneId; use frame_support::parameter_types; +use sp_core::H160; +use testnet_parachains_constants::westend::snowbridge::EthereumNetwork; +use crate::XcmRouter; +use crate::xcm_config; +use sp_runtime::traits::ConstU32; +use sp_runtime::traits::ConstU128; +use sp_runtime::traits::ConstU8; parameter_types! { pub storage RequiredStakeForStakeAndSlash: Balance = 1_000_000; @@ -33,6 +40,12 @@ parameter_types! { pub storage DeliveryRewardInBalance: u64 = 1_000_000; } +parameter_types! { + pub WethAddress: H160 = H160(hex_literal::hex!("fff9976782d46cc05630d1f6ebab18b2324d6b14")); +} + +pub const ASSET_HUB_ID: u32 = westend_runtime_constants::system_parachain::ASSET_HUB_ID; + /// Allows collect and claim rewards for relayers pub type RelayersForLegacyLaneIdsMessagesInstance = (); impl pallet_bridge_relayers::Config for Runtime { @@ -53,4 +66,16 @@ impl pallet_bridge_relayers::Config fo >; type WeightInfo = weights::pallet_bridge_relayers::WeightInfo; type LaneId = LegacyLaneId; + + type AssetHubParaId = ConstU32; + type EthereumNetwork = EthereumNetwork; + type WethAddress = WethAddress; + #[cfg(not(feature = "runtime-benchmarks"))] + type XcmSender = XcmRouter; + #[cfg(feature = "runtime-benchmarks")] + type XcmSender = DoNothingRouter; + type Token = Balances; + type AssetTransactor = ::AssetTransactor; + type InboundQueuePalletInstance = ConstU8<80>; + type AssetHubXCMFee = ConstU128<1_000_000_000_000>; } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/bridge_to_ethereum_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/bridge_to_ethereum_config.rs index 6fece1520fe4..0b6bd0c85764 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/bridge_to_ethereum_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/bridge_to_ethereum_config.rs @@ -16,11 +16,12 @@ #[cfg(not(feature = "runtime-benchmarks"))] use crate::XcmRouter; +use crate::BridgeRelayers; use crate::{ xcm_config, xcm_config::{TreasuryAccount, UniversalLocation}, Balances, EthereumInboundQueue, EthereumOutboundQueue, EthereumSystem, MessageQueue, Runtime, - RuntimeEvent, TransactionByteFee, EthereumRewards + RuntimeEvent, TransactionByteFee, }; use parachains_common::{AccountId, Balance}; use snowbridge_beacon_primitives::{Fork, ForkVersions}; @@ -35,6 +36,7 @@ use testnet_parachains_constants::westend::{ fee::WeightToFee, snowbridge::{EthereumLocation, EthereumNetwork, INBOUND_QUEUE_PALLET_INDEX}, }; +use sp_runtime::traits::ConstU8; use crate::xcm_config::RelayNetwork; #[cfg(feature = "runtime-benchmarks")] @@ -42,7 +44,7 @@ use benchmark_helpers::DoNothingRouter; use frame_support::{parameter_types, weights::ConstantMultiplier}; use pallet_xcm::EnsureXcm; use sp_runtime::{ - traits::{ConstU32, ConstU8, Keccak256}, + traits::{ConstU32, Keccak256}, FixedU128, }; use xcm::prelude::{GlobalConsensus, InteriorLocation, Location, Parachain}; @@ -123,7 +125,7 @@ impl snowbridge_pallet_inbound_queue_v2::Config for Runtime { type GatewayAddress = EthereumGatewayAddress; #[cfg(feature = "runtime-benchmarks")] type Helper = Runtime; - type RewardLedger = EthereumRewards; + type RewardLedger = BridgeRelayers; type Token = Balances; type WeightInfo = crate::weights::snowbridge_pallet_inbound_queue_v2::WeightInfo; } @@ -154,10 +156,9 @@ impl snowbridge_pallet_outbound_queue_v2::Config for Runtime { type WeightToFee = WeightToFee; type Verifier = snowbridge_pallet_ethereum_client::Pallet; type GatewayAddress = EthereumGatewayAddress; - type RewardLedger = EthereumRewards; + type RewardLedger = BridgeRelayers; type Token = Balances; type WeightInfo = crate::weights::snowbridge_pallet_outbound_queue_v2::WeightInfo; - type RewardLedger = (); } #[cfg(any(feature = "std", feature = "fast-runtime", feature = "runtime-benchmarks", test))] @@ -235,26 +236,6 @@ impl snowbridge_pallet_system::Config for Runtime { type EthereumLocation = EthereumLocation; } -parameter_types! { - pub WethAddress: H160 = H160(hex_literal::hex!("fff9976782d46cc05630d1f6ebab18b2324d6b14")); -} - -pub const ASSET_HUB_ID: u32 = westend_runtime_constants::system_parachain::ASSET_HUB_ID; - -impl snowbridge_pallet_rewards::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type AssetHubParaId = ConstU32; - type EthereumNetwork = EthereumNetwork; - type WethAddress = WethAddress; - #[cfg(not(feature = "runtime-benchmarks"))] - type XcmSender = XcmRouter; - #[cfg(feature = "runtime-benchmarks")] - type XcmSender = DoNothingRouter; - type WeightInfo = (); // TODO generate weights - type Token = Balances; - type AssetTransactor = ::AssetTransactor; -} - #[cfg(feature = "runtime-benchmarks")] pub mod benchmark_helpers { use crate::{EthereumBeaconClient, Runtime, RuntimeOrigin}; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs index 0782ea874793..38cbe2337a32 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs @@ -559,7 +559,6 @@ construct_runtime!( EthereumSystem: snowbridge_pallet_system = 83, EthereumInboundQueueV2: snowbridge_pallet_inbound_queue_v2 = 84, EthereumOutboundQueueV2: snowbridge_pallet_outbound_queue_v2 = 85, - EthereumRewards: snowbridge_pallet_rewards = 86, // Message Queue. Importantly, is registered last so that messages are processed after // the `on_initialize` hooks of bridging pallets. diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/pallet_bridge_relayers.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/pallet_bridge_relayers.rs index 74be73df1403..98ebb57f2273 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/pallet_bridge_relayers.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/pallet_bridge_relayers.rs @@ -120,4 +120,13 @@ impl pallet_bridge_relayers::WeightInfo for WeightInfo< .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } + fn claim() -> Weight { + // Proof Size summary in bytes: + // Measured: `80` + // Estimated: `3517` + // Minimum execution time: 44_000_000 picoseconds. + Weight::from_parts(44_000_000, 3517) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } }