mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 22:11:02 +00:00
Unify the operating mode for bridge pallets (#1483)
Unify the operating mode for bridge pallets - define the OperationMode trait and BasicOperatingMode enum - use the OperationMode trait in all the bridge pallets - use BasicOperatingMode instead of IsHalted for the Grandpa pallet - use BasicOperatingMode as part of MessagesOperatingMode Signed-off-by: Serban Iorga <serban@parity.io>
This commit is contained in:
committed by
Bastian Köcher
parent
ff342fafa9
commit
f8ff3c9142
@@ -23,6 +23,7 @@ use bp_header_chain::{
|
||||
justification::{verify_justification, GrandpaJustification},
|
||||
FinalityProof,
|
||||
};
|
||||
use bp_runtime::{BasicOperatingMode, OperatingMode};
|
||||
use codec::{Decode, Encode};
|
||||
use finality_grandpa::voter_set::VoterSet;
|
||||
use num_traits::{One, Zero};
|
||||
@@ -44,10 +45,12 @@ pub trait Engine<C: Chain>: Send {
|
||||
type FinalityProof: FinalityProof<BlockNumberOf<C>> + Decode + Encode;
|
||||
/// Type of bridge pallet initialization data.
|
||||
type InitializationData: std::fmt::Debug + Send + Sync + 'static;
|
||||
/// Type of bridge pallet operating mode.
|
||||
type OperatingMode: OperatingMode + 'static;
|
||||
|
||||
/// Returns storage key at the bridged (target) chain that corresponds to the `bool` value,
|
||||
/// which is true when the bridge pallet is halted.
|
||||
fn is_halted_key() -> StorageKey;
|
||||
/// Returns storage key at the bridged (target) chain that corresponds to the variable
|
||||
/// that holds the operating mode of the pallet.
|
||||
fn pallet_operating_mode_key() -> StorageKey;
|
||||
/// Returns storage at the bridged (target) chain that corresponds to some value that is
|
||||
/// missing from the storage until bridge pallet is initialized.
|
||||
///
|
||||
@@ -74,7 +77,11 @@ pub trait Engine<C: Chain>: Send {
|
||||
async fn is_halted<TargetChain: Chain>(
|
||||
target_client: &Client<TargetChain>,
|
||||
) -> Result<bool, SubstrateError> {
|
||||
Ok(target_client.storage_value(Self::is_halted_key(), None).await?.unwrap_or(false))
|
||||
Ok(target_client
|
||||
.storage_value::<Self::OperatingMode>(Self::pallet_operating_mode_key(), None)
|
||||
.await?
|
||||
.map(|operating_mode| operating_mode.is_halted())
|
||||
.unwrap_or(false))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,9 +119,10 @@ impl<C: ChainWithGrandpa> Engine<C> for Grandpa<C> {
|
||||
const ID: ConsensusEngineId = sp_finality_grandpa::GRANDPA_ENGINE_ID;
|
||||
type FinalityProof = GrandpaJustification<HeaderOf<C>>;
|
||||
type InitializationData = bp_header_chain::InitializationData<C::Header>;
|
||||
type OperatingMode = BasicOperatingMode;
|
||||
|
||||
fn is_halted_key() -> StorageKey {
|
||||
bp_header_chain::storage_keys::is_halted_key(C::WITH_CHAIN_GRANDPA_PALLET_NAME)
|
||||
fn pallet_operating_mode_key() -> StorageKey {
|
||||
bp_header_chain::storage_keys::pallet_operating_mode_key(C::WITH_CHAIN_GRANDPA_PALLET_NAME)
|
||||
}
|
||||
|
||||
fn is_initialized_key() -> StorageKey {
|
||||
@@ -237,7 +245,7 @@ impl<C: ChainWithGrandpa> Engine<C> for Grandpa<C> {
|
||||
} else {
|
||||
initial_authorities_set_id
|
||||
},
|
||||
is_halted: false,
|
||||
operating_mode: BasicOperatingMode::Normal,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,10 +31,10 @@ use async_std::sync::Arc;
|
||||
use async_trait::async_trait;
|
||||
use bp_messages::{
|
||||
storage_keys::{operating_mode_key, outbound_lane_data_key},
|
||||
InboundMessageDetails, LaneId, MessageData, MessageNonce, OperatingMode, OutboundLaneData,
|
||||
OutboundMessageDetails, UnrewardedRelayersState,
|
||||
InboundMessageDetails, LaneId, MessageData, MessageNonce, MessagesOperatingMode,
|
||||
OutboundLaneData, OutboundMessageDetails, UnrewardedRelayersState,
|
||||
};
|
||||
use bp_runtime::messages::DispatchFeePayment;
|
||||
use bp_runtime::{messages::DispatchFeePayment, BasicOperatingMode};
|
||||
use bridge_runtime_common::messages::{
|
||||
source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof,
|
||||
};
|
||||
@@ -420,7 +420,8 @@ where
|
||||
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);
|
||||
let is_halted =
|
||||
operating_mode == Some(MessagesOperatingMode::Basic(BasicOperatingMode::Halted));
|
||||
if is_halted {
|
||||
Err(SubstrateError::BridgePalletIsHalted)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user