-
Notifications
You must be signed in to change notification settings - Fork 476
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5299 from Algo-devops-service/relstable3.15.1
- Loading branch information
Showing
7 changed files
with
261 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0 | ||
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// Copyright (C) 2019-2023 Algorand, Inc. | ||
// This file is part of go-algorand | ||
// | ||
// go-algorand is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as | ||
// published by the Free Software Foundation, either version 3 of the | ||
// License, or (at your option) any later version. | ||
// | ||
// go-algorand is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package followerNode | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/algorand/go-algorand/config" | ||
"github.com/algorand/go-algorand/daemon/algod/api/client" | ||
"github.com/algorand/go-algorand/test/framework/fixtures" | ||
"github.com/algorand/go-algorand/test/partitiontest" | ||
) | ||
|
||
// Overview of this test: | ||
// Start a two-node network--one in follower mode (follower has 0%, secondary has 100%) | ||
// with the nodes having a max account lookback of 2. | ||
// Advance the primary node to particular rounds, set the follower's sync round | ||
// and then advance the follower node as much as possible. | ||
// Restart the network and verify that the sync round hasn't advanced. | ||
// | ||
// NOTE: with a max account lookback of MAL, and the follower's sync round at SR: | ||
// the follower cannot advance past round SR - 1 + MAL | ||
func TestSyncRestart(t *testing.T) { | ||
partitiontest.PartitionTest(t) | ||
defer fixtures.ShutdownSynchronizedTest(t) | ||
|
||
if testing.Short() { | ||
t.Skip() | ||
} | ||
t.Parallel() | ||
a := require.New(fixtures.SynchronizedTest(t)) | ||
|
||
var fixture fixtures.RestClientFixture | ||
fixture.Setup(t, filepath.Join("nettemplates", "TwoNodesFollower100SecondMaxAccountLookback2.json")) | ||
|
||
defer fixture.Shutdown() | ||
|
||
// sanity check that the follower has the expected max account lookback of 2: | ||
followerCtrl, err := fixture.GetNodeController("Follower") | ||
a.NoError(err) | ||
cfg, err := config.LoadConfigFromDisk(followerCtrl.GetDataDir()) | ||
a.NoError(err) | ||
a.Equal(uint64(2), cfg.MaxAcctLookback) | ||
|
||
waitTill := func(node string, round uint64) { | ||
controller, err := fixture.GetNodeController(node) | ||
a.NoError(err) | ||
err = fixture.ClientWaitForRoundWithTimeout(fixture.GetAlgodClientForController(controller), round) | ||
a.NoError(err) | ||
} | ||
|
||
getAlgod := func(node string) client.RestClient { | ||
controller, err := fixture.GetNodeController(node) | ||
a.NoError(err) | ||
algod := fixture.GetAlgodClientForController(controller) | ||
return algod | ||
} | ||
|
||
getRound := func(node string) uint64 { | ||
algod := getAlgod(node) | ||
status, err := algod.Status() | ||
a.NoError(err) | ||
return status.LastRound | ||
} | ||
|
||
getSyncRound := func() uint64 { | ||
followClient := getAlgod("Follower") | ||
rResp, err := followClient.GetSyncRound() | ||
a.NoError(err) | ||
return rResp.Round | ||
} | ||
|
||
a.Equal(uint64(1), getSyncRound()) | ||
|
||
waitTill("Primary", 3) | ||
// with a max account lookback of 2, and the sync round at 1, | ||
// the follower cannot advance past round 2 = 1 - 1 + 2 | ||
waitTill("Follower", 2) | ||
a.LessOrEqual(uint64(3), getRound("Primary")) | ||
a.Equal(uint64(2), getRound("Follower")) | ||
a.Equal(uint64(1), getSyncRound()) | ||
|
||
/** restart the network **/ | ||
fixture.ShutdownImpl(true) | ||
fixture.Start() | ||
|
||
a.LessOrEqual(uint64(3), getRound("Primary")) | ||
a.Equal(uint64(1), getSyncRound()) | ||
a.Equal(uint64(2), getRound("Follower")) | ||
|
||
waitTill("Primary", 6) | ||
followerClient := getAlgod("Follower") | ||
err = followerClient.SetSyncRound(uint64(3)) | ||
a.NoError(err) | ||
a.Equal(uint64(3), getSyncRound()) | ||
// with a max account lookback of 2, and the sync round at 3, | ||
// the follower cannot advance past round 4 = 3 - 1 + 2 | ||
waitTill("Follower", 4) | ||
a.LessOrEqual(uint64(6), getRound("Primary")) | ||
a.Equal(uint64(4), getRound("Follower")) | ||
a.Equal(uint64(3), getSyncRound()) | ||
|
||
fixture.ShutdownImpl(true) | ||
fixture.Start() | ||
|
||
a.LessOrEqual(uint64(6), getRound("Primary")) | ||
a.Equal(uint64(4), getRound("Follower")) | ||
a.Equal(uint64(3), getSyncRound()) | ||
} |
28 changes: 28 additions & 0 deletions
28
test/testdata/nettemplates/TwoNodesFollower100SecondMaxAccountLookback2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"Genesis": { | ||
"LastPartKeyRound": 3000, | ||
"NetworkName": "tbd", | ||
"Wallets": [ | ||
{ | ||
"Name": "Wallet1", | ||
"Stake": 100, | ||
"Online": true | ||
} | ||
] | ||
}, | ||
"Nodes": [ | ||
{ | ||
"Name": "Follower", | ||
"Wallets": [], | ||
"ConfigJSONOverride": "{\"EnableFollowMode\":true, \"MaxAcctLookback\":2}" | ||
}, | ||
{ | ||
"Name": "Primary", | ||
"IsRelay": true, | ||
"Wallets": [ | ||
{ "Name": "Wallet1", | ||
"ParticipationOnly": false } | ||
] | ||
} | ||
] | ||
} |