Skip to content

Commit be500fc

Browse files
authored
Bridges subtree update (#2602)
## Summary This PR aligns Rococo/Westend bridge with latest Bridges repo development: - paritytech/parity-bridges-common#2727 - paritytech/parity-bridges-common#2728 - paritytech/parity-bridges-common#2729 Part of: paritytech/parity-bridges-common#2452
1 parent e7651cf commit be500fc

File tree

33 files changed

+1057
-232
lines changed

33 files changed

+1057
-232
lines changed

Cargo.lock

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ members = [
1313
"bridges/modules/messages",
1414
"bridges/modules/parachains",
1515
"bridges/modules/relayers",
16+
"bridges/modules/xcm-bridge-hub",
1617
"bridges/modules/xcm-bridge-hub-router",
1718
"bridges/primitives/chain-asset-hub-rococo",
1819
"bridges/primitives/chain-asset-hub-westend",
@@ -33,6 +34,7 @@ members = [
3334
"bridges/primitives/relayers",
3435
"bridges/primitives/runtime",
3536
"bridges/primitives/test-utils",
37+
"bridges/primitives/xcm-bridge-hub",
3638
"bridges/primitives/xcm-bridge-hub-router",
3739
"cumulus/client/cli",
3840
"cumulus/client/collator",

bridges/bin/runtime-common/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ bp-parachains = { path = "../../primitives/parachains", default-features = false
2222
bp-polkadot-core = { path = "../../primitives/polkadot-core", default-features = false }
2323
bp-relayers = { path = "../../primitives/relayers", default-features = false }
2424
bp-runtime = { path = "../../primitives/runtime", default-features = false }
25+
bp-xcm-bridge-hub = { path = "../../primitives/xcm-bridge-hub", default-features = false }
2526
bp-xcm-bridge-hub-router = { path = "../../primitives/xcm-bridge-hub-router", default-features = false }
2627
pallet-bridge-grandpa = { path = "../../modules/grandpa", default-features = false }
2728
pallet-bridge-messages = { path = "../../modules/messages", default-features = false }
@@ -59,6 +60,7 @@ std = [
5960
"bp-relayers/std",
6061
"bp-runtime/std",
6162
"bp-xcm-bridge-hub-router/std",
63+
"bp-xcm-bridge-hub/std",
6264
"codec/std",
6365
"frame-support/std",
6466
"frame-system/std",

bridges/bin/runtime-common/src/messages_xcm_extension.rs

Lines changed: 46 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,23 @@
2222
//! `XcmRouter` <- `MessageDispatch` <- `InboundMessageQueue`
2323
2424
use bp_messages::{
25-
source_chain::{MessagesBridge, OnMessagesDelivered},
25+
source_chain::OnMessagesDelivered,
2626
target_chain::{DispatchMessage, MessageDispatch},
2727
LaneId, MessageNonce,
2828
};
2929
use bp_runtime::messages::MessageDispatchResult;
30+
pub use bp_xcm_bridge_hub::XcmAsPlainPayload;
3031
use bp_xcm_bridge_hub_router::XcmChannelStatusProvider;
3132
use codec::{Decode, Encode};
3233
use frame_support::{traits::Get, weights::Weight, CloneNoBound, EqNoBound, PartialEqNoBound};
3334
use pallet_bridge_messages::{
34-
Config as MessagesConfig, OutboundLanesCongestedSignals, Pallet as MessagesPallet,
35-
WeightInfoExt as MessagesPalletWeights,
35+
Config as MessagesConfig, OutboundLanesCongestedSignals, WeightInfoExt as MessagesPalletWeights,
3636
};
3737
use scale_info::TypeInfo;
3838
use sp_runtime::SaturatedConversion;
3939
use sp_std::{fmt::Debug, marker::PhantomData};
4040
use xcm::prelude::*;
41-
use xcm_builder::{DispatchBlob, DispatchBlobError, HaulBlob, HaulBlobError};
42-
43-
/// Plain "XCM" payload, which we transfer through bridge
44-
pub type XcmAsPlainPayload = sp_std::prelude::Vec<u8>;
41+
use xcm_builder::{DispatchBlob, DispatchBlobError};
4542

4643
/// Message dispatch result type for single message
4744
#[derive(CloneNoBound, EqNoBound, PartialEqNoBound, Encode, Decode, Debug, TypeInfo)]
@@ -123,6 +120,7 @@ impl<
123120

124121
/// A pair of sending chain location and message lane, used by this chain to send messages
125122
/// over the bridge.
123+
#[cfg_attr(feature = "std", derive(Debug, Eq, PartialEq))]
126124
pub struct SenderAndLane {
127125
/// Sending chain relative location.
128126
pub location: MultiLocation,
@@ -144,8 +142,6 @@ pub trait XcmBlobHauler {
144142
type Runtime: MessagesConfig<Self::MessagesInstance>;
145143
/// Instance of the messages pallet that is used to send messages.
146144
type MessagesInstance: 'static;
147-
/// Returns lane used by this hauler.
148-
type SenderAndLane: Get<SenderAndLane>;
149145

150146
/// Actual XCM message sender (`HRMP` or `UMP`) to the source chain
151147
/// location (`Self::SenderAndLane::get().location`).
@@ -166,54 +162,25 @@ pub trait XcmBlobHauler {
166162
/// makes sure that XCM blob is sent to the outbound lane to be relayed.
167163
///
168164
/// It needs to be used at the source bridge hub.
169-
pub struct XcmBlobHaulerAdapter<XcmBlobHauler>(sp_std::marker::PhantomData<XcmBlobHauler>);
165+
pub struct XcmBlobHaulerAdapter<XcmBlobHauler, Lanes>(
166+
sp_std::marker::PhantomData<(XcmBlobHauler, Lanes)>,
167+
);
170168

171-
impl<H: XcmBlobHauler> HaulBlob for XcmBlobHaulerAdapter<H>
172-
where
173-
H::Runtime: MessagesConfig<H::MessagesInstance, OutboundPayload = XcmAsPlainPayload>,
169+
impl<
170+
H: XcmBlobHauler,
171+
Lanes: Get<sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorMultiLocation))>>,
172+
> OnMessagesDelivered for XcmBlobHaulerAdapter<H, Lanes>
174173
{
175-
fn haul_blob(blob: sp_std::prelude::Vec<u8>) -> Result<(), HaulBlobError> {
176-
let sender_and_lane = H::SenderAndLane::get();
177-
MessagesPallet::<H::Runtime, H::MessagesInstance>::send_message(sender_and_lane.lane, blob)
178-
.map(|artifacts| {
179-
log::info!(
180-
target: crate::LOG_TARGET_BRIDGE_DISPATCH,
181-
"haul_blob result - ok: {:?} on lane: {:?}. Enqueued messages: {}",
182-
artifacts.nonce,
183-
sender_and_lane.lane,
184-
artifacts.enqueued_messages,
185-
);
186-
187-
// notify XCM queue manager about updated lane state
188-
LocalXcmQueueManager::<H>::on_bridge_message_enqueued(
189-
&sender_and_lane,
190-
artifacts.enqueued_messages,
191-
);
192-
})
193-
.map_err(|error| {
194-
log::error!(
195-
target: crate::LOG_TARGET_BRIDGE_DISPATCH,
196-
"haul_blob result - error: {:?} on lane: {:?}",
197-
error,
198-
sender_and_lane.lane,
199-
);
200-
HaulBlobError::Transport("MessageSenderError")
201-
})
202-
}
203-
}
204-
205-
impl<H: XcmBlobHauler> OnMessagesDelivered for XcmBlobHaulerAdapter<H> {
206174
fn on_messages_delivered(lane: LaneId, enqueued_messages: MessageNonce) {
207-
let sender_and_lane = H::SenderAndLane::get();
208-
if sender_and_lane.lane != lane {
209-
return
175+
if let Some(sender_and_lane) =
176+
Lanes::get().iter().find(|link| link.0.lane == lane).map(|link| &link.0)
177+
{
178+
// notify XCM queue manager about updated lane state
179+
LocalXcmQueueManager::<H>::on_bridge_messages_delivered(
180+
sender_and_lane,
181+
enqueued_messages,
182+
);
210183
}
211-
212-
// notify XCM queue manager about updated lane state
213-
LocalXcmQueueManager::<H>::on_bridge_messages_delivered(
214-
&sender_and_lane,
215-
enqueued_messages,
216-
);
217184
}
218185
}
219186

@@ -356,6 +323,9 @@ mod tests {
356323
location: MultiLocation::new(1, X1(Parachain(1000))),
357324
lane: TEST_LANE_ID,
358325
};
326+
pub TestLanes: sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorMultiLocation))> = sp_std::vec![
327+
(TestSenderAndLane::get(), (NetworkId::ByGenesis([0; 32]), InteriorMultiLocation::Here))
328+
];
359329
pub DummyXcmMessage: Xcm<()> = Xcm::new();
360330
}
361331

@@ -389,56 +359,69 @@ mod tests {
389359
impl XcmBlobHauler for TestBlobHauler {
390360
type Runtime = TestRuntime;
391361
type MessagesInstance = ();
392-
type SenderAndLane = TestSenderAndLane;
393362

394363
type ToSourceChainSender = DummySendXcm;
395364
type CongestedMessage = DummyXcmMessage;
396365
type UncongestedMessage = DummyXcmMessage;
397366
}
398367

399-
type TestBlobHaulerAdapter = XcmBlobHaulerAdapter<TestBlobHauler>;
368+
type TestBlobHaulerAdapter = XcmBlobHaulerAdapter<TestBlobHauler, TestLanes>;
400369

401-
fn fill_up_lane_to_congestion() {
370+
fn fill_up_lane_to_congestion() -> MessageNonce {
371+
let latest_generated_nonce = OUTBOUND_LANE_CONGESTED_THRESHOLD;
402372
OutboundLanes::<TestRuntime, ()>::insert(
403373
TEST_LANE_ID,
404374
OutboundLaneData {
405375
oldest_unpruned_nonce: 0,
406376
latest_received_nonce: 0,
407-
latest_generated_nonce: OUTBOUND_LANE_CONGESTED_THRESHOLD,
377+
latest_generated_nonce,
408378
},
409379
);
380+
latest_generated_nonce
410381
}
411382

412383
#[test]
413384
fn congested_signal_is_not_sent_twice() {
414385
run_test(|| {
415-
fill_up_lane_to_congestion();
386+
let enqueued = fill_up_lane_to_congestion();
416387

417388
// next sent message leads to congested signal
418-
TestBlobHaulerAdapter::haul_blob(vec![42]).unwrap();
389+
LocalXcmQueueManager::<TestBlobHauler>::on_bridge_message_enqueued(
390+
&TestSenderAndLane::get(),
391+
enqueued + 1,
392+
);
419393
assert_eq!(DummySendXcm::messages_sent(), 1);
420394

421395
// next sent message => we don't sent another congested signal
422-
TestBlobHaulerAdapter::haul_blob(vec![42]).unwrap();
396+
LocalXcmQueueManager::<TestBlobHauler>::on_bridge_message_enqueued(
397+
&TestSenderAndLane::get(),
398+
enqueued,
399+
);
423400
assert_eq!(DummySendXcm::messages_sent(), 1);
424401
});
425402
}
426403

427404
#[test]
428405
fn congested_signal_is_not_sent_when_outbound_lane_is_not_congested() {
429406
run_test(|| {
430-
TestBlobHaulerAdapter::haul_blob(vec![42]).unwrap();
407+
LocalXcmQueueManager::<TestBlobHauler>::on_bridge_message_enqueued(
408+
&TestSenderAndLane::get(),
409+
1,
410+
);
431411
assert_eq!(DummySendXcm::messages_sent(), 0);
432412
});
433413
}
434414

435415
#[test]
436416
fn congested_signal_is_sent_when_outbound_lane_is_congested() {
437417
run_test(|| {
438-
fill_up_lane_to_congestion();
418+
let enqueued = fill_up_lane_to_congestion();
439419

440420
// next sent message leads to congested signal
441-
TestBlobHaulerAdapter::haul_blob(vec![42]).unwrap();
421+
LocalXcmQueueManager::<TestBlobHauler>::on_bridge_message_enqueued(
422+
&TestSenderAndLane::get(),
423+
enqueued + 1,
424+
);
442425
assert_eq!(DummySendXcm::messages_sent(), 1);
443426
assert!(LocalXcmQueueManager::<TestBlobHauler>::is_congested_signal_sent(TEST_LANE_ID));
444427
});

bridges/bin/runtime-common/src/mock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,8 @@ impl ChainWithGrandpa for BridgedUnderlyingChain {
376376
const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = "";
377377
const MAX_AUTHORITIES_COUNT: u32 = 16;
378378
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8;
379-
const MAX_HEADER_SIZE: u32 = 256;
380-
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
379+
const MAX_MANDATORY_HEADER_SIZE: u32 = 256;
380+
const AVERAGE_HEADER_SIZE: u32 = 64;
381381
}
382382

383383
impl Chain for BridgedUnderlyingParachain {

bridges/modules/grandpa/src/call_ext.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
1616

1717
use crate::{weights::WeightInfo, BridgedBlockNumber, BridgedHeader, Config, Error, Pallet};
18-
use bp_header_chain::{justification::GrandpaJustification, ChainWithGrandpa};
18+
use bp_header_chain::{
19+
justification::GrandpaJustification, max_expected_submit_finality_proof_arguments_size,
20+
ChainWithGrandpa, GrandpaConsensusLogReader,
21+
};
1922
use bp_runtime::{BlockNumberOf, OwnedBridgeModule};
2023
use codec::Encode;
2124
use frame_support::{dispatch::CallableCallFor, traits::IsSubType, weights::Weight};
@@ -169,28 +172,28 @@ pub(crate) fn submit_finality_proof_info_from_args<T: Config<I>, I: 'static>(
169172
Weight::zero()
170173
};
171174

175+
// check if the `finality_target` is a mandatory header. If so, we are ready to refund larger
176+
// size
177+
let is_mandatory_finality_target =
178+
GrandpaConsensusLogReader::<BridgedBlockNumber<T, I>>::find_scheduled_change(
179+
finality_target.digest(),
180+
)
181+
.is_some();
182+
172183
// we can estimate extra call size easily, without any additional significant overhead
173184
let actual_call_size: u32 = finality_target
174185
.encoded_size()
175186
.saturating_add(justification.encoded_size())
176187
.saturated_into();
177-
let max_expected_call_size = max_expected_call_size::<T, I>(required_precommits);
188+
let max_expected_call_size = max_expected_submit_finality_proof_arguments_size::<T::BridgedChain>(
189+
is_mandatory_finality_target,
190+
required_precommits,
191+
);
178192
let extra_size = actual_call_size.saturating_sub(max_expected_call_size);
179193

180194
SubmitFinalityProofInfo { block_number, extra_weight, extra_size }
181195
}
182196

183-
/// Returns maximal expected size of `submit_finality_proof` call arguments.
184-
fn max_expected_call_size<T: Config<I>, I: 'static>(required_precommits: u32) -> u32 {
185-
let max_expected_justification_size =
186-
GrandpaJustification::<BridgedHeader<T, I>>::max_reasonable_size::<T::BridgedChain>(
187-
required_precommits,
188-
);
189-
190-
// call arguments are header and justification
191-
T::BridgedChain::MAX_HEADER_SIZE.saturating_add(max_expected_justification_size)
192-
}
193-
194197
#[cfg(test)]
195198
mod tests {
196199
use crate::{

bridges/modules/grandpa/src/mock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ impl ChainWithGrandpa for TestBridgedChain {
8686
const WITH_CHAIN_GRANDPA_PALLET_NAME: &'static str = "";
8787
const MAX_AUTHORITIES_COUNT: u32 = MAX_BRIDGED_AUTHORITIES;
8888
const REASONABLE_HEADERS_IN_JUSTIFICATON_ANCESTRY: u32 = 8;
89-
const MAX_HEADER_SIZE: u32 = 256;
90-
const AVERAGE_HEADER_SIZE_IN_JUSTIFICATION: u32 = 64;
89+
const MAX_MANDATORY_HEADER_SIZE: u32 = 256;
90+
const AVERAGE_HEADER_SIZE: u32 = 64;
9191
}
9292

9393
/// Return test externalities to use in tests.

0 commit comments

Comments
 (0)