Skip to content

Commit

Permalink
Implement additional require primitives for dynamic fees directly for…
Browse files Browse the repository at this point in the history
… pallet-xcm-bridge-hub (#2261)

* added backoff mechanism to inbound bridge queue

* impl backpressure in the XcmBlobHaulerAdapter

* leave TODOs

* BridgeMessageProcessor prototype

* another TODO

* Revert "also temporary (?) remove BridgesByLocalOrigin because the storage format will likely change to be able to resume bridges from the on_iniitalize/on_idle"

This reverts commit bdd7ae1.

* prototype for QueuePausedQuery

* implement ExportXcm and MessageDispatch for pallet-xcm-bridge-hub

* spelling

* flush

* small comments to myself

* more backports from dynamic-fees-v1

* use new pallet as exporter and dispatcher in Millau

* use new pallet as exporter and dispatcher in Rialto

* use new pallet as exporter and dispatcher in RialtoParachain

* flush

* fix remaining compilation issues

* warnings + fmt

* fix tests

* LocalXcmChannelManager

* change lane ids

* it works!

* remove bp-xcm-bridge-hub-router and use LocalXcmChannelManager everywhere

* removed commented code

* cleaning up

* cleaning up

* cleaning up

* - separated BridgeId and LaneId
- BridgeId now uses versioned universal locations
- added missing stuff to exporter.rs

* OnMessagesDelivered is back

* start using bp-xcm-bridge-hub as OnMessagesDelivered

* cleaning up

* spelling

* fix stupid issues

* Backport latest relevant dynamic fees changes from v1 to v2 (#2372)

* backport latest relevant dynamic fees changes from v1 to v2

* fix comment
  • Loading branch information
svyatonik authored Aug 25, 2023
1 parent b995ac0 commit bd87488
Show file tree
Hide file tree
Showing 61 changed files with 1,282 additions and 788 deletions.
19 changes: 13 additions & 6 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ members = [
"primitives/runtime",
"primitives/test-utils",
"primitives/xcm-bridge-hub",
"primitives/xcm-bridge-hub-router",
"relays/bin-substrate",
"relays/client-bridge-hub-kusama",
"relays/client-bridge-hub-polkadot",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ You will also see the message lane relayers listening for new messages.

```
# Message Relayer Logs
[Millau_to_Rialto_MessageLane_0x52011894c856c0c613a2ad2395dfbb509090f6b7a6aef9359adb75aa26a586c7] [date] DEBUG bridge Asking Millau::ReceivingConfirmationsDelivery about best message nonces
[Millau_to_Rialto_MessageLane_0xefed785b626e94da3969257012f506524bcec78867420e26ff8c55ddcdb0f7b7] [date] DEBUG bridge Asking Millau::ReceivingConfirmationsDelivery about best message nonces
[...] [date] INFO bridge Synced Some(2) of Some(3) nonces in Millau::MessagesDelivery -> Rialto::MessagesDelivery race
[...] [date] DEBUG bridge Asking Millau::MessagesDelivery about message nonces
[...] [date] DEBUG bridge Received best nonces from Millau::ReceivingConfirmationsDelivery: TargetClientNonces { latest_nonce: 0, nonces_data: () }
Expand Down
4 changes: 4 additions & 0 deletions bin/millau/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "mast
substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-network-common = { git = "https://github.com/paritytech/substrate", branch = "master" }

# Polkadot Dependencies

xcm = { git = "https://github.com/paritytech/polkadot", branch = "master" }

[build-dependencies]
substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "master" }
frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "master" }
Expand Down
28 changes: 21 additions & 7 deletions bin/millau/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.

use bridge_runtime_common::messages_xcm_extension::XcmBlobHauler;
use millau_runtime::{
AccountId, AuraConfig, BalancesConfig, BeefyConfig, BridgeRialtoMessagesConfig,
BridgeRialtoParachainMessagesConfig, BridgeWestendGrandpaConfig, GrandpaConfig,
RuntimeGenesisConfig, SessionConfig, SessionKeys, Signature, SudoConfig, SystemConfig,
WASM_BINARY,
XcmRialtoBridgeHubConfig, XcmRialtoParachainBridgeHubConfig, WASM_BINARY,
};
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_consensus_beefy::crypto::AuthorityId as BeefyId;
Expand Down Expand Up @@ -225,19 +224,34 @@ fn testnet_genesis(
},
bridge_rialto_messages: BridgeRialtoMessagesConfig {
owner: Some(get_account_id_from_seed::<sr25519::Public>(RIALTO_MESSAGES_PALLET_OWNER)),
opened_lanes: vec![millau_runtime::rialto_messages::ToRialtoXcmBlobHauler::xcm_lane()],
opened_lanes: vec![millau_runtime::rialto_messages::Bridge::get().lane_id()],
..Default::default()
},
bridge_rialto_parachain_messages: BridgeRialtoParachainMessagesConfig {
owner: Some(get_account_id_from_seed::<sr25519::Public>(
RIALTO_PARACHAIN_MESSAGES_PALLET_OWNER,
)),
opened_lanes: vec![
millau_runtime::rialto_parachain_messages::ToRialtoParachainXcmBlobHauler::xcm_lane(
),
],
opened_lanes: vec![millau_runtime::rialto_parachain_messages::Bridge::get().lane_id()],
..Default::default()
},
xcm_pallet: Default::default(),
xcm_rialto_bridge_hub: XcmRialtoBridgeHubConfig {
opened_bridges: vec![(
xcm::latest::Junctions::Here.into(),
xcm::latest::InteriorMultiLocation::from(
millau_runtime::xcm_config::RialtoNetwork::get(),
),
)],
..Default::default()
},
xcm_rialto_parachain_bridge_hub: XcmRialtoParachainBridgeHubConfig {
opened_bridges: vec![(
xcm::latest::Junctions::Here.into(),
xcm::latest::InteriorMultiLocation::from(
millau_runtime::xcm_config::RialtoParachainNetwork::get(),
),
)],
..Default::default()
},
}
}
7 changes: 5 additions & 2 deletions bin/millau/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ bp-rialto = { path = "../../../primitives/chain-rialto", default-features = fals
bp-rialto-parachain = { path = "../../../primitives/chain-rialto-parachain", default-features = false }
bp-runtime = { path = "../../../primitives/runtime", default-features = false }
bp-westend = { path = "../../../primitives/chain-westend", default-features = false }
bp-xcm-bridge-hub-router = { path = "../../../primitives/xcm-bridge-hub-router", default-features = false }
bp-xcm-bridge-hub = { path = "../../../primitives/xcm-bridge-hub", default-features = false }
bridge-runtime-common = { path = "../../runtime-common", default-features = false }
pallet-bridge-grandpa = { path = "../../../modules/grandpa", default-features = false }
pallet-bridge-messages = { path = "../../../modules/messages", default-features = false }
pallet-bridge-parachains = { path = "../../../modules/parachains", default-features = false }
pallet-bridge-relayers = { path = "../../../modules/relayers", default-features = false }
pallet-shift-session-manager = { path = "../../../modules/shift-session-manager", default-features = false }
pallet-xcm-bridge-hub = { path = "../../../modules/xcm-bridge-hub", default-features = false }
pallet-xcm-bridge-hub-router = { path = "../../../modules/xcm-bridge-hub-router", default-features = false }

# Substrate Dependencies
Expand Down Expand Up @@ -92,7 +93,7 @@ std = [
"bp-rialto-parachain/std",
"bp-runtime/std",
"bp-westend/std",
"bp-xcm-bridge-hub-router/std",
"bp-xcm-bridge-hub/std",
"bridge-runtime-common/std",
"codec/std",
"frame-executive/std",
Expand All @@ -117,6 +118,7 @@ std = [
"pallet-transaction-payment/std",
"pallet-utility/std",
"pallet-xcm/std",
"pallet-xcm-bridge-hub/std",
"pallet-xcm-bridge-hub-router/std",
"scale-info/std",
"sp-api/std",
Expand Down Expand Up @@ -144,6 +146,7 @@ runtime-benchmarks = [
"pallet-bridge-parachains/runtime-benchmarks",
"pallet-bridge-relayers/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"pallet-xcm-bridge-hub/runtime-benchmarks",
"pallet-xcm-bridge-hub-router/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
Expand Down
81 changes: 72 additions & 9 deletions bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ use sp_std::prelude::*;
#[cfg(feature = "std")]
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;
use xcm_builder::NetworkExportTable;

// to be able to use Millau runtime in `bridge-runtime-common` tests
pub use bridge_runtime_common;
Expand Down Expand Up @@ -442,17 +443,18 @@ impl pallet_bridge_messages::Config<WithRialtoMessagesInstance> for Runtime {
type BridgedChain = bp_rialto::Rialto;
type BridgedHeaderChain = BridgeRialtoGrandpa;

type OutboundPayload = bridge_runtime_common::messages_xcm_extension::XcmAsPlainPayload;
type InboundPayload = bridge_runtime_common::messages_xcm_extension::XcmAsPlainPayload;
type OutboundPayload = bp_xcm_bridge_hub::XcmAsPlainPayload;
type InboundPayload = bp_xcm_bridge_hub::XcmAsPlainPayload;

type DeliveryPayments = ();
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
Runtime,
WithRialtoMessagesInstance,
frame_support::traits::ConstU64<100_000>,
>;
type OnMessagesDelivered = XcmRialtoBridgeHub;

type MessageDispatch = crate::rialto_messages::FromRialtoMessageDispatch;
type MessageDispatch = XcmRialtoBridgeHub;
}

/// Instance of the messages pallet used to relay messages to/from RialtoParachain chain.
Expand All @@ -470,17 +472,18 @@ impl pallet_bridge_messages::Config<WithRialtoParachainMessagesInstance> for Run
bp_rialto_parachain::RialtoParachain,
>;

type OutboundPayload = bridge_runtime_common::messages_xcm_extension::XcmAsPlainPayload;
type InboundPayload = bridge_runtime_common::messages_xcm_extension::XcmAsPlainPayload;
type OutboundPayload = bp_xcm_bridge_hub::XcmAsPlainPayload;
type InboundPayload = bp_xcm_bridge_hub::XcmAsPlainPayload;

type DeliveryPayments = ();
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
Runtime,
WithRialtoParachainMessagesInstance,
frame_support::traits::ConstU64<100_000>,
>;
type OnMessagesDelivered = XcmRialtoParachainBridgeHub;

type MessageDispatch = crate::rialto_parachain_messages::FromRialtoParachainMessageDispatch;
type MessageDispatch = XcmRialtoParachainBridgeHub;
}

parameter_types! {
Expand Down Expand Up @@ -527,21 +530,75 @@ impl pallet_utility::Config for Runtime {

// this config is totally incorrect - the pallet is not actually used at this runtime. We need
// it only to be able to run benchmarks and make required traits (and default weights for tests).

parameter_types! {
pub BridgeTable: Vec<(xcm::prelude::NetworkId, xcm::prelude::MultiLocation, Option<xcm::prelude::MultiAsset>)>
= vec![(
xcm_config::RialtoNetwork::get(),
xcm_config::TokenLocation::get(),
Some((xcm_config::TokenAssetId::get(), 1_000_000_000_u128).into()),
)];
}

impl pallet_xcm_bridge_hub_router::Config for Runtime {
type WeightInfo = ();

type UniversalLocation = xcm_config::UniversalLocation;
type SiblingBridgeHubLocation = xcm_config::TokenLocation;
type BridgedNetworkId = xcm_config::RialtoNetwork;
type Bridges = NetworkExportTable<BridgeTable>;

type ToBridgeHubSender = xcm_config::XcmRouter;
type WithBridgeHubChannel = xcm_config::EmulatedSiblingXcmpChannel;
type LocalXcmChannelManager = xcm_config::EmulatedSiblingXcmpChannel;

type BaseFee = ConstU128<1_000_000_000>;
type ByteFee = ConstU128<1_000>;
type FeeAsset = xcm_config::TokenAssetId;
}

/// Instance of the XCM bridge hub pallet used to relay messages to/from Rialto chain.
pub type WithRialtoXcmBridgeHubInstance = ();

impl pallet_xcm_bridge_hub::Config<WithRialtoXcmBridgeHubInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;

type UniversalLocation = xcm_config::UniversalLocation;
type BridgedNetworkId = xcm_config::RialtoNetwork;
type BridgeMessagesPalletInstance = WithRialtoMessagesInstance;

type MaxSuspendedBridges = ConstU32<1>;
type OpenBridgeOrigin = frame_support::traits::NeverEnsureOrigin<xcm::latest::MultiLocation>;
type BridgeOriginAccountIdConverter = xcm_config::SovereignAccountOf;

type BridgeReserve = ConstU64<1_000_000_000>;
type NativeCurrency = Balances;

type LocalXcmChannelManager = ();
type BlobDispatcher = xcm_config::OnMillauBlobDispatcher;
type MessageExportPrice = ();
}

/// Instance of the XCM bridge hub pallet used to relay messages to/from RialtoParachain chain.
pub type WithRialtoParachainXcmBridgeHubInstance = pallet_xcm_bridge_hub::Instance1;

impl pallet_xcm_bridge_hub::Config<WithRialtoParachainXcmBridgeHubInstance> for Runtime {
type RuntimeEvent = RuntimeEvent;

type UniversalLocation = xcm_config::UniversalLocation;
type BridgedNetworkId = xcm_config::RialtoParachainNetwork;
type BridgeMessagesPalletInstance = WithRialtoParachainMessagesInstance;

type MaxSuspendedBridges = ConstU32<1>;
type OpenBridgeOrigin = frame_support::traits::NeverEnsureOrigin<xcm::latest::MultiLocation>;
type BridgeOriginAccountIdConverter = xcm_config::SovereignAccountOf;

type BridgeReserve = ConstU64<1_000_000_000>;
type NativeCurrency = Balances;

type LocalXcmChannelManager = ();
type BlobDispatcher = xcm_config::OnMillauBlobDispatcher;
type MessageExportPrice = ();
}

construct_runtime!(
pub enum Runtime {
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Expand Down Expand Up @@ -569,6 +626,7 @@ construct_runtime!(
BridgeRelayers: pallet_bridge_relayers::{Pallet, Call, Storage, Event<T>},
BridgeRialtoGrandpa: pallet_bridge_grandpa::{Pallet, Call, Storage, Event<T>},
BridgeRialtoMessages: pallet_bridge_messages::{Pallet, Call, Storage, Event<T>, Config<T>},
XcmRialtoBridgeHub: pallet_xcm_bridge_hub::{Pallet, Call, Storage, Event<T>, Config<T>},

// Westend bridge modules.
BridgeWestendGrandpa: pallet_bridge_grandpa::<Instance1>::{Pallet, Call, Config<T>, Storage, Event<T>},
Expand All @@ -577,6 +635,7 @@ construct_runtime!(
// RialtoParachain bridge modules.
BridgeRialtoParachains: pallet_bridge_parachains::{Pallet, Call, Storage, Event<T>},
BridgeRialtoParachainMessages: pallet_bridge_messages::<Instance1>::{Pallet, Call, Storage, Event<T>, Config<T>},
XcmRialtoParachainBridgeHub: pallet_xcm_bridge_hub::<Instance1>::{Pallet, Call, Storage, Event<T>, Config<T>},

// Pallet for sending XCM.
XcmPallet: pallet_xcm::{Pallet, Call, Storage, Event<T>, Origin, Config<T>} = 99,
Expand All @@ -602,7 +661,11 @@ pub type PriorityBoostPerMessage = ConstU64<351_343_108>;
pub type BridgeRefundRialtoParachainMessages = RefundBridgedParachainMessages<
Runtime,
RefundableParachain<WithRialtoParachainsInstance, bp_rialto_parachain::RialtoParachain>,
RefundableMessagesLane<Runtime, WithRialtoParachainMessagesInstance>,
RefundableMessagesLane<
Runtime,
WithRialtoParachainMessagesInstance,
rialto_parachain_messages::Lane,
>,
ActualFeeRefund<Runtime>,
PriorityBoostPerMessage,
StrBridgeRefundRialtoPara2000Lane0Msgs,
Expand Down
Loading

0 comments on commit bd87488

Please sign in to comment.