-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
125 additions
and
11 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
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,61 @@ | ||
package itests | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/filecoin-project/go-state-types/abi" | ||
"github.com/filecoin-project/lotus/chain/types" | ||
"github.com/filecoin-project/lotus/itests/kit" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCheckpointFork(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
blocktime := 100 * time.Millisecond | ||
// Create three miners. | ||
miners := make([]*kit.TestMiner, 3) | ||
n1, ens := kit.EnsembleOneMany(t, | ||
miners, | ||
kit.MockProofs(), | ||
kit.ThroughRPC(), | ||
) | ||
|
||
// Start 2 of them. | ||
ens.InterconnectAll().BeginMining(blocktime, miners[:2]...) | ||
|
||
{ | ||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
n1.WaitTillChain(ctx, kit.HeightAtLeast(abi.ChainEpoch(5))) | ||
cancel() | ||
} | ||
|
||
// Wait till both participate in a single tipset. | ||
var target *types.TipSet | ||
{ | ||
// find the first tipset where two miners mine a block. | ||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) | ||
target = n1.WaitTillChain(ctx, func(ts *types.TipSet) bool { | ||
return len(ts.Blocks()) == 2 | ||
}) | ||
cancel() | ||
} | ||
|
||
// Wait till we've moved on from that tipset. | ||
targetHeight := target.Height() + 10 | ||
n1.WaitTillChain(ctx, kit.HeightAtLeast(targetHeight)) | ||
|
||
// Forcibly sync to this fork tipset. | ||
forkTs, err := types.NewTipSet(target.Blocks()[:1]) | ||
require.NoError(t, err) | ||
require.NoError(t, n1.SyncCheckpoint(ctx, forkTs.Key())) | ||
ens.BeginMining(blocktime, miners[2]) | ||
|
||
// See if we can start making progress again! | ||
newHead := n1.WaitTillChain(ctx, kit.HeightAtLeast(targetHeight)) | ||
forkTs2, err := n1.ChainGetTipSetByHeight(ctx, forkTs.Height(), newHead.Key()) | ||
require.NoError(t, err) | ||
require.True(t, forkTs.Equals(forkTs2)) | ||
} |
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