Skip to content

Commit

Permalink
Start the equivocation detection loop from the complex relayer (#2507) (
Browse files Browse the repository at this point in the history
#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 Aug 31, 2023
1 parent 7fbb67d commit 5fdbaf4
Show file tree
Hide file tree
Showing 59 changed files with 26,206 additions and 611 deletions.
1,323 changes: 983 additions & 340 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions 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 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 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>,
{
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
- targets:
- relay-millau-rialto:9616
- detect-millau-to-rialto-equivocations:9616
- detect-rialto-to-millau-equivocations:9616
20 changes: 20 additions & 0 deletions deployments/bridges/rialto-millau/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ services:
depends_on:
- relay-millau-rialto

detect-millau-to-rialto-equivocations:
<<: *sub-bridge-relay
environment:
RUST_LOG: bridge=trace
entrypoint: /entrypoints/detect-millau-to-rialto-equivocations-entrypoint.sh
ports:
- "10616:9616"
depends_on:
- relay-millau-rialto

detect-rialto-to-millau-equivocations:
<<: *sub-bridge-relay
environment:
RUST_LOG: bridge=trace
entrypoint: /entrypoints/detect-rialto-to-millau-equivocations-entrypoint.sh
ports:
- "10716:9616"
depends_on:
- relay-millau-rialto

# Note: These are being overridden from the top level `monitoring` compose file.
grafana-dashboard:
environment:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -eu

sleep 15

exec /home/user/substrate-relay detect-equivocations millau-to-rialto \
--source-host millau-node-alice \
--source-port 9944 \
--source-signer //Rialto.HeadersAndMessagesRelay \
--source-transactions-mortality=64 \
--target-host rialto-node-alice \
--target-port 9944 \
--prometheus-host=0.0.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -eu

sleep 15

exec /home/user/substrate-relay detect-equivocations rialto-to-millau \
--source-host rialto-node-alice \
--source-port 9944 \
--source-signer //Millau.HeadersAndMessagesRelay \
--source-transactions-mortality=64 \
--target-host millau-node-alice \
--target-port 9944 \
--prometheus-host=0.0.0.0
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- targets:
- relay-millau-rialto-parachain-1:9616
- relay-millau-rialto-parachain-2:9616
- detect-millau-to-rialto-parachain-equivocations:9616
- detect-rialto-to-millau-equivocations:9616
20 changes: 20 additions & 0 deletions deployments/bridges/rialto-parachain-millau/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,26 @@ services:
depends_on:
- relay-messages-millau-to-rialto-parachain-generator

detect-millau-to-rialto-parachain-equivocations:
<<: *sub-bridge-relay
environment:
RUST_LOG: bridge=trace
entrypoint: /entrypoints/detect-millau-to-rialto-parachain-equivocations-entrypoint.sh
ports:
- "11019:9616"
depends_on:
- relay-millau-rialto-parachain-1

detect-rialto-to-millau-equivocations:
<<: *sub-bridge-relay
environment:
RUST_LOG: bridge=trace
entrypoint: /entrypoints/detect-rialto-to-millau-equivocations-entrypoint.sh
ports:
- "11020:9616"
depends_on:
- relay-millau-rialto-parachain-1

# Note: These are being overridden from the top level `monitoring` compose file.
grafana-dashboard:
environment:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -eu

sleep 15

exec /home/user/substrate-relay detect-equivocations millau-to-rialto-parachain \
--source-host millau-node-alice \
--source-port 9944 \
--source-signer //RialtoParachain.HeadersAndMessagesRelay1 \
--source-transactions-mortality=64 \
--target-host rialto-parachain-collator-charlie \
--target-port 9944 \
--prometheus-host=0.0.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -eu

sleep 15

exec /home/user/substrate-relay detect-equivocations rialto-to-millau \
--source-host rialto-node-alice \
--source-port 9944 \
--source-signer //Millau.HeadersAndMessagesRelay \
--source-transactions-mortality=64 \
--target-host millau-node-alice \
--target-port 9944 \
--prometheus-host=0.0.0.0
91 changes: 5 additions & 86 deletions 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 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 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 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 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

0 comments on commit 5fdbaf4

Please sign in to comment.