7
7
8
8
"github.com/stretchr/testify/require"
9
9
10
+ "github.com/filecoin-project/lotus/chain/actors/policy"
10
11
"github.com/filecoin-project/lotus/chain/gen"
11
12
)
12
13
@@ -20,6 +21,7 @@ func TestChainCheckpoint(t *testing.T) {
20
21
if err != nil {
21
22
t .Fatal (err )
22
23
}
24
+ cg .AdvanceState = false
23
25
24
26
// Let the first miner mine some blocks.
25
27
last := cg .CurTipset .TipSet ()
@@ -83,4 +85,41 @@ func TestChainCheckpoint(t *testing.T) {
83
85
84
86
head = cs .GetHeaviestTipSet ()
85
87
require .True (t , head .Equals (checkpoint ))
88
+
89
+ // Now extend the fork 900 epochs into the future.
90
+ for i := 0 ; i < int (policy .ChainFinality )+ 10 ; i ++ {
91
+ ts , err := cg .NextTipSetFromMiners (last , cg .Miners [1 :], 0 )
92
+ require .NoError (t , err )
93
+
94
+ last = ts .TipSet .TipSet ()
95
+ }
96
+
97
+ // Try to re-checkpoint to the long fork. This will work because we only have to revert a
98
+ // single epoch.
99
+ err = cs .SetCheckpoint (ctx , last )
100
+ require .NoError (t , err )
101
+
102
+ head = cs .GetHeaviestTipSet ()
103
+ require .True (t , head .Equals (last ))
104
+
105
+ // Now try to go back to the checkpoint. This should fail because it's too far in the past
106
+ // on the wrong fork.
107
+ err = cs .SetCheckpoint (ctx , checkpoint )
108
+ require .Error (t , err )
109
+
110
+ // Now extend the checkpoint chain to the same tipset.
111
+ for checkpoint .Height () < last .Height () {
112
+ ts , err := cg .NextTipSetFromMiners (checkpoint , cg .Miners [1 :], 0 )
113
+ require .NoError (t , err )
114
+
115
+ checkpoint = ts .TipSet .TipSet ()
116
+ }
117
+
118
+ // We should still refuse to switch.
119
+ err = cs .SetCheckpoint (ctx , checkpoint )
120
+ require .Error (t , err )
121
+
122
+ // But it should be possible to set a checkpoint on a common chain
123
+ err = cs .SetCheckpoint (ctx , checkpointParents )
124
+ require .NoError (t , err )
86
125
}
0 commit comments