Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signed extension to refund relayer at the target chain #1657

Merged
merged 25 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8999d63
add utlity pallet to the Millau runtime
svyatonik Nov 22, 2022
89a9268
RefundRelayerForMessagesDeliveryFromParachain prototype
svyatonik Nov 22, 2022
20f90aa
Merge branch 'master' into signed-extension-to-refund-relayer-at-targ…
svyatonik Nov 25, 2022
dc35853
done with RefundRelayerForMessagesDeliveryFromParachain::post_dispatch
svyatonik Nov 25, 2022
25e4c09
parse calls
svyatonik Nov 25, 2022
e72c723
check batch for obsolete headers/messages
svyatonik Nov 28, 2022
4bb3766
fmt
svyatonik Nov 28, 2022
54e350b
shorten generic arg names + add parachain id generic arg
svyatonik Nov 28, 2022
92cc156
check lane_id
svyatonik Nov 28, 2022
5dc098a
impl all state read functions
svyatonik Nov 28, 2022
29dc969
Merge branch 'master' into signed-extension-to-refund-relayer-at-targ…
svyatonik Nov 28, 2022
e581c4d
fix typos from review
svyatonik Nov 29, 2022
d067da3
renamed extension + reference issue from TODO
svyatonik Nov 29, 2022
8ab7c9f
tests for pre-dispaytch
svyatonik Nov 29, 2022
da8699e
renamed extension source file
svyatonik Nov 29, 2022
d2596ab
tests for post-dispatch
svyatonik Nov 29, 2022
3f5e08d
abstract fee calculation
svyatonik Nov 30, 2022
7d31015
clippy
svyatonik Nov 30, 2022
3258a8e
actually fix clippy
svyatonik Nov 30, 2022
ecf5f7c
Merge branch 'master' into signed-extension-to-refund-relayer-at-targ…
svyatonik Nov 30, 2022
9b3b5f3
Update bin/runtime-common/src/refund_relayer_extension.rs
svyatonik Dec 9, 2022
557fce8
Update bin/runtime-common/src/refund_relayer_extension.rs
svyatonik Dec 9, 2022
16686ee
Update bin/runtime-common/src/refund_relayer_extension.rs
svyatonik Dec 9, 2022
054d4e8
Update bin/runtime-common/src/refund_relayer_extension.rs
svyatonik Dec 9, 2022
948db62
Merge branch 'master' into signed-extension-to-refund-relayer-at-targ…
svyatonik Dec 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/runtime-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use xcm::v3::NetworkId;

pub mod messages;
pub mod messages_api;
pub mod messages_batch_extension;
pub mod messages_benchmarking;
pub mod messages_extension;
pub mod parachains_benchmarking;
Expand Down
138 changes: 138 additions & 0 deletions bin/runtime-common/src/messages_batch_extension.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
// Copyright 2021 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/>.

//! Signed extension that refunds relayer if he has delivered some new messages.
//! It also refunds transacation cost if the transaction is an `utility.batchAll()`
//! with calls that are: delivering new messsage and all necessary underlying headers
//! (parachain or relay chain).

use codec::{Decode, Encode};
use frame_support::{dispatch::Dispatchable, Parameter, RuntimeDebug};
use scale_info::TypeInfo;
use sp_runtime::{
traits::{DispatchInfoOf, PostDispatchInfoOf, SignedExtension},
transaction_validity::{TransactionValidity, TransactionValidityError, ValidTransaction},
DispatchResult,
};
use sp_std::marker::PhantomData;

// TODO: is it possible to impl it for several bridges at once? Like what we have in
// `BridgeRejectObsoleteHeadersAndMessages`? If it is hard to do now - just submit an issue

#[derive(Clone, Decode, Encode, Eq, PartialEq, RuntimeDebug, TypeInfo)]
pub struct RefundRelayerForMessagesDeliveryFromParachain<AccountId, Call>(
PhantomData<(AccountId, Call)>,
);

impl<AccountId, Call> SignedExtension
for RefundRelayerForMessagesDeliveryFromParachain<AccountId, Call>
where
AccountId: 'static + Parameter + Send + Sync,
Call: 'static + Dispatchable + Parameter + Send + Sync,
{
const IDENTIFIER: &'static str = "RefundRelayerForMessagesDeliveryFromParachain";
type AccountId = AccountId;
type Call = Call;
type AdditionalSigned = ();
type Pre = ();

fn additional_signed(&self) -> Result<(), TransactionValidityError> {
Ok(())
}

fn validate(
&self,
_who: &Self::AccountId,
_call: &Self::Call,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> TransactionValidity {
Ok(ValidTransaction::default())
}

fn pre_dispatch(
self,
_who: &Self::AccountId,
_call: &Self::Call,
_post_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> Result<(), TransactionValidityError> {
// TODO: for every call from the batch - call the `BridgesExtension` to ensure that every
// call transaction brings something new and reject obsolete transactions
Ok(())
}

fn post_dispatch(
_pre: Option<Self::Pre>,
_info: &DispatchInfoOf<Self::Call>,
_post_info: &PostDispatchInfoOf<Self::Call>,
_len: usize,
_result: &DispatchResult,
) -> Result<(), TransactionValidityError> {
// TODO:
// if batch matches!(relay-chain-finality-call, parachain-finality-call,
// deliver-messages-call) then:
svyatonik marked this conversation as resolved.
Show resolved Hide resolved
//
// 0) ensure that the `result` is `Ok(_)`
//
// 1) ensure that all calls are dependent (relaychain -> parachain of this relaychain and
// proof is using new relaychain header -> messages of this parachain and proof is using new
// parachain head). Otherwise - no refund!!!
//
// 2) ensure that the parachain finality transaction is for single parachain (our special
// case). Otherwise - no refund!!!
//
// 3) check result of every call - e.g. parachain finality call succeeds even if it is not
// updating anything. But we are only interesting in refunding calls that have succeeded. If
// at least one call has not succeeded - no refund!!!
//
// 4) now we may refund using `pallet-bridge-relayers`. The sum of refund is
// `pallet_transaction_payment::Pallet::<Runtime>::compute_actual_fee(len as u32, info,
// post_info, tip)`

// TODO:
// if batch matches!(parachain-finality-call, deliver-messages-call) then:
//
// 0) ensure that the `result` is `Ok(_)`
//
// 1) ensure that all calls are dependent (parachain -> messages of this parachain and proof
// is using new parachain head). Otherwise - no refund!!!
//
// 2) ensure that the parachain finality transaction is for single parachain (our special
// case). Otherwise - no refund!!!
//
// 3) check result of every call - e.g. parachain finality call succeeds even if it is not
// updating anything. But we are only interesting in refunding calls that have succeeded. If
// at least one call has not succeeded - no refund!!!
//
// 4) now we may refund using
// `pallet-bridge-relayers`. The sum of refund is
// `pallet_transaction_payment::Pallet::<Runtime>::compute_actual_fee(len as u32, info,
// post_info, tip)`

// TODO: if the call is just deliver-message-call then:
//
// 0) ensure that the `result` is `Ok(_)`
//
// 1) check that at least some messages were accepted. Otherwise - no refund!!!;
//
// 2) now we may refund using `pallet-bridge-relayers`. The sum of refund is
// `pallet_transaction_payment::Pallet::<Runtime>::compute_actual_fee(len as u32, info,
// post_info, tip)`

Ok(())
}
}