From 00cc982bcb4571fea5105746e1c5f0a06e8e82f3 Mon Sep 17 00:00:00 2001 From: Yusef Napora Date: Mon, 6 Jul 2020 16:10:53 -0400 Subject: [PATCH] panic if we fail to mine 100x in a row --- lotus-soup/testkit/role_miner.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lotus-soup/testkit/role_miner.go b/lotus-soup/testkit/role_miner.go index fe8cfefa1..5f951985e 100644 --- a/lotus-soup/testkit/role_miner.go +++ b/lotus-soup/testkit/role_miner.go @@ -352,7 +352,9 @@ func (m *LotusMiner) RunDefault() error { t.SyncClient.MustSignalAndWait(ctx, stateMineNext, miners) ch := make(chan error) - for { + const maxRetries = 100 + success := false + for retries := 0; retries < maxRetries; retries++ { err := m.MineOne(ctx, func(mined bool, err error) { if mined { t.D().Counter(fmt.Sprintf("block.mine,miner=%s", myActorAddr)).Inc(1) @@ -365,10 +367,15 @@ func (m *LotusMiner) RunDefault() error { miningErr := <-ch if miningErr == nil { + success = true break } t.D().Counter("block.mine.err").Inc(1) - t.RecordMessage("retrying block [%d] due to mining error: %s", i, miningErr) + t.RecordMessage("retrying block [%d] after %d attempts due to mining error: %s", + i, retries, miningErr) + } + if !success { + panic(fmt.Errorf("failed to mine block %d after %d retries", i, maxRetries)) } }