Skip to content

Commit 1bbc77f

Browse files
serban300bkchr
authored andcommitted
Start the equivocation detection loop from the complex relayer (#2507) (#2512)
* Impl SubstrateEquivocationDetectionPipeline for Millau * Impl SubstrateEquivocationDetectionPipeline for Rialto * Make BridgeHubSignedExtension more generic * Define generate_report_equivocation_call_builder!() macro * Impl SubstrateEquivocationDetectionPipeline for Rococo * Impl SubstrateEquivocationDetectionPipeline for Wococo * Impl SubstrateEquivocationDetectionPipeline for Kusama * Impl SubstrateEquivocationDetectionPipeline for Polkadot * Complex relayer simplification - remove `signer` and `transactions_mortality` and add `tx_params` - change the order of some fields * Add equivocation detection CLI traits * Complex relayer: start equivocation detectin loop * Update runtimes regeneration script * Equivocation loop: Fix infinite loop * Revert "Complex relayer: start equivocation detectin loop" This reverts commit b518ef85679d73654f9f0e2add38cd3839552057. * Add subcommand for starting the equivocation detection loop * Fixes * Initialize empty metrics for the equivocations detector loop
1 parent 588508a commit 1bbc77f

File tree

48 files changed

+25091
-244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+25091
-244
lines changed

bridges/bin/rialto-parachain/runtime/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ scale-info = { version = "2.9.0", default-features = false, features = ["derive"
1919
bp-header-chain = { path = "../../../primitives/header-chain", default-features = false }
2020
bp-messages = { path = "../../../primitives/messages", default-features = false }
2121
bp-millau = { path = "../../../primitives/chain-millau", default-features = false }
22+
bp-polkadot-core = { path = "../../../primitives/polkadot-core", default-features = false }
2223
bp-relayers = { path = "../../../primitives/relayers", default-features = false }
2324
bp-runtime = { path = "../../../primitives/runtime", default-features = false }
2425
bp-rialto-parachain = { path = "../../../primitives/chain-rialto-parachain", default-features = false }

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

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -858,12 +858,10 @@ mod tests {
858858
target_chain::{DispatchMessage, DispatchMessageData, MessageDispatch},
859859
LaneId, MessageKey,
860860
};
861-
use bridge_runtime_common::{
862-
integrity::check_additional_signed, messages_xcm_extension::XcmBlobMessageDispatchResult,
863-
};
861+
use bridge_runtime_common::messages_xcm_extension::XcmBlobMessageDispatchResult;
864862
use codec::Encode;
865863
use pallet_bridge_messages::OutboundLanes;
866-
use sp_runtime::generic::Era;
864+
use sp_runtime::{generic::Era, traits::Zero};
867865
use xcm_executor::XcmExecutor;
868866

869867
fn new_test_ext() -> sp_io::TestExternalities {
@@ -941,24 +939,36 @@ mod tests {
941939

942940
#[test]
943941
fn ensure_signed_extension_definition_is_correct() {
944-
let payload: SignedExtra = (
945-
frame_system::CheckNonZeroSender::new(),
946-
frame_system::CheckSpecVersion::new(),
947-
frame_system::CheckTxVersion::new(),
948-
frame_system::CheckGenesis::new(),
949-
frame_system::CheckEra::from(Era::Immortal),
950-
frame_system::CheckNonce::from(10),
951-
frame_system::CheckWeight::new(),
952-
pallet_transaction_payment::ChargeTransactionPayment::from(10),
953-
BridgeRejectObsoleteHeadersAndMessages,
954-
DummyBridgeRefundMillauMessages,
955-
);
956-
let indirect_payload = bp_rialto_parachain::SignedExtension::new(
957-
((), (), (), (), Era::Immortal, 10.into(), (), 10.into(), (), ()),
958-
None,
959-
);
960-
assert_eq!(payload.encode(), indirect_payload.encode());
961-
962-
check_additional_signed::<SignedExtra, bp_rialto_parachain::SignedExtension>();
942+
use bp_polkadot_core::SuffixedCommonSignedExtensionExt;
943+
944+
sp_io::TestExternalities::default().execute_with(|| {
945+
frame_system::BlockHash::<Runtime>::insert(BlockNumber::zero(), Hash::default());
946+
let payload: SignedExtra = (
947+
frame_system::CheckNonZeroSender::new(),
948+
frame_system::CheckSpecVersion::new(),
949+
frame_system::CheckTxVersion::new(),
950+
frame_system::CheckGenesis::new(),
951+
frame_system::CheckEra::from(Era::Immortal),
952+
frame_system::CheckNonce::from(10),
953+
frame_system::CheckWeight::new(),
954+
pallet_transaction_payment::ChargeTransactionPayment::from(10),
955+
BridgeRejectObsoleteHeadersAndMessages,
956+
DummyBridgeRefundMillauMessages,
957+
);
958+
let indirect_payload = bp_rialto_parachain::SignedExtension::from_params(
959+
VERSION.spec_version,
960+
VERSION.transaction_version,
961+
bp_runtime::TransactionEra::Immortal,
962+
System::block_hash(BlockNumber::zero()),
963+
10,
964+
10,
965+
(((), ()), ((), ())),
966+
);
967+
assert_eq!(payload.encode(), indirect_payload.encode());
968+
assert_eq!(
969+
payload.additional_signed().unwrap().encode(),
970+
indirect_payload.additional_signed().unwrap().encode()
971+
)
972+
});
963973
}
964974
}

bridges/bin/runtime-common/src/integrity.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use codec::Encode;
2727
use frame_support::{storage::generator::StorageValue, traits::Get, weights::Weight};
2828
use frame_system::limits;
2929
use pallet_bridge_messages::WeightInfoExt as _;
30-
use sp_runtime::traits::SignedExtension;
3130

3231
/// Macro that ensures that the runtime configuration and chain primitives crate are sharing
3332
/// the same types (nonce, block number, hash, hasher, account id and header).
@@ -347,15 +346,3 @@ pub fn check_message_lane_weights<
347346
);
348347
}
349348
}
350-
351-
/// Check that the `AdditionalSigned` type of a wrapped runtime is the same as the one of the
352-
/// corresponding actual runtime.
353-
///
354-
/// This method doesn't perform any `assert`. If the condition is not true it will generate a
355-
/// compile-time error.
356-
pub fn check_additional_signed<SignedExt, IndirectSignedExt: SignedExtension>()
357-
where
358-
SignedExt: SignedExtension,
359-
IndirectSignedExt: SignedExtension<AdditionalSigned = SignedExt::AdditionalSigned>,
360-
{
361-
}

bridges/primitives/chain-bridge-hub-cumulus/src/lib.rs

Lines changed: 5 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ pub use bp_polkadot_core::{
2323
};
2424

2525
use bp_messages::*;
26+
use bp_polkadot_core::SuffixedCommonSignedExtension;
2627
use bp_runtime::extensions::{
27-
BridgeRejectObsoleteHeadersAndMessages, ChargeTransactionPayment, CheckEra, CheckGenesis,
28-
CheckNonZeroSender, CheckNonce, CheckSpecVersion, CheckTxVersion, CheckWeight,
29-
GenericSignedExtension, RefundBridgedParachainMessagesSchema,
28+
BridgeRejectObsoleteHeadersAndMessages, RefundBridgedParachainMessagesSchema,
3029
};
3130
use frame_support::{
3231
dispatch::DispatchClass,
@@ -133,88 +132,8 @@ pub const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce = 1024;
133132
/// analysis (like the one above).
134133
pub const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce = 4096;
135134

136-
/// Extra signed extension data that is used by all bridge hubs.
137-
pub type SignedExtra = (
138-
CheckNonZeroSender,
139-
CheckSpecVersion,
140-
CheckTxVersion,
141-
CheckGenesis<Hash>,
142-
CheckEra<Hash>,
143-
CheckNonce<Nonce>,
144-
CheckWeight,
145-
ChargeTransactionPayment<Balance>,
135+
/// Signed extension that is used by all bridge hubs.
136+
pub type SignedExtension = SuffixedCommonSignedExtension<(
146137
BridgeRejectObsoleteHeadersAndMessages,
147138
RefundBridgedParachainMessagesSchema,
148-
);
149-
150-
/// Signed extension that is used by all bridge hubs.
151-
pub type SignedExtension = GenericSignedExtension<SignedExtra>;
152-
153-
/// Helper trait to define some extra methods on bridge hubs signed extension (and
154-
/// overcome Rust limitations).
155-
pub trait BridgeHubSignedExtension {
156-
/// Create signed extension from its components.
157-
fn from_params(
158-
spec_version: u32,
159-
transaction_version: u32,
160-
era: bp_runtime::TransactionEra<BlockNumber, Hash>,
161-
genesis_hash: Hash,
162-
nonce: Nonce,
163-
tip: Balance,
164-
) -> Self;
165-
166-
/// Return transaction nonce.
167-
fn nonce(&self) -> Nonce;
168-
169-
/// Return transaction tip.
170-
fn tip(&self) -> Balance;
171-
}
172-
173-
impl BridgeHubSignedExtension for SignedExtension {
174-
/// Create signed extension from its components.
175-
fn from_params(
176-
spec_version: u32,
177-
transaction_version: u32,
178-
era: bp_runtime::TransactionEra<BlockNumber, Hash>,
179-
genesis_hash: Hash,
180-
nonce: Nonce,
181-
tip: Balance,
182-
) -> Self {
183-
GenericSignedExtension::new(
184-
(
185-
(), // non-zero sender
186-
(), // spec version
187-
(), // tx version
188-
(), // genesis
189-
era.frame_era(), // era
190-
nonce.into(), // nonce (compact encoding)
191-
(), // Check weight
192-
tip.into(), // transaction payment / tip (compact encoding)
193-
(), // bridge reject obsolete headers and msgs
194-
(), // bridge reward to relayer for message passing
195-
),
196-
Some((
197-
(),
198-
spec_version,
199-
transaction_version,
200-
genesis_hash,
201-
era.signed_payload(genesis_hash),
202-
(),
203-
(),
204-
(),
205-
(),
206-
(),
207-
)),
208-
)
209-
}
210-
211-
/// Return transaction nonce.
212-
fn nonce(&self) -> Nonce {
213-
self.payload.5 .0
214-
}
215-
216-
/// Return transaction tip.
217-
fn tip(&self) -> Balance {
218-
self.payload.7 .0
219-
}
220-
}
139+
)>;

bridges/primitives/chain-kusama/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ impl ChainWithGrandpa for Kusama {
5757
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
5858
}
5959

60+
// The SignedExtension used by Kusama.
61+
pub use bp_polkadot_core::CommonSignedExtension as SignedExtension;
62+
6063
/// Name of the parachains pallet in the Kusama runtime.
6164
pub const PARAS_PALLET_NAME: &str = "Paras";
6265

bridges/primitives/chain-polkadot/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
pub use bp_polkadot_core::*;
2222

2323
use bp_header_chain::ChainWithGrandpa;
24-
use bp_runtime::{decl_bridge_finality_runtime_apis, Chain};
24+
use bp_runtime::{decl_bridge_finality_runtime_apis, extensions::PrevalidateAttests, Chain};
2525
use frame_support::weights::Weight;
2626
use sp_std::prelude::Vec;
2727

@@ -57,6 +57,9 @@ impl ChainWithGrandpa for Polkadot {
5757
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
5858
}
5959

60+
/// The SignedExtension used by Polkadot.
61+
pub type SignedExtension = SuffixedCommonSignedExtension<PrevalidateAttests>;
62+
6063
/// Name of the parachains pallet in the Polkadot runtime.
6164
pub const PARAS_PALLET_NAME: &str = "Paras";
6265

bridges/primitives/chain-rococo/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ parameter_types! {
6161
pub const SS58Prefix: u8 = 42;
6262
}
6363

64+
// The SignedExtension used by Rococo.
65+
pub use bp_polkadot_core::CommonSignedExtension as SignedExtension;
66+
6467
/// Name of the parachains pallet in the Rococo runtime.
6568
pub const PARAS_PALLET_NAME: &str = "Paras";
6669

bridges/primitives/chain-wococo/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ impl ChainWithGrandpa for Wococo {
6060
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
6161
}
6262

63+
// The SignedExtension used by Wococo.
64+
pub use bp_rococo::CommonSignedExtension as SignedExtension;
65+
6366
/// Name of the With-Wococo GRANDPA pallet instance that is deployed at bridged chains.
6467
pub const WITH_WOCOCO_GRANDPA_PALLET_NAME: &str = "BridgeWococoGrandpa";
6568

bridges/primitives/polkadot-core/src/lib.rs

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@
1717
#![cfg_attr(not(feature = "std"), no_std)]
1818

1919
use bp_messages::MessageNonce;
20-
use bp_runtime::{Chain, EncodedOrDecodedCall, StorageMapKeyProvider};
20+
use bp_runtime::{
21+
self,
22+
extensions::{
23+
ChargeTransactionPayment, CheckEra, CheckGenesis, CheckNonZeroSender, CheckNonce,
24+
CheckSpecVersion, CheckTxVersion, CheckWeight, GenericSignedExtension,
25+
SignedExtensionSchema,
26+
},
27+
Chain, EncodedOrDecodedCall, StorageMapKeyProvider, TransactionEra,
28+
};
2129
use frame_support::{
2230
dispatch::DispatchClass,
2331
parameter_types,
@@ -272,6 +280,99 @@ impl AccountInfoStorageMapKeyProvider {
272280
}
273281
}
274282

283+
/// Extra signed extension data that is used by most chains.
284+
pub type CommonSignedExtra = (
285+
CheckNonZeroSender,
286+
CheckSpecVersion,
287+
CheckTxVersion,
288+
CheckGenesis<Hash>,
289+
CheckEra<Hash>,
290+
CheckNonce<Nonce>,
291+
CheckWeight,
292+
ChargeTransactionPayment<Balance>,
293+
);
294+
295+
/// Extra signed extension data that starts with `CommonSignedExtra`.
296+
pub type SuffixedCommonSignedExtension<Suffix> =
297+
GenericSignedExtension<(CommonSignedExtra, Suffix)>;
298+
299+
/// Helper trait to define some extra methods on `SuffixedCommonSignedExtension`.
300+
pub trait SuffixedCommonSignedExtensionExt<Suffix: SignedExtensionSchema> {
301+
/// Create signed extension from its components.
302+
fn from_params(
303+
spec_version: u32,
304+
transaction_version: u32,
305+
era: TransactionEra<BlockNumber, Hash>,
306+
genesis_hash: Hash,
307+
nonce: Nonce,
308+
tip: Balance,
309+
extra: (Suffix::Payload, Suffix::AdditionalSigned),
310+
) -> Self;
311+
312+
/// Return transaction nonce.
313+
fn nonce(&self) -> Nonce;
314+
315+
/// Return transaction tip.
316+
fn tip(&self) -> Balance;
317+
}
318+
319+
impl<Suffix> SuffixedCommonSignedExtensionExt<Suffix> for SuffixedCommonSignedExtension<Suffix>
320+
where
321+
Suffix: SignedExtensionSchema,
322+
{
323+
fn from_params(
324+
spec_version: u32,
325+
transaction_version: u32,
326+
era: TransactionEra<BlockNumber, Hash>,
327+
genesis_hash: Hash,
328+
nonce: Nonce,
329+
tip: Balance,
330+
extra: (Suffix::Payload, Suffix::AdditionalSigned),
331+
) -> Self {
332+
GenericSignedExtension::new(
333+
(
334+
(
335+
(), // non-zero sender
336+
(), // spec version
337+
(), // tx version
338+
(), // genesis
339+
era.frame_era(), // era
340+
nonce.into(), // nonce (compact encoding)
341+
(), // Check weight
342+
tip.into(), // transaction payment / tip (compact encoding)
343+
),
344+
extra.0,
345+
),
346+
Some((
347+
(
348+
(),
349+
spec_version,
350+
transaction_version,
351+
genesis_hash,
352+
era.signed_payload(genesis_hash),
353+
(),
354+
(),
355+
(),
356+
),
357+
extra.1,
358+
)),
359+
)
360+
}
361+
362+
fn nonce(&self) -> Nonce {
363+
let common_payload = self.payload.0;
364+
common_payload.5 .0
365+
}
366+
367+
fn tip(&self) -> Balance {
368+
let common_payload = self.payload.0;
369+
common_payload.7 .0
370+
}
371+
}
372+
373+
/// Signed extension that is used by most chains.
374+
pub type CommonSignedExtension = SuffixedCommonSignedExtension<()>;
375+
275376
#[cfg(test)]
276377
mod tests {
277378
use super::*;

0 commit comments

Comments
 (0)