From 29bfd8abab2f4b8967315871fca2af3446a9a440 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 23 Jun 2020 19:16:06 +0200 Subject: [PATCH] Fix rance in GetBestMiningCandidate Signed-off-by: Jakub Sztandera --- api/test/mining.go | 5 ++--- miner/miner.go | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/api/test/mining.go b/api/test/mining.go index b190954501f..511aeb51aa4 100644 --- a/api/test/mining.go +++ b/api/test/mining.go @@ -133,11 +133,10 @@ func TestDealMining(t *testing.T, b APIBuilder, blocktime time.Duration, carExpo wait := make(chan int, 2) mdone := func(mined bool) { go func() { - n := 0 if mined { - n = 1 + wait <- 1 } - wait <- n + wait <- 0 }() } diff --git a/miner/miner.go b/miner/miner.go index bdeed8ac5da..cc4aa847ccc 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -215,6 +215,9 @@ type MiningBase struct { } func (m *Miner) GetBestMiningCandidate(ctx context.Context) (*MiningBase, error) { + m.lk.Lock() + defer m.lk.Unlock() + bts, err := m.api.ChainHead(ctx) if err != nil { return nil, err