Skip to content

Commit

Permalink
mempool/mining: Implement aggregate fee sorting.
Browse files Browse the repository at this point in the history
This modifies the mining prioritization logic to sort transactions by an aggregate fee based on a transaction’s ancestors in the mempool.

This modifies the mining prioritization logic to sort transactions by an
aggregate fee based on a transaction’s ancestors in the mempool.

Currently, the mining code prioritizes transactions by fee and only
includes them in the block template if they have no dependencies.  When
a transaction is included in the block template, it is removed as a
dependency from transactions that depend on it, making those dependent
transactions eligible for block template inclusion.

Aggregating ancestor statistics for large graphs of transactions in the
mempool may have high computational costs.  Performing this aggregation
in the block template generator would delay miners requesting a block
template since all of the aggregation would need to occur for each
transaction, at once.  To solve this problem, the complexity is spread
over time such that the transaction statistics are updated with mempool
event hooks.  Since the mempool is not locked during the entirety of
template generation, a mining view interface is exposed to safely
interact with a snapshot of the mempool.

The biggest risk in terms of performance are reorgs where transactions
with many descendants are added back to the mempool.  The number of
transactions added to the mempool in this way is limited by the block
size and proof of work, but the mempool has no restrictions on the
number of ancestors tracked for a given transaction.

A potential - and not implemented - solution to this reorg problem would
be to establish a limit on the number of ancestors a transaction may
have in the mempool.
  • Loading branch information
sefbkn authored Oct 15, 2020
1 parent 00933dc commit 15c3817
Show file tree
Hide file tree
Showing 6 changed files with 1,211 additions and 175 deletions.
3 changes: 3 additions & 0 deletions blockmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2028,6 +2028,9 @@ func (b *blockManager) handleBlockchainNotification(notification *blockchain.Not
b.cfg.PeerNotifier.TransactionConfirmed(tx)
}
}

// Add regular transactions back to the mempool,
// excluding the coinbase since it does not belong in the mempool.
handleConnectedBlockTxns(block.Transactions()[1:])
if isTreasuryEnabled {
// Skip treasurybase
Expand Down
Loading

0 comments on commit 15c3817

Please sign in to comment.