avoid double BlockMiner instantiation.
This commit is contained in:
parent
120dd14979
commit
2e9e1c2330
@ -109,6 +109,7 @@ type Ensemble struct {
|
|||||||
active struct {
|
active struct {
|
||||||
fullnodes []*TestFullNode
|
fullnodes []*TestFullNode
|
||||||
miners []*TestMiner
|
miners []*TestMiner
|
||||||
|
bms map[*TestMiner]*BlockMiner
|
||||||
}
|
}
|
||||||
genesis struct {
|
genesis struct {
|
||||||
miners []genesis.Miner
|
miners []genesis.Miner
|
||||||
@ -125,6 +126,7 @@ func NewEnsemble(t *testing.T, opts ...EnsembleOpt) *Ensemble {
|
|||||||
}
|
}
|
||||||
|
|
||||||
n := &Ensemble{t: t, options: &options}
|
n := &Ensemble{t: t, options: &options}
|
||||||
|
n.active.bms = make(map[*TestMiner]*BlockMiner)
|
||||||
|
|
||||||
// add accounts from ensemble options to genesis.
|
// add accounts from ensemble options to genesis.
|
||||||
for _, acc := range options.accounts {
|
for _, acc := range options.accounts {
|
||||||
@ -597,7 +599,14 @@ func (n *Ensemble) BeginMining(blocktime time.Duration, miners ...*TestMiner) []
|
|||||||
|
|
||||||
var bms []*BlockMiner
|
var bms []*BlockMiner
|
||||||
if len(miners) == 0 {
|
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 {
|
for _, m := range miners {
|
||||||
@ -606,6 +615,8 @@ func (n *Ensemble) BeginMining(blocktime time.Duration, miners ...*TestMiner) []
|
|||||||
n.t.Cleanup(bm.Stop)
|
n.t.Cleanup(bm.Stop)
|
||||||
|
|
||||||
bms = append(bms, bm)
|
bms = append(bms, bm)
|
||||||
|
|
||||||
|
n.active.bms[m] = bm
|
||||||
}
|
}
|
||||||
|
|
||||||
return bms
|
return bms
|
||||||
|
Loading…
Reference in New Issue
Block a user