Allow Substrate Pallet to be Halted (#485)

* Copy-Pasta owner and freezing code from `message-lane`

* Halt pallet if bridge hasn't been initialized

* Make owner optional in `message-lane` pallet

* Add `is_halted` to `InitializationData`

* Fix initialization tests

* Only allow pallet to be initialized once

* Add some logging around halting and ownership changes

* Remove `target` in debugging calls
This commit is contained in:
Hernando Castano
2020-11-09 16:43:22 -05:00
committed by Bastian Köcher
parent 6c0110c11e
commit 3f7655a056
6 changed files with 223 additions and 52 deletions
+17 -13
View File
@@ -148,7 +148,7 @@ decl_storage! {
/// `None`, then there are no direct ways to halt/resume pallet operations, but other
/// runtime methods may still be used to do that (i.e. democracy::referendum to update halt
/// flag directly or call the `halt_operations`).
pub ModuleOwner get(fn module_owner) config(): Option<T::AccountId>;
pub ModuleOwner get(fn module_owner): Option<T::AccountId>;
/// If true, all pallet transactions are failed immediately.
pub IsHalted get(fn is_halted) config(): bool;
/// Map of lane id => inbound lane data.
@@ -160,6 +160,12 @@ decl_storage! {
}
add_extra_genesis {
config(phantom): sp_std::marker::PhantomData<I>;
config(owner): Option<T::AccountId>;
build(|config| {
if let Some(ref owner) = config.owner {
<ModuleOwner<T, I>>::put(owner);
}
})
}
}
@@ -188,8 +194,14 @@ decl_module! {
pub fn set_owner(origin, new_owner: Option<T::AccountId>) {
ensure_owner_or_root::<T, I>(origin)?;
match new_owner {
Some(new_owner) => ModuleOwner::<T, I>::put(new_owner),
None => ModuleOwner::<T, I>::kill(),
Some(new_owner) => {
ModuleOwner::<T, I>::put(&new_owner);
frame_support::debug::info!("Setting pallet Owner to: {:?}", new_owner);
},
None => {
ModuleOwner::<T, I>::kill();
frame_support::debug::info!("Removed Owner of pallet.");
},
}
}
@@ -200,6 +212,7 @@ decl_module! {
pub fn halt_operations(origin) {
ensure_owner_or_root::<T, I>(origin)?;
IsHalted::<I>::put(true);
frame_support::debug::warn!("Stopping pallet operations.");
}
/// Resume all pallet operations. May be called even if pallet is halted.
@@ -209,6 +222,7 @@ decl_module! {
pub fn resume_operations(origin) {
ensure_owner_or_root::<T, I>(origin)?;
IsHalted::<I>::put(false);
frame_support::debug::info!("Resuming pallet operations.");
}
/// Send message over lane.
@@ -225,7 +239,6 @@ decl_module! {
// let's first check if message can be delivered to target chain
T::TargetHeaderChain::verify_message(&payload).map_err(|err| {
frame_support::debug::trace!(
target: "runtime",
"Message to lane {:?} is rejected by target chain: {:?}",
lane_id,
err,
@@ -242,7 +255,6 @@ decl_module! {
&payload,
).map_err(|err| {
frame_support::debug::trace!(
target: "runtime",
"Message to lane {:?} is rejected by lane verifier: {:?}",
lane_id,
err,
@@ -257,7 +269,6 @@ decl_module! {
&delivery_and_dispatch_fee,
).map_err(|err| {
frame_support::debug::trace!(
target: "runtime",
"Message to lane {:?} is rejected because submitter {:?} is unable to pay fee {:?}: {:?}",
lane_id,
submitter,
@@ -277,7 +288,6 @@ decl_module! {
lane.prune_messages(T::MaxMessagesToPruneAtOnce::get());
frame_support::debug::trace!(
target: "runtime",
"Accepted message {} to lane {:?}",
nonce,
lane_id,
@@ -303,7 +313,6 @@ decl_module! {
let messages = verify_and_decode_messages_proof::<T::SourceHeaderChain, T::InboundMessageFee, T::InboundPayload>(proof)
.map_err(|err| {
frame_support::debug::trace!(
target: "runtime",
"Rejecting invalid messages proof: {:?}",
err,
);
@@ -323,7 +332,6 @@ decl_module! {
.sum();
if dispatch_weight < actual_dispatch_weight {
frame_support::debug::trace!(
target: "runtime",
"Rejecting messages proof because of dispatch weight mismatch: declared={}, expected={}",
dispatch_weight,
actual_dispatch_weight,
@@ -342,7 +350,6 @@ decl_module! {
let updated_latest_confirmed_nonce = lane.receive_state_update(lane_state);
if let Some(updated_latest_confirmed_nonce) = updated_latest_confirmed_nonce {
frame_support::debug::trace!(
target: "runtime",
"Received lane {:?} state update: latest_confirmed_nonce={}",
lane_id,
updated_latest_confirmed_nonce,
@@ -361,7 +368,6 @@ decl_module! {
}
frame_support::debug::trace!(
target: "runtime",
"Received messages: total={}, valid={}",
total_messages,
valid_messages,
@@ -378,7 +384,6 @@ decl_module! {
let confirmation_relayer = ensure_signed(origin)?;
let (lane_id, lane_data) = T::TargetHeaderChain::verify_messages_delivery_proof(proof).map_err(|err| {
frame_support::debug::trace!(
target: "runtime",
"Rejecting invalid messages delivery proof: {:?}",
err,
);
@@ -414,7 +419,6 @@ decl_module! {
}
frame_support::debug::trace!(
target: "runtime",
"Received messages delivery proof up to (and including) {} at lane {:?}",
lane_data.latest_received_nonce,
lane_id,