referrerpolicy=no-referrer-when-downgrade

pallet_bridge_relayers/extension/
messages_adapter.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Parity Bridges Common.
3
4// Parity Bridges Common is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Parity Bridges Common is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Parity Bridges Common.  If not, see <http://www.gnu.org/licenses/>.
16
17//! Adapter that allows using `pallet-bridge-relayers` as a signed extension in the
18//! bridge with any remote chain. This adapter does not refund any finality transactions.
19
20use crate::{extension::verify_messages_call_succeeded, Config as BridgeRelayersConfig};
21
22use bp_relayers::{ExtensionCallData, ExtensionCallInfo, ExtensionConfig};
23use bp_runtime::StaticStrProvider;
24use core::marker::PhantomData;
25use frame_support::dispatch::{DispatchInfo, PostDispatchInfo};
26use pallet_bridge_messages::{
27	CallSubType as BridgeMessagesCallSubType, Config as BridgeMessagesConfig, LaneIdOf,
28};
29use sp_runtime::{
30	traits::{Dispatchable, Get},
31	transaction_validity::{TransactionPriority, TransactionValidityError},
32};
33
34/// Transaction extension that refunds a relayer for standalone messages delivery and confirmation
35/// transactions. Finality transactions are not refunded.
36pub struct WithMessagesExtensionConfig<
37	IdProvider,
38	Runtime,
39	BridgeMessagesPalletInstance,
40	BridgeRelayersPalletInstance,
41	PriorityBoostPerMessage,
42>(
43	PhantomData<(
44		// signed extension identifier
45		IdProvider,
46		// runtime with `pallet-bridge-messages` pallet deployed
47		Runtime,
48		// instance of BridgedChain `pallet-bridge-messages`, tracked by this extension
49		BridgeMessagesPalletInstance,
50		// instance of `pallet-bridge-relayers`, tracked by this extension
51		BridgeRelayersPalletInstance,
52		// message delivery transaction priority boost for every additional message
53		PriorityBoostPerMessage,
54	)>,
55);
56
57impl<ID, R, MI, RI, P> ExtensionConfig for WithMessagesExtensionConfig<ID, R, MI, RI, P>
58where
59	ID: StaticStrProvider,
60	R: BridgeRelayersConfig<RI> + BridgeMessagesConfig<MI>,
61	MI: 'static,
62	RI: 'static,
63	P: Get<TransactionPriority>,
64	R::RuntimeCall: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>
65		+ BridgeMessagesCallSubType<R, MI>,
66{
67	type IdProvider = ID;
68	type Runtime = R;
69	type BridgeMessagesPalletInstance = MI;
70	type BridgeRelayersPalletInstance = RI;
71	type PriorityBoostPerMessage = P;
72	type RemoteGrandpaChainBlockNumber = ();
73	type LaneId = LaneIdOf<R, Self::BridgeMessagesPalletInstance>;
74
75	fn parse_and_check_for_obsolete_call(
76		call: &R::RuntimeCall,
77	) -> Result<
78		Option<ExtensionCallInfo<Self::RemoteGrandpaChainBlockNumber, Self::LaneId>>,
79		TransactionValidityError,
80	> {
81		let call = Self::check_obsolete_parsed_call(call)?;
82		Ok(call.call_info().map(ExtensionCallInfo::Msgs))
83	}
84
85	fn check_obsolete_parsed_call(
86		call: &R::RuntimeCall,
87	) -> Result<&R::RuntimeCall, TransactionValidityError> {
88		call.check_obsolete_call()?;
89		Ok(call)
90	}
91
92	fn check_call_result(
93		call_info: &ExtensionCallInfo<Self::RemoteGrandpaChainBlockNumber, Self::LaneId>,
94		call_data: &mut ExtensionCallData,
95		relayer: &R::AccountId,
96	) -> bool {
97		verify_messages_call_succeeded::<Self>(call_info, call_data, relayer)
98	}
99}