Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start the equivocation detection loop from the complex relayer #2507

Merged
merged 17 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
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
26 changes: 26 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
53 changes: 32 additions & 21 deletions bin/rialto-parachain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,11 +871,10 @@ mod tests {
};
use bp_runtime::Chain;
use bp_xcm_bridge_hub::{Bridge, BridgeState};
use bridge_runtime_common::integrity::check_additional_signed;
use codec::Encode;
use pallet_bridge_messages::OutboundLanes;
use pallet_xcm_bridge_hub::Bridges;
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 @@ -979,24 +978,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 @@ -26,7 +26,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 @@ -332,15 +331,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>,
{
}
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:
- "10517: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:
- "10518: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,10 @@
#!/bin/bash
set -eu

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -eu

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
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,10 @@
#!/bin/bash
set -eu

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -eu

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
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 @@ -26,10 +26,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 @@ -134,88 +133,8 @@ pub const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce = 1024;
/// Maximal number of unconfirmed messages at inbound lane for Cumulus-based parachains.
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 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Once you merge this, please also update polkadot-sdk and fix breaking changes like this one while still fresh in our minds 😄 . (used here)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, I will. I have to merge it to polkadot-staging first. And then will try to update the bridges repo in polkadot-sdk.

/// 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 @@ -63,6 +63,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
Loading