Crates.io | fuel-txpool |
lib.rs | fuel-txpool |
version | 0.15.3 |
source | src |
created_at | 2022-02-04 20:08:02.803335 |
updated_at | 2023-01-17 22:48:44.237921 |
description | Transaction pool |
homepage | https://fuel.network/ |
repository | https://github.com/FuelLabs/fuel-core |
max_upload_size | |
id | 527049 |
size | 122,683 |
It contain list of transaction sorted by GasPrice, prepared to be included into new block. So when talking about gas it is important to make distinction between:
Fuel as UTXO system depends on output and input of transaction and proving that child is valid and depends on some parent in transaction can be challenging. All transactions in pool are expected to be in some sense valid or better said has potential to be includable. This plays a big role on protection against spamming and on design of fuel txpool. We are building dependency structures that would describe those parent->child relationships.
From miro diagram we can see that txpool is used by:
All Tx should be wrapped inside Arc so that we can easily move them if there is need and so that they can be referenced in multiple places.
TxPool should be periodically flush to disk so that we can recover transactions is case of client restart. Omitted for first version.
TxPoolDb trait is interface that TxPool is going to implement and can be found here
We will need to have at least three structures that do sorting of tx.
BinaryHeap
for fast sorting/inserting but it does have some downsides when we want to remove one item. For use case when a lot of tx are going to be removed we can just recreate structure from scratch. For first interaction we can use simple BTreeMap
that sorts all inputs.Few reasonings on decision and restrains made by txpool
Visualization of dependencies between three transactions:
Problem 1: T2 arriving before T1.
Solution: Have restriction that broadcast of hashes need to contain ancestor hashes and they all need to be sorted by gasPrice
Problem 2: if T2 gas price is higher then T1. This can be problematic on txpool with different sizes. One big enough pull could contains T1 but other one would prune it and we could not prove that T2 can be included without T1.
Solution: Have restriction on linked transaction within same block so that GasPrice is strictly going down. This will effect newly create contract (created in same block) but not old one.
Usage: Insertion of new T4
Graph will be needed for relationship between dependable transactions so that if one of them get included/removed/replaced we need to know what to do with their dependent children.
We will need map of all outputs in same structure so that we can fast search them. That would be something like HashMap<UtxoId, CoinState>
and HashMap<ContractId,ContractState>
for both Coin and Contract state.
It is most straightforward one: take PriceSort and iterate over transactions. DependencyGraph inclusion guarantees us that every transaction in the sorted array can be included, but only after executing those transactions we can be sure that is can be included in the block.
Some things and ideas what we can add in future:
gas_limit*gas_price
for transactions with depth one (Tx where all inputs can be found in db).