Replace InboundLaneApi::latest_received_nonce with direct storage read (#1269)

* remove inbound_latest_received_nonce

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

Co-authored-by: Adrian Catangiu <adrian@parity.io>
This commit is contained in:
Svyatoslav Nikolsky
2021-12-23 17:18:43 +03:00
committed by Bastian Köcher
parent bb249eff15
commit a88207876c
18 changed files with 27 additions and 84 deletions
-2
View File
@@ -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 =
-2
View File
@@ -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 =
@@ -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 =
-2
View File
@@ -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 =
-2
View File
@@ -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 =
@@ -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;
-2
View File
@@ -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 =
@@ -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,
};
@@ -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))
}