Skip to content

Commit 0022b5a

Browse files
svyatonikacatangiu
andauthored
Slash relayers for invalid transactions (#2025)
* slash relayer balance for invalid transactions * require some gap before unstake is possible * more clippy * log priority boost * add issue ref to TODO * fix typo * is_message_delivery_call -> is_receive_messages_proof_call * moved is_receive_messages_proof_call above * only slash relayers for priority transactions * Update primitives/relayers/src/registration.rs Co-authored-by: Adrian Catangiu <[email protected]> * Update primitives/relayers/src/registration.rs Co-authored-by: Adrian Catangiu <[email protected]> * Update bin/runtime-common/src/refund_relayer_extension.rs Co-authored-by: Adrian Catangiu <[email protected]> * Update bin/runtime-common/src/refund_relayer_extension.rs Co-authored-by: Adrian Catangiu <[email protected]> * Update bin/runtime-common/src/refund_relayer_extension.rs Co-authored-by: Adrian Catangiu <[email protected]> * Update modules/relayers/src/lib.rs Co-authored-by: Adrian Catangiu <[email protected]> * Update primitives/relayers/src/registration.rs Co-authored-by: Adrian Catangiu <[email protected]> * benificiary -> beneficiary --------- Co-authored-by: Adrian Catangiu <[email protected]>
1 parent 1981040 commit 0022b5a

File tree

12 files changed

+1495
-183
lines changed

12 files changed

+1495
-183
lines changed

bin/millau/runtime/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ parameter_types! {
372372
/// Authorities are changing every 5 minutes.
373373
pub const Period: BlockNumber = bp_millau::SESSION_LENGTH;
374374
pub const Offset: BlockNumber = 0;
375+
pub const RelayerStakeReserveId: [u8; 8] = *b"brdgrlrs";
375376
}
376377

377378
impl pallet_session::Config for Runtime {
@@ -392,6 +393,14 @@ impl pallet_bridge_relayers::Config for Runtime {
392393
type Reward = Balance;
393394
type PaymentProcedure =
394395
bp_relayers::PayRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>;
396+
type StakeAndSlash = pallet_bridge_relayers::StakeAndSlashNamed<
397+
AccountId,
398+
BlockNumber,
399+
Balances,
400+
RelayerStakeReserveId,
401+
ConstU64<1_000>,
402+
ConstU64<8>,
403+
>;
395404
type WeightInfo = ();
396405
}
397406

bin/rialto-parachain/runtime/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ impl pallet_bridge_relayers::Config for Runtime {
533533
type Reward = Balance;
534534
type PaymentProcedure =
535535
bp_relayers::PayRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>;
536+
type StakeAndSlash = ();
536537
type WeightInfo = ();
537538
}
538539

bin/rialto/runtime/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ impl pallet_bridge_relayers::Config for Runtime {
389389
type Reward = Balance;
390390
type PaymentProcedure =
391391
bp_relayers::PayRewardFromAccount<pallet_balances::Pallet<Runtime>, AccountId>;
392+
type StakeAndSlash = ();
392393
type WeightInfo = ();
393394
}
394395

bin/runtime-common/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pallet-bridge-relayers = { path = "../../modules/relayers", default-features = f
3030

3131
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
3232
frame-system = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
33+
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
3334
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
3435
pallet-utility = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
3536
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
@@ -62,6 +63,7 @@ std = [
6263
"frame-system/std",
6364
"hash-db/std",
6465
"log/std",
66+
"pallet-balances/std",
6567
"pallet-bridge-grandpa/std",
6668
"pallet-bridge-messages/std",
6769
"pallet-bridge-parachains/std",

bin/runtime-common/src/messages_call_ext.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ pub enum CallInfo {
115115
ReceiveMessagesDeliveryProof(ReceiveMessagesDeliveryProofInfo),
116116
}
117117

118+
impl CallInfo {
119+
/// Returns range of messages, bundled with the call.
120+
pub fn bundled_messages(&self) -> RangeInclusive<MessageNonce> {
121+
match *self {
122+
Self::ReceiveMessagesProof(ref info) => info.base.bundled_range.clone(),
123+
Self::ReceiveMessagesDeliveryProof(ref info) => info.0.bundled_range.clone(),
124+
}
125+
}
126+
}
127+
118128
/// Helper struct that provides methods for working with a call supported by `CallInfo`.
119129
pub struct CallHelper<T: Config<I>, I: 'static> {
120130
pub _phantom_data: sp_std::marker::PhantomData<(T, I)>,

bin/runtime-common/src/mock.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use crate::messages::{
3535
use bp_header_chain::{ChainWithGrandpa, HeaderChain};
3636
use bp_messages::{target_chain::ForbidInboundMessages, LaneId, MessageNonce};
3737
use bp_parachains::SingleParaStoredHeaderDataBuilder;
38+
use bp_relayers::PayRewardFromAccount;
3839
use bp_runtime::{Chain, ChainId, Parachain, UnderlyingChainProvider};
3940
use codec::{Decode, Encode};
4041
use frame_support::{
@@ -83,6 +84,20 @@ pub type BridgedChainHasher = BlakeTwo256;
8384
pub type BridgedChainHeader =
8485
sp_runtime::generic::Header<BridgedChainBlockNumber, BridgedChainHasher>;
8586

87+
/// Rewards payment procedure.
88+
pub type TestPaymentProcedure = PayRewardFromAccount<Balances, ThisChainAccountId>;
89+
/// Stake that we are using in tests.
90+
pub type TestStake = ConstU64<5_000>;
91+
/// Stake and slash mechanism to use in tests.
92+
pub type TestStakeAndSlash = pallet_bridge_relayers::StakeAndSlashNamed<
93+
ThisChainAccountId,
94+
ThisChainBlockNumber,
95+
Balances,
96+
ReserveId,
97+
TestStake,
98+
ConstU32<8>,
99+
>;
100+
86101
/// Message lane used in tests.
87102
pub const TEST_LANE_ID: LaneId = LaneId([0, 0, 0, 0]);
88103
/// Bridged chain id used in tests.
@@ -128,6 +143,7 @@ parameter_types! {
128143
pub MaximumMultiplier: Multiplier = sp_runtime::traits::Bounded::max_value();
129144
pub const MaxUnrewardedRelayerEntriesAtInboundLane: MessageNonce = 16;
130145
pub const MaxUnconfirmedMessagesAtInboundLane: MessageNonce = 1_000;
146+
pub const ReserveId: [u8; 8] = *b"brdgrlrs";
131147
}
132148

133149
impl frame_system::Config for TestRuntime {
@@ -244,7 +260,8 @@ impl pallet_bridge_messages::Config for TestRuntime {
244260
impl pallet_bridge_relayers::Config for TestRuntime {
245261
type RuntimeEvent = RuntimeEvent;
246262
type Reward = ThisChainBalance;
247-
type PaymentProcedure = ();
263+
type PaymentProcedure = TestPaymentProcedure;
264+
type StakeAndSlash = TestStakeAndSlash;
248265
type WeightInfo = ();
249266
}
250267

@@ -400,3 +417,8 @@ impl ThisChainWithMessages for BridgedChain {
400417
}
401418

402419
impl BridgedChainWithMessages for BridgedChain {}
420+
421+
/// Run test within test externalities.
422+
pub fn run_test(test: impl FnOnce()) {
423+
sp_io::TestExternalities::new(Default::default()).execute_with(test)
424+
}

0 commit comments

Comments
 (0)