Skip to content

Commit

Permalink
replace From<>InboundLaneApi with direct storage reads (paritytech#1348)
Browse files Browse the repository at this point in the history
  • Loading branch information
svyatonik authored Mar 9, 2022
1 parent f6c5ca3 commit 3085302
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 144 deletions.
6 changes: 0 additions & 6 deletions bridges/bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,12 +779,6 @@ impl_runtime_apis! {
}
}

impl bp_rialto::FromRialtoInboundLaneApi<Block> for Runtime {
fn unrewarded_relayers_state(lane: bp_messages::LaneId) -> bp_messages::UnrewardedRelayersState {
BridgeRialtoMessages::inbound_unrewarded_relayers_state(lane)
}
}

#[cfg(feature = "runtime-benchmarks")]
impl frame_benchmarking::Benchmark<Block> for Runtime {
fn benchmark_metadata(extra: bool) -> (
Expand Down
6 changes: 0 additions & 6 deletions bridges/bin/rialto/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,12 +903,6 @@ impl_runtime_apis! {
>(lane, begin, end)
}
}

impl bp_millau::FromMillauInboundLaneApi<Block> for Runtime {
fn unrewarded_relayers_state(lane: bp_messages::LaneId) -> bp_messages::UnrewardedRelayersState {
BridgeMillauMessages::inbound_unrewarded_relayers_state(lane)
}
}
}

/// Millau account ownership digest from Rialto.
Expand Down
33 changes: 16 additions & 17 deletions bridges/modules/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,21 +764,6 @@ pub mod pallet {
) -> Option<MessageData<T::OutboundMessageFee>> {
OutboundMessages::<T, I>::get(MessageKey { lane_id: lane, nonce })
}

/// Get state of unrewarded relayers set.
pub fn inbound_unrewarded_relayers_state(
lane: bp_messages::LaneId,
) -> bp_messages::UnrewardedRelayersState {
let relayers = InboundLanes::<T, I>::get(&lane).relayers;
bp_messages::UnrewardedRelayersState {
unrewarded_relayer_entries: relayers.len() as _,
messages_in_oldest_entry: relayers
.front()
.map(|entry| 1 + entry.messages.end - entry.messages.begin)
.unwrap_or(0),
total_messages: total_unrewarded_messages(&relayers).unwrap_or(MessageNonce::MAX),
}
}
}
}

Expand Down Expand Up @@ -1127,6 +1112,20 @@ mod tests {
System::<TestRuntime>::reset_events();
}

fn inbound_unrewarded_relayers_state(
lane: bp_messages::LaneId,
) -> bp_messages::UnrewardedRelayersState {
let relayers = InboundLanes::<TestRuntime, ()>::get(&lane).relayers;
bp_messages::UnrewardedRelayersState {
unrewarded_relayer_entries: relayers.len() as _,
messages_in_oldest_entry: relayers
.front()
.map(|entry| 1 + entry.messages.end - entry.messages.begin)
.unwrap_or(0),
total_messages: total_unrewarded_messages(&relayers).unwrap_or(MessageNonce::MAX),
}
}

