2021-12-10 10:33:29 +00:00
|
|
|
//stm: #integration
|
2021-05-17 12:28:09 +00:00
|
|
|
package itests
|
2020-07-01 14:49:17 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2022-03-16 18:05:53 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
|
|
|
sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
|
2020-07-01 14:49:17 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-12-08 17:11:19 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2021-12-08 17:11:19 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/network"
|
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"
|
|
|
|
|
2021-12-08 17:11:19 +00:00
|
|
|
"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
|
|
|
)
|
|
|
|
|
2021-05-18 20:32:10 +00:00
|
|
|
func TestCCUpgrade(t *testing.T) {
|
2021-12-13 12:41:04 +00:00
|
|
|
//stm: @CHAIN_SYNCER_LOAD_GENESIS_001, @CHAIN_SYNCER_FETCH_TIPSET_001,
|
|
|
|
//stm: @CHAIN_SYNCER_START_001, @CHAIN_SYNCER_SYNC_001, @BLOCKCHAIN_BEACON_VALIDATE_BLOCK_VALUES_01
|
|
|
|
//stm: @CHAIN_SYNCER_COLLECT_CHAIN_001, @CHAIN_SYNCER_COLLECT_HEADERS_001, @CHAIN_SYNCER_VALIDATE_TIPSET_001
|
|
|
|
//stm: @CHAIN_SYNCER_NEW_PEER_HEAD_001, @CHAIN_SYNCER_VALIDATE_MESSAGE_META_001, @CHAIN_SYNCER_STOP_001
|
2021-12-10 15:08:25 +00:00
|
|
|
|
|
|
|
//stm: @CHAIN_STATE_MINER_GET_INFO_001
|
2021-12-14 10:33:33 +00:00
|
|
|
//stm: @CHAIN_INCOMING_HANDLE_INCOMING_BLOCKS_001, @CHAIN_INCOMING_VALIDATE_BLOCK_PUBSUB_001, @CHAIN_INCOMING_VALIDATE_MESSAGE_PUBSUB_001
|
2021-12-15 14:30:42 +00:00
|
|
|
|
|
|
|
//stm: @MINER_SECTOR_LIST_001
|
2021-06-18 18:45:29 +00:00
|
|
|
kit.QuietMiningLogs()
|
2021-05-18 20:32:10 +00:00
|
|
|
|
2022-02-08 13:28:13 +00:00
|
|
|
runTestCCUpgrade(t)
|
2020-10-05 17:56:00 +00:00
|
|
|
}
|
|
|
|
|
2022-02-03 12:51:59 +00:00
|
|
|
func runTestCCUpgrade(t *testing.T) *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
|
|
|
|
2022-02-08 13:28:13 +00:00
|
|
|
client, miner, ens := kit.EnsembleMinimal(t, kit.GenesisNetworkVersion(network.Version15), kit.ThroughRPC())
|
2021-12-08 17:11:19 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2021-12-08 17:11:19 +00:00
|
|
|
CCUpgrade := abi.SectorNumber(kit.DefaultPresealsPerBootstrapMiner + 1)
|
|
|
|
fmt.Printf("CCUpgrade: %d\n", CCUpgrade)
|
2020-07-01 14:49:17 +00:00
|
|
|
|
2021-12-08 17:11:19 +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")
|
2021-12-08 17:11:19 +00:00
|
|
|
require.Equal(t, CCUpgrade, sl[0], "unexpected sector number")
|
2020-07-01 14:49:17 +00:00
|
|
|
{
|
2021-12-08 17:11:19 +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))
|
|
|
|
}
|
2021-12-08 17:11:19 +00:00
|
|
|
waitForSectorActive(ctx, t, CCUpgrade, client, maddr)
|
2020-07-01 14:49:17 +00:00
|
|
|
|
2021-12-08 17:11:19 +00:00
|
|
|
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
|
|
|
|
2021-12-08 17:11:19 +00:00
|
|
|
sl, err = miner.SectorsList(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, sl, 1, "expected 1 sector")
|
|
|
|
|
2021-06-23 09:24:55 +00:00
|
|
|
dh := kit.NewDealHarness(t, client, miner, miner)
|
2021-06-23 18:14:27 +00:00
|
|
|
deal, res, inPath := dh.MakeOnlineDeal(ctx, kit.MakeFullDealParams{
|
|
|
|
Rseed: 6,
|
|
|
|
SuspendUntilCryptoeconStable: true,
|
|
|
|
})
|
2021-06-21 17:19:26 +00:00
|
|
|
outPath := dh.PerformRetrieval(context.Background(), deal, res.Root, false)
|
|
|
|
kit.AssertFilesEqual(t, inPath, outPath)
|
2020-07-01 14:49:17 +00:00
|
|
|
|
2021-12-08 17:11:19 +00:00
|
|
|
status, err := miner.SectorsStatus(ctx, CCUpgrade, true)
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, 1, len(status.Deals))
|
2022-02-08 14:29:30 +00:00
|
|
|
|
|
|
|
miner.WaitSectorsProving(ctx, map[abi.SectorNumber]struct{}{
|
|
|
|
CCUpgrade: {},
|
|
|
|
})
|
|
|
|
|
2021-12-08 17:11:19 +00:00
|
|
|
return client
|
|
|
|
}
|
2020-07-01 14:49:17 +00:00
|
|
|
|
2021-12-08 17:11:19 +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)
|
2021-12-08 17:11:19 +00:00
|
|
|
for _, si := range active {
|
|
|
|
if si.SectorNumber == sn {
|
|
|
|
fmt.Printf("ACTIVE\n")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2020-07-01 14:49:17 +00:00
|
|
|
|
2021-12-08 17:11:19 +00:00
|
|
|
time.Sleep(time.Second)
|
2020-07-01 14:49:17 +00:00
|
|
|
}
|
2021-12-08 17:11:19 +00:00
|
|
|
}
|
2020-09-25 19:16:35 +00:00
|
|
|
|
2021-12-08 17:11:19 +00:00
|
|
|
func TestCCUpgradeAndPoSt(t *testing.T) {
|
|
|
|
kit.QuietMiningLogs()
|
|
|
|
t.Run("upgrade and then post", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
2022-02-03 12:51:59 +00:00
|
|
|
n := runTestCCUpgrade(t)
|
2021-12-08 17:11:19 +00:00
|
|
|
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")
|
|
|
|
|
2021-12-08 17:11:19 +00:00
|
|
|
n.WaitTillChain(ctx, func(ts *types.TipSet) bool {
|
|
|
|
if ts.Height() > start+abi.ChainEpoch(2880) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2022-03-16 18:05:53 +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)
|
|
|
|
}
|
|
|
|
|
|
|
|
CCUpgrade := abi.SectorNumber(kit.DefaultPresealsPerBootstrapMiner + 1)
|
|
|
|
fmt.Printf("CCUpgrade: %d\n", CCUpgrade)
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
miner.PledgeSectors(ctx, 1, 0, nil)
|
|
|
|
sl, err := miner.SectorsList(ctx)
|
|
|
|
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))
|
|
|
|
}
|
|
|
|
waitForSectorActive(ctx, t, CCUpgrade, client, maddr)
|
|
|
|
|
|
|
|
err = miner.SectorMarkForUpgrade(ctx, sl[0], true)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
sl, err = miner.SectorsList(ctx)
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|