Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9c54c04
Companion for 1352
svyatonik May 16, 2022
5c6b11f
Companion for 1199
wuminzhe Aug 5, 2022
300e6a5
Companion for 1218
wuminzhe Aug 5, 2022
12e1484
Companion for 1410
wuminzhe Aug 5, 2022
231c671
Companion for 1430
svyatonik Jun 1, 2022
5202109
Companion for 1432
wuminzhe Aug 5, 2022
73a4f09
Companion for 1435
svyatonik Jun 6, 2022
9d978e1
Companion for 1436
svyatonik Jun 7, 2022
849fe3f
Companion for 1442
svyatonik Jun 7, 2022
4b813a5
Companion for 1444
svyatonik Jun 7, 2022
209ef6b
Companion for 1446
svyatonik Jun 9, 2022
7b7efe4
Companion for 1468
svyatonik Jun 21, 2022
bfe2174
Companion for 1475
svyatonik Jun 24, 2022
66a77cd
Avoid duplicate function definitions
serban300 Jun 24, 2022
37cedca
Companion for 1483
serban300 Jun 28, 2022
3e58ffb
Companion for 1484
svyatonik Jun 29, 2022
70c9c61
Define const LOG_TARGET for bridge pallets
serban300 Jun 29, 2022
a6a2f8f
Test pallet owner calls using macro
serban300 Jun 29, 2022
f8c61d4
Add owner calls to the parachains pallet
serban300 Jun 29, 2022
116723d
[parachains pallet] add unit test
serban300 Jun 30, 2022
58e9c84
[parachains pallet] implement genesis_build
serban300 Jun 30, 2022
404adaa
Companion for 1487
svyatonik Jul 4, 2022
bde5c77
Companion for 1489
svyatonik Jul 5, 2022
4f9fca3
Companion for 1494
svyatonik Jul 7, 2022
77d2b5e
Companion for 1505
svyatonik Jul 14, 2022
18e1097
Companion for 1511
serban300 Jul 18, 2022
108e6e6
Companion for 1517
svyatonik Jul 20, 2022
8a69b7f
Reduce the number of macros used for SignedExtensions
serban300 Jul 25, 2022
e4dfb68
Deduplicate parachains validation
serban300 Jul 25, 2022
ccfa2e9
Define StorageDoubleMapKeyProvider
serban300 Jul 26, 2022
a2f68db
Remove `instant_payments` (#183)
boundless-forest Sep 27, 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
485 changes: 255 additions & 230 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions bin/runtime-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
ed25519-dalek = { version = "1.0", default-features = false, optional = true }
log = { version = "0.4.14", default-features = false }
hash-db = { version = "0.15.2", default-features = false }
scale-info = { version = "2.0.1", default-features = false, features = ["derive"] }

# Bridge dependencies

bp-message-dispatch = { path = "../../primitives/message-dispatch", default-features = false }
bp-messages = { path = "../../primitives/messages", default-features = false }
bp-parachains = { path = "../../primitives/parachains", default-features = false }
bp-polkadot-core = { path = "../../primitives/polkadot-core", default-features = false }
bp-runtime = { path = "../../primitives/runtime", default-features = false }
pallet-bridge-dispatch = { path = "../../modules/dispatch", default-features = false }
pallet-bridge-grandpa = { path = "../../modules/grandpa", default-features = false }
pallet-bridge-messages = { path = "../../modules/messages", default-features = false }
pallet-bridge-parachains = { path = "../../modules/parachains", default-features = false }

# Substrate dependencies

Expand All @@ -41,6 +45,8 @@ default = ["std"]
std = [
"bp-message-dispatch/std",
"bp-messages/std",
"bp-parachains/std",
"bp-polkadot-core/std",
"bp-runtime/std",
"codec/std",
"frame-support/std",
Expand All @@ -49,6 +55,7 @@ std = [
"pallet-bridge-dispatch/std",
"pallet-bridge-grandpa/std",
"pallet-bridge-messages/std",
"pallet-bridge-parachains/std",
"pallet-transaction-payment/std",
"scale-info/std",
"sp-api/std",
Expand Down
169 changes: 169 additions & 0 deletions bin/runtime-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,174 @@

#![cfg_attr(not(feature = "std"), no_std)]

use bp_runtime::FilterCall;
use sp_runtime::transaction_validity::TransactionValidity;

pub mod messages;
pub mod messages_benchmarking;
pub mod messages_extension;
pub mod parachains_benchmarking;

/// A duplication of the `FilterCall` trait.
///
/// We need this trait in order to be able to implement it for the messages pallet,
/// since the implementation is done outside of the pallet crate.
pub trait BridgeRuntimeFilterCall<Call> {
/// Checks if a runtime call is valid.
fn validate(call: &Call) -> TransactionValidity;
}

impl<Call, T, I> BridgeRuntimeFilterCall<Call> for pallet_bridge_grandpa::Pallet<T, I>
where
pallet_bridge_grandpa::Pallet<T, I>: FilterCall<Call>,
{
fn validate(call: &Call) -> TransactionValidity {
<pallet_bridge_grandpa::Pallet<T, I> as FilterCall<Call>>::validate(call)
}
}

impl<Call, T, I> BridgeRuntimeFilterCall<Call> for pallet_bridge_parachains::Pallet<T, I>
where
pallet_bridge_parachains::Pallet<T, I>: FilterCall<Call>,
{
fn validate(call: &Call) -> TransactionValidity {
<pallet_bridge_parachains::Pallet<T, I> as FilterCall<Call>>::validate(call)
}
}

/// Declares a runtime-specific `BridgeRejectObsoleteHeadersAndMessages` signed extension.
///
/// ## Example
///
/// ```nocompile
/// generate_bridge_reject_obsolete_headers_and_messages!{
/// Call, AccountId
/// BridgeRialtoGrandpa, BridgeWestendGrandpa,
/// BridgeRialtoParachains
/// }
/// ```
///
/// The goal of this extension is to avoid "mining" transactions that provide outdated bridged
/// headers and messages. Without that extension, even honest relayers may lose their funds if
/// there are multiple relays running and submitting the same information.
#[macro_export]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

macro_rules! generate_bridge_reject_obsolete_headers_and_messages {
($call:ty, $account_id:ty, $($filter_call:ty),*) => {
#[derive(Clone, codec::Decode, codec::Encode, Eq, PartialEq, frame_support::RuntimeDebug, scale_info::TypeInfo)]
pub struct BridgeRejectObsoleteHeadersAndMessages;
impl sp_runtime::traits::SignedExtension for BridgeRejectObsoleteHeadersAndMessages {
const IDENTIFIER: &'static str = "BridgeRejectObsoleteHeadersAndMessages";
type AccountId = $account_id;
type Call = $call;
type AdditionalSigned = ();
type Pre = ();

fn additional_signed(&self) -> sp_std::result::Result<
(),
sp_runtime::transaction_validity::TransactionValidityError,
> {
Ok(())
}

fn validate(
&self,
_who: &Self::AccountId,
call: &Self::Call,
_info: &sp_runtime::traits::DispatchInfoOf<Self::Call>,
_len: usize,
) -> sp_runtime::transaction_validity::TransactionValidity {
let valid = sp_runtime::transaction_validity::ValidTransaction::default();
$(
let valid = valid
.combine_with(<$filter_call as $crate::BridgeRuntimeFilterCall<$call>>::validate(call)?);
)*
Ok(valid)
}

fn pre_dispatch(
self,
who: &Self::AccountId,
call: &Self::Call,
info: &sp_runtime::traits::DispatchInfoOf<Self::Call>,
len: usize,
) -> Result<Self::Pre, sp_runtime::transaction_validity::TransactionValidityError> {
self.validate(who, call, info, len).map(drop)
}
}
};
}

#[cfg(test)]
mod tests {
use crate::BridgeRuntimeFilterCall;
use frame_support::{assert_err, assert_ok};
use sp_runtime::{
traits::SignedExtension,
transaction_validity::{InvalidTransaction, TransactionValidity, ValidTransaction},
};

pub struct MockCall {
data: u32,
}

impl sp_runtime::traits::Dispatchable for MockCall {
type Config = ();
type Info = ();
type Origin = ();
type PostInfo = ();

fn dispatch(
self,
_origin: Self::Origin,
) -> sp_runtime::DispatchResultWithInfo<Self::PostInfo> {
unimplemented!()
}
}

struct FirstFilterCall;
impl BridgeRuntimeFilterCall<MockCall> for FirstFilterCall {
fn validate(call: &MockCall) -> TransactionValidity {
if call.data <= 1 {
return InvalidTransaction::Custom(1).into();
}

Ok(ValidTransaction { priority: 1, ..Default::default() })
}
}

struct SecondFilterCall;
impl BridgeRuntimeFilterCall<MockCall> for SecondFilterCall {
fn validate(call: &MockCall) -> TransactionValidity {
if call.data <= 2 {
return InvalidTransaction::Custom(2).into();
}

Ok(ValidTransaction { priority: 2, ..Default::default() })
}
}

#[test]
fn test() {
generate_bridge_reject_obsolete_headers_and_messages!(
MockCall,
(),
FirstFilterCall,
SecondFilterCall
);

assert_err!(
BridgeRejectObsoleteHeadersAndMessages.validate(&(), &MockCall { data: 1 }, &(), 0),
InvalidTransaction::Custom(1)
);

assert_err!(
BridgeRejectObsoleteHeadersAndMessages.validate(&(), &MockCall { data: 2 }, &(), 0),
InvalidTransaction::Custom(2)
);

assert_ok!(
BridgeRejectObsoleteHeadersAndMessages.validate(&(), &MockCall { data: 3 }, &(), 0),
ValidTransaction { priority: 3, ..Default::default() }
)
}
}
Loading