2021-05-17 12:28:09 +00:00
|
|
|
package itests
|
2020-10-12 06:31:23 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-state-types/network"
|
|
|
|
"github.com/filecoin-project/lotus/api"
|
|
|
|
"github.com/filecoin-project/lotus/build"
|
|
|
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
|
|
|
sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
|
2021-05-18 21:01:10 +00:00
|
|
|
"github.com/filecoin-project/lotus/itests/kit"
|
2020-10-12 06:31:23 +00:00
|
|
|
"github.com/filecoin-project/lotus/node"
|
|
|
|
"github.com/filecoin-project/lotus/node/impl"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2021-05-18 20:32:10 +00:00
|
|
|
func TestTapeFix(t *testing.T) {
|
2021-05-18 21:01:10 +00:00
|
|
|
kit.QuietMiningLogs()
|
2021-05-18 20:32:10 +00:00
|
|
|
|
|
|
|
var blocktime = 2 * time.Millisecond
|
|
|
|
|
2021-02-19 21:08:43 +00:00
|
|
|
// The "before" case is disabled, because we need the builder to mock 32 GiB sectors to accurately repro this case
|
|
|
|
// TODO: Make the mock sector size configurable and reenable this
|
2021-05-18 20:32:10 +00:00
|
|
|
// t.Run("before", func(t *testing.T) { testTapeFix(t, b, blocktime, false) })
|
2021-05-20 11:17:41 +00:00
|
|
|
t.Run("after", func(t *testing.T) { testTapeFix(t, kit.MockMinerBuilder, blocktime, true) })
|
2020-10-12 06:31:23 +00:00
|
|
|
}
|
2021-05-18 20:32:10 +00:00
|
|
|
|
2021-05-18 21:01:10 +00:00
|
|
|
func testTapeFix(t *testing.T, b kit.APIBuilder, blocktime time.Duration, after bool) {
|
2020-10-12 06:31:23 +00:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
upgradeSchedule := stmgr.UpgradeSchedule{{
|
|
|
|
Network: build.ActorUpgradeNetworkVersion,
|
|
|
|
Height: 1,
|
|
|
|
Migration: stmgr.UpgradeActorsV2,
|
|
|
|
}}
|
|
|
|
if after {
|
|
|
|
upgradeSchedule = append(upgradeSchedule, stmgr.Upgrade{
|
|
|
|
Network: network.Version5,
|
|
|
|
Height: 2,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-05-19 10:47:37 +00:00
|
|
|
n, sn := b(t, []kit.FullNodeOpts{{Opts: func(_ []kit.TestFullNode) node.Option {
|
2020-10-12 06:31:23 +00:00
|
|
|
return node.Override(new(stmgr.UpgradeSchedule), upgradeSchedule)
|
2021-05-18 21:01:10 +00:00
|
|
|
}}}, kit.OneMiner)
|
2020-10-12 06:31:23 +00:00
|
|
|
|
|
|
|
client := n[0].FullNode.(*impl.FullNodeAPI)
|
|
|
|
miner := sn[0]
|
|
|
|
|
|
|
|
addrinfo, err := client.NetAddrsListen(ctx)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := miner.NetConnect(ctx, addrinfo); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
build.Clock.Sleep(time.Second)
|
|
|
|
|
|
|
|
done := make(chan struct{})
|
|
|
|
go func() {
|
|
|
|
defer close(done)
|
|
|
|
for ctx.Err() == nil {
|
|
|
|
build.Clock.Sleep(blocktime)
|
2021-05-18 21:01:10 +00:00
|
|
|
if err := sn[0].MineOne(ctx, kit.MineNext); err != nil {
|
2020-10-12 06:31:23 +00:00
|
|
|
if ctx.Err() != nil {
|
|
|
|
// context was canceled, ignore the error.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
defer func() {
|
|
|
|
cancel()
|
|
|
|
<-done
|
|
|
|
}()
|
|
|
|
|
2021-02-16 18:19:16 +00:00
|
|
|
sid, err := miner.PledgeSector(ctx)
|
2020-10-12 06:31:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fmt.Printf("All sectors is fsm\n")
|
|
|
|
|
|
|
|
// If before, we expect the precommit to fail
|
|
|
|
successState := api.SectorState(sealing.CommitFailed)
|
|
|
|
failureState := api.SectorState(sealing.Proving)
|
|
|
|
if after {
|
|
|
|
// otherwise, it should succeed.
|
|
|
|
successState, failureState = failureState, successState
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
2021-02-16 18:19:16 +00:00
|
|
|
st, err := miner.SectorsStatus(ctx, sid.Number, false)
|
2020-10-12 06:31:23 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
if st.State == successState {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
require.NotEqual(t, failureState, st.State)
|
|
|
|
build.Clock.Sleep(100 * time.Millisecond)
|
|
|
|
fmt.Println("WaitSeal")
|
|
|
|
}
|
|
|
|
}
|