reth_transaction_pool/pool/events.rs
1use crate::{traits::PropagateKind, PoolTransaction, ValidPoolTransaction};
2use alloy_primitives::{TxHash, B256};
3use std::sync::Arc;
4
5#[cfg(feature = "serde")]
6use serde::{Deserialize, Serialize};
7
8/// An event that happened to a transaction and contains its full body where possible.
9#[derive(Debug)]
10pub enum FullTransactionEvent<T: PoolTransaction> {
11 /// Transaction has been added to the pending pool.
12 Pending(TxHash),
13 /// Transaction has been added to the queued pool.
14 Queued(TxHash),
15 /// Transaction has been included in the block belonging to this hash.
16 Mined {
17 /// The hash of the mined transaction.
18 tx_hash: TxHash,
19 /// The hash of the mined block that contains the transaction.
20 block_hash: B256,
21 },
22 /// Transaction has been replaced by the transaction belonging to the hash.
23 ///
24 /// E.g. same (sender + nonce) pair
25 Replaced {
26 /// The transaction that was replaced.
27 transaction: Arc<ValidPoolTransaction<T>>,
28 /// The transaction that replaced the event subject.
29 replaced_by: TxHash,
30 },
31 /// Transaction was dropped due to configured limits.
32 Discarded(TxHash),
33 /// Transaction became invalid indefinitely.
34 Invalid(TxHash),
35 /// Transaction was propagated to peers.
36 Propagated(Arc<Vec<PropagateKind>>),
37}
38
39impl<T: PoolTransaction> Clone for FullTransactionEvent<T> {
40 fn clone(&self) -> Self {
41 match self {
42 Self::Pending(hash) => Self::Pending(*hash),
43 Self::Queued(hash) => Self::Queued(*hash),
44 Self::Mined { tx_hash, block_hash } => {
45 Self::Mined { tx_hash: *tx_hash, block_hash: *block_hash }
46 }
47 Self::Replaced { transaction, replaced_by } => {
48 Self::Replaced { transaction: Arc::clone(transaction), replaced_by: *replaced_by }
49 }
50 Self::Discarded(hash) => Self::Discarded(*hash),
51 Self::Invalid(hash) => Self::Invalid(*hash),
52 Self::Propagated(propagated) => Self::Propagated(Arc::clone(propagated)),
53 }
54 }
55}
56
57/// Various events that describe status changes of a transaction.
58#[derive(Debug, Clone, Eq, PartialEq)]
59#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
60pub enum TransactionEvent {
61 /// Transaction has been added to the pending pool.
62 Pending,
63 /// Transaction has been added to the queued pool.
64 Queued,
65 /// Transaction has been included in the block belonging to this hash.
66 Mined(B256),
67 /// Transaction has been replaced by the transaction belonging to the hash.
68 ///
69 /// E.g. same (sender + nonce) pair
70 Replaced(TxHash),
71 /// Transaction was dropped due to configured limits.
72 Discarded,
73 /// Transaction became invalid indefinitely.
74 Invalid,
75 /// Transaction was propagated to peers.
76 Propagated(Arc<Vec<PropagateKind>>),
77}
78
79impl TransactionEvent {
80 /// Returns `true` if the event is final and no more events are expected for this transaction
81 /// hash.
82 pub const fn is_final(&self) -> bool {
83 matches!(self, Self::Replaced(_) | Self::Mined(_) | Self::Discarded)
84 }
85}