fn send_regular_message() -> Weight {
get_ready_for_events();

Expand Down Expand Up @@ -1571,7 +1570,7 @@ mod tests {
},
);
assert_eq!(
Pallet::<TestRuntime>::inbound_unrewarded_relayers_state(TEST_LANE_ID),
inbound_unrewarded_relayers_state(TEST_LANE_ID),
UnrewardedRelayersState {
unrewarded_relayer_entries: 2,
messages_in_oldest_entry: 1,
Expand Down Expand Up @@ -1606,7 +1605,7 @@ mod tests {
},
);
assert_eq!(
Pallet::<TestRuntime>::inbound_unrewarded_relayers_state(TEST_LANE_ID),
inbound_unrewarded_relayers_state(TEST_LANE_ID),
UnrewardedRelayersState {
unrewarded_relayer_entries: 2,
messages_in_oldest_entry: 1,
Expand Down
15 changes: 1 addition & 14 deletions bridges/primitives/chain-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// Runtime-generated DecodeLimit::decode_all_with_depth_limit
#![allow(clippy::unnecessary_mut_passed)]

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

/// Name of the `FromKusamaInboundLaneApi::unrewarded_relayers_state` runtime method.
pub const FROM_KUSAMA_UNREWARDED_RELAYERS_STATE: &str =
"FromKusamaInboundLaneApi_unrewarded_relayers_state";

sp_api::decl_runtime_apis! {
/// API for querying information about the finalized Kusama headers.
///
Expand Down Expand Up @@ -151,13 +147,4 @@ sp_api::decl_runtime_apis! {
end: MessageNonce,
) -> Vec<MessageDetails<OutboundMessageFee>>;
}

/// Inbound message lane API for messages sent by Kusama chain.
///
/// This API is implemented by runtimes that are receiving messages from Kusama chain, not the
/// Kusama runtime itself.
pub trait FromKusamaInboundLaneApi {
/// State of the unrewarded relayers set at given lane.
fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState;
}
}
15 changes: 1 addition & 14 deletions bridges/primitives/chain-millau/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

mod millau_hash;

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

/// Name of the `FromMillauInboundLaneApi::unrewarded_relayers_state` runtime method.
pub const FROM_MILLAU_UNREWARDED_RELAYERS_STATE: &str =
"FromMillauInboundLaneApi_unrewarded_relayers_state";

sp_api::decl_runtime_apis! {
/// API for querying information about the finalized Millau headers.
///
Expand Down Expand Up @@ -328,15 +324,6 @@ sp_api::decl_runtime_apis! {
end: MessageNonce,
) -> Vec<MessageDetails<OutboundMessageFee>>;
}

/// Inbound message lane API for messages sent by Millau chain.
///
/// This API is implemented by runtimes that are receiving messages from Millau chain, not the
/// Millau runtime itself.
pub trait FromMillauInboundLaneApi {
/// State of the unrewarded relayers set at given lane.
fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState;
}
}

#[cfg(test)]
Expand Down
15 changes: 1 addition & 14 deletions bridges/primitives/chain-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// Runtime-generated DecodeLimit::decode_all_with_depth_limit
#![allow(clippy::unnecessary_mut_passed)]

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

/// Name of the `FromPolkadotInboundLaneApi::unrewarded_relayers_state` runtime method.
pub const FROM_POLKADOT_UNREWARDED_RELAYERS_STATE: &str =
"FromPolkadotInboundLaneApi_unrewarded_relayers_state";

sp_api::decl_runtime_apis! {
/// API for querying information about the finalized Polkadot headers.
///
Expand Down Expand Up @@ -151,13 +147,4 @@ sp_api::decl_runtime_apis! {
end: MessageNonce,
) -> Vec<MessageDetails<OutboundMessageFee>>;
}

/// Inbound message lane API for messages sent by Polkadot chain.
///
/// This API is implemented by runtimes that are receiving messages from Polkadot chain, not the
/// Polkadot runtime itself.
pub trait FromPolkadotInboundLaneApi {
/// State of the unrewarded relayers set at given lane.
fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState;
}
}
15 changes: 1 addition & 14 deletions bridges/primitives/chain-rialto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// Runtime-generated DecodeLimit::decode_all_With_depth_limit
#![allow(clippy::unnecessary_mut_passed)]

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

/// Name of the `FromRialtoInboundLaneApi::unrewarded_relayers_state` runtime method.
pub const FROM_RIALTO_UNREWARDED_RELAYERS_STATE: &str =
"FromRialtoInboundLaneApi_unrewarded_relayers_state";

sp_api::decl_runtime_apis! {
/// API for querying information about the finalized Rialto headers.
///
Expand Down Expand Up @@ -294,15 +290,6 @@ sp_api::decl_runtime_apis! {
end: MessageNonce,
) -> Vec<MessageDetails<OutboundMessageFee>>;
}

/// Inbound message lane API for messages sent by Rialto chain.
///
/// This API is implemented by runtimes that are receiving messages from Rialto chain, not the
/// Rialto runtime itself.
pub trait FromRialtoInboundLaneApi {
/// State of the unrewarded relayers set at given lane.
fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState;
}
}

#[cfg(test)]
Expand Down
15 changes: 1 addition & 14 deletions bridges/primitives/chain-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// Runtime-generated DecodeLimit::decode_all_with_depth_limit
#![allow(clippy::unnecessary_mut_passed)]

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

/// Name of the `FromRococoInboundLaneApi::unrewarded_relayers_state` runtime method.
pub const FROM_ROCOCO_UNREWARDED_RELAYERS_STATE: &str =
"FromRococoInboundLaneApi_unrewarded_relayers_state";

/// Existential deposit on Rococo.
pub const EXISTENTIAL_DEPOSIT: Balance = 1_000_000_000_000 / 100;

Expand Down Expand Up @@ -147,13 +143,4 @@ sp_api::decl_runtime_apis! {
end: MessageNonce,
) -> Vec<MessageDetails<OutboundMessageFee>>;
}

/// Inbound message lane API for messages sent by Rococo chain.
///
/// This API is implemented by runtimes that are receiving messages from Rococo chain, not the
/// Rococo runtime itself.
pub trait FromRococoInboundLaneApi {
/// State of the unrewarded relayers set at given lane.
fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState;
}
}
15 changes: 1 addition & 14 deletions bridges/primitives/chain-wococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// Runtime-generated DecodeLimit::decode_all_with_depth_limit
#![allow(clippy::unnecessary_mut_passed)]

use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState};
use bp_messages::{LaneId, MessageDetails, MessageNonce};
use sp_runtime::FixedU128;
use sp_std::prelude::*;

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

