Skip to content

Commit f95456d

Browse files
svyatonikbkchr
authored andcommitted
replace From<>InboundLaneApi with direct storage reads (#1348)
1 parent ba2b0b0 commit f95456d

File tree

17 files changed

+39
-144
lines changed

17 files changed

+39
-144
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -779,12 +779,6 @@ impl_runtime_apis! {
779779
}
780780
}
781781

782-
impl bp_rialto::FromRialtoInboundLaneApi<Block> for Runtime {
783-
fn unrewarded_relayers_state(lane: bp_messages::LaneId) -> bp_messages::UnrewardedRelayersState {
784-
BridgeRialtoMessages::inbound_unrewarded_relayers_state(lane)
785-
}
786-
}
787-
788782
#[cfg(feature = "runtime-benchmarks")]
789783
impl frame_benchmarking::Benchmark<Block> for Runtime {
790784
fn benchmark_metadata(extra: bool) -> (

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -903,12 +903,6 @@ impl_runtime_apis! {
903903
>(lane, begin, end)
904904
}
905905
}
906-
907-
impl bp_millau::FromMillauInboundLaneApi<Block> for Runtime {
908-
fn unrewarded_relayers_state(lane: bp_messages::LaneId) -> bp_messages::UnrewardedRelayersState {
909-
BridgeMillauMessages::inbound_unrewarded_relayers_state(lane)
910-
}
911-
}
912906
}
913907

914908
/// Millau account ownership digest from Rialto.

bridges/modules/messages/src/lib.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -764,21 +764,6 @@ pub mod pallet {
764764
) -> Option<MessageData<T::OutboundMessageFee>> {
765765
OutboundMessages::<T, I>::get(MessageKey { lane_id: lane, nonce })
766766
}
767-
768-
/// Get state of unrewarded relayers set.
769-
pub fn inbound_unrewarded_relayers_state(
770-
lane: bp_messages::LaneId,
771-
) -> bp_messages::UnrewardedRelayersState {
772-
let relayers = InboundLanes::<T, I>::get(&lane).relayers;
773-
bp_messages::UnrewardedRelayersState {
774-
unrewarded_relayer_entries: relayers.len() as _,
775-
messages_in_oldest_entry: relayers
776-
.front()
777-
.map(|entry| 1 + entry.messages.end - entry.messages.begin)
778-
.unwrap_or(0),
779-
total_messages: total_unrewarded_messages(&relayers).unwrap_or(MessageNonce::MAX),
780-
}
781-
}
782767
}
783768
}
784769

@@ -1127,6 +1112,20 @@ mod tests {
11271112
System::<TestRuntime>::reset_events();
11281113
}
11291114

