Skip to content

Commit

Permalink
Replace InboundLaneApi::latest_received_nonce with direct storage read (
Browse files Browse the repository at this point in the history
paritytech#1269)

* remove inbound_latest_received_nonce

* Update relays/lib-substrate-relay/src/messages_target.rs

Co-authored-by: Adrian Catangiu <adrian@parity.io>
  • Loading branch information
svyatonik and acatangiu committed Dec 23, 2021
1 parent ff9a253 commit ebaa49a
Show file tree
Hide file tree
Showing 18 changed files with 27 additions and 84 deletions.
4 changes: 0 additions & 4 deletions bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,10 +767,6 @@ impl_runtime_apis! {
}

impl bp_rialto::FromRialtoInboundLaneApi<Block> for Runtime {
fn latest_received_nonce(lane: bp_messages::LaneId) -> bp_messages::MessageNonce {
BridgeRialtoMessages::inbound_latest_received_nonce(lane)
}

fn latest_confirmed_nonce(lane: bp_messages::LaneId) -> bp_messages::MessageNonce {
BridgeRialtoMessages::inbound_latest_confirmed_nonce(lane)
}
Expand Down
4 changes: 0 additions & 4 deletions bin/rialto/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -915,10 +915,6 @@ impl_runtime_apis! {
}

impl bp_millau::FromMillauInboundLaneApi<Block> for Runtime {
fn latest_received_nonce(lane: bp_messages::LaneId) -> bp_messages::MessageNonce {
BridgeMillauMessages::inbound_latest_received_nonce(lane)
}

fn latest_confirmed_nonce(lane: bp_messages::LaneId) -> bp_messages::MessageNonce {
BridgeMillauMessages::inbound_latest_confirmed_nonce(lane)
}
Expand Down
28 changes: 14 additions & 14 deletions modules/messages/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ benchmarks_instance_pallet! {
}: send_message(RawOrigin::Signed(sender), lane_id, payload, fee)
verify {
assert_eq!(
crate::Pallet::<T, I>::outbound_latest_generated_nonce(T::bench_lane_id()),
crate::OutboundLanes::<T, I>::get(&T::bench_lane_id()).latest_generated_nonce,
T::MaxMessagesToPruneAtOnce::get() + 1,
);
}
Expand Down Expand Up @@ -192,7 +192,7 @@ benchmarks_instance_pallet! {
}: send_message(RawOrigin::Signed(sender), lane_id, payload, fee)
verify {
assert_eq!(
crate::Pallet::<T, I>::outbound_latest_generated_nonce(T::bench_lane_id()),
crate::OutboundLanes::<T, I>::get(&T::bench_lane_id()).latest_generated_nonce,
T::MaxMessagesToPruneAtOnce::get() + 1,
);
}
Expand Down Expand Up @@ -229,7 +229,7 @@ benchmarks_instance_pallet! {
}: send_message(RawOrigin::Signed(sender), lane_id, payload, fee)
verify {
assert_eq!(
crate::Pallet::<T, I>::outbound_latest_generated_nonce(T::bench_lane_id()),
crate::OutboundLanes::<T, I>::get(&T::bench_lane_id()).latest_generated_nonce,
T::MaxMessagesToPruneAtOnce::get() + 1,
);
}
Expand Down Expand Up @@ -297,7 +297,7 @@ benchmarks_instance_pallet! {
}: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight)
verify {
assert_eq!(
crate::Pallet::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
crate::InboundLanes::<T, I>::get(&T::bench_lane_id()).last_delivered_nonce(),
21,
);
assert!(T::is_message_dispatched(21));
Expand Down Expand Up @@ -331,7 +331,7 @@ benchmarks_instance_pallet! {
}: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 2, dispatch_weight)
verify {
assert_eq!(
crate::Pallet::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
crate::InboundLanes::<T, I>::get(&T::bench_lane_id()).last_delivered_nonce(),
22,
);
assert!(T::is_message_dispatched(22));
Expand Down Expand Up @@ -369,7 +369,7 @@ benchmarks_instance_pallet! {
}: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight)
verify {
assert_eq!(
crate::Pallet::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
crate::InboundLanes::<T, I>::get(&T::bench_lane_id()).last_delivered_nonce(),
21,
);
assert_eq!(
Expand Down Expand Up @@ -405,7 +405,7 @@ benchmarks_instance_pallet! {
}: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight)
verify {
assert_eq!(
crate::Pallet::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
crate::InboundLanes::<T, I>::get(&T::bench_lane_id()).last_delivered_nonce(),
21,
);
assert!(T::is_message_dispatched(21));
Expand Down Expand Up @@ -439,7 +439,7 @@ benchmarks_instance_pallet! {
}: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight)
verify {
assert_eq!(
crate::Pallet::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
crate::InboundLanes::<T, I>::get(&T::bench_lane_id()).last_delivered_nonce(),
21,
);
assert!(T::is_message_dispatched(21));
Expand Down Expand Up @@ -472,7 +472,7 @@ benchmarks_instance_pallet! {
}: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight)
verify {
assert_eq!(
crate::Pallet::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
crate::InboundLanes::<T, I>::get(&T::bench_lane_id()).last_delivered_nonce(),
21,
);
assert!(T::is_message_dispatched(21));
Expand Down Expand Up @@ -634,7 +634,7 @@ benchmarks_instance_pallet! {
}: send_message(RawOrigin::Signed(sender), lane_id, payload, fee)
verify {
assert_eq!(
crate::Pallet::<T, I>::outbound_latest_generated_nonce(T::bench_lane_id()),
crate::OutboundLanes::<T, I>::get(&T::bench_lane_id()).latest_generated_nonce,
T::MaxMessagesToPruneAtOnce::get() + 1,
);
}
Expand Down Expand Up @@ -674,7 +674,7 @@ benchmarks_instance_pallet! {
)
verify {
assert_eq!(
crate::Pallet::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
crate::InboundLanes::<T, I>::get(&T::bench_lane_id()).last_delivered_nonce(),
20 + i as MessageNonce,
);
}
Expand Down Expand Up @@ -712,7 +712,7 @@ benchmarks_instance_pallet! {
)
verify {
assert_eq!(
crate::Pallet::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
crate::InboundLanes::<T, I>::get(&T::bench_lane_id()).last_delivered_nonce(),
21,
);
}
Expand Down Expand Up @@ -750,7 +750,7 @@ benchmarks_instance_pallet! {
)
verify {
assert_eq!(
crate::Pallet::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
crate::InboundLanes::<T, I>::get(&T::bench_lane_id()).last_delivered_nonce(),
21,
);
}
Expand Down Expand Up @@ -794,7 +794,7 @@ benchmarks_instance_pallet! {
)
verify {
assert_eq!(
crate::Pallet::<T, I>::inbound_latest_received_nonce(T::bench_lane_id()),
crate::InboundLanes::<T, I>::get(&T::bench_lane_id()).last_delivered_nonce(),
20 + i as MessageNonce,
);
assert_eq!(
Expand Down
10 changes: 0 additions & 10 deletions modules/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,16 +764,6 @@ pub mod pallet {
OutboundMessages::<T, I>::get(MessageKey { lane_id: lane, nonce })
}

/// Get nonce of the latest generated message at given outbound lane.
pub fn outbound_latest_generated_nonce(lane: LaneId) -> MessageNonce {
OutboundLanes::<T, I>::get(&lane).latest_generated_nonce
}

/// Get nonce of the latest received message at given inbound lane.
pub fn inbound_latest_received_nonce(lane: LaneId) -> MessageNonce {
InboundLanes::<T, I>::get(&lane).last_delivered_nonce()
}

/// Get nonce of the latest confirmed message at given inbound lane.
pub fn inbound_latest_confirmed_nonce(lane: LaneId) -> MessageNonce {
InboundLanes::<T, I>::get(&lane).last_confirmed_nonce
Expand Down
5 changes: 0 additions & 5 deletions primitives/chain-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,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::latest_received_nonce` runtime method.
pub const FROM_KUSAMA_LATEST_RECEIVED_NONCE_METHOD: &str =
"FromKusamaInboundLaneApi_latest_received_nonce";
/// Name of the `FromKusamaInboundLaneApi::latest_onfirmed_nonce` runtime method.
pub const FROM_KUSAMA_LATEST_CONFIRMED_NONCE_METHOD: &str =
"FromKusamaInboundLaneApi_latest_confirmed_nonce";
Expand Down Expand Up @@ -157,8 +154,6 @@ sp_api::decl_runtime_apis! {
/// This API is implemented by runtimes that are receiving messages from Kusama chain, not the
/// Kusama runtime itself.
pub trait FromKusamaInboundLaneApi {
/// Returns nonce of the latest message, received by given lane.
fn latest_received_nonce(lane: LaneId) -> MessageNonce;
/// Nonce of the latest message that has been confirmed to the bridged chain.
fn latest_confirmed_nonce(lane: LaneId) -> MessageNonce;
/// State of the unrewarded relayers set at given lane.
Expand Down
5 changes: 0 additions & 5 deletions primitives/chain-millau/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,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::latest_received_nonce` runtime method.
pub const FROM_MILLAU_LATEST_RECEIVED_NONCE_METHOD: &str =
"FromMillauInboundLaneApi_latest_received_nonce";
/// Name of the `FromMillauInboundLaneApi::latest_onfirmed_nonce` runtime method.
pub const FROM_MILLAU_LATEST_CONFIRMED_NONCE_METHOD: &str =
"FromMillauInboundLaneApi_latest_confirmed_nonce";
Expand Down Expand Up @@ -334,8 +331,6 @@ sp_api::decl_runtime_apis! {
/// This API is implemented by runtimes that are receiving messages from Millau chain, not the
/// Millau runtime itself.
pub trait FromMillauInboundLaneApi {
/// Returns nonce of the latest message, received by given lane.
fn latest_received_nonce(lane: LaneId) -> MessageNonce;
/// Nonce of the latest message that has been confirmed to the bridged chain.
fn latest_confirmed_nonce(lane: LaneId) -> MessageNonce;
/// State of the unrewarded relayers set at given lane.
Expand Down
5 changes: 0 additions & 5 deletions primitives/chain-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,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::latest_received_nonce` runtime method.
pub const FROM_POLKADOT_LATEST_RECEIVED_NONCE_METHOD: &str =
"FromPolkadotInboundLaneApi_latest_received_nonce";
/// Name of the `FromPolkadotInboundLaneApi::latest_onfirmed_nonce` runtime method.
pub const FROM_POLKADOT_LATEST_CONFIRMED_NONCE_METHOD: &str =
"FromPolkadotInboundLaneApi_latest_confirmed_nonce";
Expand Down Expand Up @@ -157,8 +154,6 @@ sp_api::decl_runtime_apis! {
/// This API is implemented by runtimes that are receiving messages from Polkadot chain, not the
/// Polkadot runtime itself.
pub trait FromPolkadotInboundLaneApi {
/// Returns nonce of the latest message, received by given lane.
fn latest_received_nonce(lane: LaneId) -> MessageNonce;
/// Nonce of the latest message that has been confirmed to the bridged chain.
fn latest_confirmed_nonce(lane: LaneId) -> MessageNonce;
/// State of the unrewarded relayers set at given lane.
Expand Down
5 changes: 0 additions & 5 deletions primitives/chain-rialto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +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::latest_received_nonce` runtime method.
pub const FROM_RIALTO_LATEST_RECEIVED_NONCE_METHOD: &str =
"FromRialtoInboundLaneApi_latest_received_nonce";
/// Name of the `FromRialtoInboundLaneApi::latest_onfirmed_nonce` runtime method.
pub const FROM_RIALTO_LATEST_CONFIRMED_NONCE_METHOD: &str =
"FromRialtoInboundLaneApi_latest_confirmed_nonce";
Expand Down Expand Up @@ -306,8 +303,6 @@ sp_api::decl_runtime_apis! {
/// This API is implemented by runtimes that are receiving messages from Rialto chain, not the
/// Rialto runtime itself.
pub trait FromRialtoInboundLaneApi {
/// Returns nonce of the latest message, received by given lane.
fn latest_received_nonce(lane: LaneId) -> MessageNonce;
/// Nonce of the latest message that has been confirmed to the bridged chain.
fn latest_confirmed_nonce(lane: LaneId) -> MessageNonce;
/// State of the unrewarded relayers set at given lane.
Expand Down
5 changes: 0 additions & 5 deletions primitives/chain-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,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::latest_received_nonce` runtime method.
pub const FROM_ROCOCO_LATEST_RECEIVED_NONCE_METHOD: &str =
"FromRococoInboundLaneApi_latest_received_nonce";
/// Name of the `FromRococoInboundLaneApi::latest_onfirmed_nonce` runtime method.
pub const FROM_ROCOCO_LATEST_CONFIRMED_NONCE_METHOD: &str =
"FromRococoInboundLaneApi_latest_confirmed_nonce";
Expand Down Expand Up @@ -158,8 +155,6 @@ sp_api::decl_runtime_apis! {
/// This API is implemented by runtimes that are receiving messages from Rococo chain, not the
/// Rococo runtime itself.
pub trait FromRococoInboundLaneApi {
/// Returns nonce of the latest message, received by given lane.
fn latest_received_nonce(lane: LaneId) -> MessageNonce;
/// Nonce of the latest message that has been confirmed to the bridged chain.
fn latest_confirmed_nonce(lane: LaneId) -> MessageNonce;
/// State of the unrewarded relayers set at given lane.
Expand Down
5 changes: 0 additions & 5 deletions primitives/chain-wococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,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::latest_received_nonce` runtime method.
pub const FROM_WOCOCO_LATEST_RECEIVED_NONCE_METHOD: &str =
"FromWococoInboundLaneApi_latest_received_nonce";
/// Name of the `FromWococoInboundLaneApi::latest_onfirmed_nonce` runtime method.
pub const FROM_WOCOCO_LATEST_CONFIRMED_NONCE_METHOD: &str =
"FromWococoInboundLaneApi_latest_confirmed_nonce";
Expand Down Expand Up @@ -111,8 +108,6 @@ sp_api::decl_runtime_apis! {
/// This API is implemented by runtimes that are receiving messages from Wococo chain, not the
/// Wococo runtime itself.
pub trait FromWococoInboundLaneApi {
/// Returns nonce of the latest message, received by given lane.
fn latest_received_nonce(lane: LaneId) -> MessageNonce;
/// Nonce of the latest message that has been confirmed to the bridged chain.
fn latest_confirmed_nonce(lane: LaneId) -> MessageNonce;
/// State of the unrewarded relayers set at given lane.
Expand Down
2 changes: 0 additions & 2 deletions 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_LATEST_RECEIVED_NONCE_METHOD: &'static str =
bp_kusama::FROM_KUSAMA_LATEST_RECEIVED_NONCE_METHOD;
const FROM_CHAIN_LATEST_CONFIRMED_NONCE_METHOD: &'static str =
bp_kusama::FROM_KUSAMA_LATEST_CONFIRMED_NONCE_METHOD;
const FROM_CHAIN_UNREWARDED_RELAYERS_STATE: &'static str =
Expand Down
2 changes: 0 additions & 2 deletions 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_LATEST_RECEIVED_NONCE_METHOD: &'static str =
bp_millau::FROM_MILLAU_LATEST_RECEIVED_NONCE_METHOD;
const FROM_CHAIN_LATEST_CONFIRMED_NONCE_METHOD: &'static str =
bp_millau::FROM_MILLAU_LATEST_CONFIRMED_NONCE_METHOD;
const FROM_CHAIN_UNREWARDED_RELAYERS_STATE: &'static str =
Expand Down
2 changes: 0 additions & 2 deletions 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_LATEST_RECEIVED_NONCE_METHOD: &'static str =
bp_polkadot::FROM_POLKADOT_LATEST_RECEIVED_NONCE_METHOD;
const FROM_CHAIN_LATEST_CONFIRMED_NONCE_METHOD: &'static str =
bp_polkadot::FROM_POLKADOT_LATEST_CONFIRMED_NONCE_METHOD;
const FROM_CHAIN_UNREWARDED_RELAYERS_STATE: &'static str =
Expand Down
2 changes: 0 additions & 2 deletions 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_LATEST_RECEIVED_NONCE_METHOD: &'static str =
bp_rialto::FROM_RIALTO_LATEST_RECEIVED_NONCE_METHOD;
const FROM_CHAIN_LATEST_CONFIRMED_NONCE_METHOD: &'static str =
bp_rialto::FROM_RIALTO_LATEST_CONFIRMED_NONCE_METHOD;
const FROM_CHAIN_UNREWARDED_RELAYERS_STATE: &'static str =
Expand Down
2 changes: 0 additions & 2 deletions 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_LATEST_RECEIVED_NONCE_METHOD: &'static str =
bp_rococo::FROM_ROCOCO_LATEST_RECEIVED_NONCE_METHOD;
const FROM_CHAIN_LATEST_CONFIRMED_NONCE_METHOD: &'static str =
bp_rococo::FROM_ROCOCO_LATEST_CONFIRMED_NONCE_METHOD;
const FROM_CHAIN_UNREWARDED_RELAYERS_STATE: &'static str =
Expand Down
3 changes: 0 additions & 3 deletions relays/client-substrate/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +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::latest_received_nonce` runtime method.
/// The method is provided by the runtime that is bridged with this `ChainWithMessages`.
const FROM_CHAIN_LATEST_RECEIVED_NONCE_METHOD: &'static str;
/// Name of the `From<ChainWithMessages>InboundLaneApi::latest_confirmed_nonce` runtime method.
/// The method is provided by the runtime that is bridged with this `ChainWithMessages`.
const FROM_CHAIN_LATEST_CONFIRMED_NONCE_METHOD: &'static str;
Expand Down
2 changes: 0 additions & 2 deletions 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_LATEST_RECEIVED_NONCE_METHOD: &'static str =
bp_wococo::FROM_WOCOCO_LATEST_RECEIVED_NONCE_METHOD;
const FROM_CHAIN_LATEST_CONFIRMED_NONCE_METHOD: &'static str =
bp_wococo::FROM_WOCOCO_LATEST_CONFIRMED_NONCE_METHOD;
const FROM_CHAIN_UNREWARDED_RELAYERS_STATE: &'static str =
Expand Down
20 changes: 13 additions & 7 deletions relays/lib-substrate-relay/src/messages_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ use crate::{
};

use async_trait::async_trait;
use bp_messages::{LaneId, MessageNonce, UnrewardedRelayersState};
use bp_messages::{
storage_keys::inbound_lane_data_key, InboundLaneData, LaneId, MessageNonce,
UnrewardedRelayersState,
};
use bridge_runtime_common::messages::{
source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof,
};
Expand Down Expand Up @@ -130,16 +133,19 @@ where
&self,
id: TargetHeaderIdOf<MessageLaneAdapter<P>>,
) -> Result<(TargetHeaderIdOf<MessageLaneAdapter<P>>, MessageNonce), SubstrateError> {
let encoded_response = self
let inbound_lane_data: Option<InboundLaneData<AccountIdOf<P::SourceChain>>> = self
.client
.state_call(
P::SourceChain::FROM_CHAIN_LATEST_RECEIVED_NONCE_METHOD.into(),
Bytes(self.lane_id.encode()),
.storage_value(
inbound_lane_data_key(
P::SourceChain::WITH_CHAIN_MESSAGES_PALLET_NAME,
&self.lane_id,
),
Some(id.1),
)
.await?;
let latest_received_nonce: MessageNonce = Decode::decode(&mut &encoded_response.0[..])
.map_err(SubstrateError::ResponseParseFailed)?;
// lane data missing from the storage is fine until first message is received
let latest_received_nonce =
inbound_lane_data.map(|data| data.last_delivered_nonce()).unwrap_or(0);
Ok((id, latest_received_nonce))
}

Expand Down

0 comments on commit ebaa49a

Please sign in to comment.