Skip to content

Commit 4cdd959

Browse files
svyatonikbkchr
authored andcommitted
Refactor message relay helpers (#1234)
* refactor message relay helpers * single standalone_metrics function * fixed tests * clippy + fmt * removed commented code * add calls tracing * fix spelling * cargo fmt * -commented code * fix build again * post-merge build fix * clippy + fmt
1 parent 90f2b3c commit 4cdd959

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1484
-2455
lines changed

bridges/bin/millau/node/src/service.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ type FullClient =
6666
type FullBackend = sc_service::TFullBackend<Block>;
6767
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;
6868

69+
#[allow(clippy::type_complexity)]
6970
pub fn new_partial(
7071
config: &Configuration,
7172
) -> Result<
@@ -89,7 +90,7 @@ pub fn new_partial(
8990
ServiceError,
9091
> {
9192
if config.keystore_remote.is_some() {
92-
return Err(ServiceError::Other(format!("Remote Keystores are not supported.")))
93+
return Err(ServiceError::Other("Remote Keystores are not supported.".into()))
9394
}
9495

9596
let telemetry = config
@@ -111,7 +112,7 @@ pub fn new_partial(
111112

112113
let (client, backend, keystore_container, task_manager) =
113114
sc_service::new_full_parts::<Block, RuntimeApi, _>(
114-
&config,
115+
config,
115116
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
116117
executor,
117118
)?;
@@ -178,7 +179,7 @@ pub fn new_partial(
178179
})
179180
}
180181

181-
fn remote_keystore(_url: &String) -> Result<Arc<LocalKeystore>, &'static str> {
182+
fn remote_keystore(_url: &str) -> Result<Arc<LocalKeystore>, &'static str> {
182183
// FIXME: here would the concrete keystore be built,
183184
// must return a concrete type (NOT `LocalKeystore`) that
184185
// implements `CryptoStore` and `SyncCryptoStore`

bridges/bin/millau/runtime/src/lib.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,9 @@ impl pallet_shift_session_manager::Config for Runtime {}
407407
parameter_types! {
408408
pub const MaxMessagesToPruneAtOnce: bp_messages::MessageNonce = 8;
409409
pub const MaxUnrewardedRelayerEntriesAtInboundLane: bp_messages::MessageNonce =
410-
bp_millau::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE;
410+
bp_rialto::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX;
411411
pub const MaxUnconfirmedMessagesAtInboundLane: bp_messages::MessageNonce =
412-
bp_millau::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE;
412+
bp_rialto::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
413413
// `IdentityFee` is used by Millau => we may use weight directly
414414
pub const GetDeliveryConfirmationTransactionFee: Balance =
415415
bp_millau::MAX_SINGLE_MESSAGE_DELIVERY_CONFIRMATION_TX_WEIGHT as _;
@@ -875,6 +875,7 @@ where
875875
#[cfg(test)]
876876
mod tests {
877877
use super::*;
878+
use bp_runtime::Chain;
878879
use bridge_runtime_common::messages;
879880

880881
#[test]
@@ -891,30 +892,30 @@ mod tests {
891892
);
892893

893894
let max_incoming_message_proof_size = bp_rialto::EXTRA_STORAGE_PROOF_SIZE.saturating_add(
894-
messages::target::maximal_incoming_message_size(bp_millau::max_extrinsic_size()),
895+
messages::target::maximal_incoming_message_size(bp_millau::Millau::max_extrinsic_size()),
895896
);
896897
pallet_bridge_messages::ensure_able_to_receive_message::<Weights>(
897-
bp_millau::max_extrinsic_size(),
898-
bp_millau::max_extrinsic_weight(),
898+
bp_millau::Millau::max_extrinsic_size(),
899+
bp_millau::Millau::max_extrinsic_weight(),
899900
max_incoming_message_proof_size,
900901
messages::target::maximal_incoming_message_dispatch_weight(
901-
bp_millau::max_extrinsic_weight(),
902+
bp_millau::Millau::max_extrinsic_weight(),
902903
),
903904
);
904905

905906
let max_incoming_inbound_lane_data_proof_size =
906907
bp_messages::InboundLaneData::<()>::encoded_size_hint(
907908
bp_millau::MAXIMAL_ENCODED_ACCOUNT_ID_SIZE,
908-
bp_rialto::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE as _,
909-
bp_rialto::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE as _,
909+
bp_millau::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX as _,
910+
bp_millau::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX as _,
910911
)
911912
.unwrap_or(u32::MAX);
912913
pallet_bridge_messages::ensure_able_to_receive_confirmation::<Weights>(
913-
bp_millau::max_extrinsic_size(),
914-
bp_millau::max_extrinsic_weight(),
914+
bp_millau::Millau::max_extrinsic_size(),
915+
bp_millau::Millau::max_extrinsic_weight(),
915916
max_incoming_inbound_lane_data_proof_size,
916-
bp_rialto::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE,
917-
bp_rialto::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE,
917+
bp_millau::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX,
918+
bp_millau::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX,
918919
DbWeight::get(),
919920
);
920921
}

bridges/bin/millau/runtime/src/rialto_messages.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use bp_messages::{
2323
target_chain::{ProvedMessages, SourceHeaderChain},
2424
InboundLaneData, LaneId, Message, MessageNonce, Parameter as MessagesParameter,
2525
};
26-
use bp_runtime::{ChainId, MILLAU_CHAIN_ID, RIALTO_CHAIN_ID};
26+
use bp_runtime::{Chain, ChainId, MILLAU_CHAIN_ID, RIALTO_CHAIN_ID};
2727
use bridge_runtime_common::messages::{self, MessageBridge, MessageTransaction};
2828
use codec::{Decode, Encode};
2929
use frame_support::{
@@ -86,7 +86,7 @@ impl MessageBridge for WithRialtoMessageBridge {
8686
const RELAYER_FEE_PERCENT: u32 = 10;
8787
const THIS_CHAIN_ID: ChainId = MILLAU_CHAIN_ID;
8888
const BRIDGED_CHAIN_ID: ChainId = RIALTO_CHAIN_ID;
89-
const BRIDGED_MESSAGES_PALLET_NAME: &'static str = bp_rialto::WITH_MILLAU_MESSAGES_PALLET_NAME;
89+
const BRIDGED_MESSAGES_PALLET_NAME: &'static str = bp_millau::WITH_MILLAU_MESSAGES_PALLET_NAME;
9090

9191
type ThisChain = Millau;
9292
type BridgedChain = Rialto;
@@ -172,13 +172,13 @@ impl messages::ChainWithMessages for Rialto {
172172

173173
impl messages::BridgedChainWithMessages for Rialto {
174174
fn maximal_extrinsic_size() -> u32 {
175-
bp_rialto::max_extrinsic_size()
175+
bp_rialto::Rialto::max_extrinsic_size()
176176
}
177177

178178
fn message_weight_limits(_message_payload: &[u8]) -> RangeInclusive<Weight> {
179179
// we don't want to relay too large messages + keep reserve for future upgrades
180180
let upper_limit = messages::target::maximal_incoming_message_dispatch_weight(
181-
bp_rialto::max_extrinsic_weight(),
181+
bp_rialto::Rialto::max_extrinsic_weight(),
182182
);
183183

184184
// we're charging for payload bytes in `WithRialtoMessageBridge::transaction_payment`

bridges/bin/rialto/runtime/src/lib.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,9 @@ impl pallet_shift_session_manager::Config for Runtime {}
434434
parameter_types! {
435435
pub const MaxMessagesToPruneAtOnce: bp_messages::MessageNonce = 8;
436436
pub const MaxUnrewardedRelayerEntriesAtInboundLane: bp_messages::MessageNonce =
437-
bp_rialto::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE;
437+
bp_millau::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX;
438438
pub const MaxUnconfirmedMessagesAtInboundLane: bp_messages::MessageNonce =
439-
bp_rialto::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE;
439+
bp_millau::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
440440
// `IdentityFee` is used by Rialto => we may use weight directly
441441
pub const GetDeliveryConfirmationTransactionFee: Balance =
442442
bp_rialto::MAX_SINGLE_MESSAGE_DELIVERY_CONFIRMATION_TX_WEIGHT as _;
@@ -1183,6 +1183,7 @@ where
11831183
#[cfg(test)]
11841184
mod tests {
11851185
use super::*;
1186+
use bp_runtime::Chain;
11861187
use bridge_runtime_common::messages;
11871188

11881189
#[test]
@@ -1198,30 +1199,30 @@ mod tests {
11981199
);
11991200

12001201
let max_incoming_message_proof_size = bp_millau::EXTRA_STORAGE_PROOF_SIZE.saturating_add(
1201-
messages::target::maximal_incoming_message_size(bp_rialto::max_extrinsic_size()),
1202+
messages::target::maximal_incoming_message_size(bp_rialto::Rialto::max_extrinsic_size()),
12021203
);
12031204
pallet_bridge_messages::ensure_able_to_receive_message::<Weights>(
1204-
bp_rialto::max_extrinsic_size(),
1205-
bp_rialto::max_extrinsic_weight(),
1205+
bp_rialto::Rialto::max_extrinsic_size(),
1206+
bp_rialto::Rialto::max_extrinsic_weight(),
12061207
max_incoming_message_proof_size,
12071208
messages::target::maximal_incoming_message_dispatch_weight(
1208-
bp_rialto::max_extrinsic_weight(),
1209+
bp_rialto::Rialto::max_extrinsic_weight(),
12091210
),
12101211
);
12111212

12121213
let max_incoming_inbound_lane_data_proof_size =
12131214
bp_messages::InboundLaneData::<()>::encoded_size_hint(
12141215
bp_rialto::MAXIMAL_ENCODED_ACCOUNT_ID_SIZE,
1215-
bp_millau::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE as _,
1216-
bp_millau::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE as _,
1216+
bp_rialto::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX as _,
1217+
bp_rialto::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX as _,
12171218
)
12181219
.unwrap_or(u32::MAX);
12191220
pallet_bridge_messages::ensure_able_to_receive_confirmation::<Weights>(
1220-
bp_rialto::max_extrinsic_size(),
1221-
bp_rialto::max_extrinsic_weight(),
1221+
bp_rialto::Rialto::max_extrinsic_size(),
1222+
bp_rialto::Rialto::max_extrinsic_weight(),
12221223
max_incoming_inbound_lane_data_proof_size,
1223-
bp_millau::MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE,
1224-
bp_millau::MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE,
1224+
bp_rialto::MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX,
1225+
bp_rialto::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX,
12251226
DbWeight::get(),
12261227
);
12271228
}

bridges/bin/rialto/runtime/src/millau_messages.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use bp_messages::{
2323
target_chain::{ProvedMessages, SourceHeaderChain},
2424
InboundLaneData, LaneId, Message, MessageNonce, Parameter as MessagesParameter,
2525
};
26-
use bp_runtime::{ChainId, MILLAU_CHAIN_ID, RIALTO_CHAIN_ID};
26+
use bp_runtime::{Chain, ChainId, MILLAU_CHAIN_ID, RIALTO_CHAIN_ID};
2727
use bridge_runtime_common::messages::{self, MessageBridge, MessageTransaction};
2828
use codec::{Decode, Encode};
2929
use frame_support::{
@@ -86,7 +86,7 @@ impl MessageBridge for WithMillauMessageBridge {
8686
const RELAYER_FEE_PERCENT: u32 = 10;
8787
const THIS_CHAIN_ID: ChainId = RIALTO_CHAIN_ID;
8888
const BRIDGED_CHAIN_ID: ChainId = MILLAU_CHAIN_ID;
89-
const BRIDGED_MESSAGES_PALLET_NAME: &'static str = bp_millau::WITH_RIALTO_MESSAGES_PALLET_NAME;
89+
const BRIDGED_MESSAGES_PALLET_NAME: &'static str = bp_rialto::WITH_RIALTO_MESSAGES_PALLET_NAME;
9090

9191
type ThisChain = Rialto;
9292
type BridgedChain = Millau;
@@ -170,13 +170,13 @@ impl messages::ChainWithMessages for Millau {
170170

171171
impl messages::BridgedChainWithMessages for Millau {
172172
fn maximal_extrinsic_size() -> u32 {
173-
bp_millau::max_extrinsic_size()
173+
bp_millau::Millau::max_extrinsic_size()
174174
}
175175

176176
fn message_weight_limits(_message_payload: &[u8]) -> RangeInclusive<Weight> {
177177
// we don't want to relay too large messages + keep reserve for future upgrades
178178
let upper_limit = messages::target::maximal_incoming_message_dispatch_weight(
179-
bp_millau::max_extrinsic_weight(),
179+
bp_millau::Millau::max_extrinsic_weight(),
180180
);
181181

182182
// we're charging for payload bytes in `WithMillauMessageBridge::transaction_payment`

bridges/modules/grandpa/src/mock.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ impl Chain for TestBridgedChain {
106106
type Balance = u64;
107107
type Index = u64;
108108
type Signature = Signature;
109+
110+
fn max_extrinsic_size() -> u32 {
111+
unreachable!()
112+
}
113+
fn max_extrinsic_weight() -> Weight {
114+
unreachable!()
115+
}
109116
}
110117

111118
pub fn run_test<T>(test: impl FnOnce() -> T) -> T {

bridges/modules/token-swap/src/mock.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ impl bp_runtime::Chain for BridgedChain {
142142
type Balance = BridgedBalance;
143143
type Index = u64;
144144
type Signature = BridgedAccountSignature;
145+
146+
fn max_extrinsic_size() -> u32 {
147+
unreachable!()
148+
}
149+
fn max_extrinsic_weight() -> Weight {
150+
unreachable!()
151+
}
145152
}
146153

147154
pub struct TestMessagesBridge;

bridges/primitives/chain-kusama/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ pub const EXISTENTIAL_DEPOSIT: Balance = 1_000_000_000_000 / 30_000;
8181
/// conditions.
8282
pub const SESSION_LENGTH: BlockNumber = time_units::HOURS;
8383

84-
/// Name of the With-Polkadot messages pallet instance in the Kusama runtime.
85-
pub const WITH_POLKADOT_MESSAGES_PALLET_NAME: &str = "BridgePolkadotMessages";
84+
/// Name of the With-Kusama messages pallet instance that is deployed at bridged chains.
85+
pub const WITH_KUSAMA_MESSAGES_PALLET_NAME: &str = "BridgeKusamaMessages";
8686

8787
/// Name of the DOT->KSM conversion rate stored in the Kusama runtime.
8888
pub const POLKADOT_TO_KUSAMA_CONVERSION_RATE_PARAMETER_NAME: &str =

bridges/primitives/chain-millau/src/lib.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
6868
/// Represents the portion of a block that will be used by Normal extrinsics.
6969
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
7070

71-
/// Maximal number of unrewarded relayer entries at inbound lane.
72-
pub const MAX_UNREWARDED_RELAYER_ENTRIES_AT_INBOUND_LANE: MessageNonce = 1024;
71+
/// Maximal number of unrewarded relayer entries in Millau confirmation transaction.
72+
pub const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce = 128;
7373

74-
/// Maximal number of unconfirmed messages at inbound lane.
75-
pub const MAX_UNCONFIRMED_MESSAGES_AT_INBOUND_LANE: MessageNonce = 1024;
74+
/// Maximal number of unconfirmed messages in Millau confirmation transaction.
75+
pub const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce = 128;
7676

7777
/// Weight of single regular message delivery transaction on Millau chain.
7878
///
@@ -172,6 +172,17 @@ impl Chain for Millau {
172172
type Balance = Balance;
173173
type Index = Index;
174174
type Signature = Signature;
175+
176+
fn max_extrinsic_size() -> u32 {
177+
*BlockLength::get().max.get(DispatchClass::Normal)
178+
}
179+
180+
fn max_extrinsic_weight() -> Weight {
181+
BlockWeights::get()
182+
.get(DispatchClass::Normal)
183+
.max_extrinsic
184+
.unwrap_or(Weight::MAX)
185+
}
175186
}
176187

177188
/// Millau Hasher (Blake2-256 ++ Keccak-256) implementation.
@@ -246,21 +257,12 @@ frame_support::parameter_types! {
246257
.build_or_panic();
247258
}
248259

249-
/// Get the maximum weight (compute time) that a Normal extrinsic on the Millau chain can use.
250-
pub fn max_extrinsic_weight() -> Weight {
251-
BlockWeights::get()
252-
.get(DispatchClass::Normal)
253-
.max_extrinsic
254-
.unwrap_or(Weight::MAX)
255-
}
260+
/// Name of the With-Millau messages pallet instance that is deployed at bridged chains.
261+
pub const WITH_MILLAU_MESSAGES_PALLET_NAME: &str = "BridgeMillauMessages";
256262

257-
/// Get the maximum length in bytes that a Normal extrinsic on the Millau chain requires.
258-
pub fn max_extrinsic_size() -> u32 {
259-
*BlockLength::get().max.get(DispatchClass::Normal)
260-
}
263+
/// Name of the Rialto->Millau (actually DOT->KSM) conversion rate stored in the Millau runtime.
264+
pub const RIALTO_TO_MILLAU_CONVERSION_RATE_PARAMETER_NAME: &str = "RialtoToMillauConversionRate";
261265

262-
/// Name of the With-Rialto messages pallet instance in the Millau runtime.
263-
pub const WITH_RIALTO_MESSAGES_PALLET_NAME: &str = "BridgeRialtoMessages";
264266
/// Name of the With-Rialto token swap pallet instance in the Millau runtime.
265267
pub const WITH_RIALTO_TOKEN_SWAP_PALLET_NAME: &str = "BridgeRialtoTokenSwap";
266268

bridges/primitives/chain-polkadot/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ pub const EXISTENTIAL_DEPOSIT: Balance = 10_000_000_000;
8181
/// conditions.
8282
pub const SESSION_LENGTH: BlockNumber = 4 * time_units::HOURS;
8383

84-
/// Name of the With-Kusama messages pallet instance in the Polkadot runtime.
85-
pub const WITH_KUSAMA_MESSAGES_PALLET_NAME: &str = "BridgeKusamaMessages";
84+
/// Name of the With-Polkadot messages pallet instance that is deployed at bridged chains.
85+
pub const WITH_POLKADOT_MESSAGES_PALLET_NAME: &str = "BridgePolkadotMessages";
8686

8787
/// Name of the KSM->DOT conversion rate stored in the Polkadot runtime.
8888
pub const KUSAMA_TO_POLKADOT_CONVERSION_RATE_PARAMETER_NAME: &str =

0 commit comments

Comments
 (0)