Clone transactions before returning them out of mempool (#1571)

Co-authored-by: Elichai Turkel <elichai.turkel@gmail.com>
This commit is contained in:
Svarog 2021-03-02 17:28:53 +02:00 committed by GitHub
parent 05df6e3e4e
commit 32cd643e8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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++
}