Skip to content

Commit

Permalink
Leave lookback at 320 for suspension test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jannotti committed Apr 17, 2024
1 parent e0c5d4f commit f1082f5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
5 changes: 3 additions & 2 deletions test/e2e-go/features/incentives/payouts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"path/filepath"
"testing"
"time"

"github.com/stretchr/testify/require"

Expand All @@ -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()
Expand Down
36 changes: 19 additions & 17 deletions test/e2e-go/features/incentives/suspension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"path/filepath"
"testing"
"time"

"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -137,31 +139,31 @@ 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)
for i, c := range []libgoal.Client{c10, c20} {
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)
Expand Down
14 changes: 9 additions & 5 deletions test/framework/fixtures/libgoalFixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f1082f5

Please sign in to comment.