Skip to content

Commit

Permalink
Add new commitment hook (#6)
Browse files Browse the repository at this point in the history
* add on_new_commitment hook
  • Loading branch information
ParthDesai authored and tmpolaczyk committed Jan 8, 2025
1 parent 9263aff commit e18209b
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bridges/snowbridge/pallets/outbound-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ use sp_runtime::{
DigestItem, Saturating,
};
use sp_std::prelude::*;
pub use types::{CommittedMessage, ProcessMessageOriginOf};
pub use types::{CommittedMessage, ProcessMessageOriginOf, OnNewCommitment};
pub use weights::WeightInfo;

pub use pallet::*;
Expand Down Expand Up @@ -171,6 +171,8 @@ pub mod pallet {

type PricingParameters: Get<PricingParameters<Self::Balance>>;

type OnNewCommitment: OnNewCommitment;

/// Convert a weight value into a deductible fee based.
type WeightToFee: WeightToFee<Balance = Self::Balance>;

Expand Down Expand Up @@ -292,6 +294,8 @@ pub mod pallet {
// Create merkle root of messages
let root = merkle_root::<<T as Config>::Hashing, _>(MessageLeaves::<T>::stream_iter());

T::OnNewCommitment::on_new_commitment(root);

let digest_item: DigestItem = CustomDigestItem::Snowbridge(root).into();

// Insert merkle root into the header digest
Expand Down
1 change: 1 addition & 0 deletions bridges/snowbridge/pallets/outbound-queue/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ impl crate::Config for Test {
type PricingParameters = Parameters;
type Channels = Everything;
type WeightToFee = IdentityFee<u128>;
type OnNewCommitment = ();
type WeightInfo = ();
}

Expand Down
10 changes: 10 additions & 0 deletions bridges/snowbridge/pallets/outbound-queue/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,13 @@ impl From<CommittedMessage> for Token {
])
}
}


/// Hook that will be called when new message commitment is constructed
pub trait OnNewCommitment {
fn on_new_commitment(commitment: H256);
}

impl OnNewCommitment for () {
fn on_new_commitment(_commitment: H256) {}
}
1 change: 1 addition & 0 deletions bridges/snowbridge/pallets/system/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ impl snowbridge_pallet_outbound_queue::Config for Test {
type PricingParameters = EthereumSystem;
type Channels = EthereumSystem;
type WeightToFee = IdentityFee<u128>;
type OnNewCommitment = ();
type WeightInfo = ();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ impl snowbridge_pallet_outbound_queue::Config for Runtime {
type Channels = EthereumSystem;
type AggregateMessageOrigin = AggregateMessageOrigin;
type GetAggregateMessageOrigin = GetAggregateMessageOrigin;
type OnNewCommitment = ();
}

#[cfg(any(feature = "std", feature = "fast-runtime", feature = "runtime-benchmarks", test))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ impl snowbridge_pallet_outbound_queue::Config for Runtime {
type Channels = EthereumSystem;
type AggregateMessageOrigin = AggregateMessageOrigin;
type GetAggregateMessageOrigin = GetAggregateMessageOrigin;
type OnNewCommitment = ();
}

#[cfg(any(feature = "std", feature = "fast-runtime", feature = "runtime-benchmarks", test))]
Expand Down

0 comments on commit e18209b

Please sign in to comment.