From 2e9e1c2330b9dcb3eca7fdd6682aab6a8db98176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= Date: Tue, 22 Jun 2021 18:15:38 +0100 Subject: [PATCH] avoid double BlockMiner instantiation. --- itests/kit/ensemble.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/itests/kit/ensemble.go b/itests/kit/ensemble.go index 2e04c37c8..788aa40c0 100644 --- a/itests/kit/ensemble.go +++ b/itests/kit/ensemble.go @@ -109,6 +109,7 @@ type Ensemble struct { active struct { fullnodes []*TestFullNode miners []*TestMiner + bms map[*TestMiner]*BlockMiner } genesis struct { miners []genesis.Miner @@ -125,6 +126,7 @@ func NewEnsemble(t *testing.T, opts ...EnsembleOpt) *Ensemble { } n := &Ensemble{t: t, options: &options} + n.active.bms = make(map[*TestMiner]*BlockMiner) // add accounts from ensemble options to genesis. for _, acc := range options.accounts { @@ -597,7 +599,14 @@ func (n *Ensemble) BeginMining(blocktime time.Duration, miners ...*TestMiner) [] var bms []*BlockMiner if len(miners) == 0 { - miners = n.active.miners + // no miners have been provided explicitly, instantiate block miners + // for all active miners that aren't still mining. + for _, m := range n.active.miners { + if _, ok := n.active.bms[m]; ok { + continue // skip, already have a block miner + } + miners = append(miners, m) + } } for _, m := range miners { @@ -606,6 +615,8 @@ func (n *Ensemble) BeginMining(blocktime time.Duration, miners ...*TestMiner) [] n.t.Cleanup(bm.Stop) bms = append(bms, bm) + + n.active.bms[m] = bm } return bms