mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-11 08:36:43 +00:00
Clone transactions before returning them out of mempool (#1571)
Co-authored-by: Elichai Turkel <elichai.turkel@gmail.com>
This commit is contained in:
parent
05df6e3e4e
commit
32cd643e8b
@ -11,6 +11,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/kaspanet/kaspad/infrastructure/logger"
|
||||
|
||||
"github.com/kaspanet/kaspad/domain/consensus/utils/constants"
|
||||
|
||||
"github.com/kaspanet/kaspad/domain/consensus/utils/transactionhelper"
|
||||
@ -937,10 +939,14 @@ func (mp *mempool) ChainedCount() int {
|
||||
func (mp *mempool) BlockCandidateTransactions() []*consensusexternalapi.DomainTransaction {
|
||||
mp.mtx.RLock()
|
||||
defer mp.mtx.RUnlock()
|
||||
|
||||
onEnd := logger.LogAndMeasureExecutionTime(log, "BlockCandidateTransactions")
|
||||
defer onEnd()
|
||||
|
||||
descs := make([]*consensusexternalapi.DomainTransaction, len(mp.pool))
|
||||
i := 0
|
||||
for _, desc := range mp.pool {
|
||||
descs[i] = desc.DomainTransaction
|
||||
descs[i] = desc.DomainTransaction.Clone() // Clone the transaction to prevent data races. A shallow-copy might do as well
|
||||
i++
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user