1115+
fn inbound_unrewarded_relayers_state(
1116+
lane: bp_messages::LaneId,
1117+
) -> bp_messages::UnrewardedRelayersState {
1118+
let relayers = InboundLanes::<TestRuntime, ()>::get(&lane).relayers;
1119+
bp_messages::UnrewardedRelayersState {
1120+
unrewarded_relayer_entries: relayers.len() as _,
1121+
messages_in_oldest_entry: relayers
1122+
.front()
1123+
.map(|entry| 1 + entry.messages.end - entry.messages.begin)
1124+
.unwrap_or(0),
1125+
total_messages: total_unrewarded_messages(&relayers).unwrap_or(MessageNonce::MAX),
1126+
}
1127+
}
1128+
11301129
fn send_regular_message() -> Weight {
11311130
get_ready_for_events();
11321131

@@ -1571,7 +1570,7 @@ mod tests {
15711570
},
15721571
);
15731572
assert_eq!(
1574-
Pallet::<TestRuntime>::inbound_unrewarded_relayers_state(TEST_LANE_ID),
1573+
inbound_unrewarded_relayers_state(TEST_LANE_ID),
15751574
UnrewardedRelayersState {
15761575
unrewarded_relayer_entries: 2,
15771576
messages_in_oldest_entry: 1,
@@ -1606,7 +1605,7 @@ mod tests {
16061605
},
16071606
);
16081607
assert_eq!(
1609-
Pallet::<TestRuntime>::inbound_unrewarded_relayers_state(TEST_LANE_ID),
1608+
inbound_unrewarded_relayers_state(TEST_LANE_ID),
16101609
UnrewardedRelayersState {
16111610
unrewarded_relayer_entries: 2,
16121611
messages_in_oldest_entry: 1,

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// Runtime-generated DecodeLimit::decode_all_with_depth_limit
2121
#![allow(clippy::unnecessary_mut_passed)]
2222

23-
use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState};
23+
use bp_messages::{LaneId, MessageDetails, MessageNonce};
2424
use frame_support::weights::{
2525
WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
2626
};
@@ -107,10 +107,6 @@ pub const TO_KUSAMA_ESTIMATE_MESSAGE_FEE_METHOD: &str =
107107
/// Name of the `ToKusamaOutboundLaneApi::message_details` runtime method.
108108
pub const TO_KUSAMA_MESSAGE_DETAILS_METHOD: &str = "ToKusamaOutboundLaneApi_message_details";
109109

110-
/// Name of the `FromKusamaInboundLaneApi::unrewarded_relayers_state` runtime method.
111-
pub const FROM_KUSAMA_UNREWARDED_RELAYERS_STATE: &str =
112-
"FromKusamaInboundLaneApi_unrewarded_relayers_state";
113-
114110
sp_api::decl_runtime_apis! {
115111
/// API for querying information about the finalized Kusama headers.
116112
///
@@ -151,13 +147,4 @@ sp_api::decl_runtime_apis! {
151147
end: MessageNonce,
152148
) -> Vec<MessageDetails<OutboundMessageFee>>;
153149
}
154-
155-
/// Inbound message lane API for messages sent by Kusama chain.
156-
///
157-
/// This API is implemented by runtimes that are receiving messages from Kusama chain, not the
158-
/// Kusama runtime itself.
159-
pub trait FromKusamaInboundLaneApi {
160-
/// State of the unrewarded relayers set at given lane.
161-
fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState;
162-
}
163150
}

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
mod millau_hash;
2424

25-
use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState};
25+
use bp_messages::{LaneId, MessageDetails, MessageNonce};
2626
use bp_runtime::Chain;
2727
use frame_support::{
2828
weights::{constants::WEIGHT_PER_SECOND, DispatchClass, IdentityFee, Weight},
@@ -284,10 +284,6 @@ pub const TO_MILLAU_ESTIMATE_MESSAGE_FEE_METHOD: &str =
284284
/// Name of the `ToMillauOutboundLaneApi::message_details` runtime method.
285285
pub const TO_MILLAU_MESSAGE_DETAILS_METHOD: &str = "ToMillauOutboundLaneApi_message_details";
286286

287-
/// Name of the `FromMillauInboundLaneApi::unrewarded_relayers_state` runtime method.
288-
pub const FROM_MILLAU_UNREWARDED_RELAYERS_STATE: &str =
289-
"FromMillauInboundLaneApi_unrewarded_relayers_state";
290-
291287
sp_api::decl_runtime_apis! {
292288
/// API for querying information about the finalized Millau headers.
293289
///
@@ -328,15 +324,6 @@ sp_api::decl_runtime_apis! {
328324
end: MessageNonce,
329325
) -> Vec<MessageDetails<OutboundMessageFee>>;
330326
}
331-
332-
/// Inbound message lane API for messages sent by Millau chain.
333-
///
334-
/// This API is implemented by runtimes that are receiving messages from Millau chain, not the
335-
/// Millau runtime itself.
336-
pub trait FromMillauInboundLaneApi {
337-
/// State of the unrewarded relayers set at given lane.
338-
fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState;
339-
}
340327
}
341328

342329
#[cfg(test)]

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// Runtime-generated DecodeLimit::decode_all_with_depth_limit
2121
#![allow(clippy::unnecessary_mut_passed)]
2222

23-
use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState};
23+
use bp_messages::{LaneId, MessageDetails, MessageNonce};
2424
use frame_support::weights::{
2525
WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
2626
};
@@ -107,10 +107,6 @@ pub const TO_POLKADOT_ESTIMATE_MESSAGE_FEE_METHOD: &str =
107107
/// Name of the `ToPolkadotOutboundLaneApi::message_details` runtime method.
108108
pub const TO_POLKADOT_MESSAGE_DETAILS_METHOD: &str = "ToPolkadotOutboundLaneApi_message_details";
109109

110-
/// Name of the `FromPolkadotInboundLaneApi::unrewarded_relayers_state` runtime method.
111-
pub const FROM_POLKADOT_UNREWARDED_RELAYERS_STATE: &str =
112-
"FromPolkadotInboundLaneApi_unrewarded_relayers_state";
113-
114110
sp_api::decl_runtime_apis! {
115111
/// API for querying information about the finalized Polkadot headers.
116112
///
@@ -151,13 +147,4 @@ sp_api::decl_runtime_apis! {
151147
end: MessageNonce,
152148
) -> Vec<MessageDetails<OutboundMessageFee>>;
153149
}
154-
155-
/// Inbound message lane API for messages sent by Polkadot chain.
156-
///
157-
/// This API is implemented by runtimes that are receiving messages from Polkadot chain, not the
158-
/// Polkadot runtime itself.
159-
pub trait FromPolkadotInboundLaneApi {
160-
/// State of the unrewarded relayers set at given lane.
161-
fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState;
162-
}
163150
}

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// Runtime-generated DecodeLimit::decode_all_With_depth_limit
2121
#![allow(clippy::unnecessary_mut_passed)]
2222

