ancestors
:std::set
ofuint256
descendants
:std::set
ofuint256
nSize
:CAmount
txFee
:uint64_t
If the transaction does not have any parents:
- Create a new
mapMemPoolTxs
entry with 0 ancestors and 0 descendants. - Record fee statistics using the tx ancestorScore (which will basically be the same as the tx fee rate).
If the transaction has parent(s) (Use the m_has_no_mempool_parents
boolean to decides that):
- Create a new
mapMemPoolTxs
entry for the transaction. - Get the input txIds.
- For each input (parent of the transaction), find their iterator in
mapMemPoolTxs
. - If the iterator exist:
- Add the transaction as a descendant of the each parents.
- Add the each parents as the ancestor of the transaction.
- Add the transaction as a descendant to any of the parents' ancestors if they exist.
- Add each of the parents ancestors as the transaction ancestors if they exist.
- Assign the
nSize
fee andtxFee
.
- Descendants are set to 0.
NB: Ancestors of the new transaction are the transaction's parents' ancestors plus the parents themselves.
- Record the transaction in the fee stats using the transaction's ancestorScore.
3. When we Receive a notification that a Transaction is removed from mempool for any reason other than block
Get the mapMemPoolTxs
entry of the transaction.
- Remove the transaction from the fee stats (using the transaction's ancestorScore) and count it as a failure.
- For all the ancestors of the transaction:
- Remove the transaction from their list of descendants.
- For all the descendants of the transaction:
- Remove each descendant from the fee stats (using the ancestorScore) without counting as a failure.
- Clear them from
mapMemPoolTxs
.
Iterate through the vector of the transactions from the end so that children come first before ancestors.
Get the mapMemPoolTxs entry of the transaction.
If the transaction has descendant(s):
- For all descendant(s) of the transaction:
- Remove the transaction from their ancestor list.
- Update the fee stats of each descendant to track the new ancestorScore.
If the transaction has ancestor(s) and its a CPFP[0]:
Record the fee stats of the transaction as a success with the ancestorScore.
For all the transaction's ancestors:
- Remove them from the fee stats without counting as a failure. (We should continue here, as the CPFP is what we will consider for our fee estimate. The child transaction incentivizes the inclusion of all the ancestors, so there's no need to account them in fee estimation. Recording the child transaction as a success should be sufficient).
- For all the descendants of each ancestor:
- Remove the ancestor from the descendant's ancestor list.
- Update the fee stats to be tracking the new ancestorScore of the descendant.
If the transaction has ancestor(s) and its not CPFP[0]:
-
Update the fee stats of the transaction to it’s actual fee rate not ancestorScore.
-
Record the fee stats of the transaction as a success with the transaction actual fee rate.
-
For all the transaction's ancestors:
- Remove the transaction as a descendant
Note: AncestorScore will be calculated as CFeerate(sum of ancestors' txFee and the transaction's txFee, sum of the ancestors' nSize and the transaction's nSize).
[0]- We detect whether a transaction is a CPFP or not by checking if it's ancestor score is greater than its individual fee rate, then it sponsor all its ancestors to be confirmed in the new block