Skip to content

Commit

Permalink
Add events to the bridge parachains pallet (paritytech#1568)
Browse files Browse the repository at this point in the history
* add events to the bridge parachains pallet

* clippy + spellcheck

* fix compilation

* untracked is not a word?
  • Loading branch information
svyatonik authored and serban300 committed Apr 9, 2024
1 parent 79752e1 commit 4f3f574
Show file tree
Hide file tree
Showing 4 changed files with 275 additions and 17 deletions.
6 changes: 4 additions & 2 deletions bridges/bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ parameter_types! {
pub type WithRialtoParachainsInstance = ();

impl pallet_bridge_parachains::Config<WithRialtoParachainsInstance> for Runtime {
type Event = Event;
type WeightInfo = pallet_bridge_parachains::weights::MillauWeight<Runtime>;
type BridgesGrandpaPalletInstance = RialtoGrandpaInstance;
type ParasPalletName = RialtoParasPalletName;
Expand All @@ -551,6 +552,7 @@ impl pallet_bridge_parachains::Config<WithRialtoParachainsInstance> for Runtime
pub type WithWestendParachainsInstance = pallet_bridge_parachains::Instance1;

impl pallet_bridge_parachains::Config<WithWestendParachainsInstance> for Runtime {
type Event = Event;
type WeightInfo = pallet_bridge_parachains::weights::MillauWeight<Runtime>;
type BridgesGrandpaPalletInstance = WestendGrandpaInstance;
type ParasPalletName = WestendParasPalletName;
Expand Down Expand Up @@ -592,10 +594,10 @@ construct_runtime!(

// Westend bridge modules.
BridgeWestendGrandpa: pallet_bridge_grandpa::<Instance1>::{Pallet, Call, Config<T>, Storage},
BridgeWestendParachains: pallet_bridge_parachains::<Instance1>::{Pallet, Call, Storage},
BridgeWestendParachains: pallet_bridge_parachains::<Instance1>::{Pallet, Call, Storage, Event<T>},

// RialtoParachain bridge modules.
BridgeRialtoParachains: pallet_bridge_parachains::{Pallet, Call, Storage},
BridgeRialtoParachains: pallet_bridge_parachains::{Pallet, Call, Storage, Event<T>},
BridgeRialtoParachainMessages: pallet_bridge_messages::<Instance1>::{Pallet, Call, Storage, Event<T>, Config<T>},

// Pallet for sending XCM.
Expand Down
12 changes: 9 additions & 3 deletions bridges/modules/parachains/src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use crate::{Config, Pallet, RelayBlockHash, RelayBlockHasher, RelayBlockNumber};
use bp_runtime::FilterCall;
use frame_support::{dispatch::CallableCallFor, traits::IsSubType};
use sp_runtime::transaction_validity::{TransactionValidity, ValidTransaction};
use sp_runtime::transaction_validity::{InvalidTransaction, TransactionValidity, ValidTransaction};

/// Validate parachain heads in order to avoid "mining" transactions that provide
/// outdated bridged parachain heads. Without this validation, even honest relayers
Expand Down Expand Up @@ -57,13 +57,19 @@ where
};

let maybe_stored_best_head = crate::ParasInfo::<T, I>::get(parachain);
Self::validate_updated_parachain_head(
let is_valid = Self::validate_updated_parachain_head(
parachain,
&maybe_stored_best_head,
updated_at_relay_block_number,
parachain_head_hash,
"Rejecting obsolete parachain-head transaction",
)
);

if is_valid {
Ok(ValidTransaction::default())
} else {
InvalidTransaction::Stale.into()
}
}
}

Expand Down
Loading

0 comments on commit 4f3f574

Please sign in to comment.