mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-10-14 00:59:33 +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"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/kaspanet/kaspad/infrastructure/logger"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/constants"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/constants"
|
||||||
|
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/utils/transactionhelper"
|
"github.com/kaspanet/kaspad/domain/consensus/utils/transactionhelper"
|
||||||
@ -937,10 +939,14 @@ func (mp *mempool) ChainedCount() int {
|
|||||||
func (mp *mempool) BlockCandidateTransactions() []*consensusexternalapi.DomainTransaction {
|
func (mp *mempool) BlockCandidateTransactions() []*consensusexternalapi.DomainTransaction {
|
||||||
mp.mtx.RLock()
|
mp.mtx.RLock()
|
||||||
defer mp.mtx.RUnlock()
|
defer mp.mtx.RUnlock()
|
||||||
|
|
||||||
|
onEnd := logger.LogAndMeasureExecutionTime(log, "BlockCandidateTransactions")
|
||||||
|
defer onEnd()
|
||||||
|
|
||||||
descs := make([]*consensusexternalapi.DomainTransaction, len(mp.pool))
|
descs := make([]*consensusexternalapi.DomainTransaction, len(mp.pool))
|
||||||
i := 0
|
i := 0
|
||||||
for _, desc := range mp.pool {
|
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++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user