multi: Update ProcessOrphans to use AgendaFlags.

This updates the mempool ProcessOrphans method to accept agenda flags
rather than just a boolean indicating if the treasury is active.

This allows for accommodating future agendas without having to add
additional boolean fields for each agenda.
This commit is contained in:
Ryan Staudt 2021-07-27 13:13:23 -05:00 committed by Dave Collins
parent c2e6094447
commit 87128cd43f
2 changed files with 16 additions and 6 deletions

View File

@ -1808,9 +1808,12 @@ func (mp *TxPool) MaybeAcceptTransaction(tx *dcrutil.Tx, isNew, rateLimit bool)
// ProcessOrphans. See the comment for ProcessOrphans for more details.
//
// This function MUST be called with the mempool lock held (for writes).
func (mp *TxPool) processOrphans(acceptedTx *dcrutil.Tx, isTreasuryEnabled bool) []*dcrutil.Tx {
func (mp *TxPool) processOrphans(acceptedTx *dcrutil.Tx, checkTxFlags blockchain.AgendaFlags) []*dcrutil.Tx {
var acceptedTxns []*dcrutil.Tx
// Determine active agendas based on flags.
isTreasuryEnabled := checkTxFlags.IsTreasuryEnabled()
// Start with processing at least the passed transaction.
processList := []*dcrutil.Tx{acceptedTx}
for len(processList) > 0 {
@ -2005,9 +2008,9 @@ func (mp *TxPool) PruneExpiredTx() {
// no transactions were moved from the orphan pool to the mempool.
//
// This function is safe for concurrent access.
func (mp *TxPool) ProcessOrphans(acceptedTx *dcrutil.Tx, isTreasuryEnabled bool) []*dcrutil.Tx {
func (mp *TxPool) ProcessOrphans(acceptedTx *dcrutil.Tx, checkTxFlags blockchain.AgendaFlags) []*dcrutil.Tx {
mp.mtx.Lock()
acceptedTxns := mp.processOrphans(acceptedTx, isTreasuryEnabled)
acceptedTxns := mp.processOrphans(acceptedTx, checkTxFlags)
mp.mtx.Unlock()
return acceptedTxns
}
@ -2029,6 +2032,13 @@ func (mp *TxPool) ProcessTransaction(tx *dcrutil.Tx, allowOrphan, rateLimit, all
return nil, err
}
// Create agenda flags for checking transactions based on which ones are
// active.
checkTxFlags := blockchain.AFNone
if isTreasuryEnabled {
checkTxFlags |= blockchain.AFTreasuryEnabled
}
// Protect concurrent access.
mp.mtx.Lock()
defer mp.mtx.Unlock()
@ -2052,7 +2062,7 @@ func (mp *TxPool) ProcessTransaction(tx *dcrutil.Tx, allowOrphan, rateLimit, all
// transaction (they may no longer be orphans if all inputs
// are now available) and repeat for those accepted
// transactions until there are no more.
newTxs := mp.processOrphans(tx, isTreasuryEnabled)
newTxs := mp.processOrphans(tx, checkTxFlags)
acceptedTxs := make([]*dcrutil.Tx, len(newTxs)+1)
// Add the parent transaction first so remote nodes

View File

@ -2614,7 +2614,7 @@ func (s *server) handleBlockchainNotification(notification *blockchain.Notificat
txMemPool.MaybeAcceptDependents(tx, isTreasuryEnabled)
txMemPool.RemoveDoubleSpends(tx, isTreasuryEnabled)
txMemPool.RemoveOrphan(tx, isTreasuryEnabled)
acceptedTxs := txMemPool.ProcessOrphans(tx, isTreasuryEnabled)
acceptedTxs := txMemPool.ProcessOrphans(tx, ntfn.CheckTxFlags)
s.AnnounceNewTransactions(acceptedTxs)
// Now that this block is in the blockchain, mark the
@ -2739,7 +2739,7 @@ func (s *server) handleBlockchainNotification(notification *blockchain.Notificat
txMemPool.MaybeAcceptDependents(tx, isTreasuryEnabled)
txMemPool.RemoveDoubleSpends(tx, isTreasuryEnabled)
txMemPool.RemoveOrphan(tx, isTreasuryEnabled)
txMemPool.ProcessOrphans(tx, isTreasuryEnabled)
txMemPool.ProcessOrphans(tx, ntfn.CheckTxFlags)
}
}