fix miner synchronization

This commit is contained in:
vyzo 2020-06-26 17:27:10 +03:00
parent 119defc5e7
commit f7af27f1d2
2 changed files with 6 additions and 3 deletions

View File

@ -2,8 +2,11 @@ package main
import ( import (
"context" "context"
"fmt"
"math/rand" "math/rand"
"time" "time"
"github.com/testground/sdk-go/sync"
) )
func runBootstrapper(t *TestEnvironment) error { func runBootstrapper(t *TestEnvironment) error {
@ -35,10 +38,11 @@ func runMiner(t *TestEnvironment) error {
done := make(chan struct{}) done := make(chan struct{})
go func() { go func() {
defer close(done) defer close(done)
for mine { for i := 0; mine; i++ {
// synchronize all miners to mine the next block // synchronize all miners to mine the next block
t.RecordMessage("synchronizing all miners to mine next block") t.RecordMessage("synchronizing all miners to mine next block [%d]", i)
stateMineNext := sync.State(fmt.Sprintf("mine-block-%d", i))
t.SyncClient.MustSignalAndWait(ctx, stateMineNext, miners) t.SyncClient.MustSignalAndWait(ctx, stateMineNext, miners)
// add some random delay to encourage a different miner winning each round // add some random delay to encourage a different miner winning each round

View File

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