2020-06-01 12:49:48 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-05-27 16:06:15 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/big"
|
|
|
|
|
2020-06-01 12:49:48 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2020-08-03 16:56:59 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2021-01-13 23:11:41 +00:00
|
|
|
"github.com/filecoin-project/go-bitfield"
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2021-01-22 03:48:34 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/crypto"
|
2021-01-22 17:34:15 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/dline"
|
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"
|
2021-01-22 03:48:34 +00:00
|
|
|
proof3 "github.com/filecoin-project/specs-actors/v3/actors/runtime/proof"
|
2020-11-05 12:43:05 +00:00
|
|
|
"github.com/filecoin-project/specs-storage/storage"
|
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"
|
2021-01-22 03:48:34 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
2021-01-22 22:30:54 +00:00
|
|
|
minerActor "github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
2020-06-01 12:49:48 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
"github.com/filecoin-project/lotus/node/impl"
|
|
|
|
)
|
|
|
|
|
|
|
|
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{
|
2021-04-23 12:29:46 +00:00
|
|
|
-1, // before
|
2020-10-03 00:31:26 +00:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-01-13 23:11:41 +00:00
|
|
|
|
2020-10-03 00:15:31 +00:00
|
|
|
func testWindowPostUpgrade(t *testing.T, b APIBuilder, blocktime time.Duration, nSectors int,
|
|
|
|
upgradeHeight abi.ChainEpoch) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2021-04-26 14:48:20 +00:00
|
|
|
n, sn := b(t, []FullNodeOpts{FullNodeWithLatestActorsAt(upgradeHeight)}, OneMiner)
|
2020-10-03 00:15:31 +00:00
|
|
|
|
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-10-03 00:47:01 +00:00
|
|
|
if ctx.Err() != nil {
|
|
|
|
// context was canceled, ignore the error.
|
|
|
|
return
|
|
|
|
}
|
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-11-05 12:43:05 +00:00
|
|
|
return miner.StorageMiner.(*impl.StorageMinerAPI).IStorageMgr.(*mock.SectorMgr).MarkCorrupted(storage.SectorRef{
|
|
|
|
ID: abi.SectorID{
|
|
|
|
Miner: abi.ActorID(mid),
|
|
|
|
Number: abi.SectorNumber(sid),
|
|
|
|
},
|
2020-08-03 16:56:59 +00:00
|
|
|
}, true)
|
2020-07-23 17:23:21 +00:00
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2020-11-05 12:43:05 +00:00
|
|
|
var s storage.SectorRef
|
2020-08-03 16:56:59 +00:00
|
|
|
|
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-11-05 12:43:05 +00:00
|
|
|
s = storage.SectorRef{
|
|
|
|
ID: abi.SectorID{
|
|
|
|
Miner: abi.ActorID(mid),
|
|
|
|
Number: abi.SectorNumber(sn),
|
|
|
|
},
|
2020-08-03 16:56:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2021-01-13 23:11:41 +00:00
|
|
|
|
|
|
|
func TestTerminate(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
nSectors := uint64(2)
|
|
|
|
|
2021-04-26 14:48:20 +00:00
|
|
|
n, sn := b(t, []FullNodeOpts{FullNodeWithLatestActorsAt(-1)}, []StorageMiner{{Full: 0, Preseal: int(nSectors)}})
|
2021-01-13 23:11:41 +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)
|
|
|
|
}
|
|
|
|
build.Clock.Sleep(time.Second)
|
|
|
|
|
|
|
|
done := make(chan struct{})
|
|
|
|
go func() {
|
|
|
|
defer close(done)
|
|
|
|
for ctx.Err() == nil {
|
|
|
|
build.Clock.Sleep(blocktime)
|
|
|
|
if err := sn[0].MineOne(ctx, MineNext); err != nil {
|
|
|
|
if ctx.Err() != nil {
|
|
|
|
// context was canceled, ignore the error.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
defer func() {
|
|
|
|
cancel()
|
|
|
|
<-done
|
|
|
|
}()
|
|
|
|
|
|
|
|
maddr, err := miner.ActorAddress(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
ssz, err := miner.ActorSectorSize(ctx, maddr)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
p, err := client.StateMinerPower(ctx, maddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, p.MinerPower, p.TotalPower)
|
|
|
|
require.Equal(t, p.MinerPower.RawBytePower, types.NewInt(uint64(ssz)*nSectors))
|
|
|
|
|
|
|
|
fmt.Printf("Seal a sector\n")
|
|
|
|
|
|
|
|
pledgeSectors(t, ctx, miner, 1, 0, nil)
|
|
|
|
|
|
|
|
fmt.Printf("wait for power\n")
|
|
|
|
|
|
|
|
{
|
|
|
|
// Wait until proven.
|
|
|
|
di, err := client.StateMinerProvingDeadline(ctx, maddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
waitUntil := di.PeriodStart + di.WPoStProvingPeriod + 2
|
|
|
|
fmt.Printf("End for head.Height > %d\n", waitUntil)
|
|
|
|
|
|
|
|
for {
|
|
|
|
head, err := client.ChainHead(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
if head.Height() > waitUntil {
|
|
|
|
fmt.Printf("Now head.Height = %d\n", head.Height())
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nSectors++
|
|
|
|
|
|
|
|
p, err = client.StateMinerPower(ctx, maddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, p.MinerPower, p.TotalPower)
|
|
|
|
require.Equal(t, p.MinerPower.RawBytePower, types.NewInt(uint64(ssz)*nSectors))
|
|
|
|
|
|
|
|
fmt.Println("Terminate a sector")
|
|
|
|
|
|
|
|
toTerminate := abi.SectorNumber(3)
|
|
|
|
|
2021-01-14 11:41:27 +00:00
|
|
|
err = miner.SectorTerminate(ctx, toTerminate)
|
2021-01-13 23:11:41 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
msgTriggerred := false
|
|
|
|
loop:
|
|
|
|
for {
|
|
|
|
si, err := miner.SectorsStatus(ctx, toTerminate, false)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fmt.Println("state: ", si.State, msgTriggerred)
|
|
|
|
|
|
|
|
switch sealing.SectorState(si.State) {
|
|
|
|
case sealing.Terminating:
|
|
|
|
if !msgTriggerred {
|
2021-01-14 11:41:27 +00:00
|
|
|
{
|
|
|
|
p, err := miner.SectorTerminatePending(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, p, 1)
|
|
|
|
require.Equal(t, abi.SectorNumber(3), p[0].Number)
|
2021-01-13 23:11:41 +00:00
|
|
|
}
|
2021-01-14 11:41:27 +00:00
|
|
|
|
|
|
|
c, err := miner.SectorTerminateFlush(ctx)
|
|
|
|
require.NoError(t, err)
|
2021-01-13 23:11:41 +00:00
|
|
|
if c != nil {
|
|
|
|
msgTriggerred = true
|
|
|
|
fmt.Println("terminate message:", c)
|
2021-01-14 11:41:27 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
p, err := miner.SectorTerminatePending(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, p, 0)
|
|
|
|
}
|
2021-01-13 23:11:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
case sealing.TerminateWait, sealing.TerminateFinality, sealing.Removed:
|
|
|
|
break loop
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
}
|
|
|
|
|
|
|
|
// check power decreased
|
|
|
|
p, err = client.StateMinerPower(ctx, maddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, p.MinerPower, p.TotalPower)
|
|
|
|
require.Equal(t, p.MinerPower.RawBytePower, types.NewInt(uint64(ssz)*(nSectors-1)))
|
|
|
|
|
|
|
|
// check in terminated set
|
|
|
|
{
|
|
|
|
parts, err := client.StateMinerPartitions(ctx, maddr, 1, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Greater(t, len(parts), 0)
|
|
|
|
|
|
|
|
bflen := func(b bitfield.BitField) uint64 {
|
|
|
|
l, err := b.Count()
|
|
|
|
require.NoError(t, err)
|
|
|
|
return l
|
|
|
|
}
|
|
|
|
|
|
|
|
require.Equal(t, uint64(1), bflen(parts[0].AllSectors))
|
|
|
|
require.Equal(t, uint64(0), bflen(parts[0].LiveSectors))
|
|
|
|
}
|
|
|
|
|
|
|
|
di, err := client.StateMinerProvingDeadline(ctx, maddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
for {
|
|
|
|
head, err := client.ChainHead(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
if head.Height() > di.PeriodStart+di.WPoStProvingPeriod+2 {
|
|
|
|
fmt.Printf("Now head.Height = %d\n", head.Height())
|
|
|
|
break
|
|
|
|
}
|
|
|
|
build.Clock.Sleep(blocktime)
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
fmt.Printf("End for head.Height > %d\n", di.PeriodStart+di.WPoStProvingPeriod+2)
|
|
|
|
|
|
|
|
p, err = client.StateMinerPower(ctx, maddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, p.MinerPower, p.TotalPower)
|
|
|
|
require.Equal(t, p.MinerPower.RawBytePower, types.NewInt(uint64(ssz)*(nSectors-1)))
|
|
|
|
}
|
2021-01-22 03:48:34 +00:00
|
|
|
|
|
|
|
func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
// First, we configure two miners. After sealing, we're going to turn off the first miner so
|
|
|
|
// it doesn't submit proofs.
|
|
|
|
///
|
|
|
|
// Then we're going to manually submit bad proofs.
|
|
|
|
n, sn := b(t, []FullNodeOpts{
|
2021-05-25 19:27:32 +00:00
|
|
|
FullNodeWithV4ActorsAt(-1),
|
2021-01-22 03:48:34 +00:00
|
|
|
}, []StorageMiner{
|
|
|
|
{Full: 0, Preseal: PresealGenesis},
|
|
|
|
{Full: 0},
|
|
|
|
})
|
|
|
|
|
|
|
|
client := n[0].FullNode.(*impl.FullNodeAPI)
|
|
|
|
chainMiner := sn[0]
|
|
|
|
evilMiner := sn[1]
|
|
|
|
|
|
|
|
{
|
|
|
|
addrinfo, err := client.NetAddrsListen(ctx)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := chainMiner.NetConnect(ctx, addrinfo); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := evilMiner.NetConnect(ctx, addrinfo); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:15 +00:00
|
|
|
defaultFrom, err := client.WalletDefaultAddress(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-01-22 03:48:34 +00:00
|
|
|
build.Clock.Sleep(time.Second)
|
|
|
|
|
|
|
|
// Mine with the _second_ node (the good one).
|
|
|
|
done := make(chan struct{})
|
|
|
|
go func() {
|
|
|
|
defer close(done)
|
|
|
|
for ctx.Err() == nil {
|
|
|
|
build.Clock.Sleep(blocktime)
|
|
|
|
if err := chainMiner.MineOne(ctx, MineNext); err != nil {
|
|
|
|
if ctx.Err() != nil {
|
|
|
|
// context was canceled, ignore the error.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
defer func() {
|
|
|
|
cancel()
|
|
|
|
<-done
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Give the chain miner enough sectors to win every block.
|
|
|
|
pledgeSectors(t, ctx, chainMiner, 10, 0, nil)
|
|
|
|
// And the evil one 1 sector. No cookie for you.
|
|
|
|
pledgeSectors(t, ctx, evilMiner, 1, 0, nil)
|
|
|
|
|
|
|
|
// Let the evil miner's sectors gain power.
|
|
|
|
evilMinerAddr, err := evilMiner.ActorAddress(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
di, err := client.StateMinerProvingDeadline(ctx, evilMinerAddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fmt.Printf("Running one proving period\n")
|
|
|
|
fmt.Printf("End for head.Height > %d\n", di.PeriodStart+di.WPoStProvingPeriod*2)
|
|
|
|
|
|
|
|
for {
|
|
|
|
head, err := client.ChainHead(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
if head.Height() > di.PeriodStart+di.WPoStProvingPeriod*2 {
|
|
|
|
fmt.Printf("Now head.Height = %d\n", head.Height())
|
|
|
|
break
|
|
|
|
}
|
|
|
|
build.Clock.Sleep(blocktime)
|
|
|
|
}
|
|
|
|
|
|
|
|
p, err := client.StateMinerPower(ctx, evilMinerAddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
ssz, err := evilMiner.ActorSectorSize(ctx, evilMinerAddr)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// make sure it has gained power.
|
|
|
|
require.Equal(t, p.MinerPower.RawBytePower, types.NewInt(uint64(ssz)))
|
|
|
|
|
|
|
|
evilSectors, err := evilMiner.SectorsList(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
evilSectorNo := evilSectors[0] // only one.
|
|
|
|
evilSectorLoc, err := client.StateSectorPartition(ctx, evilMinerAddr, evilSectorNo, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fmt.Println("evil miner stopping")
|
|
|
|
|
|
|
|
// Now stop the evil miner, and start manually submitting bad proofs.
|
|
|
|
require.NoError(t, evilMiner.Stop(ctx))
|
|
|
|
|
|
|
|
fmt.Println("evil miner stopped")
|
|
|
|
|
|
|
|
// Wait until we need to prove our sector.
|
|
|
|
for {
|
|
|
|
di, err = client.StateMinerProvingDeadline(ctx, evilMinerAddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
2021-06-01 17:14:08 +00:00
|
|
|
if di.Index == evilSectorLoc.Deadline && di.CurrentEpoch-di.PeriodStart > 1 {
|
2021-01-22 03:48:34 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
build.Clock.Sleep(blocktime)
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:15 +00:00
|
|
|
err = submitBadProof(ctx, client, evilMinerAddr, di, evilSectorLoc.Deadline, evilSectorLoc.Partition)
|
|
|
|
require.NoError(t, err, "evil proof not accepted")
|
2021-01-22 03:48:34 +00:00
|
|
|
|
|
|
|
// Wait until after the proving period.
|
|
|
|
for {
|
2021-01-22 16:29:00 +00:00
|
|
|
di, err = client.StateMinerProvingDeadline(ctx, evilMinerAddr, types.EmptyTSK)
|
2021-01-22 03:48:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
if di.Index != evilSectorLoc.Deadline {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
build.Clock.Sleep(blocktime)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("accepted evil proof")
|
|
|
|
|
|
|
|
// Make sure the evil node didn't lose any power.
|
|
|
|
p, err = client.StateMinerPower(ctx, evilMinerAddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, p.MinerPower.RawBytePower, types.NewInt(uint64(ssz)))
|
|
|
|
|
|
|
|
// OBJECTION! The good miner files a DISPUTE!!!!
|
|
|
|
{
|
2021-01-22 22:30:54 +00:00
|
|
|
params := &minerActor.DisputeWindowedPoStParams{
|
2021-01-22 03:48:34 +00:00
|
|
|
Deadline: evilSectorLoc.Deadline,
|
|
|
|
PoStIndex: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
enc, aerr := actors.SerializeParams(params)
|
|
|
|
require.NoError(t, aerr)
|
|
|
|
|
|
|
|
msg := &types.Message{
|
|
|
|
To: evilMinerAddr,
|
2021-01-22 22:30:54 +00:00
|
|
|
Method: minerActor.Methods.DisputeWindowedPoSt,
|
2021-01-22 03:48:34 +00:00
|
|
|
Params: enc,
|
|
|
|
Value: types.NewInt(0),
|
2021-01-22 19:15:43 +00:00
|
|
|
From: defaultFrom,
|
2021-01-22 03:48:34 +00:00
|
|
|
}
|
|
|
|
sm, err := client.MpoolPushMessage(ctx, msg, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fmt.Println("waiting dispute")
|
2021-04-05 19:34:03 +00:00
|
|
|
rec, err := client.StateWaitMsg(ctx, sm.Cid(), build.MessageConfidence, api.LookbackNoLimit, true)
|
2021-01-22 03:48:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Zero(t, rec.Receipt.ExitCode, "dispute not accepted: %s", rec.Receipt.ExitCode.Error())
|
|
|
|
}
|
2021-01-22 16:29:00 +00:00
|
|
|
|
|
|
|
// Objection SUSTAINED!
|
|
|
|
// Make sure the evil node lost power.
|
|
|
|
p, err = client.StateMinerPower(ctx, evilMinerAddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, p.MinerPower.RawBytePower.IsZero())
|
|
|
|
|
|
|
|
// Now we begin the redemption arc.
|
|
|
|
require.True(t, p.MinerPower.RawBytePower.IsZero())
|
|
|
|
|
|
|
|
// First, recover the sector.
|
|
|
|
|
|
|
|
{
|
2021-01-22 17:34:15 +00:00
|
|
|
minerInfo, err := client.StateMinerInfo(ctx, evilMinerAddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-01-22 22:30:54 +00:00
|
|
|
params := &minerActor.DeclareFaultsRecoveredParams{
|
|
|
|
Recoveries: []minerActor.RecoveryDeclaration{{
|
2021-01-22 16:29:00 +00:00
|
|
|
Deadline: evilSectorLoc.Deadline,
|
|
|
|
Partition: evilSectorLoc.Partition,
|
|
|
|
Sectors: bitfield.NewFromSet([]uint64{uint64(evilSectorNo)}),
|
|
|
|
}},
|
|
|
|
}
|
|
|
|
|
|
|
|
enc, aerr := actors.SerializeParams(params)
|
|
|
|
require.NoError(t, aerr)
|
|
|
|
|
|
|
|
msg := &types.Message{
|
|
|
|
To: evilMinerAddr,
|
2021-01-22 22:30:54 +00:00
|
|
|
Method: minerActor.Methods.DeclareFaultsRecovered,
|
2021-01-22 16:29:00 +00:00
|
|
|
Params: enc,
|
2021-01-22 17:34:15 +00:00
|
|
|
Value: types.FromFil(30), // repay debt.
|
2021-01-22 19:15:43 +00:00
|
|
|
From: minerInfo.Owner,
|
2021-01-22 16:29:00 +00:00
|
|
|
}
|
|
|
|
sm, err := client.MpoolPushMessage(ctx, msg, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-04-05 19:34:03 +00:00
|
|
|
rec, err := client.StateWaitMsg(ctx, sm.Cid(), build.MessageConfidence, api.LookbackNoLimit, true)
|
2021-01-22 16:29:00 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Zero(t, rec.Receipt.ExitCode, "recovery not accepted: %s", rec.Receipt.ExitCode.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Then wait for the deadline.
|
|
|
|
for {
|
|
|
|
di, err = client.StateMinerProvingDeadline(ctx, evilMinerAddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
2021-06-01 17:14:08 +00:00
|
|
|
if di.Index == evilSectorLoc.Deadline && di.CurrentEpoch-di.PeriodStart > 1 {
|
2021-01-22 16:29:00 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
build.Clock.Sleep(blocktime)
|
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:15 +00:00
|
|
|
// Now try to be evil again
|
|
|
|
err = submitBadProof(ctx, client, evilMinerAddr, di, evilSectorLoc.Deadline, evilSectorLoc.Partition)
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Contains(t, err.Error(), "message execution failed: exit 16, reason: window post failed: invalid PoSt")
|
2021-01-22 16:29:00 +00:00
|
|
|
|
2021-01-22 17:34:15 +00:00
|
|
|
// It didn't work because we're recovering.
|
|
|
|
}
|
2021-01-22 16:29:00 +00:00
|
|
|
|
2021-01-22 17:34:15 +00:00
|
|
|
func submitBadProof(
|
|
|
|
ctx context.Context,
|
|
|
|
client api.FullNode, maddr address.Address,
|
|
|
|
di *dline.Info, dlIdx, partIdx uint64,
|
|
|
|
) error {
|
|
|
|
head, err := client.ChainHead(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-01-22 16:29:00 +00:00
|
|
|
|
2021-01-22 17:34:15 +00:00
|
|
|
from, err := client.WalletDefaultAddress(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-01-22 16:29:00 +00:00
|
|
|
|
2021-01-22 17:34:15 +00:00
|
|
|
minerInfo, err := client.StateMinerInfo(ctx, maddr, head.Key())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-01-22 16:29:00 +00:00
|
|
|
}
|
|
|
|
|
2021-01-22 17:34:15 +00:00
|
|
|
commEpoch := di.Open
|
|
|
|
commRand, err := client.ChainGetRandomnessFromTickets(
|
|
|
|
ctx, head.Key(), crypto.DomainSeparationTag_PoStChainCommit,
|
|
|
|
commEpoch, nil,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-01-22 22:30:54 +00:00
|
|
|
params := &minerActor.SubmitWindowedPoStParams{
|
2021-01-22 17:34:15 +00:00
|
|
|
ChainCommitEpoch: commEpoch,
|
|
|
|
ChainCommitRand: commRand,
|
|
|
|
Deadline: dlIdx,
|
2021-01-22 22:30:54 +00:00
|
|
|
Partitions: []minerActor.PoStPartition{{Index: partIdx}},
|
2021-01-22 17:34:15 +00:00
|
|
|
Proofs: []proof3.PoStProof{{
|
|
|
|
PoStProof: minerInfo.WindowPoStProofType,
|
|
|
|
ProofBytes: []byte("I'm soooo very evil."),
|
|
|
|
}},
|
|
|
|
}
|
|
|
|
|
|
|
|
enc, aerr := actors.SerializeParams(params)
|
|
|
|
if aerr != nil {
|
|
|
|
return aerr
|
|
|
|
}
|
|
|
|
|
|
|
|
msg := &types.Message{
|
|
|
|
To: maddr,
|
2021-01-22 22:30:54 +00:00
|
|
|
Method: minerActor.Methods.SubmitWindowedPoSt,
|
2021-01-22 17:34:15 +00:00
|
|
|
Params: enc,
|
|
|
|
Value: types.NewInt(0),
|
|
|
|
From: from,
|
|
|
|
}
|
|
|
|
sm, err := client.MpoolPushMessage(ctx, msg, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-04-05 19:34:03 +00:00
|
|
|
rec, err := client.StateWaitMsg(ctx, sm.Cid(), build.MessageConfidence, api.LookbackNoLimit, true)
|
2021-01-22 17:34:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if rec.Receipt.ExitCode.IsError() {
|
|
|
|
return rec.Receipt.ExitCode
|
|
|
|
}
|
|
|
|
return nil
|
2021-01-22 03:48:34 +00:00
|
|
|
}
|
2021-01-22 22:30:54 +00:00
|
|
|
|
|
|
|
func TestWindowPostDisputeFails(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2021-05-25 19:27:32 +00:00
|
|
|
n, sn := b(t, []FullNodeOpts{FullNodeWithV4ActorsAt(-1)}, OneMiner)
|
2021-01-22 22:30:54 +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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
defaultFrom, err := client.WalletDefaultAddress(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
maddr, err := miner.ActorAddress(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
build.Clock.Sleep(time.Second)
|
|
|
|
|
|
|
|
// Mine with the _second_ node (the good one).
|
|
|
|
done := make(chan struct{})
|
|
|
|
go func() {
|
|
|
|
defer close(done)
|
|
|
|
for ctx.Err() == nil {
|
|
|
|
build.Clock.Sleep(blocktime)
|
|
|
|
if err := miner.MineOne(ctx, MineNext); err != nil {
|
|
|
|
if ctx.Err() != nil {
|
|
|
|
// context was canceled, ignore the error.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
defer func() {
|
|
|
|
cancel()
|
|
|
|
<-done
|
|
|
|
}()
|
|
|
|
|
|
|
|
pledgeSectors(t, ctx, miner, 10, 0, nil)
|
|
|
|
|
|
|
|
di, err := client.StateMinerProvingDeadline(ctx, maddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
fmt.Printf("Running one proving period\n")
|
|
|
|
fmt.Printf("End for head.Height > %d\n", di.PeriodStart+di.WPoStProvingPeriod*2)
|
|
|
|
|
|
|
|
for {
|
|
|
|
head, err := client.ChainHead(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
if head.Height() > di.PeriodStart+di.WPoStProvingPeriod*2 {
|
|
|
|
fmt.Printf("Now head.Height = %d\n", head.Height())
|
|
|
|
break
|
|
|
|
}
|
|
|
|
build.Clock.Sleep(blocktime)
|
|
|
|
}
|
|
|
|
|
|
|
|
ssz, err := miner.ActorSectorSize(ctx, maddr)
|
|
|
|
require.NoError(t, err)
|
|
|
|
expectedPower := types.NewInt(uint64(ssz) * (GenesisPreseals + 10))
|
|
|
|
|
|
|
|
p, err := client.StateMinerPower(ctx, maddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// make sure it has gained power.
|
|
|
|
require.Equal(t, p.MinerPower.RawBytePower, expectedPower)
|
|
|
|
|
|
|
|
// Wait until a proof has been submitted.
|
|
|
|
var targetDeadline uint64
|
|
|
|
waitForProof:
|
|
|
|
for {
|
|
|
|
deadlines, err := client.StateMinerDeadlines(ctx, maddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
for dlIdx, dl := range deadlines {
|
|
|
|
nonEmpty, err := dl.PostSubmissions.IsEmpty()
|
|
|
|
require.NoError(t, err)
|
|
|
|
if nonEmpty {
|
|
|
|
targetDeadline = uint64(dlIdx)
|
|
|
|
break waitForProof
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
build.Clock.Sleep(blocktime)
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
|
|
|
di, err := client.StateMinerProvingDeadline(ctx, maddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
// wait until the deadline finishes.
|
|
|
|
if di.Index == ((targetDeadline + 1) % di.WPoStPeriodDeadlines) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
build.Clock.Sleep(blocktime)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to object to the proof. This should fail.
|
|
|
|
{
|
|
|
|
params := &minerActor.DisputeWindowedPoStParams{
|
|
|
|
Deadline: targetDeadline,
|
|
|
|
PoStIndex: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
enc, aerr := actors.SerializeParams(params)
|
|
|
|
require.NoError(t, aerr)
|
|
|
|
|
|
|
|
msg := &types.Message{
|
|
|
|
To: maddr,
|
|
|
|
Method: minerActor.Methods.DisputeWindowedPoSt,
|
|
|
|
Params: enc,
|
|
|
|
Value: types.NewInt(0),
|
|
|
|
From: defaultFrom,
|
|
|
|
}
|
|
|
|
_, err := client.MpoolPushMessage(ctx, msg, nil)
|
|
|
|
require.Error(t, err)
|
|
|
|
require.Contains(t, err.Error(), "failed to dispute valid post (RetCode=16)")
|
|
|
|
}
|
|
|
|
}
|
2021-05-27 16:06:15 +00:00
|
|
|
|
|
|
|
func TestWindowPostBaseFeeNoBurn(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
och := build.UpgradeClausHeight
|
|
|
|
build.UpgradeClausHeight = 10
|
|
|
|
n, sn := b(t, DefaultFullOpts(1), OneMiner)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
maddr, err := miner.ActorAddress(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
mi, err := client.StateMinerInfo(ctx, maddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
build.Clock.Sleep(time.Second)
|
|
|
|
|
|
|
|
done := make(chan struct{})
|
|
|
|
go func() {
|
|
|
|
defer close(done)
|
|
|
|
for ctx.Err() == nil {
|
|
|
|
build.Clock.Sleep(blocktime)
|
|
|
|
if err := miner.MineOne(ctx, MineNext); err != nil {
|
|
|
|
if ctx.Err() != nil {
|
|
|
|
// context was canceled, ignore the error.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
defer func() {
|
|
|
|
cancel()
|
|
|
|
<-done
|
|
|
|
}()
|
|
|
|
|
|
|
|
pledgeSectors(t, ctx, miner, 10, 0, nil)
|
|
|
|
wact, err := client.StateGetActor(ctx, mi.Worker, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
en := wact.Nonce
|
|
|
|
|
|
|
|
// wait for a new message to be sent from worker address, it will be a PoSt
|
|
|
|
|
|
|
|
waitForProof:
|
|
|
|
for {
|
|
|
|
wact, err := client.StateGetActor(ctx, mi.Worker, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
if wact.Nonce > en {
|
|
|
|
break waitForProof
|
|
|
|
}
|
|
|
|
|
|
|
|
build.Clock.Sleep(blocktime)
|
|
|
|
}
|
|
|
|
|
|
|
|
slm, err := client.StateListMessages(ctx, &api.MessageMatch{To: maddr}, types.EmptyTSK, 0)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
pmr, err := client.StateReplay(ctx, types.EmptyTSK, slm[0])
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, pmr.GasCost.BaseFeeBurn, big.Zero())
|
|
|
|
|
|
|
|
build.UpgradeClausHeight = och
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestWindowPostBaseFeeBurn(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
n, sn := b(t, []FullNodeOpts{FullNodeWithLatestActorsAt(-1)}, OneMiner)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
maddr, err := miner.ActorAddress(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
mi, err := client.StateMinerInfo(ctx, maddr, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
build.Clock.Sleep(time.Second)
|
|
|
|
|
|
|
|
done := make(chan struct{})
|
|
|
|
go func() {
|
|
|
|
defer close(done)
|
|
|
|
for ctx.Err() == nil {
|
|
|
|
build.Clock.Sleep(blocktime)
|
|
|
|
if err := miner.MineOne(ctx, MineNext); err != nil {
|
|
|
|
if ctx.Err() != nil {
|
|
|
|
// context was canceled, ignore the error.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
defer func() {
|
|
|
|
cancel()
|
|
|
|
<-done
|
|
|
|
}()
|
|
|
|
|
|
|
|
pledgeSectors(t, ctx, miner, 10, 0, nil)
|
|
|
|
wact, err := client.StateGetActor(ctx, mi.Worker, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
en := wact.Nonce
|
|
|
|
|
|
|
|
// wait for a new message to be sent from worker address, it will be a PoSt
|
|
|
|
|
|
|
|
waitForProof:
|
|
|
|
for {
|
|
|
|
wact, err := client.StateGetActor(ctx, mi.Worker, types.EmptyTSK)
|
|
|
|
require.NoError(t, err)
|
|
|
|
if wact.Nonce > en {
|
|
|
|
break waitForProof
|
|
|
|
}
|
|
|
|
|
|
|
|
build.Clock.Sleep(blocktime)
|
|
|
|
}
|
|
|
|
|
|
|
|
slm, err := client.StateListMessages(ctx, &api.MessageMatch{To: maddr}, types.EmptyTSK, 0)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
pmr, err := client.StateReplay(ctx, types.EmptyTSK, slm[0])
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.NotEqual(t, pmr.GasCost.BaseFeeBurn, big.Zero())
|
|
|
|
}
|