fix miner synchronization
This commit is contained in:
parent
119defc5e7
commit
f7af27f1d2
@ -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
|
||||||
|
@ -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")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user