1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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())
}
|