Txpool
Code is here
The following are the interfaces of the core functions. Developers can customize their own trading pools if required.
func BaseCheck(*SignedTxn) error
func TripodsCheck(stxn *SignedTxn) error
func NecessaryCheck(stxn *SignedTxn) error
BaseCheck()
: when inserts transaction data into the transaction pool, it will do some basic checks. The basic checks are: whether the transaction data is too large, whether the transaction pool capacity has reached the upper limit, whether the signature in the transaction is legal, whether there is
Transactions are repeated. The first three will return an error if the check fails. When the transaction is repeated, the message will be ignored but no error will be returned.
TripodsCheck()
: After the basic check of TripodsChecks
, the tripods check will be performed, which is the transaction check rule defined by the developer.
NecessaryCheck()
represents a necessity check, which only checks whether the transaction data is too large, whether the signature is valid, and the tripods check. After the node receives the block from the P2P network, the synchronization
Check the transaction data in the block, and directly store it in txdb
after checking.
func Insert(txn *SignedTxn) error
Insert()
means inserting transaction data into the transaction pool. This function has two types of checks, BaseCheck
and TripodsCheck
. Only after passing the check will it be inserted into the transaction pool, otherwise an error will be returned.
func Pack(numLimit uint64) ([]*SignedTxn, error)
func PackFor(numLimit uint64, filter func(*SignedTxn) error) ([]*SignedTxn, error)
Pack(numLimit)
means to pack a maximum of numLimit
transactions from the transaction pool. The packaged transactions will be marked, but will not be deleted from the transaction pool immediately.
PackFor(numLimit, filter)
has one more filter function than Pack
. All packed transactions must pass the filter of filter
. If filter
returns an error, the transaction will not be packed.
func GetTxn(hash Hash) (*SignedTxn, error)
func Reset(*Block) error
GetTxn(hash)
gets transaction data according to the transaction hash value
Reset(*Block)
clears the transactions in the given block from the transaction pool as they are already packed.