Skip to content

Commit

Permalink
fix extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
svyatonik authored and bkontur committed Jun 7, 2024
1 parent 8982e9d commit 90e5578
Show file tree
Hide file tree
Showing 10 changed files with 907 additions and 689 deletions.
797 changes: 797 additions & 0 deletions bridges/bin/runtime-common/src/extensions.rs

Large diffs are not rendered by default.

659 changes: 0 additions & 659 deletions bridges/bin/runtime-common/src/extensions/check_obsolete_extension.rs

This file was deleted.

19 changes: 0 additions & 19 deletions bridges/bin/runtime-common/src/extensions/mod.rs

This file was deleted.

1 change: 0 additions & 1 deletion bridges/bin/runtime-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#![cfg_attr(not(feature = "std"), no_std)]

pub mod extensions;

pub mod messages_api;
pub mod messages_benchmarking;
pub mod parachains_benchmarking;
Expand Down
3 changes: 1 addition & 2 deletions bridges/modules/relayers/src/extension/grandpa_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ where
{
type IdProvider = ID;
type Runtime = R;
type BatchCallUnpacker = BCU;
type BridgeMessagesPalletInstance = MI;
type PriorityBoostPerMessage = P;
type Reward = R::Reward;
Expand All @@ -96,7 +95,7 @@ where
Option<ExtensionCallInfo<Self::RemoteGrandpaChainBlockNumber>>,
TransactionValidityError,
> {
let calls = Self::BatchCallUnpacker::unpack(call, 2);
let calls = BCU::unpack(call, 2);
let total_calls = calls.len();
let mut calls = calls.into_iter().map(Self::check_obsolete_parsed_call).rev();

Expand Down
94 changes: 94 additions & 0 deletions bridges/modules/relayers/src/extension/messages_adapter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Parity Bridges Common.

// Parity Bridges Common is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity Bridges Common is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.

//! Adapter that allows using `pallet-bridge-relayers` as a signed extension in the
//! bridge with any remote chain. This adapter does not refund any finality transactions.
use crate::{extension::verify_messages_call_succeeded, Config as BridgeRelayersConfig};

use bp_relayers::{ExtensionCallData, ExtensionCallInfo, ExtensionConfig};
use bp_runtime::StaticStrProvider;
use frame_support::dispatch::{DispatchInfo, PostDispatchInfo};
use pallet_bridge_messages::{
CallSubType as BridgeMessagesCallSubType, Config as BridgeMessagesConfig,
};
use sp_runtime::{
traits::{Dispatchable, Get},
transaction_validity::{TransactionPriority, TransactionValidityError},
};
use sp_std::marker::PhantomData;

/// Transaction extension that refunds a relayer for standalone messages delivery and confirmation
/// transactions. Finality transactions are not refunded.
pub struct MessagesExtensionConfig<
IdProvider,
Runtime,
BridgeMessagesPalletInstance,
PriorityBoostPerMessage,
>(
PhantomData<(
// signed extension identifier
IdProvider,
// runtime with `pallet-bridge-messages` pallet deployed
Runtime,
// instance of BridgedChain `pallet-bridge-messages`, tracked by this extension
BridgeMessagesPalletInstance,
// message delivery transaction priority boost for every additional message
PriorityBoostPerMessage,
)>,
);

impl<ID, R, MI, P> ExtensionConfig for MessagesExtensionConfig<ID, R, MI, P>
where
ID: StaticStrProvider,
R: BridgeRelayersConfig + BridgeMessagesConfig<MI>,
MI: 'static,
P: Get<TransactionPriority>,
R::RuntimeCall: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>
+ BridgeMessagesCallSubType<R, MI>,
{
type IdProvider = ID;
type Runtime = R;
type BridgeMessagesPalletInstance = MI;
type PriorityBoostPerMessage = P;
type Reward = R::Reward;
type RemoteGrandpaChainBlockNumber = ();

fn parse_and_check_for_obsolete_call(
call: &R::RuntimeCall,
) -> Result<
Option<ExtensionCallInfo<Self::RemoteGrandpaChainBlockNumber>>,
TransactionValidityError,
> {
let call = Self::check_obsolete_parsed_call(call)?;
Ok(call.call_info().map(ExtensionCallInfo::Msgs))
}

fn check_obsolete_parsed_call(
call: &R::RuntimeCall,
) -> Result<&R::RuntimeCall, TransactionValidityError> {
call.check_obsolete_call()?;
Ok(call)
}

fn check_call_result(
call_info: &ExtensionCallInfo<Self::RemoteGrandpaChainBlockNumber>,
call_data: &mut ExtensionCallData,
relayer: &R::AccountId,
) -> bool {
verify_messages_call_succeeded::<Self, MI>(call_info, call_data, relayer)
}
}
2 changes: 2 additions & 0 deletions bridges/modules/relayers/src/extension/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ use sp_runtime::{
use sp_std::{fmt::Debug, marker::PhantomData};

pub use grandpa_adapter::WithGrandpaChainExtensionConfig;
pub use messages_adapter::MessagesExtensionConfig;
pub use parachain_adapter::WithParachainExtensionConfig;
pub use priority::*;

mod grandpa_adapter;
mod messages_adapter;
mod parachain_adapter;
mod priority;

Expand Down
5 changes: 1 addition & 4 deletions bridges/modules/relayers/src/extension/parachain_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ where
{
type IdProvider = ID;
type Runtime = R;
type BatchCallUnpacker = BCU;
type BridgeMessagesPalletInstance = MI;
type PriorityBoostPerMessage = P;
type Reward = R::Reward;
Expand All @@ -103,8 +102,7 @@ where
Option<ExtensionCallInfo<Self::RemoteGrandpaChainBlockNumber>>,
TransactionValidityError,
> {
log::trace!(target: LOG_TARGET, "=== call: {:?}", call);
let calls = Self::BatchCallUnpacker::unpack(call, 3);
let calls = BCU::unpack(call, 3);
let total_calls = calls.len();
let mut calls = calls.into_iter().map(Self::check_obsolete_parsed_call).rev();

Expand All @@ -117,7 +115,6 @@ where
});
let relay_finality_call =
calls.next().transpose()?.and_then(|c| c.submit_finality_proof_info());
log::trace!(target: LOG_TARGET, "=== {} {:?} {:?} {:?}", total_calls, relay_finality_call, para_finality_call, msgs_call);
Ok(match (total_calls, relay_finality_call, para_finality_call, msgs_call) {
(3, Some(relay_finality_call), Some(para_finality_call), Some(msgs_call)) =>
Some(ExtensionCallInfo::AllFinalityAndMsgs(
Expand Down
14 changes: 12 additions & 2 deletions bridges/modules/relayers/src/extension/priority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use frame_support::traits::Get;
use sp_runtime::transaction_validity::TransactionPriority;

// reexport everything from `integrity_tests` module
#[allow(unused_imports)]
pub use integrity_tests::*;

/// We'll deal with different bridge items here - messages, headers, ...
Expand Down Expand Up @@ -237,7 +238,12 @@ mod integrity_tests {
/// almost the same priority if we'll add `tip_boost_per_header` tip to the `TX1`. We want
/// to be sure that if we add plain `PriorityBoostPerHeader` priority to `TX1`, the priority
/// will be close to `TX2` as well.
pub fn ensure_priority_boost_is_sane<Runtime, ParachainsInstance, Para, PriorityBoostPerHeader>(
pub fn ensure_priority_boost_is_sane<
Runtime,
ParachainsInstance,
Para,
PriorityBoostPerHeader,
>(
tip_boost_per_header: BalanceOf<Runtime>,
) where
Runtime: pallet_transaction_payment::Config
Expand Down Expand Up @@ -271,7 +277,11 @@ mod integrity_tests {

/// Estimate parachain header delivery transaction priority.
#[cfg(feature = "integrity-test")]
fn estimate_parachain_header_submit_transaction_priority<Runtime, ParachainsInstance, Para>(
fn estimate_parachain_header_submit_transaction_priority<
Runtime,
ParachainsInstance,
Para,
>(
tip: BalanceOf<Runtime>,
) -> TransactionPriority
where
Expand Down
2 changes: 0 additions & 2 deletions bridges/primitives/relayers/src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ pub trait ExtensionConfig {
/// Runtime that optionally supports batched calls. We assume that batched call
/// succeeds if and only if all of its nested calls succeed.
type Runtime: frame_system::Config;
/// Batch calls unpacker.
type BatchCallUnpacker: BatchCallUnpacker<Self::Runtime>;
/// Messages pallet instance.
type BridgeMessagesPalletInstance: 'static;
/// Additional priority that is added to base message delivery transaction priority
Expand Down

0 comments on commit 90e5578

Please sign in to comment.