topsoil_core/traits/tx_pause.rs
1// This file is part of Soil.
2
3// Copyright (C) Soil contributors.
4// Copyright (C) Parity Technologies (UK) Ltd.
5// SPDX-License-Identifier: Apache-2.0 OR GPL-3.0-or-later WITH Classpath-exception-2.0
6
7//! Types to pause calls in the runtime.
8
9/// Can pause specific transactions from being processed.
10///
11/// Note that paused transactions will not be queued for later execution. Instead they will be
12/// dropped.
13pub trait TransactionPause {
14 /// How to unambiguously identify a call.
15 ///
16 /// For example `(pallet_index, call_index)`.
17 type CallIdentifier;
18
19 /// Whether this call is paused.
20 fn is_paused(call: Self::CallIdentifier) -> bool;
21
22 /// Whether this call can be paused.
23 ///
24 /// This holds for the current block, but may change in the future.
25 fn can_pause(call: Self::CallIdentifier) -> bool;
26
27 /// Pause this call immediately.
28 ///
29 /// This takes effect in the same block and must succeed if `can_pause` returns `true`.
30 fn pause(call: Self::CallIdentifier) -> Result<(), TransactionPauseError>;
31
32 /// Unpause this call immediately.
33 ///
34 /// This takes effect in the same block and must succeed if `is_paused` returns `true`. This
35 /// invariant is important to not have un-resumable calls.
36 fn unpause(call: Self::CallIdentifier) -> Result<(), TransactionPauseError>;
37}
38
39/// The error type for [`TransactionPause`].
40pub enum TransactionPauseError {
41 /// The call could not be found in the runtime.
42 ///
43 /// This is a permanent error but could change after a runtime upgrade.
44 NotFound,
45 /// Call cannot be paused.
46 ///
47 /// This may or may not resolve in a future block.
48 Unpausable,
49 /// Call is already paused.
50 AlreadyPaused,
51 /// Call is already unpaused.
52 AlreadyUnpaused,
53 /// Unknown error.
54 Unknown,
55}