23-
use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState};
23+
use bp_messages::{LaneId, MessageDetails, MessageNonce};
2424
use bp_runtime::Chain;
2525
use frame_support::{
2626
weights::{constants::WEIGHT_PER_SECOND, DispatchClass, IdentityFee, Weight},
@@ -250,10 +250,6 @@ pub const TO_RIALTO_ESTIMATE_MESSAGE_FEE_METHOD: &str =
250250
/// Name of the `ToRialtoOutboundLaneApi::message_details` runtime method.
251251
pub const TO_RIALTO_MESSAGE_DETAILS_METHOD: &str = "ToRialtoOutboundLaneApi_message_details";
252252

253-
/// Name of the `FromRialtoInboundLaneApi::unrewarded_relayers_state` runtime method.
254-
pub const FROM_RIALTO_UNREWARDED_RELAYERS_STATE: &str =
255-
"FromRialtoInboundLaneApi_unrewarded_relayers_state";
256-
257253
sp_api::decl_runtime_apis! {
258254
/// API for querying information about the finalized Rialto headers.
259255
///
@@ -294,15 +290,6 @@ sp_api::decl_runtime_apis! {
294290
end: MessageNonce,
295291
) -> Vec<MessageDetails<OutboundMessageFee>>;
296292
}
297-
298-
/// Inbound message lane API for messages sent by Rialto chain.
299-
///
300-
/// This API is implemented by runtimes that are receiving messages from Rialto chain, not the
301-
/// Rialto runtime itself.
302-
pub trait FromRialtoInboundLaneApi {
303-
/// State of the unrewarded relayers set at given lane.
304-
fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState;
305-
}
306293
}
307294

308295
#[cfg(test)]

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// Runtime-generated DecodeLimit::decode_all_with_depth_limit
2121
#![allow(clippy::unnecessary_mut_passed)]
2222

23-
use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState};
23+
use bp_messages::{LaneId, MessageDetails, MessageNonce};
2424
use frame_support::weights::{
2525
Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
2626
};
@@ -91,10 +91,6 @@ pub const TO_ROCOCO_ESTIMATE_MESSAGE_FEE_METHOD: &str =
9191
/// Name of the `ToRococoOutboundLaneApi::message_details` runtime method.
9292
pub const TO_ROCOCO_MESSAGE_DETAILS_METHOD: &str = "ToRococoOutboundLaneApi_message_details";
9393

94-
/// Name of the `FromRococoInboundLaneApi::unrewarded_relayers_state` runtime method.
95-
pub const FROM_ROCOCO_UNREWARDED_RELAYERS_STATE: &str =
96-
"FromRococoInboundLaneApi_unrewarded_relayers_state";
97-
9894
/// Existential deposit on Rococo.
9995
pub const EXISTENTIAL_DEPOSIT: Balance = 1_000_000_000_000 / 100;
10096

@@ -147,13 +143,4 @@ sp_api::decl_runtime_apis! {
147143
end: MessageNonce,
148144
) -> Vec<MessageDetails<OutboundMessageFee>>;
149145
}
150-
151-
/// Inbound message lane API for messages sent by Rococo chain.
152-
///
153-
/// This API is implemented by runtimes that are receiving messages from Rococo chain, not the
154-
/// Rococo runtime itself.
155-
pub trait FromRococoInboundLaneApi {
156-
/// State of the unrewarded relayers set at given lane.
157-
fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState;
158-
}
159146
}

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// Runtime-generated DecodeLimit::decode_all_with_depth_limit
2121
#![allow(clippy::unnecessary_mut_passed)]
2222

23-
use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState};
23+
use bp_messages::{LaneId, MessageDetails, MessageNonce};
2424
use sp_runtime::FixedU128;
2525
use sp_std::prelude::*;
2626

@@ -60,10 +60,6 @@ pub const TO_WOCOCO_ESTIMATE_MESSAGE_FEE_METHOD: &str =
6060
/// Name of the `ToWococoOutboundLaneApi::message_details` runtime method.
6161
pub const TO_WOCOCO_MESSAGE_DETAILS_METHOD: &str = "ToWococoOutboundLaneApi_message_details";
6262

63-
/// Name of the `FromWococoInboundLaneApi::unrewarded_relayers_state` runtime method.
64-
pub const FROM_WOCOCO_UNREWARDED_RELAYERS_STATE: &str =
65-
"FromWococoInboundLaneApi_unrewarded_relayers_state";
66-
6763
sp_api::decl_runtime_apis! {
6864
/// API for querying information about the finalized Wococo headers.
6965
///
@@ -104,13 +100,4 @@ sp_api::decl_runtime_apis! {
104100
end: MessageNonce,
105101
) -> Vec<MessageDetails<OutboundMessageFee>>;
106102
}
107-
108-
/// Inbound message lane API for messages sent by Wococo chain.
109-
///
110-
/// This API is implemented by runtimes that are receiving messages from Wococo chain, not the
111-
/// Wococo runtime itself.
112-
pub trait FromWococoInboundLaneApi {
113-
/// State of the unrewarded relayers set at given lane.
114-
fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState;
115-
}
116103
}

bridges/relays/client-kusama/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ impl ChainWithMessages for Kusama {
7979
bp_kusama::WITH_KUSAMA_MESSAGES_PALLET_NAME;
8080
const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
8181
bp_kusama::TO_KUSAMA_MESSAGE_DETAILS_METHOD;
82-
const FROM_CHAIN_UNREWARDED_RELAYERS_STATE: &'static str =
83-
bp_kusama::FROM_KUSAMA_UNREWARDED_RELAYERS_STATE;
8482
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight =
8583
bp_kusama::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
8684
const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce =

0 commit comments

Comments
 (0)