soil_client/transaction_pool/
error.rs1use subsoil::runtime::transaction_validity::{
10 InvalidTransaction, TransactionPriority as Priority, UnknownTransaction,
11};
12
13pub type Result<T> = std::result::Result<T, Error>;
15
16#[derive(Debug, thiserror::Error, strum::AsRefStr)]
18#[allow(missing_docs)]
19pub enum Error {
20 #[error("Unknown transaction validity: {0:?}")]
21 UnknownTransaction(UnknownTransaction),
22
23 #[error("Invalid transaction validity: {0:?}")]
24 InvalidTransaction(InvalidTransaction),
25
26 #[error("Transaction does not provide any tags, so the pool can't identify it")]
31 NoTagsProvided,
32
33 #[error("Transaction temporarily Banned")]
34 TemporarilyBanned,
35
36 #[error("[{0:?}] Already imported")]
37 AlreadyImported(Box<dyn std::any::Any + Send + Sync>),
38
39 #[error("Too low priority ({} > {})", old, new)]
40 TooLowPriority {
41 old: Priority,
43 new: Priority,
45 },
46 #[error("Transaction with cyclic dependency")]
47 CycleDetected,
48
49 #[error("Transaction couldn't enter the pool because of the limit")]
50 ImmediatelyDropped,
51
52 #[error("Transaction cannot be propagated and the local node does not author blocks")]
53 Unactionable,
54
55 #[error("{0}")]
56 InvalidBlockId(String),
57
58 #[error("The pool is not accepting future transactions")]
59 RejectedFutureTransaction,
60}
61
62impl Error {
63 pub fn is_retriable(&self) -> bool {
68 match self {
69 Error::TemporarilyBanned |
72 Error::ImmediatelyDropped |
74 Error::InvalidBlockId(_) |
77 Error::RejectedFutureTransaction => {
79 true
80 }
81 _ => false
82 }
83 }
84}
85
86pub trait IntoPoolError: std::error::Error + Send + Sized + Sync {
88 fn into_pool_error(self) -> std::result::Result<Error, Self> {
94 Err(self)
95 }
96}
97
98impl IntoPoolError for Error {
99 fn into_pool_error(self) -> std::result::Result<Error, Self> {
100 Ok(self)
101 }
102}
103
104pub trait IntoMetricsLabel {
106 fn label(&self) -> String;
112}
113
114impl IntoMetricsLabel for Error {
115 fn label(&self) -> String {
116 self.as_ref().to_string()
117 }
118}