2022-03-17 20:21:52 +00:00
|
|
|
package itests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/go-state-types/network"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/api"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
"github.com/filecoin-project/lotus/itests/kit"
|
2022-06-14 17:41:59 +00:00
|
|
|
sealing "github.com/filecoin-project/lotus/storage/pipeline"
|
2022-03-17 20:21:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAbortUpgradeAvailable(t *testing.T) {
|
|
|
|
kit.QuietMiningLogs()
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
blockTime := 1 * time.Millisecond
|
|
|
|
|
|
|
|
client, miner, ens := kit.EnsembleMinimal(t, kit.GenesisNetworkVersion(network.Version15), kit.ThroughRPC())
|
|
|
|
ens.InterconnectAll().BeginMiningMustPost(blockTime)
|
|
|
|
|
|
|
|
maddr, err := miner.ActorAddress(ctx)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2022-08-02 14:05:29 +00:00
|
|
|
CCUpgrade := abi.SectorNumber(kit.DefaultPresealsPerBootstrapMiner)
|
2022-03-17 20:21:52 +00:00
|
|
|
fmt.Printf("CCUpgrade: %d\n", CCUpgrade)
|
|
|
|
|
|
|
|
miner.PledgeSectors(ctx, 1, 0, nil)
|
2022-08-02 13:29:38 +00:00
|
|
|
sl, err := miner.SectorsListNonGenesis(ctx)
|
2022-03-17 20:21:52 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, sl, 1, "expected 1 sector")
|
|
|
|
require.Equal(t, CCUpgrade, sl[0], "unexpected sector number")
|
|
|
|
{
|
|
|
|
si, err := client.StateSectorGetInfo(ctx, maddr, CCUpgrade, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Less(t, 50000, int(si.Expiration))
|
|
|
|
}
|
2022-03-17 20:39:52 +00:00
|
|
|
client.WaitForSectorActive(ctx, t, CCUpgrade, maddr)
|
2022-03-17 20:21:52 +00:00
|
|
|
|
|
|
|
err = miner.SectorMarkForUpgrade(ctx, sl[0], true)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-08-02 13:29:38 +00:00
|
|
|
sl, err = miner.SectorsListNonGenesis(ctx)
|
2022-03-17 20:21:52 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, sl, 1, "expected 1 sector")
|
|
|
|
|
|
|
|
ss, err := miner.SectorsStatus(ctx, sl[0], false)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
for i := 0; i < 100; i++ {
|
|
|
|
ss, err = miner.SectorsStatus(ctx, sl[0], false)
|
|
|
|
require.NoError(t, err)
|
|
|
|
if ss.State == api.SectorState(sealing.Proving) {
|
|
|
|
time.Sleep(50 * time.Millisecond)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
require.Equal(t, api.SectorState(sealing.Available), ss.State)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
require.NoError(t, miner.SectorAbortUpgrade(ctx, sl[0]))
|
|
|
|
|
|
|
|
for i := 0; i < 100; i++ {
|
|
|
|
ss, err = miner.SectorsStatus(ctx, sl[0], false)
|
|
|
|
require.NoError(t, err)
|
|
|
|
if ss.State == api.SectorState(sealing.Available) {
|
|
|
|
time.Sleep(50 * time.Millisecond)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
require.Equal(t, api.SectorState(sealing.Proving), ss.State)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|