From 87128cd43f80feb4331161a187bcb3a91b5df29b Mon Sep 17 00:00:00 2001 From: Ryan Staudt Date: Tue, 27 Jul 2021 13:13:23 -0500 Subject: [PATCH] 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. --- internal/mempool/mempool.go | 18 ++++++++++++++---- server.go | 4 ++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/internal/mempool/mempool.go b/internal/mempool/mempool.go index c7291d33..b8be2480 100644 --- a/internal/mempool/mempool.go +++ b/internal/mempool/mempool.go @@ -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 diff --git a/server.go b/server.go index 895ab085..34602af6 100644 --- a/server.go +++ b/server.go @@ -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) } }