2020-06-01 12:49:48 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2020-07-20 18:33:15 +00:00
|
|
|
|
2020-06-01 12:49:48 +00:00
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2020-08-03 16:56:59 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2020-08-17 13:26:18 +00:00
|
|
|
"github.com/filecoin-project/lotus/extern/sector-storage/mock"
|
2020-08-17 13:39:33 +00:00
|
|
|
sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
|
2020-10-03 00:15:31 +00:00
|
|
|
"github.com/filecoin-project/lotus/node"
|
2020-06-01 12:49:48 +00:00
|
|
|
|
2020-08-03 16:56:59 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
|
|
|
"github.com/filecoin-project/lotus/build"
|
2020-10-03 00:15:31 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
2020-06-01 12:49:48 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2020-07-28 16:16:46 +00:00
|
|
|
bminer "github.com/filecoin-project/lotus/miner"
|
2020-06-01 12:49:48 +00:00
|
|
|
"github.com/filecoin-project/lotus/node/impl"
|
|
|
|
)
|
|
|
|
|
2020-08-20 04:49:10 +00:00
|
|
|
func init() {
|
|
|
|
err := os.Setenv("BELLMAN_NO_GPU", "1")
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Sprintf("failed to set BELLMAN_NO_GPU env variable: %s", err))
|
|
|
|
}
|
|
|
|
}
|
2020-06-01 12:49:48 +00:00
|
|
|
|
2020-08-20 04:49:10 +00:00
|
|
|
func TestPledgeSector(t *testing.T, b APIBuilder, blocktime time.Duration, nSectors int) {
|
2020-06-01 12:49:48 +00:00
|
|
|
ctx := context.Background()
|
2020-08-13 20:37:09 +00:00
|
|
|
n, sn := b(t, 1, OneMiner)
|
2020-06-01 12:49:48 +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)
|
|
|
|
}
|
2020-07-10 14:43:14 +00:00
|
|
|
build.Clock.Sleep(time.Second)
|
2020-06-01 12:49:48 +00:00
|
|
|
|
|
|
|
mine := true
|
|
|
|
done := make(chan struct{})
|
|
|
|
go func() {
|
|
|
|
defer close(done)
|
|
|
|
for mine {
|
2020-07-10 14:43:14 +00:00
|
|
|
build.Clock.Sleep(blocktime)
|
2020-08-27 00:51:16 +00:00
|
|
|
if err := sn[0].MineOne(ctx, bminer.MineReq{Done: func(bool, abi.ChainEpoch, error) {
|
2020-07-20 18:33:15 +00:00
|
|
|
|
2020-07-28 16:16:46 +00:00
|
|
|
}}); err != nil {
|
2020-06-01 12:49:48 +00:00
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2020-08-08 22:36:44 +00:00
|
|
|
pledgeSectors(t, ctx, miner, nSectors, 0, nil)
|
2020-06-01 12:49:48 +00:00
|
|
|
|
|
|
|
mine = false
|
|
|
|
<-done
|
|
|
|
}
|
|
|
|
|
2020-08-03 18:28:18 +00:00
|
|
|
func pledgeSectors(t *testing.T, ctx context.Context, miner TestStorageNode, n, existing int, blockNotif <-chan struct{}) {
|
2020-06-01 12:49:48 +00:00
|
|
|
for i := 0; i < n; i++ {
|
|
|
|
err := miner.PledgeSector(ctx)
|
|
|
|
require.NoError(t, err)
|
2020-07-20 18:33:15 +00:00
|
|
|
if i%3 == 0 && blockNotif != nil {
|
|
|
|
<-blockNotif
|
|
|
|
}
|
2020-06-01 12:49:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
|
|
|
s, err := miner.SectorsList(ctx) // Note - the test builder doesn't import genesis sectors into FSM
|
|
|
|
require.NoError(t, err)
|
|
|
|
fmt.Printf("Sectors: %d\n", len(s))
|
2020-08-04 17:07:31 +00:00
|
|
|
if len(s) >= n+existing {
|
2020-06-01 12:49:48 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2020-07-10 14:43:14 +00:00
|
|
|
build.Clock.Sleep(100 * time.Millisecond)
|
2020-06-01 12:49:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("All sectors is fsm\n")
|
|
|
|
|
|
|
|
s, err := miner.SectorsList(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
toCheck := map[abi.SectorNumber]struct{}{}
|
|
|
|
for _, number := range s {
|
|
|
|
toCheck[number] = struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
for len(toCheck) > 0 {
|
|
|
|
for n := range toCheck {
|
2020-07-24 08:04:04 +00:00
|
|
|
st, err := miner.SectorsStatus(ctx, n, false)
|
2020-06-01 12:49:48 +00:00
|
|
|
require.NoError(t, err)
|
2020-06-01 12:59:51 +00:00
|
|
|
if st.State == api.SectorState(sealing.Proving) {
|
2020-06-01 12:49:48 +00:00
|
|
|
delete(toCheck, n)
|
|
|
|
}
|
|
|
|
if strings.Contains(string(st.State), "Fail") {
|
|
|
|
t.Fatal("sector in a failed state", st.State)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-10 14:43:14 +00:00
|
|
|
build.Clock.Sleep(100 * time.Millisecond)
|
2020-06-01 12:49:48 +00:00
|
|
|
fmt.Printf("WaitSeal: %d\n", len(s))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestWindowPost(t *testing.T, b APIBuilder, blocktime time.Duration, nSectors int) {
|
2020-10-03 00:15:31 +00:00
|
|
|
for _, height := range []abi.ChainEpoch{
|
2020-10-03 00:31:26 +00:00
|
|
|
1, // before
|
|
|
|
162, // while sealing
|
|
|
|
5000, // while proving
|
2020-10-03 00:15:31 +00:00
|
|
|
} {
|
2020-10-03 00:45:01 +00:00
|
|
|
height := height // copy to satisfy lints
|
2020-10-03 00:15:31 +00:00
|
|
|
t.Run(fmt.Sprintf("upgrade-%d", height), func(t *testing.T) {
|
|
|
|
testWindowPostUpgrade(t, b, blocktime, nSectors, height)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
func testWindowPostUpgrade(t *testing.T, b APIBuilder, blocktime time.Duration, nSectors int,
|
|
|
|
upgradeHeight abi.ChainEpoch) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
n, sn := b(t, 1, OneMiner, node.Override(new(stmgr.UpgradeSchedule), stmgr.UpgradeSchedule{{
|
|
|
|
Network: build.ActorUpgradeNetworkVersion,
|
|
|
|
Height: upgradeHeight,
|
|
|
|
Migration: stmgr.UpgradeActorsV2,
|
|
|
|
}}))
|
|
|
|
|
2020-06-01 12:49:48 +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)
|
|
|
|
}
|
2020-07-10 14:43:14 +00:00
|
|
|
build.Clock.Sleep(time.Second)
|
2020-06-01 12:49:48 +00:00
|
|
|
|
|
|
|
done := make(chan struct{})
|
|
|
|
go func() {
|
|
|
|
defer close(done)
|
2020-10-03 00:15:31 +00:00
|
|
|
for ctx.Err() == nil {
|
2020-07-10 14:43:14 +00:00
|
|
|
build.Clock.Sleep(blocktime)
|
2020-07-28 16:16:46 +00:00
|
|
|
if err := sn[0].MineOne(ctx, MineNext); err != nil {
|
2020-06-01 12:49:48 +00:00
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
2020-10-03 00:15:31 +00:00
|
|
|
defer func() {
|
|
|
|
cancel()
|
|
|
|
<-done
|
|
|
|
}()
|
2020-06-01 12:49:48 +00:00
|
|
|
|
2020-08-03 18:28:18 +00:00
|
|
|
pledgeSectors(t, ctx, miner, nSectors, 0, nil)
|
2020-06-01 12:49:48 +00:00
|
|
|
|
|
|
|
maddr, err := miner.ActorAddress(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
di, err := client.StateMinerProvingDeadline(ctx, maddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-08-03 16:56:59 +00:00
|
|
|
mid, err := address.IDFromAddress(maddr)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fmt.Printf("Running one proving period\n")
|
2020-09-26 09:30:58 +00:00
|
|
|
fmt.Printf("End for head.Height > %d\n", di.PeriodStart+di.WPoStProvingPeriod+2)
|
2020-06-01 12:49:48 +00:00
|
|
|
|
|
|
|
for {
|
|
|
|
head, err := client.ChainHead(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-10-03 00:15:31 +00:00
|
|
|
if head.Height() > di.PeriodStart+di.WPoStProvingPeriod+2 {
|
2020-09-26 09:30:58 +00:00
|
|
|
fmt.Printf("Now head.Height = %d\n", head.Height())
|
2020-06-01 12:49:48 +00:00
|
|
|
break
|
|
|
|
}
|
2020-07-10 14:43:14 +00:00
|
|
|
build.Clock.Sleep(blocktime)
|
2020-06-01 12:49:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p, err := client.StateMinerPower(ctx, maddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
ssz, err := miner.ActorSectorSize(ctx, maddr)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, p.MinerPower, p.TotalPower)
|
2020-06-01 18:11:55 +00:00
|
|
|
require.Equal(t, p.MinerPower.RawBytePower, types.NewInt(uint64(ssz)*uint64(nSectors+GenesisPreseals)))
|
2020-06-01 12:49:48 +00:00
|
|
|
|
2020-08-03 16:56:59 +00:00
|
|
|
fmt.Printf("Drop some sectors\n")
|
|
|
|
|
2020-07-23 17:23:21 +00:00
|
|
|
// Drop 2 sectors from deadline 2 partition 0 (full partition / deadline)
|
|
|
|
{
|
|
|
|
parts, err := client.StateMinerPartitions(ctx, maddr, 2, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Greater(t, len(parts), 0)
|
|
|
|
|
2020-09-17 15:30:15 +00:00
|
|
|
secs := parts[0].AllSectors
|
2020-09-16 21:20:25 +00:00
|
|
|
n, err := secs.Count()
|
2020-07-23 17:23:21 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, uint64(2), n)
|
|
|
|
|
|
|
|
// Drop the partition
|
2020-09-16 21:20:25 +00:00
|
|
|
err = secs.ForEach(func(sid uint64) error {
|
2020-09-10 00:59:37 +00:00
|
|
|
return miner.StorageMiner.(*impl.StorageMinerAPI).IStorageMgr.(*mock.SectorMgr).MarkCorrupted(abi.SectorID{
|
2020-08-03 16:56:59 +00:00
|
|
|
Miner: abi.ActorID(mid),
|
|
|
|
Number: abi.SectorNumber(sid),
|
|
|
|
}, true)
|
2020-07-23 17:23:21 +00:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2020-08-03 16:56:59 +00:00
|
|
|
var s abi.SectorID
|
|
|
|
|
2020-07-23 17:23:21 +00:00
|
|
|
// Drop 1 sectors from deadline 3 partition 0
|
|
|
|
{
|
|
|
|
parts, err := client.StateMinerPartitions(ctx, maddr, 3, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Greater(t, len(parts), 0)
|
|
|
|
|
2020-09-17 15:30:15 +00:00
|
|
|
secs := parts[0].AllSectors
|
2020-09-16 21:20:25 +00:00
|
|
|
n, err := secs.Count()
|
2020-07-23 17:23:21 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, uint64(2), n)
|
|
|
|
|
|
|
|
// Drop the sector
|
2020-09-16 21:20:25 +00:00
|
|
|
sn, err := secs.First()
|
2020-07-23 17:23:21 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-09-16 21:20:25 +00:00
|
|
|
all, err := secs.All(2)
|
2020-08-26 02:53:21 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
fmt.Println("the sectors", all)
|
|
|
|
|
2020-08-03 16:56:59 +00:00
|
|
|
s = abi.SectorID{
|
|
|
|
Miner: abi.ActorID(mid),
|
|
|
|
Number: abi.SectorNumber(sn),
|
|
|
|
}
|
|
|
|
|
|
|
|
err = miner.StorageMiner.(*impl.StorageMinerAPI).IStorageMgr.(*mock.SectorMgr).MarkFailed(s, true)
|
2020-07-23 17:23:21 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
di, err = client.StateMinerProvingDeadline(ctx, maddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-08-03 16:56:59 +00:00
|
|
|
fmt.Printf("Go through another PP, wait for sectors to become faulty\n")
|
2020-09-26 09:30:58 +00:00
|
|
|
fmt.Printf("End for head.Height > %d\n", di.PeriodStart+di.WPoStProvingPeriod+2)
|
2020-08-03 16:56:59 +00:00
|
|
|
|
2020-07-23 17:23:21 +00:00
|
|
|
for {
|
|
|
|
head, err := client.ChainHead(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-09-17 21:53:57 +00:00
|
|
|
if head.Height() > di.PeriodStart+(di.WPoStProvingPeriod)+2 {
|
2020-09-26 09:30:58 +00:00
|
|
|
fmt.Printf("Now head.Height = %d\n", head.Height())
|
2020-07-23 17:23:21 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
build.Clock.Sleep(blocktime)
|
|
|
|
}
|
|
|
|
|
|
|
|
p, err = client.StateMinerPower(ctx, maddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, p.MinerPower, p.TotalPower)
|
|
|
|
|
|
|
|
sectors := p.MinerPower.RawBytePower.Uint64() / uint64(ssz)
|
2020-07-27 11:23:55 +00:00
|
|
|
require.Equal(t, nSectors+GenesisPreseals-3, int(sectors)) // -3 just removed sectors
|
2020-06-01 12:49:48 +00:00
|
|
|
|
2020-08-03 16:56:59 +00:00
|
|
|
fmt.Printf("Recover one sector\n")
|
|
|
|
|
|
|
|
err = miner.StorageMiner.(*impl.StorageMinerAPI).IStorageMgr.(*mock.SectorMgr).MarkFailed(s, false)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
di, err = client.StateMinerProvingDeadline(ctx, maddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-09-26 09:30:58 +00:00
|
|
|
fmt.Printf("End for head.Height > %d\n", di.PeriodStart+di.WPoStProvingPeriod+2)
|
|
|
|
|
2020-08-03 16:56:59 +00:00
|
|
|
for {
|
|
|
|
head, err := client.ChainHead(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-09-17 21:53:57 +00:00
|
|
|
if head.Height() > di.PeriodStart+di.WPoStProvingPeriod+2 {
|
2020-09-26 09:30:58 +00:00
|
|
|
fmt.Printf("Now head.Height = %d\n", head.Height())
|
2020-08-03 16:56:59 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
build.Clock.Sleep(blocktime)
|
|
|
|
}
|
|
|
|
|
|
|
|
p, err = client.StateMinerPower(ctx, maddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, p.MinerPower, p.TotalPower)
|
|
|
|
|
|
|
|
sectors = p.MinerPower.RawBytePower.Uint64() / uint64(ssz)
|
|
|
|
require.Equal(t, nSectors+GenesisPreseals-2, int(sectors)) // -2 not recovered sectors
|
|
|
|
|
2020-08-03 18:28:18 +00:00
|
|
|
// pledge a sector after recovery
|
|
|
|
|
|
|
|
pledgeSectors(t, ctx, miner, 1, nSectors, nil)
|
|
|
|
|
|
|
|
{
|
2020-10-03 00:15:31 +00:00
|
|
|
// Wait until proven.
|
|
|
|
di, err = client.StateMinerProvingDeadline(ctx, maddr, types.EmptyTSK)
|
2020-08-03 18:28:18 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-10-03 00:15:31 +00:00
|
|
|
waitUntil := di.PeriodStart + di.WPoStProvingPeriod + 2
|
2020-09-26 09:30:58 +00:00
|
|
|
fmt.Printf("End for head.Height > %d\n", waitUntil)
|
2020-08-03 18:28:18 +00:00
|
|
|
|
|
|
|
for {
|
|
|
|
head, err := client.ChainHead(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
if head.Height() > waitUntil {
|
2020-09-26 09:30:58 +00:00
|
|
|
fmt.Printf("Now head.Height = %d\n", head.Height())
|
2020-08-03 18:28:18 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p, err = client.StateMinerPower(ctx, maddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, p.MinerPower, p.TotalPower)
|
|
|
|
|
|
|
|
sectors = p.MinerPower.RawBytePower.Uint64() / uint64(ssz)
|
|
|
|
require.Equal(t, nSectors+GenesisPreseals-2+1, int(sectors)) // -2 not recovered sectors + 1 just pledged
|
2020-06-01 12:49:48 +00:00
|
|
|
}
|