[NOD-613] Fix concurrent access to ecmh cache (#565)

* [NOD-613] Fix concurrent access to ecmh cache.

* [NOD-613] Localized dag.Lock().
This commit is contained in:
stasatdaglabs 2020-01-02 18:03:25 +02:00 committed by Ori Newman
parent d984151549
commit e41d9866c3

View File

@ -377,10 +377,14 @@ func (g *BlkTmplGenerator) UpdateExtraNonce(msgBlock *wire.MsgBlock, extraNonce
hashMerkleTree := blockdag.BuildHashMerkleTreeStore(block.Transactions())
msgBlock.Header.HashMerkleRoot = hashMerkleTree.Root()
utxoCommitment, err := g.buildUTXOCommitment(msgBlock.Transactions)
if err != nil {
return err
}
// buildUTXOCommitment is the only function in UpdateExtraNonce that
// requires the dagLock, and as such we lock and unlock it locally.
utxoCommitment, err := func() (*daghash.Hash, error) {
g.dag.Lock()
defer g.dag.Unlock()
return g.buildUTXOCommitment(msgBlock.Transactions)
}()
msgBlock.Header.UTXOCommitment = utxoCommitment