Skip to content

mempool: Use blockchain for tx expiry check. #1199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1322,27 +1322,31 @@ func (mp *TxPool) pruneStakeTx(requiredStakeDifficulty, height int64) {
}
}

// pruneExpiredTx prunes expired transactions from the mempool that may no longer
// be able to be included into a block.
//
// This function MUST be called with the mempool lock held (for writes).
func (mp *TxPool) pruneExpiredTx(height int64) {
for _, tx := range mp.pool {
if blockchain.IsExpired(tx.Tx, height) {
log.Debugf("Pruning expired transaction %v from the mempool",
tx.Tx.Hash())
mp.removeTransaction(tx.Tx, true)
}
}
}

// PruneExpiredTx prunes expired transactions from the mempool that may no longer
// be able to be included into a block.
//
// This function is safe for concurrent access.
func (mp *TxPool) PruneExpiredTx(height int64) {
// Protect concurrent access.
mp.mtx.Lock()
mp.pruneExpiredTx(height)
mp.mtx.Unlock()
}

func (mp *TxPool) pruneExpiredTx(height int64) {
for _, tx := range mp.pool {
if tx.Tx.MsgTx().Expiry != 0 {
if height >= int64(tx.Tx.MsgTx().Expiry) {
log.Debugf("Pruning expired transaction %v "+
"from the mempool", tx.Tx.Hash())
mp.removeTransaction(tx.Tx, true)
}
}
}
}

// ProcessOrphans determines if there are any orphans which depend on the passed
// transaction hash (it is possible that they are no longer orphans) and
// potentially accepts them to the memory pool. It repeats the process for the
Expand Down