fuel_core_txpool/lib.rs
1//! This crate manages the verification, storage, organization and selection of the transactions for the network.
2//! A transaction in Fuel has inputs and outputs. Inputs are outputs of previous transactions.
3//! In a case where one of the input is an output of a transaction that has not been executed in a committed block (transaction still in the pool),
4//! then the new transaction is considered dependent on that transaction.
5//!
6//! If a transaction has a dependency, it cannot be selected in a block until the dependent transaction has been selected.
7//! A transaction can have a dependency per input and this dependency transaction can also have its own dependencies.
8//! This creates a dependency tree between transactions inside the pool which can be very costly to compute for insertion/deletion etc...
9//! In order to avoid too much cost, the transaction pool only allow a maximum number of transaction inside a dependency chain.
10//! There is others limits on the pool that prevent its size to grow too much: maximum gas in the pool, maximum bytes in the pool, maximum number of transactions in the pool.
11//! The pool also implements a TTL for the transactions, if a transaction is not selected in a block after a certain time, it is removed from the pool.
12//!
13//! All the transactions ordered by their ratio of gas/tip to be selected in a block.
14//! It's possible that a transaction is not profitable enough to be selected for now and so either it will be selected later or it will be removed from the pool.
15//! In order to make a transaction more likely to be selected, it's needed to submit a new colliding transaction (see below) with a higher tip/gas ratio.
16//!
17//! When a transaction is inserted it's possible that it use same inputs as one or multiple transactions already in the pool: this is what we call a collision.
18//! The pool has to choose which transaction to keep and which to remove.
19//! The pool will always try to maximize the number of transactions that can be selected in the next block and so
20//! during collision resolution it will prioritize transactions without dependencies.
21//! In a collision case, the transaction is considered a conflict and can be inserted under certain conditions :
22//! - The transaction has dependencies:
23//! - Can collide only with one other transaction. So, the user can submit
24//! the same transaction with a higher tip but not merge one or more
25//! transactions into one.
26//! - A new transaction can be accepted if its profitability is higher than
27//! the cumulative profitability of the colliding transactions, and all
28//! the transactions that depend on it.
29//! - A transaction doesn't have dependencies:
30//! - A new transaction can be accepted if its profitability is higher
31//! than the collided subtrees'.
32//!
33//! The pool provides a way to subscribe for updates on a transaction status.
34//! It usually stream one or two messages:
35//! - If the insertion of the transaction fails, you can expect only one message with the error.
36//! - If the transaction is inserted, you can expect two messages: one with the validation of the insertion and one when the transaction is selected in a block.
37
38// TODO: Rename the folder from `txpool_v2` to `txpool` after the migration is complete.
39#![deny(clippy::arithmetic_side_effects)]
40#![deny(clippy::cast_possible_truncation)]
41#![deny(unused_crate_dependencies)]
42#![deny(warnings)]
43
44mod collision_manager;
45pub mod config;
46pub mod error;
47mod extracted_outputs;
48mod pending_pool;
49mod pool;
50mod pool_worker;
51pub mod ports;
52mod selection_algorithms;
53mod service;
54mod shared_state;
55mod storage;
56
57pub type GasPrice = Word;
58
59mod spent_inputs;
60#[cfg(test)]
61mod tests;
62#[cfg(test)]
63fuel_core_trace::enable_tracing!();
64
65use fuel_core_types::fuel_asm::Word;
66pub use pool::TxPoolStats;
67pub use selection_algorithms::Constraints;
68pub use service::{
69 Service,
70 new_service,
71};
72pub use shared_state::SharedState;