From b476bc86ce602eea4269c504854fdd39e25015f5 Mon Sep 17 00:00:00 2001 From: vyzo Date: Thu, 25 Jun 2020 14:16:04 +0300 Subject: [PATCH] synchronize all miners to mine next block --- lotus-soup/baseline.go | 17 ++++++++++++----- lotus-soup/node.go | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lotus-soup/baseline.go b/lotus-soup/baseline.go index 77982a9ef..4d521b296 100644 --- a/lotus-soup/baseline.go +++ b/lotus-soup/baseline.go @@ -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 diff --git a/lotus-soup/node.go b/lotus-soup/node.go index 68ef422b4..c0dcf554e 100644 --- a/lotus-soup/node.go +++ b/lotus-soup/node.go @@ -73,6 +73,7 @@ var ( stateReady = sync.State("ready") stateDone = sync.State("done") + stateMineNext = sync.State("mine-next") stateStopMining = sync.State("stop-mining") )