diff --git a/bridges/snowbridge/pallets/outbound-queue-v2/src/lib.rs b/bridges/snowbridge/pallets/outbound-queue-v2/src/lib.rs index b0c2708a0e096..59e35085dd079 100644 --- a/bridges/snowbridge/pallets/outbound-queue-v2/src/lib.rs +++ b/bridges/snowbridge/pallets/outbound-queue-v2/src/lib.rs @@ -97,7 +97,7 @@ use sp_runtime::{ DigestItem, }; use sp_std::prelude::*; -pub use types::{PendingOrder, ProcessMessageOriginOf}; +pub use types::{OnNewCommitment, PendingOrder, ProcessMessageOriginOf}; pub use weights::WeightInfo; use xcm::prelude::NetworkId; @@ -137,6 +137,9 @@ pub mod pallet { #[pallet::constant] type MaxMessagesPerBlock: Get; + /// Hook that is called whenever there is a new commitment. + type OnNewCommitment: OnNewCommitment; + /// Convert a weight value into a deductible fee based. type WeightToFee: WeightToFee; @@ -321,6 +324,8 @@ pub mod pallet { // Insert merkle root into the header digest >::deposit_log(digest_item); + T::OnNewCommitment::on_new_commitment(root); + Self::deposit_event(Event::MessagesCommitted { root, count }); } diff --git a/bridges/snowbridge/pallets/outbound-queue-v2/src/mock.rs b/bridges/snowbridge/pallets/outbound-queue-v2/src/mock.rs index 2250d9f56eb13..01b9a9eb3d232 100644 --- a/bridges/snowbridge/pallets/outbound-queue-v2/src/mock.rs +++ b/bridges/snowbridge/pallets/outbound-queue-v2/src/mock.rs @@ -116,6 +116,7 @@ impl crate::Config for Test { type EthereumNetwork = EthereumNetwork; type RewardKind = BridgeReward; type DefaultRewardKind = DefaultMyRewardKind; + type OnNewCommitment = (); #[cfg(feature = "runtime-benchmarks")] type Helper = Test; } diff --git a/bridges/snowbridge/pallets/outbound-queue-v2/src/types.rs b/bridges/snowbridge/pallets/outbound-queue-v2/src/types.rs index d16cd031e6188..b001381d0e642 100644 --- a/bridges/snowbridge/pallets/outbound-queue-v2/src/types.rs +++ b/bridges/snowbridge/pallets/outbound-queue-v2/src/types.rs @@ -5,6 +5,7 @@ use codec::{Decode, Encode, MaxEncodedLen}; use frame_support::traits::ProcessMessage; use scale_info::TypeInfo; pub use snowbridge_merkle_tree::MerkleProof; +use sp_core::H256; use sp_runtime::RuntimeDebug; use sp_std::prelude::*; @@ -21,3 +22,12 @@ pub struct PendingOrder { #[codec(compact)] pub fee: u128, } + +/// Hook that will be called when a new message commitment is constructed. +pub trait OnNewCommitment { + fn on_new_commitment(commitment: H256); +} + +impl OnNewCommitment for () { + fn on_new_commitment(_commitment: H256) {} +} 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 7982b3a61f792..e40704ce132f3 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 @@ -192,6 +192,8 @@ impl snowbridge_pallet_outbound_queue_v2::Config for Runtime { type RewardKind = BridgeReward; type DefaultRewardKind = SnowbridgeReward; type RewardPayment = BridgeRelayers; + // No consumers of this notifier on Bridge Hub. + type OnNewCommitment = (); #[cfg(feature = "runtime-benchmarks")] type Helper = Runtime; } diff --git a/prdoc/pr_8053.prdoc b/prdoc/pr_8053.prdoc new file mode 100644 index 0000000000000..6d58dbcf5194a --- /dev/null +++ b/prdoc/pr_8053.prdoc @@ -0,0 +1,10 @@ +title: Add `OnNewCommitment` hook to outbound-queue pallet +doc: +- audience: Runtime Dev + description: |- + Add a simple hook to outbound-queue-v2 pallet which allows to perform actions whenever there is a new commitment. +crates: +- name: snowbridge-pallet-outbound-queue-v2 + bump: major +- name: bridge-hub-westend-runtime + bump: major