synchronize all miners to mine next block

This commit is contained in:
vyzo 2020-06-25 14:16:04 +03:00
parent 58923fe2ff
commit b476bc86ce
2 changed files with 13 additions and 5 deletions

View File

@ -67,26 +67,33 @@ func runBaselineMiner(t *TestEnvironment) error {
return err
}
clients := t.IntParam("clients")
miners := t.IntParam("miners")
// mine / stop mining
mine := true
done := make(chan struct{})
go func() {
defer close(done)
for mine {
time.Sleep(100 * time.Millisecond)
//t.RecordMessage("mine one block")
// synchronize all miners to mine the next block
t.RecordMessage("synchronizing all miners to mine next block")
t.SyncClient.MustSignalAndWait(context.Background(), stateMineNext, miners)
time.Sleep(time.Duration(rand.Intn(int(100 * time.Millisecond))))
// wait and synchronise
if err := miner.MineOne(context.TODO(), func(bool) {
err := miner.MineOne(context.TODO(), func(bool) {
// after a block is mined
}); err != nil {
})
if err != nil {
panic(err)
}
}
}()
// wait for a signal from all clients to stop mining
clients := t.IntParam("clients")
err = <-t.SyncClient.MustBarrier(context.Background(), stateStopMining, clients).C
if err != nil {
return err

View File

@ -73,6 +73,7 @@ var (
stateReady = sync.State("ready")
stateDone = sync.State("done")
stateMineNext = sync.State("mine-next")
stateStopMining = sync.State("stop-mining")
)