mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 19:51:02 +00:00
when messages pallet is halted, relay shall not submit messages delivery/confirmation transactions (#1289)
This commit is contained in:
committed by
Bastian Köcher
parent
0fa8c02e7a
commit
25008a5166
@@ -29,8 +29,8 @@ use crate::{
|
||||
|
||||
use async_trait::async_trait;
|
||||
use bp_messages::{
|
||||
storage_keys::outbound_lane_data_key, LaneId, MessageNonce, OutboundLaneData,
|
||||
UnrewardedRelayersState,
|
||||
storage_keys::{operating_mode_key, outbound_lane_data_key},
|
||||
LaneId, MessageNonce, OperatingMode, OutboundLaneData, UnrewardedRelayersState,
|
||||
};
|
||||
use bridge_runtime_common::messages::{
|
||||
source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof,
|
||||
@@ -99,6 +99,11 @@ impl<P: SubstrateMessageLane> SubstrateMessagesSource<P> {
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Ensure that the messages pallet at source chain is active.
|
||||
async fn ensure_pallet_active(&self) -> Result<(), SubstrateError> {
|
||||
ensure_messages_pallet_active::<P::SourceChain, P::TargetChain>(&self.client).await
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: SubstrateMessageLane> Clone for SubstrateMessagesSource<P> {
|
||||
@@ -132,6 +137,8 @@ where
|
||||
// we can't continue to deliver confirmations if source node is out of sync, because
|
||||
// it may have already received confirmations that we're going to deliver
|
||||
self.client.ensure_synced().await?;
|
||||
// we can't relay confirmations if messages pallet at source chain is halted
|
||||
self.ensure_pallet_active().await?;
|
||||
|
||||
read_client_state::<
|
||||
_,
|
||||
@@ -292,6 +299,25 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Ensure that the messages pallet at source chain is active.
|
||||
pub(crate) async fn ensure_messages_pallet_active<AtChain, WithChain>(
|
||||
client: &Client<AtChain>,
|
||||
) -> Result<(), SubstrateError>
|
||||
where
|
||||
AtChain: ChainWithMessages,
|
||||
WithChain: ChainWithMessages,
|
||||
{
|
||||
let operating_mode = client
|
||||
.storage_value(operating_mode_key(WithChain::WITH_CHAIN_MESSAGES_PALLET_NAME), None)
|
||||
.await?;
|
||||
let is_halted = operating_mode == Some(OperatingMode::Halted);
|
||||
if is_halted {
|
||||
Err(SubstrateError::BridgePalletIsHalted)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Make messages delivery proof transaction from given proof.
|
||||
fn make_messages_delivery_proof_transaction<P: SubstrateMessageLane>(
|
||||
spec_version: u32,
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
use crate::{
|
||||
messages_lane::{MessageLaneAdapter, ReceiveMessagesProofCallBuilder, SubstrateMessageLane},
|
||||
messages_metrics::StandaloneMessagesMetrics,
|
||||
messages_source::{read_client_state, SubstrateMessagesProof},
|
||||
messages_source::{ensure_messages_pallet_active, read_client_state, SubstrateMessagesProof},
|
||||
on_demand_headers::OnDemandHeadersRelay,
|
||||
TransactionParams,
|
||||
};
|
||||
@@ -100,6 +100,11 @@ impl<P: SubstrateMessageLane> SubstrateMessagesTarget<P> {
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Ensure that the messages pallet at target chain is active.
|
||||
async fn ensure_pallet_active(&self) -> Result<(), SubstrateError> {
|
||||
ensure_messages_pallet_active::<P::TargetChain, P::SourceChain>(&self.client).await
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: SubstrateMessageLane> Clone for SubstrateMessagesTarget<P> {
|
||||
@@ -136,6 +141,8 @@ where
|
||||
// we can't continue to deliver messages if target node is out of sync, because
|
||||
// it may have already received (some of) messages that we're going to deliver
|
||||
self.client.ensure_synced().await?;
|
||||
// we can't relay messages if messages pallet at target chain is halted
|
||||
self.ensure_pallet_active().await?;
|
||||
|
||||
read_client_state::<
|
||||
_,
|
||||
|
||||
Reference in New Issue
Block a user