Skip to content

Commit

Permalink
Missing instance support for rewards + Bulletin without rewards + Has…
Browse files Browse the repository at this point in the history
…hedLaneId
  • Loading branch information
bkontur committed Sep 24, 2024
1 parent e3f212b commit 98aedb2
Show file tree
Hide file tree
Showing 16 changed files with 178 additions and 80 deletions.
2 changes: 1 addition & 1 deletion bridges/chains/chain-polkadot-bulletin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,4 @@ impl ChainWithMessages for PolkadotBulletin {
}

decl_bridge_finality_runtime_apis!(polkadot_bulletin, grandpa);
decl_bridge_messages_runtime_apis!(polkadot_bulletin, bp_messages::LegacyLaneId);
decl_bridge_messages_runtime_apis!(polkadot_bulletin, bp_messages::HashedLaneId);
11 changes: 8 additions & 3 deletions bridges/modules/relayers/src/extension/grandpa_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub struct WithGrandpaChainExtensionConfig<
BridgeGrandpaPalletInstance,
// instance of BridgedChain `pallet-bridge-messages`, tracked by this extension
BridgeMessagesPalletInstance,
// instance of `pallet-bridge-relayers`, tracked by this extension
BridgeRelayersPalletInstance,
// message delivery transaction priority boost for every additional message
PriorityBoostPerMessage,
>(
Expand All @@ -63,20 +65,22 @@ pub struct WithGrandpaChainExtensionConfig<
BatchCallUnpacker,
BridgeGrandpaPalletInstance,
BridgeMessagesPalletInstance,
BridgeRelayersPalletInstance,
PriorityBoostPerMessage,
)>,
);

impl<ID, R, BCU, GI, MI, P> ExtensionConfig
for WithGrandpaChainExtensionConfig<ID, R, BCU, GI, MI, P>
impl<ID, R, BCU, GI, MI, RI, P> ExtensionConfig
for WithGrandpaChainExtensionConfig<ID, R, BCU, GI, MI, RI, P>
where
ID: StaticStrProvider,
R: BridgeRelayersConfig
R: BridgeRelayersConfig<RI>
+ BridgeMessagesConfig<MI, BridgedChain = pallet_bridge_grandpa::BridgedChain<R, GI>>
+ BridgeGrandpaConfig<GI>,
BCU: BatchCallUnpacker<R>,
GI: 'static,
MI: 'static,
RI: 'static,
P: Get<TransactionPriority>,
R::RuntimeCall: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>
+ BridgeGrandpaCallSubtype<R, GI>
Expand All @@ -85,6 +89,7 @@ where
type IdProvider = ID;
type Runtime = R;
type BridgeMessagesPalletInstance = MI;
type BridgeRelayersPalletInstance = RI;
type PriorityBoostPerMessage = P;
type RemoteGrandpaChainBlockNumber = pallet_bridge_grandpa::BridgedBlockNumber<R, GI>;
type LaneId = LaneIdOf<R, Self::BridgeMessagesPalletInstance>;
Expand Down
9 changes: 7 additions & 2 deletions bridges/modules/relayers/src/extension/messages_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct WithMessagesExtensionConfig<
IdProvider,
Runtime,
BridgeMessagesPalletInstance,
BridgeRelayersPalletInstance,
PriorityBoostPerMessage,
>(
PhantomData<(
Expand All @@ -46,23 +47,27 @@ pub struct WithMessagesExtensionConfig<
Runtime,
// instance of BridgedChain `pallet-bridge-messages`, tracked by this extension
BridgeMessagesPalletInstance,
// instance of `pallet-bridge-relayers`, tracked by this extension
BridgeRelayersPalletInstance,
// message delivery transaction priority boost for every additional message
PriorityBoostPerMessage,
)>,
);

