From f7af27f1d2e34d690ef7025bd07f3987e032941f Mon Sep 17 00:00:00 2001 From: vyzo Date: Fri, 26 Jun 2020 17:27:10 +0300 Subject: [PATCH 1/3] fix miner synchronization --- lotus-soup/common_roles.go | 8 ++++++-- lotus-soup/node.go | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lotus-soup/common_roles.go b/lotus-soup/common_roles.go index 20e0aa67d..423ab818d 100644 --- a/lotus-soup/common_roles.go +++ b/lotus-soup/common_roles.go @@ -2,8 +2,11 @@ package main import ( "context" + "fmt" "math/rand" "time" + + "github.com/testground/sdk-go/sync" ) func runBootstrapper(t *TestEnvironment) error { @@ -35,10 +38,11 @@ func runMiner(t *TestEnvironment) error { done := make(chan struct{}) go func() { defer close(done) - for mine { + for i := 0; mine; i++ { // 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) // add some random delay to encourage a different miner winning each round diff --git a/lotus-soup/node.go b/lotus-soup/node.go index 8a04b6775..4665a6110 100644 --- a/lotus-soup/node.go +++ b/lotus-soup/node.go @@ -75,7 +75,6 @@ var ( stateReady = sync.State("ready") stateDone = sync.State("done") - stateMineNext = sync.State("mine-next") stateStopMining = sync.State("stop-mining") ) From 3d5f58c8b8510a4455cda24a05637c1fedf74746 Mon Sep 17 00:00:00 2001 From: vyzo Date: Fri, 26 Jun 2020 17:30:44 +0300 Subject: [PATCH 2/3] sort preseals by miner GroupSeq --- lotus-soup/node.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lotus-soup/node.go b/lotus-soup/node.go index 4665a6110..6bdd30ebc 100644 --- a/lotus-soup/node.go +++ b/lotus-soup/node.go @@ -4,12 +4,11 @@ import ( "bytes" "context" "crypto/rand" - "os" - "strings" - - //"encoding/json" "fmt" "io/ioutil" + "os" + "sort" + "strings" "time" "github.com/filecoin-project/go-address" @@ -31,6 +30,7 @@ import ( "github.com/filecoin-project/lotus/node/modules/lp2p" modtest "github.com/filecoin-project/lotus/node/modules/testing" "github.com/filecoin-project/lotus/node/repo" + "github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi/big" "github.com/filecoin-project/specs-actors/actors/builtin" @@ -38,11 +38,13 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/specs-actors/actors/crypto" + "github.com/ipfs/go-datastore" logging "github.com/ipfs/go-log/v2" libp2p_crypto "github.com/libp2p/go-libp2p-core/crypto" "github.com/libp2p/go-libp2p-core/peer" ma "github.com/multiformats/go-multiaddr" + "github.com/testground/sdk-go/run" "github.com/testground/sdk-go/runtime" "github.com/testground/sdk-go/sync" @@ -110,6 +112,7 @@ type InitialBalanceMsg struct { type PresealMsg struct { Miner genesis.Miner + Seqno int64 } type GenesisMsg struct { @@ -305,7 +308,7 @@ func prepareMiner(t *TestEnvironment) (*Node, error) { t.RecordMessage("Miner Info: Owner: %s Worker: %s", genMiner.Owner, genMiner.Worker) - presealMsg := &PresealMsg{Miner: *genMiner} + presealMsg := &PresealMsg{Miner: *genMiner, Seqno: t.GroupSeq} t.SyncClient.Publish(ctx, presealTopic, presealMsg) // then collect the genesis block and bootstrapper address @@ -635,6 +638,10 @@ func collectPreseals(t *TestEnvironment, ctx context.Context, miners int) ([]*Pr } } + sort.Slice(preseals, func(i, j int) bool { + return preseals[i].Seqno < preseals[j].Seqno + }) + return preseals, nil } From b7403fd93c9754fb64f2fa52247cdde612bc881b Mon Sep 17 00:00:00 2001 From: vyzo Date: Fri, 26 Jun 2020 17:44:40 +0300 Subject: [PATCH 3/3] fix mining termination race condition --- lotus-soup/common_roles.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lotus-soup/common_roles.go b/lotus-soup/common_roles.go index 423ab818d..ee1a4d4df 100644 --- a/lotus-soup/common_roles.go +++ b/lotus-soup/common_roles.go @@ -38,7 +38,8 @@ func runMiner(t *TestEnvironment) error { done := make(chan struct{}) go func() { defer close(done) - for i := 0; mine; i++ { + var i int + for i = 0; mine; i++ { // synchronize all miners to mine the next block t.RecordMessage("synchronizing all miners to mine next block [%d]", i) @@ -55,6 +56,11 @@ func runMiner(t *TestEnvironment) error { panic(err) } } + + // signal the last block to make sure no miners are left stuck waiting for the next block signal + // while the others have stopped + stateMineLast := sync.State(fmt.Sprintf("mine-block-%d", i)) + t.SyncClient.MustSignalEntry(ctx, stateMineLast) }() // wait for a signal from all clients to stop mining