replace latest_confirmed_nonce runtime APIs with direct storage reads (#1282)

This commit is contained in:
Svyatoslav Nikolsky
2022-01-13 15:08:21 +03:00
committed by Bastian Köcher
parent fd816b60e3
commit 1d99ad3619
21 changed files with 57 additions and 163 deletions
-4
View File
@@ -776,10 +776,6 @@ impl_runtime_apis! {
} }
impl bp_rialto::FromRialtoInboundLaneApi<Block> for Runtime { impl bp_rialto::FromRialtoInboundLaneApi<Block> for Runtime {
fn latest_confirmed_nonce(lane: bp_messages::LaneId) -> bp_messages::MessageNonce {
BridgeRialtoMessages::inbound_latest_confirmed_nonce(lane)
}
fn unrewarded_relayers_state(lane: bp_messages::LaneId) -> bp_messages::UnrewardedRelayersState { fn unrewarded_relayers_state(lane: bp_messages::LaneId) -> bp_messages::UnrewardedRelayersState {
BridgeRialtoMessages::inbound_unrewarded_relayers_state(lane) BridgeRialtoMessages::inbound_unrewarded_relayers_state(lane)
} }
-4
View File
@@ -899,10 +899,6 @@ impl_runtime_apis! {
} }
impl bp_millau::FromMillauInboundLaneApi<Block> for Runtime { impl bp_millau::FromMillauInboundLaneApi<Block> for Runtime {
fn latest_confirmed_nonce(lane: bp_messages::LaneId) -> bp_messages::MessageNonce {
BridgeMillauMessages::inbound_latest_confirmed_nonce(lane)
}
fn unrewarded_relayers_state(lane: bp_messages::LaneId) -> bp_messages::UnrewardedRelayersState { fn unrewarded_relayers_state(lane: bp_messages::LaneId) -> bp_messages::UnrewardedRelayersState {
BridgeMillauMessages::inbound_unrewarded_relayers_state(lane) BridgeMillauMessages::inbound_unrewarded_relayers_state(lane)
} }
+3 -8
View File
@@ -367,14 +367,9 @@ benchmarks_instance_pallet! {
}); });
}: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight) }: receive_messages_proof(RawOrigin::Signed(relayer_id_on_target), relayer_id_on_source, proof, 1, dispatch_weight)
verify { verify {
assert_eq!( let lane_state = crate::InboundLanes::<T, I>::get(&T::bench_lane_id());
crate::InboundLanes::<T, I>::get(&T::bench_lane_id()).last_delivered_nonce(), assert_eq!(lane_state.last_delivered_nonce(), 21);
21, assert_eq!(lane_state.last_confirmed_nonce, 20);
);
assert_eq!(
crate::Pallet::<T, I>::inbound_latest_confirmed_nonce(T::bench_lane_id()),
20,
);
assert!(T::is_message_dispatched(21)); assert!(T::is_message_dispatched(21));
} }
-5
View File
@@ -764,11 +764,6 @@ pub mod pallet {
OutboundMessages::<T, I>::get(MessageKey { lane_id: lane, nonce }) OutboundMessages::<T, I>::get(MessageKey { lane_id: lane, 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
}
/// Get state of unrewarded relayers set. /// Get state of unrewarded relayers set.
pub fn inbound_unrewarded_relayers_state( pub fn inbound_unrewarded_relayers_state(
lane: bp_messages::LaneId, lane: bp_messages::LaneId,
@@ -100,9 +100,6 @@ pub const TO_KUSAMA_ESTIMATE_MESSAGE_FEE_METHOD: &str =
/// Name of the `ToKusamaOutboundLaneApi::message_details` runtime method. /// Name of the `ToKusamaOutboundLaneApi::message_details` runtime method.
pub const TO_KUSAMA_MESSAGE_DETAILS_METHOD: &str = "ToKusamaOutboundLaneApi_message_details"; pub const TO_KUSAMA_MESSAGE_DETAILS_METHOD: &str = "ToKusamaOutboundLaneApi_message_details";
/// Name of the `FromKusamaInboundLaneApi::latest_onfirmed_nonce` runtime method.
pub const FROM_KUSAMA_LATEST_CONFIRMED_NONCE_METHOD: &str =
"FromKusamaInboundLaneApi_latest_confirmed_nonce";
/// Name of the `FromKusamaInboundLaneApi::unrewarded_relayers_state` runtime method. /// Name of the `FromKusamaInboundLaneApi::unrewarded_relayers_state` runtime method.
pub const FROM_KUSAMA_UNREWARDED_RELAYERS_STATE: &str = pub const FROM_KUSAMA_UNREWARDED_RELAYERS_STATE: &str =
"FromKusamaInboundLaneApi_unrewarded_relayers_state"; "FromKusamaInboundLaneApi_unrewarded_relayers_state";
@@ -152,8 +149,6 @@ sp_api::decl_runtime_apis! {
/// This API is implemented by runtimes that are receiving messages from Kusama chain, not the /// This API is implemented by runtimes that are receiving messages from Kusama chain, not the
/// Kusama runtime itself. /// Kusama runtime itself.
pub trait FromKusamaInboundLaneApi { pub trait FromKusamaInboundLaneApi {
/// 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. /// State of the unrewarded relayers set at given lane.
fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState; fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState;
} }
@@ -278,9 +278,6 @@ pub const TO_MILLAU_ESTIMATE_MESSAGE_FEE_METHOD: &str =
/// Name of the `ToMillauOutboundLaneApi::message_details` runtime method. /// Name of the `ToMillauOutboundLaneApi::message_details` runtime method.
pub const TO_MILLAU_MESSAGE_DETAILS_METHOD: &str = "ToMillauOutboundLaneApi_message_details"; pub const TO_MILLAU_MESSAGE_DETAILS_METHOD: &str = "ToMillauOutboundLaneApi_message_details";
/// Name of the `FromMillauInboundLaneApi::latest_onfirmed_nonce` runtime method.
pub const FROM_MILLAU_LATEST_CONFIRMED_NONCE_METHOD: &str =
"FromMillauInboundLaneApi_latest_confirmed_nonce";
/// Name of the `FromMillauInboundLaneApi::unrewarded_relayers_state` runtime method. /// Name of the `FromMillauInboundLaneApi::unrewarded_relayers_state` runtime method.
pub const FROM_MILLAU_UNREWARDED_RELAYERS_STATE: &str = pub const FROM_MILLAU_UNREWARDED_RELAYERS_STATE: &str =
"FromMillauInboundLaneApi_unrewarded_relayers_state"; "FromMillauInboundLaneApi_unrewarded_relayers_state";
@@ -330,8 +327,6 @@ sp_api::decl_runtime_apis! {
/// This API is implemented by runtimes that are receiving messages from Millau chain, not the /// This API is implemented by runtimes that are receiving messages from Millau chain, not the
/// Millau runtime itself. /// Millau runtime itself.
pub trait FromMillauInboundLaneApi { pub trait FromMillauInboundLaneApi {
/// 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. /// State of the unrewarded relayers set at given lane.
fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState; fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState;
} }
@@ -100,9 +100,6 @@ pub const TO_POLKADOT_ESTIMATE_MESSAGE_FEE_METHOD: &str =
/// Name of the `ToPolkadotOutboundLaneApi::message_details` runtime method. /// Name of the `ToPolkadotOutboundLaneApi::message_details` runtime method.
pub const TO_POLKADOT_MESSAGE_DETAILS_METHOD: &str = "ToPolkadotOutboundLaneApi_message_details"; pub const TO_POLKADOT_MESSAGE_DETAILS_METHOD: &str = "ToPolkadotOutboundLaneApi_message_details";
/// Name of the `FromPolkadotInboundLaneApi::latest_onfirmed_nonce` runtime method.
pub const FROM_POLKADOT_LATEST_CONFIRMED_NONCE_METHOD: &str =
"FromPolkadotInboundLaneApi_latest_confirmed_nonce";
/// Name of the `FromPolkadotInboundLaneApi::unrewarded_relayers_state` runtime method. /// Name of the `FromPolkadotInboundLaneApi::unrewarded_relayers_state` runtime method.
pub const FROM_POLKADOT_UNREWARDED_RELAYERS_STATE: &str = pub const FROM_POLKADOT_UNREWARDED_RELAYERS_STATE: &str =
"FromPolkadotInboundLaneApi_unrewarded_relayers_state"; "FromPolkadotInboundLaneApi_unrewarded_relayers_state";
@@ -152,8 +149,6 @@ sp_api::decl_runtime_apis! {
/// This API is implemented by runtimes that are receiving messages from Polkadot chain, not the /// This API is implemented by runtimes that are receiving messages from Polkadot chain, not the
/// Polkadot runtime itself. /// Polkadot runtime itself.
pub trait FromPolkadotInboundLaneApi { pub trait FromPolkadotInboundLaneApi {
/// 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. /// State of the unrewarded relayers set at given lane.
fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState; fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState;
} }
@@ -250,9 +250,6 @@ pub const TO_RIALTO_ESTIMATE_MESSAGE_FEE_METHOD: &str =
/// Name of the `ToRialtoOutboundLaneApi::message_details` runtime method. /// Name of the `ToRialtoOutboundLaneApi::message_details` runtime method.
pub const TO_RIALTO_MESSAGE_DETAILS_METHOD: &str = "ToRialtoOutboundLaneApi_message_details"; pub const TO_RIALTO_MESSAGE_DETAILS_METHOD: &str = "ToRialtoOutboundLaneApi_message_details";
/// Name of the `FromRialtoInboundLaneApi::latest_onfirmed_nonce` runtime method.
pub const FROM_RIALTO_LATEST_CONFIRMED_NONCE_METHOD: &str =
"FromRialtoInboundLaneApi_latest_confirmed_nonce";
/// Name of the `FromRialtoInboundLaneApi::unrewarded_relayers_state` runtime method. /// Name of the `FromRialtoInboundLaneApi::unrewarded_relayers_state` runtime method.
pub const FROM_RIALTO_UNREWARDED_RELAYERS_STATE: &str = pub const FROM_RIALTO_UNREWARDED_RELAYERS_STATE: &str =
"FromRialtoInboundLaneApi_unrewarded_relayers_state"; "FromRialtoInboundLaneApi_unrewarded_relayers_state";
@@ -302,8 +299,6 @@ sp_api::decl_runtime_apis! {
/// This API is implemented by runtimes that are receiving messages from Rialto chain, not the /// This API is implemented by runtimes that are receiving messages from Rialto chain, not the
/// Rialto runtime itself. /// Rialto runtime itself.
pub trait FromRialtoInboundLaneApi { pub trait FromRialtoInboundLaneApi {
/// 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. /// State of the unrewarded relayers set at given lane.
fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState; fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState;
} }
@@ -89,9 +89,6 @@ pub const TO_ROCOCO_ESTIMATE_MESSAGE_FEE_METHOD: &str =
/// Name of the `ToRococoOutboundLaneApi::message_details` runtime method. /// Name of the `ToRococoOutboundLaneApi::message_details` runtime method.
pub const TO_ROCOCO_MESSAGE_DETAILS_METHOD: &str = "ToRococoOutboundLaneApi_message_details"; pub const TO_ROCOCO_MESSAGE_DETAILS_METHOD: &str = "ToRococoOutboundLaneApi_message_details";
/// Name of the `FromRococoInboundLaneApi::latest_onfirmed_nonce` runtime method.
pub const FROM_ROCOCO_LATEST_CONFIRMED_NONCE_METHOD: &str =
"FromRococoInboundLaneApi_latest_confirmed_nonce";
/// Name of the `FromRococoInboundLaneApi::unrewarded_relayers_state` runtime method. /// Name of the `FromRococoInboundLaneApi::unrewarded_relayers_state` runtime method.
pub const FROM_ROCOCO_UNREWARDED_RELAYERS_STATE: &str = pub const FROM_ROCOCO_UNREWARDED_RELAYERS_STATE: &str =
"FromRococoInboundLaneApi_unrewarded_relayers_state"; "FromRococoInboundLaneApi_unrewarded_relayers_state";
@@ -153,8 +150,6 @@ sp_api::decl_runtime_apis! {
/// This API is implemented by runtimes that are receiving messages from Rococo chain, not the /// This API is implemented by runtimes that are receiving messages from Rococo chain, not the
/// Rococo runtime itself. /// Rococo runtime itself.
pub trait FromRococoInboundLaneApi { pub trait FromRococoInboundLaneApi {
/// 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. /// State of the unrewarded relayers set at given lane.
fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState; fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState;
} }
@@ -14,7 +14,6 @@ smallvec = "1.7"
# Bridge Dependencies # Bridge Dependencies
bp-header-chain = { path = "../header-chain", default-features = false } bp-header-chain = { path = "../header-chain", default-features = false }
bp-messages = { path = "../messages", default-features = false }
bp-polkadot-core = { path = "../polkadot-core", default-features = false } bp-polkadot-core = { path = "../polkadot-core", default-features = false }
bp-runtime = { path = "../runtime", default-features = false } bp-runtime = { path = "../runtime", default-features = false }
@@ -30,7 +29,6 @@ sp-version = { git = "https://github.com/paritytech/substrate", branch = "master
default = ["std"] default = ["std"]
std = [ std = [
"bp-header-chain/std", "bp-header-chain/std",
"bp-messages/std",
"bp-polkadot-core/std", "bp-polkadot-core/std",
"bp-runtime/std", "bp-runtime/std",
"frame-support/std", "frame-support/std",
@@ -20,7 +20,6 @@
// Runtime-generated DecodeLimit::decode_all_with_depth_limit // Runtime-generated DecodeLimit::decode_all_with_depth_limit
#![allow(clippy::unnecessary_mut_passed)] #![allow(clippy::unnecessary_mut_passed)]
use bp_messages::{LaneId, MessageDetails, MessageNonce, UnrewardedRelayersState};
use frame_support::weights::{ use frame_support::weights::{
WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
}; };
@@ -110,51 +109,4 @@ sp_api::decl_runtime_apis! {
/// Returns number and hash of the best finalized header known to the bridge module. /// Returns number and hash of the best finalized header known to the bridge module.
fn best_finalized() -> (BlockNumber, Hash); fn best_finalized() -> (BlockNumber, Hash);
} }
/// Outbound message lane API for messages that are sent to Westend chain.
///
/// This API is implemented by runtimes that are sending messages to Westend chain, not the
/// Westend runtime itself.
pub trait ToWestendOutboundLaneApi<OutboundMessageFee: Parameter, OutboundPayload: Parameter> {
/// Estimate message delivery and dispatch fee that needs to be paid by the sender on
/// this chain.
///
/// Returns `None` if message is too expensive to be sent to Westend from this chain.
///
/// Please keep in mind that this method returns the lowest message fee required for message
/// to be accepted to the lane. It may be good idea to pay a bit over this price to account
/// future exchange rate changes and guarantee that relayer would deliver your message
/// to the target chain.
fn estimate_message_delivery_and_dispatch_fee(
lane_id: LaneId,
payload: OutboundPayload,
) -> Option<OutboundMessageFee>;
/// Returns dispatch weight, encoded payload size and delivery+dispatch fee of all
/// messages in given inclusive range.
///
/// If some (or all) messages are missing from the storage, they'll also will
/// be missing from the resulting vector. The vector is ordered by the nonce.
fn message_details(
lane: LaneId,
begin: MessageNonce,
end: MessageNonce,
) -> Vec<MessageDetails<OutboundMessageFee>>;
/// Returns nonce of the latest message, received by bridged chain.
fn latest_received_nonce(lane: LaneId) -> MessageNonce;
/// Returns nonce of the latest message, generated by given lane.
fn latest_generated_nonce(lane: LaneId) -> MessageNonce;
}
/// Inbound message lane API for messages sent by Westend chain.
///
/// This API is implemented by runtimes that are receiving messages from Westend chain, not the
/// Westend runtime itself.
pub trait FromWestendInboundLaneApi {
/// 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.
fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState;
}
} }
@@ -54,9 +54,6 @@ pub const TO_WOCOCO_ESTIMATE_MESSAGE_FEE_METHOD: &str =
/// Name of the `ToWococoOutboundLaneApi::message_details` runtime method. /// Name of the `ToWococoOutboundLaneApi::message_details` runtime method.
pub const TO_WOCOCO_MESSAGE_DETAILS_METHOD: &str = "ToWococoOutboundLaneApi_message_details"; pub const TO_WOCOCO_MESSAGE_DETAILS_METHOD: &str = "ToWococoOutboundLaneApi_message_details";
/// Name of the `FromWococoInboundLaneApi::latest_onfirmed_nonce` runtime method.
pub const FROM_WOCOCO_LATEST_CONFIRMED_NONCE_METHOD: &str =
"FromWococoInboundLaneApi_latest_confirmed_nonce";
/// Name of the `FromWococoInboundLaneApi::unrewarded_relayers_state` runtime method. /// Name of the `FromWococoInboundLaneApi::unrewarded_relayers_state` runtime method.
pub const FROM_WOCOCO_UNREWARDED_RELAYERS_STATE: &str = pub const FROM_WOCOCO_UNREWARDED_RELAYERS_STATE: &str =
"FromWococoInboundLaneApi_unrewarded_relayers_state"; "FromWococoInboundLaneApi_unrewarded_relayers_state";
@@ -106,8 +103,6 @@ sp_api::decl_runtime_apis! {
/// This API is implemented by runtimes that are receiving messages from Wococo chain, not the /// This API is implemented by runtimes that are receiving messages from Wococo chain, not the
/// Wococo runtime itself. /// Wococo runtime itself.
pub trait FromWococoInboundLaneApi { pub trait FromWococoInboundLaneApi {
/// 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. /// State of the unrewarded relayers set at given lane.
fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState; fn unrewarded_relayers_state(lane: LaneId) -> UnrewardedRelayersState;
} }
-2
View File
@@ -79,8 +79,6 @@ impl ChainWithMessages for Kusama {
bp_kusama::WITH_KUSAMA_MESSAGES_PALLET_NAME; bp_kusama::WITH_KUSAMA_MESSAGES_PALLET_NAME;
const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_kusama::TO_KUSAMA_MESSAGE_DETAILS_METHOD; bp_kusama::TO_KUSAMA_MESSAGE_DETAILS_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 = const FROM_CHAIN_UNREWARDED_RELAYERS_STATE: &'static str =
bp_kusama::FROM_KUSAMA_UNREWARDED_RELAYERS_STATE; bp_kusama::FROM_KUSAMA_UNREWARDED_RELAYERS_STATE;
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight = const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight =
-2
View File
@@ -63,8 +63,6 @@ impl ChainWithMessages for Millau {
bp_millau::WITH_MILLAU_MESSAGES_PALLET_NAME; bp_millau::WITH_MILLAU_MESSAGES_PALLET_NAME;
const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_millau::TO_MILLAU_MESSAGE_DETAILS_METHOD; bp_millau::TO_MILLAU_MESSAGE_DETAILS_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 = const FROM_CHAIN_UNREWARDED_RELAYERS_STATE: &'static str =
bp_millau::FROM_MILLAU_UNREWARDED_RELAYERS_STATE; bp_millau::FROM_MILLAU_UNREWARDED_RELAYERS_STATE;
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight = const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight =
@@ -80,8 +80,6 @@ impl ChainWithMessages for Polkadot {
bp_polkadot::WITH_POLKADOT_MESSAGES_PALLET_NAME; bp_polkadot::WITH_POLKADOT_MESSAGES_PALLET_NAME;
const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_polkadot::TO_POLKADOT_MESSAGE_DETAILS_METHOD; bp_polkadot::TO_POLKADOT_MESSAGE_DETAILS_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 = const FROM_CHAIN_UNREWARDED_RELAYERS_STATE: &'static str =
bp_polkadot::FROM_POLKADOT_UNREWARDED_RELAYERS_STATE; bp_polkadot::FROM_POLKADOT_UNREWARDED_RELAYERS_STATE;
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight = const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight =
-2
View File
@@ -78,8 +78,6 @@ impl ChainWithMessages for Rialto {
bp_rialto::WITH_RIALTO_MESSAGES_PALLET_NAME; bp_rialto::WITH_RIALTO_MESSAGES_PALLET_NAME;
const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_rialto::TO_RIALTO_MESSAGE_DETAILS_METHOD; bp_rialto::TO_RIALTO_MESSAGE_DETAILS_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 = const FROM_CHAIN_UNREWARDED_RELAYERS_STATE: &'static str =
bp_rialto::FROM_RIALTO_UNREWARDED_RELAYERS_STATE; bp_rialto::FROM_RIALTO_UNREWARDED_RELAYERS_STATE;
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight = const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight =
-2
View File
@@ -82,8 +82,6 @@ impl ChainWithMessages for Rococo {
bp_rococo::WITH_ROCOCO_MESSAGES_PALLET_NAME; bp_rococo::WITH_ROCOCO_MESSAGES_PALLET_NAME;
const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_rococo::TO_ROCOCO_MESSAGE_DETAILS_METHOD; bp_rococo::TO_ROCOCO_MESSAGE_DETAILS_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 = const FROM_CHAIN_UNREWARDED_RELAYERS_STATE: &'static str =
bp_rococo::FROM_ROCOCO_UNREWARDED_RELAYERS_STATE; bp_rococo::FROM_ROCOCO_UNREWARDED_RELAYERS_STATE;
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight = const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight =
@@ -91,9 +91,6 @@ pub trait ChainWithMessages: Chain {
/// The method is provided by the runtime that is bridged with this `ChainWithMessages`. /// The method is provided by the runtime that is bridged with this `ChainWithMessages`.
const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str; const TO_CHAIN_MESSAGE_DETAILS_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;
/// Name of the `From<ChainWithMessages>InboundLaneApi::unrewarded_relayers_state` runtime /// Name of the `From<ChainWithMessages>InboundLaneApi::unrewarded_relayers_state` runtime
/// method. The method is provided by the runtime that is bridged with this `ChainWithMessages`. /// method. The method is provided by the runtime that is bridged with this `ChainWithMessages`.
const FROM_CHAIN_UNREWARDED_RELAYERS_STATE: &'static str; const FROM_CHAIN_UNREWARDED_RELAYERS_STATE: &'static str;
-2
View File
@@ -82,8 +82,6 @@ impl ChainWithMessages for Wococo {
bp_wococo::WITH_WOCOCO_MESSAGES_PALLET_NAME; bp_wococo::WITH_WOCOCO_MESSAGES_PALLET_NAME;
const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str =
bp_wococo::TO_WOCOCO_MESSAGE_DETAILS_METHOD; bp_wococo::TO_WOCOCO_MESSAGE_DETAILS_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 = const FROM_CHAIN_UNREWARDED_RELAYERS_STATE: &'static str =
bp_wococo::FROM_WOCOCO_UNREWARDED_RELAYERS_STATE; bp_wococo::FROM_WOCOCO_UNREWARDED_RELAYERS_STATE;
const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight = const PAY_INBOUND_DISPATCH_FEE_WEIGHT_AT_CHAIN: Weight =
@@ -83,6 +83,22 @@ impl<P: SubstrateMessageLane> SubstrateMessagesSource<P> {
target_to_source_headers_relay, target_to_source_headers_relay,
} }
} }
/// Read outbound lane state from the on-chain storage at given block.
async fn outbound_lane_data(
&self,
id: SourceHeaderIdOf<MessageLaneAdapter<P>>,
) -> Result<Option<OutboundLaneData>, SubstrateError> {
self.client
.storage_value(
outbound_lane_data_key(
P::TargetChain::WITH_CHAIN_MESSAGES_PALLET_NAME,
&self.lane_id,
),
Some(id.1),
)
.await
}
} }
impl<P: SubstrateMessageLane> Clone for SubstrateMessagesSource<P> { impl<P: SubstrateMessageLane> Clone for SubstrateMessagesSource<P> {
@@ -129,19 +145,12 @@ where
&self, &self,
id: SourceHeaderIdOf<MessageLaneAdapter<P>>, id: SourceHeaderIdOf<MessageLaneAdapter<P>>,
) -> Result<(SourceHeaderIdOf<MessageLaneAdapter<P>>, MessageNonce), SubstrateError> { ) -> Result<(SourceHeaderIdOf<MessageLaneAdapter<P>>, MessageNonce), SubstrateError> {
let outbound_lane_data: Option<OutboundLaneData> = self
.client
.storage_value(
outbound_lane_data_key(
P::TargetChain::WITH_CHAIN_MESSAGES_PALLET_NAME,
&self.lane_id,
),
Some(id.1),
)
.await?;
// lane data missing from the storage is fine until first message is sent // lane data missing from the storage is fine until first message is sent
let latest_generated_nonce = let latest_generated_nonce = self
outbound_lane_data.map(|data| data.latest_generated_nonce).unwrap_or(0); .outbound_lane_data(id)
.await?
.map(|data| data.latest_generated_nonce)
.unwrap_or(0);
Ok((id, latest_generated_nonce)) Ok((id, latest_generated_nonce))
} }
@@ -149,19 +158,12 @@ where
&self, &self,
id: SourceHeaderIdOf<MessageLaneAdapter<P>>, id: SourceHeaderIdOf<MessageLaneAdapter<P>>,
) -> Result<(SourceHeaderIdOf<MessageLaneAdapter<P>>, MessageNonce), SubstrateError> { ) -> Result<(SourceHeaderIdOf<MessageLaneAdapter<P>>, MessageNonce), SubstrateError> {
let outbound_lane_data: Option<OutboundLaneData> = self
.client
.storage_value(
outbound_lane_data_key(
P::TargetChain::WITH_CHAIN_MESSAGES_PALLET_NAME,
&self.lane_id,
),
Some(id.1),
)
.await?;
// lane data missing from the storage is fine until first message is sent // lane data missing from the storage is fine until first message is sent
let latest_received_nonce = let latest_received_nonce = self
outbound_lane_data.map(|data| data.latest_received_nonce).unwrap_or(0); .outbound_lane_data(id)
.await?
.map(|data| data.latest_received_nonce)
.unwrap_or(0);
Ok((id, latest_received_nonce)) Ok((id, latest_received_nonce))
} }
@@ -84,6 +84,22 @@ impl<P: SubstrateMessageLane> SubstrateMessagesTarget<P> {
source_to_target_headers_relay, source_to_target_headers_relay,
} }
} }
/// Read inbound lane state from the on-chain storage at given block.
async fn inbound_lane_data(
&self,
id: TargetHeaderIdOf<MessageLaneAdapter<P>>,
) -> Result<Option<InboundLaneData<AccountIdOf<P::SourceChain>>>, SubstrateError> {
self.client
.storage_value(
inbound_lane_data_key(
P::SourceChain::WITH_CHAIN_MESSAGES_PALLET_NAME,
&self.lane_id,
),
Some(id.1),
)
.await
}
} }
impl<P: SubstrateMessageLane> Clone for SubstrateMessagesTarget<P> { impl<P: SubstrateMessageLane> Clone for SubstrateMessagesTarget<P> {
@@ -133,19 +149,12 @@ where
&self, &self,
id: TargetHeaderIdOf<MessageLaneAdapter<P>>, id: TargetHeaderIdOf<MessageLaneAdapter<P>>,
) -> Result<(TargetHeaderIdOf<MessageLaneAdapter<P>>, MessageNonce), SubstrateError> { ) -> Result<(TargetHeaderIdOf<MessageLaneAdapter<P>>, MessageNonce), SubstrateError> {
let inbound_lane_data: Option<InboundLaneData<AccountIdOf<P::SourceChain>>> = self
.client
.storage_value(
inbound_lane_data_key(
P::SourceChain::WITH_CHAIN_MESSAGES_PALLET_NAME,
&self.lane_id,
),
Some(id.1),
)
.await?;
// lane data missing from the storage is fine until first message is received // lane data missing from the storage is fine until first message is received
let latest_received_nonce = let latest_received_nonce = self
inbound_lane_data.map(|data| data.last_delivered_nonce()).unwrap_or(0); .inbound_lane_data(id)
.await?
.map(|data| data.last_delivered_nonce())
.unwrap_or(0);
Ok((id, latest_received_nonce)) Ok((id, latest_received_nonce))
} }
@@ -153,17 +162,13 @@ where
&self, &self,
id: TargetHeaderIdOf<MessageLaneAdapter<P>>, id: TargetHeaderIdOf<MessageLaneAdapter<P>>,
) -> Result<(TargetHeaderIdOf<MessageLaneAdapter<P>>, MessageNonce), SubstrateError> { ) -> Result<(TargetHeaderIdOf<MessageLaneAdapter<P>>, MessageNonce), SubstrateError> {
let encoded_response = self // lane data missing from the storage is fine until first message is received
.client let last_confirmed_nonce = self
.state_call( .inbound_lane_data(id)
P::SourceChain::FROM_CHAIN_LATEST_CONFIRMED_NONCE_METHOD.into(), .await?
Bytes(self.lane_id.encode()), .map(|data| data.last_confirmed_nonce)
Some(id.1), .unwrap_or(0);
) Ok((id, last_confirmed_nonce))
.await?;
let latest_received_nonce: MessageNonce = Decode::decode(&mut &encoded_response.0[..])
.map_err(SubstrateError::ResponseParseFailed)?;
Ok((id, latest_received_nonce))
} }
async fn unrewarded_relayers_state( async fn unrewarded_relayers_state(