From f1082f5ff53579c1446c4b8f19650d9cbaf9361c Mon Sep 17 00:00:00 2001 From: John Jannotti Date: Wed, 17 Apr 2024 15:21:23 -0400 Subject: [PATCH] Leave lookback at 320 for suspension test Part of the test requires the suspended node to re-propose after suispension. That can only happen when the balance lookback is considerably bigger than the suspension interval (here, 5*10==50) Fortunately, this test doesn't have to wait for lookback, so the benefit of short filter timeout is all we need for a quick test. --- .../features/incentives/payouts_test.go | 5 +-- .../features/incentives/suspension_test.go | 36 ++++++++++--------- test/framework/fixtures/libgoalFixture.go | 14 +++++--- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/test/e2e-go/features/incentives/payouts_test.go b/test/e2e-go/features/incentives/payouts_test.go index 3497bd2375..a7b6567d87 100644 --- a/test/e2e-go/features/incentives/payouts_test.go +++ b/test/e2e-go/features/incentives/payouts_test.go @@ -20,6 +20,7 @@ import ( "fmt" "path/filepath" "testing" + "time" "github.com/stretchr/testify/require" @@ -45,8 +46,8 @@ func TestBasicPayouts(t *testing.T) { var fixture fixtures.RestClientFixture // Make the seed lookback shorter, otherwise we need to wait 320 rounds to become IncentiveEligible. - faster := fixture.FasterConsensus(protocol.ConsensusFuture) - lookback := 4 * faster.SeedRefreshInterval + const lookback = 32 + fixture.FasterConsensus(protocol.ConsensusFuture, time.Second/2, 32) fmt.Printf("lookback is %d\n", lookback) fixture.Setup(t, filepath.Join("nettemplates", "Payouts.json")) defer fixture.Shutdown() diff --git a/test/e2e-go/features/incentives/suspension_test.go b/test/e2e-go/features/incentives/suspension_test.go index 06db1ccaad..3d3f0954f6 100644 --- a/test/e2e-go/features/incentives/suspension_test.go +++ b/test/e2e-go/features/incentives/suspension_test.go @@ -20,6 +20,7 @@ import ( "fmt" "path/filepath" "testing" + "time" "github.com/stretchr/testify/require" @@ -50,8 +51,9 @@ func TestBasicSuspension(t *testing.T) { const suspend20 = 55 var fixture fixtures.RestClientFixture - // Make the seed lookback shorter, so the test runs faster - fixture.FasterConsensus(protocol.ConsensusFuture) + // Speed up rounds, but keep long lookback, so 20% node has a chance to get + // back online after being suspended. + fixture.FasterConsensus(protocol.ConsensusFuture, time.Second/2, 320) fixture.Setup(t, filepath.Join("nettemplates", "Suspension.json")) defer fixture.Shutdown() @@ -137,23 +139,23 @@ func TestBasicSuspension(t *testing.T) { // Wait for newly restarted node to start. stat, err := lg.Status() a.NoError(err) - // Waiting for this round should show it has started and caught up. - stat, err = lg.WaitForRound(afterStop.LastRound + suspend20) + + // Get the current round, and wait for the restarted node to get there. + stat, err = fixture.AlgodClient.Status() a.NoError(err) - // Proceed until a round is proposed by n20. (Stop at 50 rounds, that's more likely a bug than luck) - for r := stat.LastRound; r < stat.LastRound+50; r++ { - err = fixture.WaitForRoundWithTimeout(r) - a.NoError(err) + // Wait for latest round to show n20 has started and caught up. + restartRound := stat.LastRound + stat, err = lg.WaitForRound(restartRound) + a.NoError(err) - // Once n20 proposes, break out early - if fixture.VerifyBlockProposed(account20.Address, 1) { - fmt.Printf("account20 proposed at round %d\n", r) - // wait one extra round, because changes are processed in block n+1. - err = fixture.WaitForRoundWithTimeout(r + 1) - a.NoError(err) - break - } + // Proceed until a round is proposed by n20. + attempts := 0 + for !fixture.VerifyBlockProposed(account20.Address, 1) { + stat, err = lg.WaitForRound(stat.LastRound + 1) + a.NoError(err) + attempts++ + a.Less(attempts, suspend20, "n20 didn't propose\n") } // paranoia. see payouts_test.go for more details. r := require.New(t) @@ -161,7 +163,7 @@ func TestBasicSuspension(t *testing.T) { account, err = c.AccountData(account20.Address) a.NoError(err) r.Equal(basics.Online, account.Status, i) - r.Greater(account.LastProposed, stat.LastRound, i) + r.Greater(account.LastProposed, restartRound, i) r.Equal(voteID, account.VoteID, i) r.False(account.IncentiveEligible, i) diff --git a/test/framework/fixtures/libgoalFixture.go b/test/framework/fixtures/libgoalFixture.go index 61e2b6dbec..1ffc6493c0 100644 --- a/test/framework/fixtures/libgoalFixture.go +++ b/test/framework/fixtures/libgoalFixture.go @@ -36,6 +36,7 @@ import ( "github.com/algorand/go-algorand/crypto/merklearray" "github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated/model" "github.com/algorand/go-algorand/data/account" + "github.com/algorand/go-algorand/data/basics" "github.com/algorand/go-algorand/gen" "github.com/algorand/go-algorand/libgoal" "github.com/algorand/go-algorand/netdeploy" @@ -70,19 +71,22 @@ func (f *RestClientFixture) SetConsensus(consensus config.ConsensusProtocols) { // refresh lookback is set to 8 (instead of 80), so the 320 round balance // lookback becomes 32. And, if the architecture implies it can be handled, // round times are shortened by lowering vote timeouts. -func (f *RestClientFixture) FasterConsensus(ver protocol.ConsensusVersion) config.ConsensusParams { +func (f *RestClientFixture) FasterConsensus(ver protocol.ConsensusVersion, timeout time.Duration, lookback basics.Round) { if f.consensus == nil { f.consensus = make(config.ConsensusProtocols) } fast := config.Consensus[ver] - fast.SeedRefreshInterval = 8 // so balanceRound ends up 2 * 8 * 2 = 32 + // balanceRound is 4 * SeedRefreshInterval + if lookback%4 != 0 { + panic(fmt.Sprintf("lookback must be a multiple of 4, got %d", lookback)) + } + fast.SeedRefreshInterval = uint64(lookback) / 4 // and speed up the rounds while we're at it if runtime.GOARCH == "amd64" || runtime.GOARCH == "arm64" { - fast.AgreementFilterTimeoutPeriod0 = time.Second / 2 - fast.AgreementFilterTimeout = time.Second / 2 + fast.AgreementFilterTimeoutPeriod0 = timeout + fast.AgreementFilterTimeout = timeout } f.consensus[ver] = fast - return fast } // Setup is called to initialize the test fixture for the test(s)