77
88 "github.com/stretchr/testify/require"
99
10+ "github.com/filecoin-project/lotus/chain/actors/policy"
1011 "github.com/filecoin-project/lotus/chain/gen"
1112)
1213
@@ -20,6 +21,7 @@ func TestChainCheckpoint(t *testing.T) {
2021 if err != nil {
2122 t .Fatal (err )
2223 }
24+ cg .AdvanceState = false
2325
2426 // Let the first miner mine some blocks.
2527 last := cg .CurTipset .TipSet ()
@@ -83,4 +85,41 @@ func TestChainCheckpoint(t *testing.T) {
8385
8486 head = cs .GetHeaviestTipSet ()
8587 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 )
86125}
0 commit comments