mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 22:11:02 +00:00
replace From<>InboundLaneApi with direct storage reads (#1348)
This commit is contained in:
committed by
Bastian Köcher
parent
ba2b0b086c
commit
f95456d4ea
@@ -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) -> (
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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,
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
@@ -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.
|
||||
///
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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},
|
||||
@@ -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.
|
||||
///
|
||||
@@ -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)]
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
@@ -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.
|
||||
///
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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},
|
||||
@@ -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.
|
||||
///
|
||||
@@ -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)]
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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::*;
|
||||
|
||||
@@ -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.
|
||||
///
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -28,13 +28,13 @@ use crate::{
|
||||
|
||||
use async_trait::async_trait;
|
||||
use bp_messages::{
|
||||
storage_keys::inbound_lane_data_key, InboundLaneData, LaneId, MessageNonce,
|
||||
UnrewardedRelayersState,
|
||||
storage_keys::inbound_lane_data_key, total_unrewarded_messages, InboundLaneData, LaneId,
|
||||
MessageNonce, UnrewardedRelayersState,
|
||||
};
|
||||
use bridge_runtime_common::messages::{
|
||||
source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof,
|
||||
};
|
||||
use codec::{Decode, Encode};
|
||||
use codec::Encode;
|
||||
use frame_support::weights::{Weight, WeightToFeePolynomial};
|
||||
use messages_relay::{
|
||||
message_lane::{MessageLane, SourceHeaderIdOf, TargetHeaderIdOf},
|
||||
@@ -49,7 +49,7 @@ use relay_substrate_client::{
|
||||
use relay_utils::{relay_loop::Client as RelayClient, HeaderId};
|
||||
use sp_core::{Bytes, Pair};
|
||||
use sp_runtime::{traits::Saturating, FixedPointNumber, FixedU128};
|
||||
use std::{convert::TryFrom, ops::RangeInclusive};
|
||||
use std::{collections::VecDeque, convert::TryFrom, ops::RangeInclusive};
|
||||
|
||||
/// Message receiving proof returned by the target Substrate node.
|
||||
pub type SubstrateMessagesDeliveryProof<C> =
|
||||
@@ -188,17 +188,19 @@ where
|
||||
id: TargetHeaderIdOf<MessageLaneAdapter<P>>,
|
||||
) -> Result<(TargetHeaderIdOf<MessageLaneAdapter<P>>, UnrewardedRelayersState), SubstrateError>
|
||||
{
|
||||
let encoded_response = self
|
||||
.target_client
|
||||
.state_call(
|
||||
P::SourceChain::FROM_CHAIN_UNREWARDED_RELAYERS_STATE.into(),
|
||||
Bytes(self.lane_id.encode()),
|
||||
Some(id.1),
|
||||
)
|
||||
.await?;
|
||||
let unrewarded_relayers_state: UnrewardedRelayersState =
|
||||
Decode::decode(&mut &encoded_response.0[..])
|
||||
.map_err(SubstrateError::ResponseParseFailed)?;
|
||||
let relayers = self
|
||||
.inbound_lane_data(id)
|
||||
.await?
|
||||
.map(|data| data.relayers)
|
||||
.unwrap_or_else(|| VecDeque::new());
|
||||
let unrewarded_relayers_state = 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),
|
||||
};
|
||||
Ok((id, unrewarded_relayers_state))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user