A priority mempool that orders transactions by fee. this mempool is useful to prioritize transactions of higher fee and hence deliver higher transction commits.
this priority mempool,
- reads transactions from a file, stores them ordered by lowest transaction fee* to highest
- drops lowest priority trnsaction once the mempool capacity is full
* transaction fee = Gas * FeePerGas
example transaction format,
TxHash=0x54030E30503453949230403 Gas=300000 FeePerGas=0.001 Signature=0x54030E30503453949230403
example of mempool with capacity 3: input:
TxHash=4 Gas=6 FeePerGas=0.001 Signature=jkl
TxHash=2 Gas=4 FeePerGas=0.001 Signature=def
TxHash=1 Gas=3 FeePerGas=0.001 Signature=abc
TxHash=3 Gas=5 FeePerGas=0.001 Signature=ghi
output:
TxHash=2 Gas=4 FeePerGas=0.001 Signature=def
TxHash=3 Gas=5 FeePerGas=0.001 Signature=ghi
TxHash=4 Gas=6 FeePerGas=0.001 Signature=jkl
In this example,
- transactions are orders by fee
- the transaction with TxHash
1gets dropped with the lowest fee
- golang version 1.17 or higher
run
go build
run
go test ./...
run
./kava-mempool
the executable by default,
- builds mempool of capacity 5000
- reads transactions from
./transactions.txtand writes prioritized transactions to./prioritized-transactions.txt
Running the command when the output file already exists, appends the output to existing contents of the file. HINT: try removing the output file.
file IO is stateful. i.e, each instance of IO reads/writes only one transaction at a time and tracks the point till which the transaction is read/written and resumes reading/ writing transactions from that point.
The transaction processing is time sensitive and needs to be processsed as soon as it is made available
do not read the whole file at once
- This helps adding transactions into mempool as it arrives at the node
- This generic interface implementation can be swapped for other source of transactions. ex: network
- disk io is not efficient
- File object is stateful. The outcome of the input utility is not idempotent
- Its Cleanup is decoupled from the initialization code
- add Makefile for build and test steps
- process HIGHEST priority transaction first. i.e, order transactions by highest transaction fee to lowest transaction fee
- create sub packages for different concerns in order to improve readability and maintainability. ex: processor, io
- move private members of the package to internal package
- accept mempool capacity, input and output files as command line arguments