lotus/itests/ccupgrade_test.go

104 lines
2.6 KiB
Go
Raw Normal View History

2021-05-17 12:28:09 +00:00
package itests
2020-07-01 14:49:17 +00:00
import (
"context"
"fmt"
"testing"
"time"
2020-09-07 03:49:10 +00:00
"github.com/filecoin-project/go-state-types/abi"
2020-07-01 14:49:17 +00:00
"github.com/filecoin-project/lotus/chain/types"
2021-06-18 18:45:29 +00:00
"github.com/filecoin-project/lotus/itests/kit"
"github.com/stretchr/testify/require"
2020-07-01 14:49:17 +00:00
)
func TestCCUpgrade(t *testing.T) {
2021-06-18 18:45:29 +00:00
kit.QuietMiningLogs()
for _, height := range []abi.ChainEpoch{
-1, // before
162, // while sealing
560, // after upgrade deal
} {
2020-10-05 18:08:46 +00:00
height := height // make linters happy by copying
t.Run(fmt.Sprintf("upgrade-%d", height), func(t *testing.T) {
2021-06-14 09:50:40 +00:00
runTestCCUpgrade(t, height)
})
}
}
2021-06-14 09:50:40 +00:00
func runTestCCUpgrade(t *testing.T, upgradeHeight abi.ChainEpoch) {
2020-07-01 14:49:17 +00:00
ctx := context.Background()
2021-06-14 09:50:40 +00:00
blockTime := 5 * time.Millisecond
2021-11-17 00:09:10 +00:00
client, miner, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.TurboUpgradeAt(upgradeHeight))
2021-06-14 09:50:40 +00:00
ens.InterconnectAll().BeginMining(blockTime)
2020-07-01 14:49:17 +00:00
maddr, err := miner.ActorAddress(ctx)
if err != nil {
t.Fatal(err)
}
2021-06-18 18:45:29 +00:00
CC := abi.SectorNumber(kit.DefaultPresealsPerBootstrapMiner + 1)
2020-07-01 14:49:17 +00:00
Upgraded := CC + 1
2021-06-14 09:50:40 +00:00
miner.PledgeSectors(ctx, 1, 0, nil)
2020-07-01 14:49:17 +00:00
sl, err := miner.SectorsList(ctx)
2021-06-15 06:27:02 +00:00
require.NoError(t, err)
require.Len(t, sl, 1, "expected 1 sector")
require.Equal(t, CC, sl[0], "unexpected sector number")
2020-07-01 14:49:17 +00:00
{
si, err := client.StateSectorGetInfo(ctx, maddr, CC, types.EmptyTSK)
require.NoError(t, err)
require.Less(t, 50000, int(si.Expiration))
}
2021-06-15 06:27:02 +00:00
err = miner.SectorMarkForUpgrade(ctx, sl[0])
require.NoError(t, err)
2020-07-01 14:49:17 +00:00
dh := kit.NewDealHarness(t, client, miner, miner)
deal, res, inPath := dh.MakeOnlineDeal(ctx, kit.MakeFullDealParams{
Rseed: 6,
SuspendUntilCryptoeconStable: true,
})
outPath := dh.PerformRetrieval(context.Background(), deal, res.Root, false)
kit.AssertFilesEqual(t, inPath, outPath)
2020-07-01 14:49:17 +00:00
// Validate upgrade
{
exp, err := client.StateSectorExpiration(ctx, maddr, CC, types.EmptyTSK)
if err != nil {
require.Contains(t, err.Error(), "failed to find sector 3") // already cleaned up
} else {
require.NoError(t, err)
require.NotNil(t, exp)
require.Greater(t, 50000, int(exp.OnTime))
}
2020-07-01 14:49:17 +00:00
}
{
exp, err := client.StateSectorExpiration(ctx, maddr, Upgraded, types.EmptyTSK)
2020-07-01 14:49:17 +00:00
require.NoError(t, err)
require.Less(t, 50000, int(exp.OnTime))
2020-07-01 14:49:17 +00:00
}
2020-09-25 19:16:35 +00:00
dlInfo, err := client.StateMinerProvingDeadline(ctx, maddr, types.EmptyTSK)
require.NoError(t, err)
// Sector should expire.
for {
// Wait for the sector to expire.
status, err := miner.SectorsStatus(ctx, CC, true)
require.NoError(t, err)
if status.OnTime == 0 && status.Early == 0 {
break
}
t.Log("waiting for sector to expire")
// wait one deadline per loop.
2021-06-14 09:50:40 +00:00
time.Sleep(time.Duration(dlInfo.WPoStChallengeWindow) * blockTime)
2020-09-25 19:16:35 +00:00
}
2020-07-01 14:49:17 +00:00
}