impl<ID, R, MI, P> ExtensionConfig for WithMessagesExtensionConfig<ID, R, MI, P>
impl<ID, R, MI, RI, P> ExtensionConfig for WithMessagesExtensionConfig<ID, R, MI, RI, P>
where
ID: StaticStrProvider,
R: BridgeRelayersConfig + BridgeMessagesConfig<MI>,
R: BridgeRelayersConfig<RI> + BridgeMessagesConfig<MI>,
MI: 'static,
RI: 'static,
P: Get<TransactionPriority>,
R::RuntimeCall: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>
+ BridgeMessagesCallSubType<R, MI>,
{
type IdProvider = ID;
type Runtime = R;
type BridgeMessagesPalletInstance = MI;
type BridgeRelayersPalletInstance = RI;
type PriorityBoostPerMessage = P;
type RemoteGrandpaChainBlockNumber = ();
type LaneId = LaneIdOf<R, Self::BridgeMessagesPalletInstance>;
Expand Down
3 changes: 3 additions & 0 deletions bridges/modules/relayers/src/extension/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ mod tests {
RuntimeWithUtilityPallet<TestRuntime>,
(),
(),
(),
ConstU64<1>,
>;
type TestGrandpaExtension =
Expand All @@ -504,6 +505,7 @@ mod tests {
RuntimeWithUtilityPallet<TestRuntime>,
(),
(),
(),
ConstU64<1>,
>;
type TestExtension =
Expand All @@ -512,6 +514,7 @@ mod tests {
StrTestMessagesExtension,
TestRuntime,
(),
(),
ConstU64<1>,
>;
type TestMessagesExtension =
Expand Down
10 changes: 8 additions & 2 deletions bridges/modules/relayers/src/extension/parachain_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ pub struct WithParachainExtensionConfig<
BridgeParachainsPalletInstance,
// instance of BridgedChain `pallet-bridge-messages`, tracked by this extension
BridgeMessagesPalletInstance,
// instance of `pallet-bridge-relayers`, tracked by this extension
BridgeRelayersPalletInstance,
// message delivery transaction priority boost for every additional message
PriorityBoostPerMessage,
>(
Expand All @@ -67,20 +69,23 @@ pub struct WithParachainExtensionConfig<
BatchCallUnpacker,
BridgeParachainsPalletInstance,
BridgeMessagesPalletInstance,
BridgeRelayersPalletInstance,
PriorityBoostPerMessage,
)>,
);

impl<ID, R, BCU, PI, MI, P> ExtensionConfig for WithParachainExtensionConfig<ID, R, BCU, PI, MI, P>
impl<ID, R, BCU, PI, MI, RI, P> ExtensionConfig
for WithParachainExtensionConfig<ID, R, BCU, PI, MI, RI, P>
where
ID: StaticStrProvider,
R: BridgeRelayersConfig
R: BridgeRelayersConfig<RI>
+ BridgeMessagesConfig<MI>
+ BridgeParachainsConfig<PI>
+ BridgeGrandpaConfig<R::BridgesGrandpaPalletInstance>,
BCU: BatchCallUnpacker<R>,
PI: 'static,
MI: 'static,
RI: 'static,
P: Get<TransactionPriority>,
R::RuntimeCall: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>
+ BridgeGrandpaCallSubtype<R, R::BridgesGrandpaPalletInstance>
Expand All @@ -91,6 +96,7 @@ where
type IdProvider = ID;
type Runtime = R;
type BridgeMessagesPalletInstance = MI;
type BridgeRelayersPalletInstance = RI;
type PriorityBoostPerMessage = P;
type RemoteGrandpaChainBlockNumber =
pallet_bridge_grandpa::BridgedBlockNumber<R, R::BridgesGrandpaPalletInstance>;
Expand Down
2 changes: 2 additions & 0 deletions bridges/primitives/relayers/src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ pub trait ExtensionConfig {
/// Runtime that optionally supports batched calls. We assume that batched call
/// succeeds if and only if all of its nested calls succeed.
type Runtime: frame_system::Config;
/// Relayers pallet instance.
type BridgeRelayersPalletInstance: 'static;
/// Messages pallet instance.
type BridgeMessagesPalletInstance: 'static;
/// Additional priority that is added to base message delivery transaction priority
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
//! GRANDPA tracking pallet only needs to be aware of one chain.

use super::{weights, AccountId, Balance, Balances, BlockNumber, Runtime, RuntimeEvent};
use bp_messages::LegacyLaneId;
use bp_parachains::SingleParaStoredHeaderDataBuilder;
use frame_support::{parameter_types, traits::ConstU32};

Expand Down Expand Up @@ -83,7 +82,29 @@ impl pallet_bridge_relayers::Config<RelayersForLegacyLaneIdsMessagesInstance> fo
RelayerStakeLease,
>;
type WeightInfo = weights::pallet_bridge_relayers::WeightInfo<Runtime>;
type LaneId = LegacyLaneId;
type LaneId = bp_messages::LegacyLaneId;
}

/// Allows collect and claim rewards for relayers
pub type RelayersForPermissionlessLanesInstance = pallet_bridge_relayers::Instance2;
impl pallet_bridge_relayers::Config<RelayersForPermissionlessLanesInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;
type Reward = Balance;
type PaymentProcedure = bp_relayers::PayRewardFromAccount<
pallet_balances::Pallet<Runtime>,
AccountId,
Self::LaneId,
>;
type StakeAndSlash = pallet_bridge_relayers::StakeAndSlashNamed<
AccountId,
BlockNumber,
Balances,
RelayerStakeReserveId,
RequiredStakeForStakeAndSlash,
RelayerStakeLease,
>;
type WeightInfo = weights::pallet_bridge_relayers::WeightInfo<Runtime>;
type LaneId = bp_messages::HashedLaneId;
}

/// Add GRANDPA bridge pallet to track Rococo Bulletin chain.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
//! are reusing Polkadot Bulletin chain primitives everywhere here.

use crate::{
weights, xcm_config::UniversalLocation, AccountId, Balance, Balances,
BridgeRococoBulletinGrandpa, BridgeRococoBulletinMessages, PolkadotXcm, Runtime, RuntimeEvent,
RuntimeHoldReason, XcmOverRococoBulletin, XcmRouter,
bridge_common_config::RelayersForPermissionlessLanesInstance, weights,
xcm_config::UniversalLocation, AccountId, Balance, Balances, BridgeRococoBulletinGrandpa,
BridgeRococoBulletinMessages, PolkadotXcm, Runtime, RuntimeEvent, RuntimeHoldReason,
XcmOverRococoBulletin, XcmRouter,
};
use bp_messages::{
source_chain::FromBridgedChainMessagesDeliveryProof,
target_chain::FromBridgedChainMessagesProof, LegacyLaneId,
target_chain::FromBridgedChainMessagesProof, HashedLaneId,
};
use bridge_hub_common::xcm_version::XcmVersionOfDestAndRemoteBridge;

Expand Down Expand Up @@ -99,6 +100,7 @@ pub type OnBridgeHubRococoRefundRococoBulletinMessages = BridgeRelayersSignedExt
StrOnBridgeHubRococoRefundRococoBulletinMessages,
Runtime,
WithRococoBulletinMessagesInstance,
RelayersForPermissionlessLanesInstance,
PriorityBoostPerMessage,
>,
LaneIdOf<Runtime, WithRococoBulletinMessagesInstance>,
Expand All @@ -118,7 +120,7 @@ impl pallet_bridge_messages::Config<WithRococoBulletinMessagesInstance> for Runt

type OutboundPayload = XcmAsPlainPayload;
type InboundPayload = XcmAsPlainPayload;
type LaneId = LegacyLaneId;
type LaneId = HashedLaneId;

type DeliveryPayments = ();
type DeliveryConfirmationPayments = ();
Expand All @@ -141,7 +143,7 @@ impl pallet_xcm_bridge_hub::Config<XcmOverPolkadotBulletinInstance> for Runtime
XcmVersionOfDestAndRemoteBridge<PolkadotXcm, RococoBulletinGlobalConsensusNetworkLocation>;

type ForceOrigin = EnsureRoot<AccountId>;
// We don't want to allow creating bridges for this instance with `LegacyLaneId`.
// We don't want to allow creating bridges for this instance.
type OpenBridgeOrigin = EnsureNever<Location>;
// Converter aligned with `OpenBridgeOrigin`.
type BridgeOriginAccountIdConverter =
Expand Down Expand Up @@ -284,8 +286,13 @@ pub mod migration {
use frame_support::traits::ConstBool;

parameter_types! {
pub RococoPeopleToRococoBulletinMessagesLane: LegacyLaneId = LegacyLaneId([0, 0, 0, 0]);
pub BulletinRococoLocation: InteriorLocation = [GlobalConsensus(RococoBulletinGlobalConsensusNetwork::get())].into();
pub RococoPeopleToRococoBulletinMessagesLane: HashedLaneId = pallet_xcm_bridge_hub::Pallet::< Runtime, XcmOverPolkadotBulletinInstance >::bridge_locations(
PeopleRococoLocation::get(),
BulletinRococoLocation::get()
)
.unwrap()
.calculate_lane_id(xcm::latest::VERSION).expect("Valid locations");
}

/// Ensure that the existing lanes for the People<>Bulletin bridge are correctly configured.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
//! Bridge definitions used on BridgeHubRococo for bridging to BridgeHubWestend.

use crate::{
bridge_common_config::{BridgeParachainWestendInstance, DeliveryRewardInBalance},
bridge_common_config::{
BridgeParachainWestendInstance, DeliveryRewardInBalance,
RelayersForLegacyLaneIdsMessagesInstance,
},
weights,
xcm_config::UniversalLocation,
AccountId, Balance, Balances, BridgeWestendMessages, PolkadotXcm, Runtime, RuntimeEvent,
Expand Down Expand Up @@ -88,6 +91,7 @@ pub type OnBridgeHubRococoRefundBridgeHubWestendMessages = BridgeRelayersSignedE
StrOnBridgeHubRococoRefundBridgeHubWestendMessages,
Runtime,
WithBridgeHubWestendMessagesInstance,
RelayersForLegacyLaneIdsMessagesInstance,
PriorityBoostPerMessage,
>,
LaneIdOf<Runtime, WithBridgeHubWestendMessagesInstance>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ pub type SignedExtra = (
frame_system::CheckWeight<Runtime>,
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
BridgeRejectObsoleteHeadersAndMessages,
(
bridge_to_westend_config::OnBridgeHubRococoRefundBridgeHubWestendMessages,
bridge_to_bulletin_config::OnBridgeHubRococoRefundRococoBulletinMessages,
),
(bridge_to_westend_config::OnBridgeHubRococoRefundBridgeHubWestendMessages,),
cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim<Runtime>,
frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
);
Expand Down Expand Up @@ -599,6 +596,9 @@ construct_runtime!(
// With-Rococo Bulletin bridge hub pallet.
XcmOverPolkadotBulletin: pallet_xcm_bridge_hub::<Instance2> = 62,

// Bridge relayers pallet, used by several bridges here (another instance).
BridgeRelayersForPermissionlessLanes: pallet_bridge_relayers::<Instance2> = 63,

EthereumInboundQueue: snowbridge_pallet_inbound_queue = 80,
EthereumOutboundQueue: snowbridge_pallet_outbound_queue = 81,
EthereumBeaconClient: snowbridge_pallet_ethereum_client = 82,
Expand Down Expand Up @@ -668,7 +668,8 @@ mod benches {
[pallet_bridge_parachains, WithinWestend]
[pallet_bridge_messages, RococoToWestend]
[pallet_bridge_messages, RococoToRococoBulletin]
[pallet_bridge_relayers, BridgeRelayersBench::<Runtime>]
[pallet_bridge_relayers, Legacy]
[pallet_bridge_relayers, PermissionlessLanes]
// Ethereum Bridge
[snowbridge_pallet_inbound_queue, EthereumInboundQueue]
[snowbridge_pallet_outbound_queue, EthereumOutboundQueue]
Expand All @@ -677,6 +678,11 @@ mod benches {
);
}

cumulus_pallet_parachain_system::register_validate_block! {
Runtime = Runtime,
BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
}

impl_runtime_apis! {
impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime {
fn slot_duration() -> sp_consensus_aura::SlotDuration {
Expand Down Expand Up @@ -1045,6 +1051,8 @@ impl_runtime_apis! {
type WithinWestend = pallet_bridge_parachains::benchmarking::Pallet::<Runtime, bridge_common_config::BridgeParachainWestendInstance>;
type RococoToWestend = pallet_bridge_messages::benchmarking::Pallet ::<Runtime, bridge_to_westend_config::WithBridgeHubWestendMessagesInstance>;
type RococoToRococoBulletin = pallet_bridge_messages::benchmarking::Pallet ::<Runtime, bridge_to_bulletin_config::WithRococoBulletinMessagesInstance>;
type Legacy = BridgeRelayersBench::<Runtime, bridge_common_config::RelayersForLegacyLaneIdsMessagesInstance>;
type PermissionlessLanes = BridgeRelayersBench::<Runtime, bridge_common_config::RelayersForPermissionlessLanesInstance>;

let mut list = Vec::<BenchmarkList>::new();
list_benchmarks!(list, extra);
Expand Down Expand Up @@ -1294,6 +1302,8 @@ impl_runtime_apis! {
type WithinWestend = pallet_bridge_parachains::benchmarking::Pallet::<Runtime, bridge_common_config::BridgeParachainWestendInstance>;
type RococoToWestend = pallet_bridge_messages::benchmarking::Pallet ::<Runtime, bridge_to_westend_config::WithBridgeHubWestendMessagesInstance>;
type RococoToRococoBulletin = pallet_bridge_messages::benchmarking::Pallet ::<Runtime, bridge_to_bulletin_config::WithRococoBulletinMessagesInstance>;
type Legacy = BridgeRelayersBench::<Runtime, bridge_common_config::RelayersForLegacyLaneIdsMessagesInstance>;
type PermissionlessLanes = BridgeRelayersBench::<Runtime, bridge_common_config::RelayersForPermissionlessLanesInstance>;

use bridge_runtime_common::messages_benchmarking::{
prepare_message_delivery_proof_from_grandpa_chain,
Expand Down Expand Up @@ -1448,7 +1458,26 @@ impl_runtime_apis! {
AccountId,
<Self as pallet_bridge_relayers::Config<bridge_common_config::RelayersForLegacyLaneIdsMessagesInstance>>::LaneId,
>::rewards_account(account_params);
Self::deposit_account(rewards_account, reward);
<Runtime as BridgeRelayersConfig<bridge_common_config::RelayersForLegacyLaneIdsMessagesInstance>>::deposit_account(rewards_account, reward);
}

fn deposit_account(account: AccountId, balance: Balance) {
use frame_support::traits::fungible::Mutate;
Balances::mint_into(&account, balance.saturating_add(ExistentialDeposit::get())).unwrap();
}
}

impl BridgeRelayersConfig<bridge_common_config::RelayersForPermissionlessLanesInstance> for Runtime {
fn prepare_rewards_account(
account_params: bp_relayers::RewardsAccountParams<<Self as pallet_bridge_relayers::Config<bridge_common_config::RelayersForPermissionlessLanesInstance>>::LaneId>,
reward: Balance,
) {
let rewards_account = bp_relayers::PayRewardFromAccount::<
Balances,
AccountId,
<Self as pallet_bridge_relayers::Config<bridge_common_config::RelayersForPermissionlessLanesInstance>>::LaneId,
>::rewards_account(account_params);
<Runtime as BridgeRelayersConfig<bridge_common_config::RelayersForPermissionlessLanesInstance>>::deposit_account(rewards_account, reward);
}

fn deposit_account(account: AccountId, balance: Balance) {
Expand Down Expand Up @@ -1493,11 +1522,6 @@ impl_runtime_apis! {
}
}

cumulus_pallet_parachain_system::register_validate_block! {
Runtime = Runtime,
BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -1525,7 +1549,6 @@ mod tests {
BridgeRejectObsoleteHeadersAndMessages,
(
bridge_to_westend_config::OnBridgeHubRococoRefundBridgeHubWestendMessages::default(),
bridge_to_bulletin_config::OnBridgeHubRococoRefundRococoBulletinMessages::default(),
),
cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim::new(),
frame_metadata_hash_extension::CheckMetadataHash::new(false),
Expand Down
Loading

0 comments on commit 98aedb2

Please sign in to comment.