mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-19 18:05:41 +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
@@ -41,6 +41,7 @@
|
|||||||
|
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
|
use bp_runtime::BasicOperatingMode;
|
||||||
use bp_test_utils::{
|
use bp_test_utils::{
|
||||||
accounts, make_justification_for_header, JustificationGeneratorParams, TEST_GRANDPA_ROUND,
|
accounts, make_justification_for_header, JustificationGeneratorParams, TEST_GRANDPA_ROUND,
|
||||||
TEST_GRANDPA_SET_ID,
|
TEST_GRANDPA_SET_ID,
|
||||||
@@ -84,7 +85,7 @@ fn prepare_benchmark_data<T: Config<I>, I: 'static>(
|
|||||||
header: Box::new(bp_test_utils::test_header(Zero::zero())),
|
header: Box::new(bp_test_utils::test_header(Zero::zero())),
|
||||||
authority_list,
|
authority_list,
|
||||||
set_id: TEST_GRANDPA_SET_ID,
|
set_id: TEST_GRANDPA_SET_ID,
|
||||||
is_halted: false,
|
operating_mode: BasicOperatingMode::Normal,
|
||||||
};
|
};
|
||||||
|
|
||||||
bootstrap_bridge::<T, I>(init_data);
|
bootstrap_bridge::<T, I>(init_data);
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ pub type BridgedHeader<T, I> = HeaderOf<<T as Config<I>>::BridgedChain>;
|
|||||||
#[frame_support::pallet]
|
#[frame_support::pallet]
|
||||||
pub mod pallet {
|
pub mod pallet {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use bp_runtime::BasicOperatingMode;
|
||||||
use frame_support::pallet_prelude::*;
|
use frame_support::pallet_prelude::*;
|
||||||
use frame_system::pallet_prelude::*;
|
use frame_system::pallet_prelude::*;
|
||||||
|
|
||||||
@@ -119,14 +120,9 @@ pub mod pallet {
|
|||||||
|
|
||||||
impl<T: Config<I>, I: 'static> OwnedBridgeModule<T> for Pallet<T, I> {
|
impl<T: Config<I>, I: 'static> OwnedBridgeModule<T> for Pallet<T, I> {
|
||||||
const LOG_TARGET: &'static str = "runtime::bridge-grandpa";
|
const LOG_TARGET: &'static str = "runtime::bridge-grandpa";
|
||||||
const OPERATING_MODE_KEY: &'static str = "IsHalted";
|
|
||||||
type OwnerStorage = PalletOwner<T, I>;
|
type OwnerStorage = PalletOwner<T, I>;
|
||||||
type OperatingMode = bool;
|
type OperatingMode = BasicOperatingMode;
|
||||||
type OperatingModeStorage = IsHalted<T, I>;
|
type OperatingModeStorage = PalletOperatingMode<T, I>;
|
||||||
|
|
||||||
fn is_halted() -> bool {
|
|
||||||
Self::OperatingModeStorage::get()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pallet::call]
|
#[pallet::call]
|
||||||
@@ -237,8 +233,11 @@ pub mod pallet {
|
|||||||
///
|
///
|
||||||
/// May only be called either by root, or by `PalletOwner`.
|
/// May only be called either by root, or by `PalletOwner`.
|
||||||
#[pallet::weight((T::DbWeight::get().reads_writes(1, 1), DispatchClass::Operational))]
|
#[pallet::weight((T::DbWeight::get().reads_writes(1, 1), DispatchClass::Operational))]
|
||||||
pub fn set_operational(origin: OriginFor<T>, operational: bool) -> DispatchResult {
|
pub fn set_operating_mode(
|
||||||
Self::set_operating_mode(origin, !operational)
|
origin: OriginFor<T>,
|
||||||
|
operating_mode: BasicOperatingMode,
|
||||||
|
) -> DispatchResult {
|
||||||
|
<Self as OwnedBridgeModule<_>>::set_operating_mode(origin, operating_mode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,9 +292,12 @@ pub mod pallet {
|
|||||||
pub type PalletOwner<T: Config<I>, I: 'static = ()> =
|
pub type PalletOwner<T: Config<I>, I: 'static = ()> =
|
||||||
StorageValue<_, T::AccountId, OptionQuery>;
|
StorageValue<_, T::AccountId, OptionQuery>;
|
||||||
|
|
||||||
/// If true, all pallet transactions are failed immediately.
|
/// The current operating mode of the pallet.
|
||||||
|
///
|
||||||
|
/// Depending on the mode either all, or no transactions will be allowed.
|
||||||
#[pallet::storage]
|
#[pallet::storage]
|
||||||
pub type IsHalted<T: Config<I>, I: 'static = ()> = StorageValue<_, bool, ValueQuery>;
|
pub type PalletOperatingMode<T: Config<I>, I: 'static = ()> =
|
||||||
|
StorageValue<_, BasicOperatingMode, ValueQuery>;
|
||||||
|
|
||||||
#[pallet::genesis_config]
|
#[pallet::genesis_config]
|
||||||
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> {
|
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> {
|
||||||
@@ -324,7 +326,7 @@ pub mod pallet {
|
|||||||
} else {
|
} else {
|
||||||
// Since the bridge hasn't been initialized we shouldn't allow anyone to perform
|
// Since the bridge hasn't been initialized we shouldn't allow anyone to perform
|
||||||
// transactions.
|
// transactions.
|
||||||
<IsHalted<T, I>>::put(true);
|
<PalletOperatingMode<T, I>>::put(BasicOperatingMode::Halted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -463,7 +465,8 @@ pub mod pallet {
|
|||||||
pub(crate) fn initialize_bridge<T: Config<I>, I: 'static>(
|
pub(crate) fn initialize_bridge<T: Config<I>, I: 'static>(
|
||||||
init_params: super::InitializationData<BridgedHeader<T, I>>,
|
init_params: super::InitializationData<BridgedHeader<T, I>>,
|
||||||
) {
|
) {
|
||||||
let super::InitializationData { header, authority_list, set_id, is_halted } = init_params;
|
let super::InitializationData { header, authority_list, set_id, operating_mode } =
|
||||||
|
init_params;
|
||||||
|
|
||||||
let initial_hash = header.hash();
|
let initial_hash = header.hash();
|
||||||
<InitialHash<T, I>>::put(initial_hash);
|
<InitialHash<T, I>>::put(initial_hash);
|
||||||
@@ -473,7 +476,7 @@ pub mod pallet {
|
|||||||
let authority_set = bp_header_chain::AuthoritySet::new(authority_list, set_id);
|
let authority_set = bp_header_chain::AuthoritySet::new(authority_list, set_id);
|
||||||
<CurrentAuthoritySet<T, I>>::put(authority_set);
|
<CurrentAuthoritySet<T, I>>::put(authority_set);
|
||||||
|
|
||||||
<IsHalted<T, I>>::put(is_halted);
|
<PalletOperatingMode<T, I>>::put(operating_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "runtime-benchmarks")]
|
#[cfg(feature = "runtime-benchmarks")]
|
||||||
@@ -576,7 +579,7 @@ pub fn initialize_for_benchmarks<T: Config<I>, I: 'static>(header: BridgedHeader
|
|||||||
authority_list: sp_std::vec::Vec::new(), /* we don't verify any proofs in external
|
authority_list: sp_std::vec::Vec::new(), /* we don't verify any proofs in external
|
||||||
* benchmarks */
|
* benchmarks */
|
||||||
set_id: 0,
|
set_id: 0,
|
||||||
is_halted: false,
|
operating_mode: bp_runtime::BasicOperatingMode::Normal,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -584,6 +587,7 @@ pub fn initialize_for_benchmarks<T: Config<I>, I: 'static>(header: BridgedHeader
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::mock::{run_test, test_header, Origin, TestHeader, TestNumber, TestRuntime};
|
use crate::mock::{run_test, test_header, Origin, TestHeader, TestNumber, TestRuntime};
|
||||||
|
use bp_runtime::BasicOperatingMode;
|
||||||
use bp_test_utils::{
|
use bp_test_utils::{
|
||||||
authority_list, make_default_justification, make_justification_for_header,
|
authority_list, make_default_justification, make_justification_for_header,
|
||||||
JustificationGeneratorParams, ALICE, BOB,
|
JustificationGeneratorParams, ALICE, BOB,
|
||||||
@@ -611,7 +615,7 @@ mod tests {
|
|||||||
header: Box::new(genesis),
|
header: Box::new(genesis),
|
||||||
authority_list: authority_list(),
|
authority_list: authority_list(),
|
||||||
set_id: 1,
|
set_id: 1,
|
||||||
is_halted: false,
|
operating_mode: BasicOperatingMode::Normal,
|
||||||
};
|
};
|
||||||
|
|
||||||
Pallet::<TestRuntime>::initialize(origin, init_data.clone()).map(|_| init_data)
|
Pallet::<TestRuntime>::initialize(origin, init_data.clone()).map(|_| init_data)
|
||||||
@@ -685,7 +689,7 @@ mod tests {
|
|||||||
CurrentAuthoritySet::<TestRuntime>::get().authorities,
|
CurrentAuthoritySet::<TestRuntime>::get().authorities,
|
||||||
init_data.authority_list
|
init_data.authority_list
|
||||||
);
|
);
|
||||||
assert!(!IsHalted::<TestRuntime>::get());
|
assert_eq!(PalletOperatingMode::<TestRuntime>::get(), BasicOperatingMode::Normal);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -707,29 +711,50 @@ mod tests {
|
|||||||
|
|
||||||
assert_ok!(Pallet::<TestRuntime>::set_owner(Origin::root(), Some(1)));
|
assert_ok!(Pallet::<TestRuntime>::set_owner(Origin::root(), Some(1)));
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Pallet::<TestRuntime>::set_operational(Origin::signed(2), false),
|
Pallet::<TestRuntime>::set_operating_mode(
|
||||||
|
Origin::signed(2),
|
||||||
|
BasicOperatingMode::Halted
|
||||||
|
),
|
||||||
DispatchError::BadOrigin,
|
DispatchError::BadOrigin,
|
||||||
);
|
);
|
||||||
assert_ok!(Pallet::<TestRuntime>::set_operational(Origin::root(), false));
|
assert_ok!(Pallet::<TestRuntime>::set_operating_mode(
|
||||||
|
Origin::root(),
|
||||||
|
BasicOperatingMode::Halted
|
||||||
|
));
|
||||||
|
|
||||||
assert_ok!(Pallet::<TestRuntime>::set_owner(Origin::signed(1), None));
|
assert_ok!(Pallet::<TestRuntime>::set_owner(Origin::signed(1), None));
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Pallet::<TestRuntime>::set_operational(Origin::signed(1), true),
|
Pallet::<TestRuntime>::set_operating_mode(
|
||||||
|
Origin::signed(1),
|
||||||
|
BasicOperatingMode::Normal
|
||||||
|
),
|
||||||
DispatchError::BadOrigin,
|
DispatchError::BadOrigin,
|
||||||
);
|
);
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Pallet::<TestRuntime>::set_operational(Origin::signed(2), true),
|
Pallet::<TestRuntime>::set_operating_mode(
|
||||||
|
Origin::signed(2),
|
||||||
|
BasicOperatingMode::Normal
|
||||||
|
),
|
||||||
DispatchError::BadOrigin,
|
DispatchError::BadOrigin,
|
||||||
);
|
);
|
||||||
assert_ok!(Pallet::<TestRuntime>::set_operational(Origin::root(), true));
|
assert_ok!(Pallet::<TestRuntime>::set_operating_mode(
|
||||||
|
Origin::root(),
|
||||||
|
BasicOperatingMode::Normal
|
||||||
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn pallet_may_be_halted_by_root() {
|
fn pallet_may_be_halted_by_root() {
|
||||||
run_test(|| {
|
run_test(|| {
|
||||||
assert_ok!(Pallet::<TestRuntime>::set_operational(Origin::root(), false));
|
assert_ok!(Pallet::<TestRuntime>::set_operating_mode(
|
||||||
assert_ok!(Pallet::<TestRuntime>::set_operational(Origin::root(), true));
|
Origin::root(),
|
||||||
|
BasicOperatingMode::Halted
|
||||||
|
));
|
||||||
|
assert_ok!(Pallet::<TestRuntime>::set_operating_mode(
|
||||||
|
Origin::root(),
|
||||||
|
BasicOperatingMode::Normal
|
||||||
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -738,21 +763,39 @@ mod tests {
|
|||||||
run_test(|| {
|
run_test(|| {
|
||||||
PalletOwner::<TestRuntime>::put(2);
|
PalletOwner::<TestRuntime>::put(2);
|
||||||
|
|
||||||
assert_ok!(Pallet::<TestRuntime>::set_operational(Origin::signed(2), false));
|
assert_ok!(Pallet::<TestRuntime>::set_operating_mode(
|
||||||
assert_ok!(Pallet::<TestRuntime>::set_operational(Origin::signed(2), true));
|
Origin::signed(2),
|
||||||
|
BasicOperatingMode::Halted
|
||||||
|
));
|
||||||
|
assert_ok!(Pallet::<TestRuntime>::set_operating_mode(
|
||||||
|
Origin::signed(2),
|
||||||
|
BasicOperatingMode::Normal
|
||||||
|
));
|
||||||
|
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Pallet::<TestRuntime>::set_operational(Origin::signed(1), false),
|
Pallet::<TestRuntime>::set_operating_mode(
|
||||||
|
Origin::signed(1),
|
||||||
|
BasicOperatingMode::Halted
|
||||||
|
),
|
||||||
DispatchError::BadOrigin,
|
DispatchError::BadOrigin,
|
||||||
);
|
);
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Pallet::<TestRuntime>::set_operational(Origin::signed(1), true),
|
Pallet::<TestRuntime>::set_operating_mode(
|
||||||
|
Origin::signed(1),
|
||||||
|
BasicOperatingMode::Normal
|
||||||
|
),
|
||||||
DispatchError::BadOrigin,
|
DispatchError::BadOrigin,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_ok!(Pallet::<TestRuntime>::set_operational(Origin::signed(2), false));
|
assert_ok!(Pallet::<TestRuntime>::set_operating_mode(
|
||||||
|
Origin::signed(2),
|
||||||
|
BasicOperatingMode::Halted
|
||||||
|
));
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Pallet::<TestRuntime>::set_operational(Origin::signed(1), true),
|
Pallet::<TestRuntime>::set_operating_mode(
|
||||||
|
Origin::signed(1),
|
||||||
|
BasicOperatingMode::Normal
|
||||||
|
),
|
||||||
DispatchError::BadOrigin,
|
DispatchError::BadOrigin,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -763,13 +806,19 @@ mod tests {
|
|||||||
run_test(|| {
|
run_test(|| {
|
||||||
initialize_substrate_bridge();
|
initialize_substrate_bridge();
|
||||||
|
|
||||||
assert_ok!(Pallet::<TestRuntime>::set_operational(Origin::root(), false));
|
assert_ok!(Pallet::<TestRuntime>::set_operating_mode(
|
||||||
|
Origin::root(),
|
||||||
|
BasicOperatingMode::Halted
|
||||||
|
));
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
submit_finality_proof(1),
|
submit_finality_proof(1),
|
||||||
Error::<TestRuntime>::BridgeModule(bp_runtime::OwnedBridgeModuleError::Halted)
|
Error::<TestRuntime>::BridgeModule(bp_runtime::OwnedBridgeModuleError::Halted)
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_ok!(Pallet::<TestRuntime>::set_operational(Origin::root(), true));
|
assert_ok!(Pallet::<TestRuntime>::set_operating_mode(
|
||||||
|
Origin::root(),
|
||||||
|
BasicOperatingMode::Normal
|
||||||
|
));
|
||||||
assert_ok!(submit_finality_proof(1));
|
assert_ok!(submit_finality_proof(1));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -851,7 +900,7 @@ mod tests {
|
|||||||
header: Box::new(genesis),
|
header: Box::new(genesis),
|
||||||
authority_list: invalid_authority_list,
|
authority_list: invalid_authority_list,
|
||||||
set_id: 1,
|
set_id: 1,
|
||||||
is_halted: false,
|
operating_mode: BasicOperatingMode::Normal,
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_ok!(Pallet::<TestRuntime>::initialize(Origin::root(), init_data));
|
assert_ok!(Pallet::<TestRuntime>::initialize(Origin::root(), init_data));
|
||||||
@@ -1115,8 +1164,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn storage_keys_computed_properly() {
|
fn storage_keys_computed_properly() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
IsHalted::<TestRuntime>::storage_value_final_key().to_vec(),
|
PalletOperatingMode::<TestRuntime>::storage_value_final_key().to_vec(),
|
||||||
bp_header_chain::storage_keys::is_halted_key("Grandpa").0,
|
bp_header_chain::storage_keys::pallet_operating_mode_key("Grandpa").0,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|||||||
@@ -57,11 +57,11 @@ use bp_messages::{
|
|||||||
DispatchMessage, MessageDispatch, ProvedLaneMessages, ProvedMessages, SourceHeaderChain,
|
DispatchMessage, MessageDispatch, ProvedLaneMessages, ProvedMessages, SourceHeaderChain,
|
||||||
},
|
},
|
||||||
total_unrewarded_messages, DeliveredMessages, InboundLaneData, InboundMessageDetails, LaneId,
|
total_unrewarded_messages, DeliveredMessages, InboundLaneData, InboundMessageDetails, LaneId,
|
||||||
MessageData, MessageKey, MessageNonce, MessagePayload, OperatingMode, OutboundLaneData,
|
MessageData, MessageKey, MessageNonce, MessagePayload, MessagesOperatingMode, OutboundLaneData,
|
||||||
OutboundMessageDetails, Parameter as MessagesParameter, UnrewardedRelayer,
|
OutboundMessageDetails, Parameter as MessagesParameter, UnrewardedRelayer,
|
||||||
UnrewardedRelayersState,
|
UnrewardedRelayersState,
|
||||||
};
|
};
|
||||||
use bp_runtime::{ChainId, OwnedBridgeModule, Size};
|
use bp_runtime::{BasicOperatingMode, ChainId, OwnedBridgeModule, Size};
|
||||||
use codec::{Decode, Encode};
|
use codec::{Decode, Encode};
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
fail,
|
fail,
|
||||||
@@ -218,14 +218,9 @@ pub mod pallet {
|
|||||||
|
|
||||||
impl<T: Config<I>, I: 'static> OwnedBridgeModule<T> for Pallet<T, I> {
|
impl<T: Config<I>, I: 'static> OwnedBridgeModule<T> for Pallet<T, I> {
|
||||||
const LOG_TARGET: &'static str = "runtime::bridge-messages";
|
const LOG_TARGET: &'static str = "runtime::bridge-messages";
|
||||||
const OPERATING_MODE_KEY: &'static str = "PalletOperatingMode";
|
|
||||||
type OwnerStorage = PalletOwner<T, I>;
|
type OwnerStorage = PalletOwner<T, I>;
|
||||||
type OperatingMode = OperatingMode;
|
type OperatingMode = MessagesOperatingMode;
|
||||||
type OperatingModeStorage = PalletOperatingMode<T, I>;
|
type OperatingModeStorage = PalletOperatingMode<T, I>;
|
||||||
|
|
||||||
fn is_halted() -> bool {
|
|
||||||
Self::OperatingModeStorage::get() == OperatingMode::Halted
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pallet::call]
|
#[pallet::call]
|
||||||
@@ -244,7 +239,7 @@ pub mod pallet {
|
|||||||
#[pallet::weight((T::DbWeight::get().reads_writes(1, 1), DispatchClass::Operational))]
|
#[pallet::weight((T::DbWeight::get().reads_writes(1, 1), DispatchClass::Operational))]
|
||||||
pub fn set_operating_mode(
|
pub fn set_operating_mode(
|
||||||
origin: OriginFor<T>,
|
origin: OriginFor<T>,
|
||||||
operating_mode: OperatingMode,
|
operating_mode: MessagesOperatingMode,
|
||||||
) -> DispatchResult {
|
) -> DispatchResult {
|
||||||
<Self as OwnedBridgeModule<_>>::set_operating_mode(origin, operating_mode)
|
<Self as OwnedBridgeModule<_>>::set_operating_mode(origin, operating_mode)
|
||||||
}
|
}
|
||||||
@@ -708,7 +703,7 @@ pub mod pallet {
|
|||||||
#[pallet::storage]
|
#[pallet::storage]
|
||||||
#[pallet::getter(fn operating_mode)]
|
#[pallet::getter(fn operating_mode)]
|
||||||
pub type PalletOperatingMode<T: Config<I>, I: 'static = ()> =
|
pub type PalletOperatingMode<T: Config<I>, I: 'static = ()> =
|
||||||
StorageValue<_, OperatingMode, ValueQuery>;
|
StorageValue<_, MessagesOperatingMode, ValueQuery>;
|
||||||
|
|
||||||
/// Map of lane id => inbound lane data.
|
/// Map of lane id => inbound lane data.
|
||||||
#[pallet::storage]
|
#[pallet::storage]
|
||||||
@@ -728,7 +723,7 @@ pub mod pallet {
|
|||||||
#[pallet::genesis_config]
|
#[pallet::genesis_config]
|
||||||
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> {
|
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> {
|
||||||
/// Initial pallet operating mode.
|
/// Initial pallet operating mode.
|
||||||
pub operating_mode: OperatingMode,
|
pub operating_mode: MessagesOperatingMode,
|
||||||
/// Initial pallet owner.
|
/// Initial pallet owner.
|
||||||
pub owner: Option<T::AccountId>,
|
pub owner: Option<T::AccountId>,
|
||||||
/// Dummy marker.
|
/// Dummy marker.
|
||||||
@@ -972,11 +967,13 @@ where
|
|||||||
|
|
||||||
/// Ensure that the pallet is in normal operational mode.
|
/// Ensure that the pallet is in normal operational mode.
|
||||||
fn ensure_normal_operating_mode<T: Config<I>, I: 'static>() -> Result<(), Error<T, I>> {
|
fn ensure_normal_operating_mode<T: Config<I>, I: 'static>() -> Result<(), Error<T, I>> {
|
||||||
if PalletOperatingMode::<T, I>::get() != OperatingMode::Normal {
|
if PalletOperatingMode::<T, I>::get() ==
|
||||||
Err(Error::<T, I>::NotOperatingNormally)
|
MessagesOperatingMode::Basic(BasicOperatingMode::Normal)
|
||||||
} else {
|
{
|
||||||
Ok(())
|
return Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Err(Error::<T, I>::NotOperatingNormally)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates new inbound lane object, backed by runtime storage.
|
/// Creates new inbound lane object, backed by runtime storage.
|
||||||
@@ -1234,26 +1231,35 @@ mod tests {
|
|||||||
|
|
||||||
assert_ok!(Pallet::<TestRuntime>::set_owner(Origin::root(), Some(1)));
|
assert_ok!(Pallet::<TestRuntime>::set_owner(Origin::root(), Some(1)));
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Pallet::<TestRuntime>::set_operating_mode(Origin::signed(2), OperatingMode::Halted),
|
Pallet::<TestRuntime>::set_operating_mode(
|
||||||
|
Origin::signed(2),
|
||||||
|
MessagesOperatingMode::Basic(BasicOperatingMode::Halted)
|
||||||
|
),
|
||||||
DispatchError::BadOrigin,
|
DispatchError::BadOrigin,
|
||||||
);
|
);
|
||||||
assert_ok!(Pallet::<TestRuntime>::set_operating_mode(
|
assert_ok!(Pallet::<TestRuntime>::set_operating_mode(
|
||||||
Origin::root(),
|
Origin::root(),
|
||||||
OperatingMode::Halted
|
MessagesOperatingMode::Basic(BasicOperatingMode::Halted)
|
||||||
));
|
));
|
||||||
|
|
||||||
assert_ok!(Pallet::<TestRuntime>::set_owner(Origin::signed(1), None));
|
assert_ok!(Pallet::<TestRuntime>::set_owner(Origin::signed(1), None));
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Pallet::<TestRuntime>::set_operating_mode(Origin::signed(1), OperatingMode::Normal),
|
Pallet::<TestRuntime>::set_operating_mode(
|
||||||
|
Origin::signed(1),
|
||||||
|
MessagesOperatingMode::Basic(BasicOperatingMode::Normal)
|
||||||
|
),
|
||||||
DispatchError::BadOrigin,
|
DispatchError::BadOrigin,
|
||||||
);
|
);
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Pallet::<TestRuntime>::set_operating_mode(Origin::signed(2), OperatingMode::Normal),
|
Pallet::<TestRuntime>::set_operating_mode(
|
||||||
|
Origin::signed(2),
|
||||||
|
MessagesOperatingMode::Basic(BasicOperatingMode::Normal)
|
||||||
|
),
|
||||||
DispatchError::BadOrigin,
|
DispatchError::BadOrigin,
|
||||||
);
|
);
|
||||||
assert_ok!(Pallet::<TestRuntime>::set_operating_mode(
|
assert_ok!(Pallet::<TestRuntime>::set_operating_mode(
|
||||||
Origin::root(),
|
Origin::root(),
|
||||||
OperatingMode::Normal
|
MessagesOperatingMode::Basic(BasicOperatingMode::Normal)
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1263,11 +1269,11 @@ mod tests {
|
|||||||
run_test(|| {
|
run_test(|| {
|
||||||
assert_ok!(Pallet::<TestRuntime>::set_operating_mode(
|
assert_ok!(Pallet::<TestRuntime>::set_operating_mode(
|
||||||
Origin::root(),
|
Origin::root(),
|
||||||
OperatingMode::Halted
|
MessagesOperatingMode::Basic(BasicOperatingMode::Halted)
|
||||||
));
|
));
|
||||||
assert_ok!(Pallet::<TestRuntime>::set_operating_mode(
|
assert_ok!(Pallet::<TestRuntime>::set_operating_mode(
|
||||||
Origin::root(),
|
Origin::root(),
|
||||||
OperatingMode::Normal
|
MessagesOperatingMode::Basic(BasicOperatingMode::Normal)
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1279,28 +1285,37 @@ mod tests {
|
|||||||
|
|
||||||
assert_ok!(Pallet::<TestRuntime>::set_operating_mode(
|
assert_ok!(Pallet::<TestRuntime>::set_operating_mode(
|
||||||
Origin::signed(2),
|
Origin::signed(2),
|
||||||
OperatingMode::Halted
|
MessagesOperatingMode::Basic(BasicOperatingMode::Halted)
|
||||||
));
|
));
|
||||||
assert_ok!(Pallet::<TestRuntime>::set_operating_mode(
|
assert_ok!(Pallet::<TestRuntime>::set_operating_mode(
|
||||||
Origin::signed(2),
|
Origin::signed(2),
|
||||||
OperatingMode::Normal
|
MessagesOperatingMode::Basic(BasicOperatingMode::Normal)
|
||||||
));
|
));
|
||||||
|
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Pallet::<TestRuntime>::set_operating_mode(Origin::signed(1), OperatingMode::Halted),
|
Pallet::<TestRuntime>::set_operating_mode(
|
||||||
|
Origin::signed(1),
|
||||||
|
MessagesOperatingMode::Basic(BasicOperatingMode::Halted)
|
||||||
|
),
|
||||||
DispatchError::BadOrigin,
|
DispatchError::BadOrigin,
|
||||||
);
|
);
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Pallet::<TestRuntime>::set_operating_mode(Origin::signed(1), OperatingMode::Normal),
|
Pallet::<TestRuntime>::set_operating_mode(
|
||||||
|
Origin::signed(1),
|
||||||
|
MessagesOperatingMode::Basic(BasicOperatingMode::Normal)
|
||||||
|
),
|
||||||
DispatchError::BadOrigin,
|
DispatchError::BadOrigin,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_ok!(Pallet::<TestRuntime>::set_operating_mode(
|
assert_ok!(Pallet::<TestRuntime>::set_operating_mode(
|
||||||
Origin::signed(2),
|
Origin::signed(2),
|
||||||
OperatingMode::Halted
|
MessagesOperatingMode::Basic(BasicOperatingMode::Halted)
|
||||||
));
|
));
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Pallet::<TestRuntime>::set_operating_mode(Origin::signed(1), OperatingMode::Normal),
|
Pallet::<TestRuntime>::set_operating_mode(
|
||||||
|
Origin::signed(1),
|
||||||
|
MessagesOperatingMode::Basic(BasicOperatingMode::Normal)
|
||||||
|
),
|
||||||
DispatchError::BadOrigin,
|
DispatchError::BadOrigin,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -1408,7 +1423,9 @@ mod tests {
|
|||||||
// send message first to be able to check that delivery_proof fails later
|
// send message first to be able to check that delivery_proof fails later
|
||||||
send_regular_message();
|
send_regular_message();
|
||||||
|
|
||||||
PalletOperatingMode::<TestRuntime, ()>::put(OperatingMode::Halted);
|
PalletOperatingMode::<TestRuntime, ()>::put(MessagesOperatingMode::Basic(
|
||||||
|
BasicOperatingMode::Halted,
|
||||||
|
));
|
||||||
|
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Pallet::<TestRuntime>::send_message(
|
Pallet::<TestRuntime>::send_message(
|
||||||
@@ -1466,7 +1483,9 @@ mod tests {
|
|||||||
// send message first to be able to check that delivery_proof fails later
|
// send message first to be able to check that delivery_proof fails later
|
||||||
send_regular_message();
|
send_regular_message();
|
||||||
|
|
||||||
PalletOperatingMode::<TestRuntime, ()>::put(OperatingMode::RejectingOutboundMessages);
|
PalletOperatingMode::<TestRuntime, ()>::put(
|
||||||
|
MessagesOperatingMode::RejectingOutboundMessages,
|
||||||
|
);
|
||||||
|
|
||||||
assert_noop!(
|
assert_noop!(
|
||||||
Pallet::<TestRuntime>::send_message(
|
Pallet::<TestRuntime>::send_message(
|
||||||
|
|||||||
@@ -400,6 +400,7 @@ mod tests {
|
|||||||
run_test, test_relay_header, Origin, TestRuntime, PARAS_PALLET_NAME, UNTRACKED_PARACHAIN_ID,
|
run_test, test_relay_header, Origin, TestRuntime, PARAS_PALLET_NAME, UNTRACKED_PARACHAIN_ID,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use bp_runtime::BasicOperatingMode;
|
||||||
use bp_test_utils::{authority_list, make_default_justification};
|
use bp_test_utils::{authority_list, make_default_justification};
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
assert_noop, assert_ok,
|
assert_noop, assert_ok,
|
||||||
@@ -420,7 +421,7 @@ mod tests {
|
|||||||
header: Box::new(test_relay_header(0, state_root)),
|
header: Box::new(test_relay_header(0, state_root)),
|
||||||
authority_list: authority_list(),
|
authority_list: authority_list(),
|
||||||
set_id: 1,
|
set_id: 1,
|
||||||
is_halted: false,
|
operating_mode: BasicOperatingMode::Normal,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#![cfg_attr(not(feature = "std"), no_std)]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
|
|
||||||
|
use bp_runtime::BasicOperatingMode;
|
||||||
use codec::{Codec, Decode, Encode, EncodeLike};
|
use codec::{Codec, Decode, Encode, EncodeLike};
|
||||||
use core::{clone::Clone, cmp::Eq, default::Default, fmt::Debug};
|
use core::{clone::Clone, cmp::Eq, default::Default, fmt::Debug};
|
||||||
use scale_info::TypeInfo;
|
use scale_info::TypeInfo;
|
||||||
@@ -66,8 +67,8 @@ pub struct InitializationData<H: HeaderT> {
|
|||||||
pub authority_list: AuthorityList,
|
pub authority_list: AuthorityList,
|
||||||
/// The ID of the initial authority set.
|
/// The ID of the initial authority set.
|
||||||
pub set_id: SetId,
|
pub set_id: SetId,
|
||||||
/// Should the pallet block transaction immediately after initialization.
|
/// Pallet operating mode.
|
||||||
pub is_halted: bool,
|
pub operating_mode: BasicOperatingMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// base trait for verifying transaction inclusion proofs.
|
/// base trait for verifying transaction inclusion proofs.
|
||||||
|
|||||||
@@ -17,18 +17,18 @@
|
|||||||
//! Storage keys of bridge GRANDPA pallet.
|
//! Storage keys of bridge GRANDPA pallet.
|
||||||
|
|
||||||
/// Name of the `IsHalted` storage value.
|
/// Name of the `IsHalted` storage value.
|
||||||
pub const IS_HALTED_VALUE_NAME: &str = "IsHalted";
|
pub const PALLET_OPERATING_MODE_VALUE_NAME: &str = "PalletOperatingMode";
|
||||||
/// Name of the `BestFinalized` storage value.
|
/// Name of the `BestFinalized` storage value.
|
||||||
pub const BEST_FINALIZED_VALUE_NAME: &str = "BestFinalized";
|
pub const BEST_FINALIZED_VALUE_NAME: &str = "BestFinalized";
|
||||||
|
|
||||||
use sp_core::storage::StorageKey;
|
use sp_core::storage::StorageKey;
|
||||||
|
|
||||||
/// Storage key of the `IsHalted` flag in the runtime storage.
|
/// Storage key of the `PalletOperatingMode` variable in the runtime storage.
|
||||||
pub fn is_halted_key(pallet_prefix: &str) -> StorageKey {
|
pub fn pallet_operating_mode_key(pallet_prefix: &str) -> StorageKey {
|
||||||
StorageKey(
|
StorageKey(
|
||||||
bp_runtime::storage_value_final_key(
|
bp_runtime::storage_value_final_key(
|
||||||
pallet_prefix.as_bytes(),
|
pallet_prefix.as_bytes(),
|
||||||
IS_HALTED_VALUE_NAME.as_bytes(),
|
PALLET_OPERATING_MODE_VALUE_NAME.as_bytes(),
|
||||||
)
|
)
|
||||||
.to_vec(),
|
.to_vec(),
|
||||||
)
|
)
|
||||||
@@ -51,13 +51,13 @@ mod tests {
|
|||||||
use hex_literal::hex;
|
use hex_literal::hex;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn is_halted_key_computed_properly() {
|
fn pallet_operating_mode_key_computed_properly() {
|
||||||
// If this test fails, then something has been changed in module storage that is breaking
|
// If this test fails, then something has been changed in module storage that is breaking
|
||||||
// compatibility with previous pallet.
|
// compatibility with previous pallet.
|
||||||
let storage_key = is_halted_key("BridgeGrandpa").0;
|
let storage_key = pallet_operating_mode_key("BridgeGrandpa").0;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
storage_key,
|
storage_key,
|
||||||
hex!("0b06f475eddb98cf933a12262e0388de9611a984bbd04e2fd39f97bbc006115f").to_vec(),
|
hex!("0b06f475eddb98cf933a12262e0388de0f4cf0917788d791142ff6c1f216e7b3").to_vec(),
|
||||||
"Unexpected storage key: {}",
|
"Unexpected storage key: {}",
|
||||||
hex::encode(&storage_key),
|
hex::encode(&storage_key),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -32,14 +32,15 @@ pub mod storage_keys;
|
|||||||
pub mod target_chain;
|
pub mod target_chain;
|
||||||
|
|
||||||
// Weight is reexported to avoid additional frame-support dependencies in related crates.
|
// Weight is reexported to avoid additional frame-support dependencies in related crates.
|
||||||
|
use bp_runtime::{BasicOperatingMode, OperatingMode};
|
||||||
pub use frame_support::weights::Weight;
|
pub use frame_support::weights::Weight;
|
||||||
|
|
||||||
/// Messages pallet operating mode.
|
/// Messages pallet operating mode.
|
||||||
#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, RuntimeDebug, TypeInfo)]
|
#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, RuntimeDebug, TypeInfo)]
|
||||||
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub enum OperatingMode {
|
pub enum MessagesOperatingMode {
|
||||||
/// Normal mode, when all operations are allowed.
|
/// Basic operating mode (Normal/Halted)
|
||||||
Normal,
|
Basic(BasicOperatingMode),
|
||||||
/// The pallet is not accepting outbound messages. Inbound messages and receiving proofs
|
/// The pallet is not accepting outbound messages. Inbound messages and receiving proofs
|
||||||
/// are still accepted.
|
/// are still accepted.
|
||||||
///
|
///
|
||||||
@@ -48,13 +49,20 @@ pub enum OperatingMode {
|
|||||||
/// queued messages to the bridged chain. Once upgrade is completed, the mode may be switched
|
/// queued messages to the bridged chain. Once upgrade is completed, the mode may be switched
|
||||||
/// back to `Normal`.
|
/// back to `Normal`.
|
||||||
RejectingOutboundMessages,
|
RejectingOutboundMessages,
|
||||||
/// The pallet is halted. All operations (except operating mode change) are prohibited.
|
|
||||||
Halted,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for OperatingMode {
|
impl Default for MessagesOperatingMode {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
OperatingMode::Normal
|
MessagesOperatingMode::Basic(BasicOperatingMode::Normal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl OperatingMode for MessagesOperatingMode {
|
||||||
|
fn is_halted(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Self::Basic(operating_mode) => operating_mode.is_halted(),
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features =
|
|||||||
hash-db = { version = "0.15.2", default-features = false }
|
hash-db = { version = "0.15.2", default-features = false }
|
||||||
num-traits = { version = "0.2", default-features = false }
|
num-traits = { version = "0.2", default-features = false }
|
||||||
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
|
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
|
||||||
|
serde = { version = "1.0", optional = true, features = ["derive"] }
|
||||||
|
|
||||||
# Substrate Dependencies
|
# Substrate Dependencies
|
||||||
|
|
||||||
@@ -35,6 +36,7 @@ std = [
|
|||||||
"hash-db/std",
|
"hash-db/std",
|
||||||
"num-traits/std",
|
"num-traits/std",
|
||||||
"scale-info/std",
|
"scale-info/std",
|
||||||
|
"serde",
|
||||||
"sp-core/std",
|
"sp-core/std",
|
||||||
"sp-io/std",
|
"sp-io/std",
|
||||||
"sp-runtime/std",
|
"sp-runtime/std",
|
||||||
|
|||||||
@@ -269,18 +269,47 @@ pub enum OwnedBridgeModuleError {
|
|||||||
Halted,
|
Halted,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Operating mode for a bridge module.
|
||||||
|
pub trait OperatingMode: Send + Copy + Debug + FullCodec {
|
||||||
|
// Returns true if the bridge module is halted.
|
||||||
|
fn is_halted(&self) -> bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Basic operating modes for a bridges module (Normal/Halted).
|
||||||
|
#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, RuntimeDebug, TypeInfo)]
|
||||||
|
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
|
||||||
|
pub enum BasicOperatingMode {
|
||||||
|
/// Normal mode, when all operations are allowed.
|
||||||
|
Normal,
|
||||||
|
/// The pallet is halted. All operations (except operating mode change) are prohibited.
|
||||||
|
Halted,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for BasicOperatingMode {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::Normal
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl OperatingMode for BasicOperatingMode {
|
||||||
|
fn is_halted(&self) -> bool {
|
||||||
|
*self == BasicOperatingMode::Halted
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Bridge module that has owner and operating mode
|
/// Bridge module that has owner and operating mode
|
||||||
pub trait OwnedBridgeModule<T: frame_system::Config> {
|
pub trait OwnedBridgeModule<T: frame_system::Config> {
|
||||||
/// The target that will be used when publishing logs related to this module.
|
/// The target that will be used when publishing logs related to this module.
|
||||||
const LOG_TARGET: &'static str;
|
const LOG_TARGET: &'static str;
|
||||||
const OPERATING_MODE_KEY: &'static str;
|
|
||||||
|
|
||||||
type OwnerStorage: StorageValue<T::AccountId, Query = Option<T::AccountId>>;
|
type OwnerStorage: StorageValue<T::AccountId, Query = Option<T::AccountId>>;
|
||||||
type OperatingMode: Copy + Debug + FullCodec;
|
type OperatingMode: OperatingMode;
|
||||||
type OperatingModeStorage: StorageValue<Self::OperatingMode>;
|
type OperatingModeStorage: StorageValue<Self::OperatingMode, Query = Self::OperatingMode>;
|
||||||
|
|
||||||
/// Check if the module is halted.
|
/// Check if the module is halted.
|
||||||
fn is_halted() -> bool;
|
fn is_halted() -> bool {
|
||||||
|
Self::OperatingModeStorage::get().is_halted()
|
||||||
|
}
|
||||||
|
|
||||||
/// Ensure that the origin is either root, or `PalletOwner`.
|
/// Ensure that the origin is either root, or `PalletOwner`.
|
||||||
fn ensure_owner_or_root(origin: T::Origin) -> Result<(), BadOrigin> {
|
fn ensure_owner_or_root(origin: T::Origin) -> Result<(), BadOrigin> {
|
||||||
@@ -325,12 +354,7 @@ pub trait OwnedBridgeModule<T: frame_system::Config> {
|
|||||||
) -> DispatchResult {
|
) -> DispatchResult {
|
||||||
Self::ensure_owner_or_root(origin)?;
|
Self::ensure_owner_or_root(origin)?;
|
||||||
Self::OperatingModeStorage::put(operating_mode);
|
Self::OperatingModeStorage::put(operating_mode);
|
||||||
log::info!(
|
log::info!(target: Self::LOG_TARGET, "Setting operating mode to {:?}.", operating_mode);
|
||||||
target: Self::LOG_TARGET,
|
|
||||||
"Setting operating mode ( {} = {:?}).",
|
|
||||||
Self::OPERATING_MODE_KEY,
|
|
||||||
operating_mode
|
|
||||||
);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ use bp_header_chain::{
|
|||||||
justification::{verify_justification, GrandpaJustification},
|
justification::{verify_justification, GrandpaJustification},
|
||||||
FinalityProof,
|
FinalityProof,
|
||||||
};
|
};
|
||||||
|
use bp_runtime::{BasicOperatingMode, OperatingMode};
|
||||||
use codec::{Decode, Encode};
|
use codec::{Decode, Encode};
|
||||||
use finality_grandpa::voter_set::VoterSet;
|
use finality_grandpa::voter_set::VoterSet;
|
||||||
use num_traits::{One, Zero};
|
use num_traits::{One, Zero};
|
||||||
@@ -44,10 +45,12 @@ pub trait Engine<C: Chain>: Send {
|
|||||||
type FinalityProof: FinalityProof<BlockNumberOf<C>> + Decode + Encode;
|
type FinalityProof: FinalityProof<BlockNumberOf<C>> + Decode + Encode;
|
||||||
/// Type of bridge pallet initialization data.
|
/// Type of bridge pallet initialization data.
|
||||||
type InitializationData: std::fmt::Debug + Send + Sync + 'static;
|
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,
|
/// Returns storage key at the bridged (target) chain that corresponds to the variable
|
||||||
/// which is true when the bridge pallet is halted.
|
/// that holds the operating mode of the pallet.
|
||||||
fn is_halted_key() -> StorageKey;
|
fn pallet_operating_mode_key() -> StorageKey;
|
||||||
/// Returns storage at the bridged (target) chain that corresponds to some value that is
|
/// Returns storage at the bridged (target) chain that corresponds to some value that is
|
||||||
/// missing from the storage until bridge pallet is initialized.
|
/// 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>(
|
async fn is_halted<TargetChain: Chain>(
|
||||||
target_client: &Client<TargetChain>,
|
target_client: &Client<TargetChain>,
|
||||||
) -> Result<bool, SubstrateError> {
|
) -> 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;
|
const ID: ConsensusEngineId = sp_finality_grandpa::GRANDPA_ENGINE_ID;
|
||||||
type FinalityProof = GrandpaJustification<HeaderOf<C>>;
|
type FinalityProof = GrandpaJustification<HeaderOf<C>>;
|
||||||
type InitializationData = bp_header_chain::InitializationData<C::Header>;
|
type InitializationData = bp_header_chain::InitializationData<C::Header>;
|
||||||
|
type OperatingMode = BasicOperatingMode;
|
||||||
|
|
||||||
fn is_halted_key() -> StorageKey {
|
fn pallet_operating_mode_key() -> StorageKey {
|
||||||
bp_header_chain::storage_keys::is_halted_key(C::WITH_CHAIN_GRANDPA_PALLET_NAME)
|
bp_header_chain::storage_keys::pallet_operating_mode_key(C::WITH_CHAIN_GRANDPA_PALLET_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_initialized_key() -> StorageKey {
|
fn is_initialized_key() -> StorageKey {
|
||||||
@@ -237,7 +245,7 @@ impl<C: ChainWithGrandpa> Engine<C> for Grandpa<C> {
|
|||||||
} else {
|
} else {
|
||||||
initial_authorities_set_id
|
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 async_trait::async_trait;
|
||||||
use bp_messages::{
|
use bp_messages::{
|
||||||
storage_keys::{operating_mode_key, outbound_lane_data_key},
|
storage_keys::{operating_mode_key, outbound_lane_data_key},
|
||||||
InboundMessageDetails, LaneId, MessageData, MessageNonce, OperatingMode, OutboundLaneData,
|
InboundMessageDetails, LaneId, MessageData, MessageNonce, MessagesOperatingMode,
|
||||||
OutboundMessageDetails, UnrewardedRelayersState,
|
OutboundLaneData, OutboundMessageDetails, UnrewardedRelayersState,
|
||||||
};
|
};
|
||||||
use bp_runtime::messages::DispatchFeePayment;
|
use bp_runtime::{messages::DispatchFeePayment, BasicOperatingMode};
|
||||||
use bridge_runtime_common::messages::{
|
use bridge_runtime_common::messages::{
|
||||||
source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof,
|
source::FromBridgedChainMessagesDeliveryProof, target::FromBridgedChainMessagesProof,
|
||||||
};
|
};
|
||||||
@@ -420,7 +420,8 @@ where
|
|||||||
let operating_mode = client
|
let operating_mode = client
|
||||||
.storage_value(operating_mode_key(WithChain::WITH_CHAIN_MESSAGES_PALLET_NAME), None)
|
.storage_value(operating_mode_key(WithChain::WITH_CHAIN_MESSAGES_PALLET_NAME), None)
|
||||||
.await?;
|
.await?;
|
||||||
let is_halted = operating_mode == Some(OperatingMode::Halted);
|
let is_halted =
|
||||||
|
operating_mode == Some(MessagesOperatingMode::Basic(BasicOperatingMode::Halted));
|
||||||
if is_halted {
|
if is_halted {
|
||||||
Err(SubstrateError::BridgePalletIsHalted)
|
Err(SubstrateError::BridgePalletIsHalted)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user