/// Name of the `FromWococoInboundLaneApi::unrewarded_relayers_state` runtime method.
pub const FROM_WOCOCO_UNREWARDED_RELAYERS_STATE: &str =
"FromWococoInboundLaneApi_unrewarded_relayers_state";

sp_api::decl_runtime_apis! {
/// API for querying information about the finalized Wococo headers.
///
Expand Down Expand Up @@ -104,13 +100,4 @@ sp_api::decl_runtime_apis! {
end: MessageNonce,
) -> Vec<MessageDetails<OutboundMessageFee>>;
}

/// Inbound message lane API for messages sent by Wococo chain.
///
/// This API is implemented by runtimes that are receiving messages from Wococo chain, not the
/// Wococo runtime itself.
pub trait FromWococoInboundLaneApi {
/// State of the unrewarded relayers set at given lane.
fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState;
}
}
2 changes: 0 additions & 2 deletions bridges/relays/client-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ impl ChainWithMessages for Kusama {
bp_kusama::WITH_KUSAMA_MESSAGES_PALLET_NAME;
const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_kusama::TO_KUSAMA_MESSAGE_DETAILS_METHOD;
const FROM_CHAIN_UNREWARDED_RELAYERS_STATE: &'static str =
bp_kusama::FROM_KUSAMA_UNREWARDED_RELAYERS_STATE;
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight =
bp_kusama::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce =
Expand Down
2 changes: 0 additions & 2 deletions bridges/relays/client-millau/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ impl ChainWithMessages for Millau {
bp_millau::WITH_MILLAU_MESSAGES_PALLET_NAME;
const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_millau::TO_MILLAU_MESSAGE_DETAILS_METHOD;
const FROM_CHAIN_UNREWARDED_RELAYERS_STATE: &'static str =
bp_millau::FROM_MILLAU_UNREWARDED_RELAYERS_STATE;
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight =
bp_millau::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce =
Expand Down
2 changes: 0 additions & 2 deletions bridges/relays/client-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ impl ChainWithMessages for Polkadot {
bp_polkadot::WITH_POLKADOT_MESSAGES_PALLET_NAME;
const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_polkadot::TO_POLKADOT_MESSAGE_DETAILS_METHOD;
const FROM_CHAIN_UNREWARDED_RELAYERS_STATE: &'static str =
bp_polkadot::FROM_POLKADOT_UNREWARDED_RELAYERS_STATE;
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight =
bp_polkadot::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce =
Expand Down
2 changes: 0 additions & 2 deletions bridges/relays/client-rialto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ impl ChainWithMessages for Rialto {
bp_rialto::WITH_RIALTO_MESSAGES_PALLET_NAME;
const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_rialto::TO_RIALTO_MESSAGE_DETAILS_METHOD;
const FROM_CHAIN_UNREWARDED_RELAYERS_STATE: &'static str =
bp_rialto::FROM_RIALTO_UNREWARDED_RELAYERS_STATE;
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight =
bp_rialto::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce =
Expand Down
2 changes: 0 additions & 2 deletions bridges/relays/client-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ impl ChainWithMessages for Rococo {
bp_rococo::WITH_ROCOCO_MESSAGES_PALLET_NAME;
const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_rococo::TO_ROCOCO_MESSAGE_DETAILS_METHOD;
const FROM_CHAIN_UNREWARDED_RELAYERS_STATE: &'static str =
bp_rococo::FROM_ROCOCO_UNREWARDED_RELAYERS_STATE;
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight =
bp_rococo::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce =
Expand Down
4 changes: 0 additions & 4 deletions bridges/relays/client-substrate/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ pub trait ChainWithMessages: Chain {
/// The method is provided by the runtime that is bridged with this `ChainWithMessages`.
const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str;

/// Name of the `From<ChainWithMessages>InboundLaneApi::unrewarded_relayers_state` runtime
/// method. The method is provided by the runtime that is bridged with this `ChainWithMessages`.
const FROM_CHAIN_UNREWARDED_RELAYERS_STATE: &'static str;

/// Additional weight of the dispatch fee payment if dispatch is paid at the target chain
/// and this `ChainWithMessages` is the target chain.
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight;
Expand Down
2 changes: 0 additions & 2 deletions bridges/relays/client-wococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ impl ChainWithMessages for Wococo {
bp_wococo::WITH_WOCOCO_MESSAGES_PALLET_NAME;
const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_wococo::TO_WOCOCO_MESSAGE_DETAILS_METHOD;
const FROM_CHAIN_UNREWARDED_RELAYERS_STATE: &'static str =
bp_wococo::FROM_WOCOCO_UNREWARDED_RELAYERS_STATE;
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight =
bp_wococo::PAY_INBOUND_DISPATCH_FEE_WEIGHT;
const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce =
Expand Down
Loading

0 comments on commit 3085302

Please sign in to comment.