lotus/itests/ccupgrade_test.go

189 lines
5.3 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"
"github.com/filecoin-project/go-address"
2020-09-07 03:49:10 +00:00
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/network"
2022-01-09 03:23:22 +00:00
"github.com/filecoin-project/lotus/api"
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/assert"
2021-06-18 18:45:29 +00:00
"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)
})
}
}
func runTestCCUpgrade(t *testing.T, upgradeHeight abi.ChainEpoch) *kit.TestFullNode {
2020-07-01 14:49:17 +00:00
ctx := context.Background()
2022-01-09 03:23:22 +00:00
blockTime := 1 * time.Millisecond
2021-06-14 09:50:40 +00:00
client, miner, ens := kit.EnsembleMinimal(t, kit.GenesisNetworkVersion(network.Version15))
ens.InterconnectAll().BeginMiningMustPost(blockTime)
2021-06-14 09:50:40 +00:00
2020-07-01 14:49:17 +00:00
maddr, err := miner.ActorAddress(ctx)
if err != nil {
t.Fatal(err)
}
CCUpgrade := abi.SectorNumber(kit.DefaultPresealsPerBootstrapMiner + 1)
fmt.Printf("CCUpgrade: %d\n", CCUpgrade)
2020-07-01 14:49:17 +00:00
// wait for deadline 0 to pass so that committing starts after post on preseals
// this gives max time for post to complete minimizing chances of timeout
// waitForDeadline(ctx, t, 1, client, maddr)
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, CCUpgrade, sl[0], "unexpected sector number")
2020-07-01 14:49:17 +00:00
{
si, err := client.StateSectorGetInfo(ctx, maddr, CCUpgrade, types.EmptyTSK)
2020-07-01 14:49:17 +00:00
require.NoError(t, err)
require.Less(t, 50000, int(si.Expiration))
}
waitForSectorActive(ctx, t, CCUpgrade, client, maddr)
err = miner.SectorMarkForUpgrade(ctx, sl[0], true)
2021-06-15 06:27:02 +00:00
require.NoError(t, err)
2020-07-01 14:49:17 +00:00
sl, err = miner.SectorsList(ctx)
require.NoError(t, err)
require.Len(t, sl, 1, "expected 1 sector")
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
status, err := miner.SectorsStatus(ctx, CCUpgrade, true)
require.NoError(t, err)
assert.Equal(t, 1, len(status.Deals))
return client
}
2020-07-01 14:49:17 +00:00
func waitForDeadline(ctx context.Context, t *testing.T, waitIdx uint64, node *kit.TestFullNode, maddr address.Address) {
for {
ts, err := node.ChainHead(ctx)
require.NoError(t, err)
dl, err := node.StateMinerProvingDeadline(ctx, maddr, ts.Key())
require.NoError(t, err)
if dl.Index == waitIdx {
return
}
2020-07-01 14:49:17 +00:00
}
}
func waitForSectorActive(ctx context.Context, t *testing.T, sn abi.SectorNumber, node *kit.TestFullNode, maddr address.Address) {
for {
active, err := node.StateMinerActiveSectors(ctx, maddr, types.EmptyTSK)
2020-07-01 14:49:17 +00:00
require.NoError(t, err)
for _, si := range active {
if si.SectorNumber == sn {
fmt.Printf("ACTIVE\n")
return
}
}
time.Sleep(time.Second)
2020-07-01 14:49:17 +00:00
}
}
2022-01-09 03:23:22 +00:00
func waitForSectorStartUpgrade(ctx context.Context, t *testing.T, sn abi.SectorNumber, miner *kit.TestMiner) {
for {
si, err := miner.StorageMiner.SectorsStatus(ctx, sn, false)
require.NoError(t, err)
if si.State != api.SectorState("Proving") {
t.Logf("Done proving sector in state: %s", si.State)
return
}
}
}
func TestCCUpgradeAndPoSt(t *testing.T) {
kit.QuietMiningLogs()
t.Run("upgrade and then post", func(t *testing.T) {
ctx := context.Background()
n := runTestCCUpgrade(t, 100)
ts, err := n.ChainHead(ctx)
require.NoError(t, err)
start := ts.Height()
// wait for a full proving period
2022-01-09 03:23:22 +00:00
t.Log("waiting for chain")
n.WaitTillChain(ctx, func(ts *types.TipSet) bool {
if ts.Height() > start+abi.ChainEpoch(2880) {
return true
}
return false
})
})
}
2020-07-01 14:49:17 +00:00
func TestTooManyMarkedForUpgrade(t *testing.T) {
kit.QuietMiningLogs()
ctx := context.Background()
2022-01-09 03:23:22 +00:00
blockTime := 1 * time.Millisecond
client, miner, ens := kit.EnsembleMinimal(t, kit.GenesisNetworkVersion(network.Version15))
2022-01-09 03:23:22 +00:00
ens.InterconnectAll().BeginMiningMustPost(blockTime)
maddr, err := miner.ActorAddress(ctx)
if err != nil {
t.Fatal(err)
}
CCUpgrade := abi.SectorNumber(kit.DefaultPresealsPerBootstrapMiner + 1)
waitForDeadline(ctx, t, 1, client, maddr)
miner.PledgeSectors(ctx, 3, 0, nil)
sl, err := miner.SectorsList(ctx)
2020-09-25 19:16:35 +00:00
require.NoError(t, err)
require.Len(t, sl, 3, "expected 3 sectors")
2020-09-25 19:16:35 +00:00
{
si, err := client.StateSectorGetInfo(ctx, maddr, CCUpgrade, types.EmptyTSK)
2020-09-25 19:16:35 +00:00
require.NoError(t, err)
require.Less(t, 50000, int(si.Expiration))
2020-09-25 19:16:35 +00:00
}
waitForSectorActive(ctx, t, CCUpgrade, client, maddr)
waitForSectorActive(ctx, t, CCUpgrade+1, client, maddr)
waitForSectorActive(ctx, t, CCUpgrade+2, client, maddr)
err = miner.SectorMarkForUpgrade(ctx, CCUpgrade, true)
require.NoError(t, err)
err = miner.SectorMarkForUpgrade(ctx, CCUpgrade+1, true)
require.NoError(t, err)
2022-01-09 03:23:22 +00:00
waitForSectorStartUpgrade(ctx, t, CCUpgrade, miner)
waitForSectorStartUpgrade(ctx, t, CCUpgrade+1, miner)
err = miner.SectorMarkForUpgrade(ctx, CCUpgrade+2, true)
require.Error(t, err)
assert.Contains(t, err.Error(), "no free resources to wait for deals")
2020-07-01 14:49:17 +00:00
}