Skip to content

Commit

Permalink
Start the equivocation detection loop from the complex relayer (parit…
Browse files Browse the repository at this point in the history
…ytech#2507) (paritytech#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
  • Loading branch information
serban300 committed Apr 8, 2024
1 parent ea0e621 commit a8dac36
Show file tree
Hide file tree
Showing 48 changed files with 25,091 additions and 244 deletions.
1 change: 1 addition & 0 deletions bridges/bin/rialto-parachain/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ scale-info = { version = "2.9.0", default-features = false, features = ["derive"
bp-header-chain = { path = "../../../primitives/header-chain", default-features = false }
bp-messages = { path = "../../../primitives/messages", default-features = false }
bp-millau = { path = "../../../primitives/chain-millau", default-features = false }
bp-polkadot-core = { path = "../../../primitives/polkadot-core", default-features = false }
bp-relayers = { path = "../../../primitives/relayers", default-features = false }
bp-runtime = { path = "../../../primitives/runtime", default-features = false }
bp-rialto-parachain = { path = "../../../primitives/chain-rialto-parachain", default-features = false }
Expand Down
56 changes: 33 additions & 23 deletions bridges/bin/rialto-parachain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,12 +858,10 @@ mod tests {
target_chain::{DispatchMessage, DispatchMessageData, MessageDispatch},
LaneId, MessageKey,
};
use bridge_runtime_common::{
integrity::check_additional_signed, messages_xcm_extension::XcmBlobMessageDispatchResult,
};
use bridge_runtime_common::messages_xcm_extension::XcmBlobMessageDispatchResult;
use codec::Encode;
use pallet_bridge_messages::OutboundLanes;
use sp_runtime::generic::Era;
use sp_runtime::{generic::Era, traits::Zero};
use xcm_executor::XcmExecutor;

fn new_test_ext() -> sp_io::TestExternalities {
Expand Down Expand Up @@ -941,24 +939,36 @@ mod tests {

#[test]
fn ensure_signed_extension_definition_is_correct() {
let payload: SignedExtra = (
frame_system::CheckNonZeroSender::new(),
frame_system::CheckSpecVersion::new(),
frame_system::CheckTxVersion::new(),
frame_system::CheckGenesis::new(),
frame_system::CheckEra::from(Era::Immortal),
frame_system::CheckNonce::from(10),
frame_system::CheckWeight::new(),
pallet_transaction_payment::ChargeTransactionPayment::from(10),
BridgeRejectObsoleteHeadersAndMessages,
DummyBridgeRefundMillauMessages,
);
let indirect_payload = bp_rialto_parachain::SignedExtension::new(
((), (), (), (), Era::Immortal, 10.into(), (), 10.into(), (), ()),
None,
);
assert_eq!(payload.encode(), indirect_payload.encode());

check_additional_signed::<SignedExtra, bp_rialto_parachain::SignedExtension>();
use bp_polkadot_core::SuffixedCommonSignedExtensionExt;

sp_io::TestExternalities::default().execute_with(|| {
frame_system::BlockHash::<Runtime>::insert(BlockNumber::zero(), Hash::default());
let payload: SignedExtra = (
frame_system::CheckNonZeroSender::new(),
frame_system::CheckSpecVersion::new(),
frame_system::CheckTxVersion::new(),
frame_system::CheckGenesis::new(),
frame_system::CheckEra::from(Era::Immortal),
frame_system::CheckNonce::from(10),
frame_system::CheckWeight::new(),
pallet_transaction_payment::ChargeTransactionPayment::from(10),
BridgeRejectObsoleteHeadersAndMessages,
DummyBridgeRefundMillauMessages,
);
let indirect_payload = bp_rialto_parachain::SignedExtension::from_params(
VERSION.spec_version,
VERSION.transaction_version,
bp_runtime::TransactionEra::Immortal,
System::block_hash(BlockNumber::zero()),
10,
10,
(((), ()), ((), ())),
);
assert_eq!(payload.encode(), indirect_payload.encode());
assert_eq!(
payload.additional_signed().unwrap().encode(),
indirect_payload.additional_signed().unwrap().encode()
)
});
}
}
13 changes: 0 additions & 13 deletions bridges/bin/runtime-common/src/integrity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use codec::Encode;
use frame_support::{storage::generator::StorageValue, traits::Get, weights::Weight};
use frame_system::limits;
use pallet_bridge_messages::WeightInfoExt as _;
use sp_runtime::traits::SignedExtension;

/// Macro that ensures that the runtime configuration and chain primitives crate are sharing
/// the same types (nonce, block number, hash, hasher, account id and header).
Expand Down Expand Up @@ -347,15 +346,3 @@ pub fn check_message_lane_weights<
);
}
}

/// Check that the `AdditionalSigned` type of a wrapped runtime is the same as the one of the
/// corresponding actual runtime.
///
/// This method doesn't perform any `assert`. If the condition is not true it will generate a
/// compile-time error.
pub fn check_additional_signed<SignedExt, IndirectSignedExt: SignedExtension>()
where
SignedExt: SignedExtension,
IndirectSignedExt: SignedExtension<AdditionalSigned = SignedExt::AdditionalSigned>,
{
}
91 changes: 5 additions & 86 deletions bridges/primitives/chain-bridge-hub-cumulus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ pub use bp_polkadot_core::{
};

use bp_messages::*;
use bp_polkadot_core::SuffixedCommonSignedExtension;
use bp_runtime::extensions::{
BridgeRejectObsoleteHeadersAndMessages, ChargeTransactionPayment, CheckEra, CheckGenesis,
CheckNonZeroSender, CheckNonce, CheckSpecVersion, CheckTxVersion, CheckWeight,
GenericSignedExtension, RefundBridgedParachainMessagesSchema,
BridgeRejectObsoleteHeadersAndMessages, RefundBridgedParachainMessagesSchema,
};
use frame_support::{
dispatch::DispatchClass,
Expand Down Expand Up @@ -133,88 +132,8 @@ pub const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce = 1024;
/// analysis (like the one above).
pub const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce = 4096;

/// Extra signed extension data that is used by all bridge hubs.
pub type SignedExtra = (
CheckNonZeroSender,
CheckSpecVersion,
CheckTxVersion,
CheckGenesis<Hash>,
CheckEra<Hash>,
CheckNonce<Nonce>,
CheckWeight,
ChargeTransactionPayment<Balance>,
/// Signed extension that is used by all bridge hubs.
pub type SignedExtension = SuffixedCommonSignedExtension<(
BridgeRejectObsoleteHeadersAndMessages,
RefundBridgedParachainMessagesSchema,
);

/// Signed extension that is used by all bridge hubs.
pub type SignedExtension = GenericSignedExtension<SignedExtra>;

/// Helper trait to define some extra methods on bridge hubs signed extension (and
/// overcome Rust limitations).
pub trait BridgeHubSignedExtension {
/// Create signed extension from its components.
fn from_params(
spec_version: u32,
transaction_version: u32,
era: bp_runtime::TransactionEra<BlockNumber, Hash>,
genesis_hash: Hash,
nonce: Nonce,
tip: Balance,
) -> Self;

/// Return transaction nonce.
fn nonce(&self) -> Nonce;

/// Return transaction tip.
fn tip(&self) -> Balance;
}

impl BridgeHubSignedExtension for SignedExtension {
/// Create signed extension from its components.
fn from_params(
spec_version: u32,
transaction_version: u32,
era: bp_runtime::TransactionEra<BlockNumber, Hash>,
genesis_hash: Hash,
nonce: Nonce,
tip: Balance,
) -> Self {
GenericSignedExtension::new(
(
(), // non-zero sender
(), // spec version
(), // tx version
(), // genesis
era.frame_era(), // era
nonce.into(), // nonce (compact encoding)
(), // Check weight
tip.into(), // transaction payment / tip (compact encoding)
(), // bridge reject obsolete headers and msgs
(), // bridge reward to relayer for message passing
),
Some((
(),
spec_version,
transaction_version,
genesis_hash,
era.signed_payload(genesis_hash),
(),
(),
(),
(),
(),
)),
)
}

/// Return transaction nonce.
fn nonce(&self) -> Nonce {
self.payload.5 .0
}

/// Return transaction tip.
fn tip(&self) -> Balance {
self.payload.7 .0
}
}
)>;
3 changes: 3 additions & 0 deletions bridges/primitives/chain-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ impl ChainWithGrandpa for Kusama {
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
}

// The SignedExtension used by Kusama.
pub use bp_polkadot_core::CommonSignedExtension as SignedExtension;

/// Name of the parachains pallet in the Kusama runtime.
pub const PARAS_PALLET_NAME: &str = "Paras";

Expand Down
5 changes: 4 additions & 1 deletion bridges/primitives/chain-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
pub use bp_polkadot_core::*;

use bp_header_chain::ChainWithGrandpa;
use bp_runtime::{decl_bridge_finality_runtime_apis, Chain};
use bp_runtime::{decl_bridge_finality_runtime_apis, extensions::PrevalidateAttests, Chain};
use frame_support::weights::Weight;
use sp_std::prelude::Vec;

Expand Down Expand Up @@ -57,6 +57,9 @@ impl ChainWithGrandpa for Polkadot {
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
}

/// The SignedExtension used by Polkadot.
pub type SignedExtension = SuffixedCommonSignedExtension<PrevalidateAttests>;

/// Name of the parachains pallet in the Polkadot runtime.
pub const PARAS_PALLET_NAME: &str = "Paras";

Expand Down
3 changes: 3 additions & 0 deletions bridges/primitives/chain-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ parameter_types! {
pub const SS58Prefix: u8 = 42;
}

// The SignedExtension used by Rococo.
pub use bp_polkadot_core::CommonSignedExtension as SignedExtension;

/// Name of the parachains pallet in the Rococo runtime.
pub const PARAS_PALLET_NAME: &str = "Paras";

Expand Down
3 changes: 3 additions & 0 deletions bridges/primitives/chain-wococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ impl ChainWithGrandpa for Wococo {
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = AVERAGE_HEADER_SIZE_IN_JUSTIFICATION;
}

// The SignedExtension used by Wococo.
pub use bp_rococo::CommonSignedExtension as SignedExtension;

/// Name of the With-Wococo GRANDPA pallet instance that is deployed at bridged chains.
pub const WITH_WOCOCO_GRANDPA_PALLET_NAME: &str = "BridgeWococoGrandpa";

Expand Down
103 changes: 102 additions & 1 deletion bridges/primitives/polkadot-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@
#![cfg_attr(not(feature = "std"), no_std)]

use bp_messages::MessageNonce;
use bp_runtime::{Chain, EncodedOrDecodedCall, StorageMapKeyProvider};
use bp_runtime::{
self,
extensions::{
ChargeTransactionPayment, CheckEra, CheckGenesis, CheckNonZeroSender, CheckNonce,
CheckSpecVersion, CheckTxVersion, CheckWeight, GenericSignedExtension,
SignedExtensionSchema,
},
Chain, EncodedOrDecodedCall, StorageMapKeyProvider, TransactionEra,
};
use frame_support::{
dispatch::DispatchClass,
parameter_types,
Expand Down Expand Up @@ -272,6 +280,99 @@ impl AccountInfoStorageMapKeyProvider {
}
}

/// Extra signed extension data that is used by most chains.
pub type CommonSignedExtra = (
CheckNonZeroSender,
CheckSpecVersion,
CheckTxVersion,
CheckGenesis<Hash>,
CheckEra<Hash>,
CheckNonce<Nonce>,
CheckWeight,
ChargeTransactionPayment<Balance>,
);

/// Extra signed extension data that starts with `CommonSignedExtra`.
pub type SuffixedCommonSignedExtension<Suffix> =
GenericSignedExtension<(CommonSignedExtra, Suffix)>;

/// Helper trait to define some extra methods on `SuffixedCommonSignedExtension`.
pub trait SuffixedCommonSignedExtensionExt<Suffix: SignedExtensionSchema> {
/// Create signed extension from its components.
fn from_params(
spec_version: u32,
transaction_version: u32,
era: TransactionEra<BlockNumber, Hash>,
genesis_hash: Hash,
nonce: Nonce,
tip: Balance,
extra: (Suffix::Payload, Suffix::AdditionalSigned),
) -> Self;

/// Return transaction nonce.
fn nonce(&self) -> Nonce;

/// Return transaction tip.
fn tip(&self) -> Balance;
}

impl<Suffix> SuffixedCommonSignedExtensionExt<Suffix> for SuffixedCommonSignedExtension<Suffix>
where
Suffix: SignedExtensionSchema,
{
fn from_params(
spec_version: u32,
transaction_version: u32,
era: TransactionEra<BlockNumber, Hash>,
genesis_hash: Hash,
nonce: Nonce,
tip: Balance,
extra: (Suffix::Payload, Suffix::AdditionalSigned),
) -> Self {
GenericSignedExtension::new(
(
(
(), // non-zero sender
(), // spec version
(), // tx version
(), // genesis
era.frame_era(), // era
nonce.into(), // nonce (compact encoding)
(), // Check weight
tip.into(), // transaction payment / tip (compact encoding)
),
extra.0,
),
Some((
(
(),
spec_version,
transaction_version,
genesis_hash,
era.signed_payload(genesis_hash),
(),
(),
(),
),
extra.1,
)),
)
}

fn nonce(&self) -> Nonce {
let common_payload = self.payload.0;
common_payload.5 .0
}

fn tip(&self) -> Balance {
let common_payload = self.payload.0;
common_payload.7 .0
}
}

/// Signed extension that is used by most chains.
pub type CommonSignedExtension = SuffixedCommonSignedExtension<()>;

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading

0 comments on commit a8dac36

Please sign in to comment.