2022-08-29 14:25:30 +00:00
|
|
|
// stm: #unit
|
2021-06-09 15:18:09 +00:00
|
|
|
package sealing_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"sort"
|
|
|
|
"sync"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/golang/mock/gomock"
|
2022-06-16 11:15:49 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2021-06-09 15:18:09 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/go-state-types/big"
|
2022-09-06 15:49:29 +00:00
|
|
|
minertypes "github.com/filecoin-project/go-state-types/builtin/v9/miner"
|
2022-06-16 11:15:49 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/crypto"
|
2021-06-09 15:18:09 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/network"
|
2022-06-14 15:00:51 +00:00
|
|
|
prooftypes "github.com/filecoin-project/go-state-types/proof"
|
|
|
|
miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner"
|
|
|
|
|
2021-06-09 15:18:09 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2021-07-01 11:33:54 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2022-08-09 11:30:34 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/ctladdr"
|
2022-06-14 18:31:17 +00:00
|
|
|
pipeline "github.com/filecoin-project/lotus/storage/pipeline"
|
2022-06-14 17:41:59 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/pipeline/mocks"
|
2022-06-15 10:06:22 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/pipeline/sealiface"
|
2022-06-17 11:52:19 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/sealer/storiface"
|
2021-06-09 15:18:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCommitBatcher(t *testing.T) {
|
2021-12-10 15:08:25 +00:00
|
|
|
//stm: @CHAIN_STATE_MINER_PRE_COM_INFO_001, @CHAIN_STATE_MINER_INFO_001, @CHAIN_STATE_NETWORK_VERSION_001
|
2021-06-09 15:18:09 +00:00
|
|
|
t0123, err := address.NewFromString("t0123")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2022-08-09 10:57:20 +00:00
|
|
|
as := asel(func(ctx context.Context, mi api.MinerInfo, use api.AddrUse, goodFunds, minFunds abi.TokenAmount) (address.Address, abi.TokenAmount, error) {
|
2021-06-09 15:18:09 +00:00
|
|
|
return t0123, big.Zero(), nil
|
2022-08-09 10:57:20 +00:00
|
|
|
})
|
2021-06-09 15:18:09 +00:00
|
|
|
|
|
|
|
maxBatch := miner5.MaxAggregatedSectors
|
|
|
|
minBatch := miner5.MinAggregatedSectors
|
|
|
|
|
2022-06-14 18:31:17 +00:00
|
|
|
cfg := func() (sealiface.Config, error) {
|
|
|
|
return sealiface.Config{
|
2021-06-09 15:18:09 +00:00
|
|
|
MaxWaitDealsSectors: 2,
|
|
|
|
MaxSealingSectors: 0,
|
|
|
|
MaxSealingSectorsForDeals: 0,
|
|
|
|
WaitDealsDelay: time.Hour * 6,
|
|
|
|
AlwaysKeepUnsealedCopy: true,
|
|
|
|
|
|
|
|
BatchPreCommits: true,
|
|
|
|
MaxPreCommitBatch: miner5.PreCommitSectorBatchMaxSize,
|
|
|
|
PreCommitBatchWait: 24 * time.Hour,
|
|
|
|
PreCommitBatchSlack: 3 * time.Hour,
|
|
|
|
|
|
|
|
AggregateCommits: true,
|
|
|
|
MinCommitBatch: minBatch,
|
|
|
|
MaxCommitBatch: maxBatch,
|
|
|
|
CommitBatchWait: 24 * time.Hour,
|
|
|
|
CommitBatchSlack: 1 * time.Hour,
|
|
|
|
|
2021-10-01 01:23:39 +00:00
|
|
|
AggregateAboveBaseFee: types.BigMul(types.PicoFil, types.NewInt(150)), // 0.15 nFIL
|
|
|
|
BatchPreCommitAboveBaseFee: types.BigMul(types.PicoFil, types.NewInt(150)), // 0.15 nFIL
|
2021-07-01 11:33:54 +00:00
|
|
|
|
2021-06-09 15:18:09 +00:00
|
|
|
TerminateBatchMin: 1,
|
|
|
|
TerminateBatchMax: 100,
|
|
|
|
TerminateBatchWait: 5 * time.Minute,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type promise func(t *testing.T)
|
2022-06-14 18:31:17 +00:00
|
|
|
type action func(t *testing.T, s *mocks.MockCommitBatcherApi, pcb *pipeline.CommitBatcher) promise
|
2021-06-09 15:18:09 +00:00
|
|
|
|
|
|
|
actions := func(as ...action) action {
|
2022-06-14 18:31:17 +00:00
|
|
|
return func(t *testing.T, s *mocks.MockCommitBatcherApi, pcb *pipeline.CommitBatcher) promise {
|
2021-06-09 15:18:09 +00:00
|
|
|
var ps []promise
|
|
|
|
for _, a := range as {
|
|
|
|
p := a(t, s, pcb)
|
|
|
|
if p != nil {
|
|
|
|
ps = append(ps, p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(ps) > 0 {
|
|
|
|
return func(t *testing.T) {
|
|
|
|
for _, p := range ps {
|
|
|
|
p(t)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-16 12:00:37 +00:00
|
|
|
addSector := func(sn abi.SectorNumber, aboveBalancer bool) action {
|
2022-06-14 18:31:17 +00:00
|
|
|
return func(t *testing.T, s *mocks.MockCommitBatcherApi, pcb *pipeline.CommitBatcher) promise {
|
|
|
|
var pcres sealiface.CommitBatchRes
|
2021-06-09 15:18:09 +00:00
|
|
|
var pcerr error
|
|
|
|
done := sync.Mutex{}
|
|
|
|
done.Lock()
|
|
|
|
|
2022-06-14 18:31:17 +00:00
|
|
|
si := pipeline.SectorInfo{
|
2021-06-09 15:18:09 +00:00
|
|
|
SectorNumber: sn,
|
|
|
|
}
|
|
|
|
|
2022-06-16 12:00:37 +00:00
|
|
|
basefee := types.PicoFil
|
|
|
|
if aboveBalancer {
|
|
|
|
basefee = types.NanoFil
|
|
|
|
}
|
|
|
|
|
|
|
|
s.EXPECT().ChainHead(gomock.Any()).Return(makeBFTs(t, basefee, 1), nil)
|
2021-06-09 15:18:09 +00:00
|
|
|
s.EXPECT().StateNetworkVersion(gomock.Any(), gomock.Any()).Return(network.Version13, nil)
|
2022-04-20 21:34:28 +00:00
|
|
|
s.EXPECT().StateSectorPreCommitInfo(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&minertypes.SectorPreCommitOnChainInfo{
|
2021-06-09 15:18:09 +00:00
|
|
|
PreCommitDeposit: big.Zero(),
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
defer done.Unlock()
|
2022-06-14 18:31:17 +00:00
|
|
|
pcres, pcerr = pcb.AddCommit(ctx, si, pipeline.AggregateInput{
|
2022-04-20 21:34:28 +00:00
|
|
|
Info: prooftypes.AggregateSealVerifyInfo{
|
2021-06-09 15:18:09 +00:00
|
|
|
Number: sn,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}()
|
|
|
|
|
|
|
|
return func(t *testing.T) {
|
|
|
|
done.Lock()
|
|
|
|
require.NoError(t, pcerr)
|
|
|
|
require.Empty(t, pcres.Error)
|
|
|
|
require.Contains(t, pcres.Sectors, si.SectorNumber)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-16 12:00:37 +00:00
|
|
|
addSectors := func(sectors []abi.SectorNumber, aboveBalancer bool) action {
|
2021-06-09 15:18:09 +00:00
|
|
|
as := make([]action, len(sectors))
|
|
|
|
for i, sector := range sectors {
|
2022-06-16 12:00:37 +00:00
|
|
|
as[i] = addSector(sector, aboveBalancer)
|
2021-06-09 15:18:09 +00:00
|
|
|
}
|
|
|
|
return actions(as...)
|
|
|
|
}
|
|
|
|
|
|
|
|
waitPending := func(n int) action {
|
2022-06-14 18:31:17 +00:00
|
|
|
return func(t *testing.T, s *mocks.MockCommitBatcherApi, pcb *pipeline.CommitBatcher) promise {
|
2021-06-09 15:18:09 +00:00
|
|
|
require.Eventually(t, func() bool {
|
|
|
|
p, err := pcb.Pending(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return len(p) == n
|
|
|
|
}, time.Second*5, 10*time.Millisecond)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-10 15:08:25 +00:00
|
|
|
//stm: @CHAIN_STATE_MINER_INFO_001, @CHAIN_STATE_NETWORK_VERSION_001, @CHAIN_STATE_MINER_GET_COLLATERAL_001
|
2021-07-01 11:51:11 +00:00
|
|
|
expectSend := func(expect []abi.SectorNumber, aboveBalancer, failOnePCI bool) action {
|
2022-06-14 18:31:17 +00:00
|
|
|
return func(t *testing.T, s *mocks.MockCommitBatcherApi, pcb *pipeline.CommitBatcher) promise {
|
2022-05-15 19:26:52 +00:00
|
|
|
s.EXPECT().StateMinerInfo(gomock.Any(), gomock.Any(), gomock.Any()).Return(api.MinerInfo{Owner: t0123, Worker: t0123}, nil)
|
2021-06-09 15:18:09 +00:00
|
|
|
|
|
|
|
ti := len(expect)
|
|
|
|
batch := false
|
|
|
|
if ti >= minBatch {
|
|
|
|
batch = true
|
|
|
|
ti = 1
|
|
|
|
}
|
2021-07-01 11:33:54 +00:00
|
|
|
|
|
|
|
basefee := types.PicoFil
|
|
|
|
if aboveBalancer {
|
|
|
|
basefee = types.NanoFil
|
|
|
|
}
|
|
|
|
|
2022-06-16 12:00:37 +00:00
|
|
|
s.EXPECT().ChainHead(gomock.Any()).Return(makeBFTs(t, basefee, 1), nil)
|
|
|
|
/*if batch {
|
2021-07-01 11:33:54 +00:00
|
|
|
s.EXPECT().ChainBaseFee(gomock.Any(), gomock.Any()).Return(basefee, nil)
|
2022-06-16 12:00:37 +00:00
|
|
|
}*/
|
2021-07-01 11:33:54 +00:00
|
|
|
|
|
|
|
if !aboveBalancer {
|
|
|
|
batch = false
|
|
|
|
ti = len(expect)
|
|
|
|
}
|
|
|
|
|
2022-06-16 12:00:37 +00:00
|
|
|
s.EXPECT().ChainHead(gomock.Any()).Return(makeBFTs(t, basefee, 1), nil)
|
2021-07-01 11:51:11 +00:00
|
|
|
|
|
|
|
pciC := len(expect)
|
|
|
|
if failOnePCI {
|
|
|
|
s.EXPECT().StateSectorPreCommitInfo(gomock.Any(), gomock.Any(), abi.SectorNumber(1), gomock.Any()).Return(nil, nil).Times(1) // not found
|
|
|
|
pciC = len(expect) - 1
|
|
|
|
if !batch {
|
|
|
|
ti--
|
|
|
|
}
|
|
|
|
}
|
2022-04-20 21:34:28 +00:00
|
|
|
s.EXPECT().StateSectorPreCommitInfo(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&minertypes.SectorPreCommitOnChainInfo{
|
2021-06-09 15:18:09 +00:00
|
|
|
PreCommitDeposit: big.Zero(),
|
2021-07-01 11:51:11 +00:00
|
|
|
}, nil).Times(pciC)
|
|
|
|
s.EXPECT().StateMinerInitialPledgeCollateral(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(big.Zero(), nil).Times(pciC)
|
|
|
|
|
2021-06-09 15:18:09 +00:00
|
|
|
if batch {
|
|
|
|
s.EXPECT().StateNetworkVersion(gomock.Any(), gomock.Any()).Return(network.Version13, nil)
|
2023-04-19 22:44:32 +00:00
|
|
|
s.EXPECT().GasEstimateMessageGas(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&types.Message{GasLimit: 100000}, nil)
|
2021-06-09 15:18:09 +00:00
|
|
|
}
|
|
|
|
|
2022-06-16 13:50:41 +00:00
|
|
|
s.EXPECT().MpoolPushMessage(gomock.Any(), funMatcher(func(i interface{}) bool {
|
|
|
|
b := i.(*types.Message)
|
2021-06-09 15:18:09 +00:00
|
|
|
if batch {
|
|
|
|
var params miner5.ProveCommitAggregateParams
|
2022-06-16 13:50:41 +00:00
|
|
|
require.NoError(t, params.UnmarshalCBOR(bytes.NewReader(b.Params)))
|
2021-06-09 15:18:09 +00:00
|
|
|
for _, number := range expect {
|
|
|
|
set, err := params.SectorNumbers.IsSet(uint64(number))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, set)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var params miner5.ProveCommitSectorParams
|
2022-06-16 13:50:41 +00:00
|
|
|
require.NoError(t, params.UnmarshalCBOR(bytes.NewReader(b.Params)))
|
2021-06-09 15:18:09 +00:00
|
|
|
}
|
|
|
|
return true
|
2022-06-16 13:50:41 +00:00
|
|
|
}), gomock.Any()).Return(dummySmsg, nil).Times(ti)
|
2021-06-09 15:18:09 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-19 22:44:32 +00:00
|
|
|
expectProcessBatch := func(expect []abi.SectorNumber, aboveBalancer, failOnePCI bool, gasOverLimit bool) action {
|
|
|
|
return func(t *testing.T, s *mocks.MockCommitBatcherApi, pcb *pipeline.CommitBatcher) promise {
|
|
|
|
s.EXPECT().StateMinerInfo(gomock.Any(), gomock.Any(), gomock.Any()).Return(api.MinerInfo{Owner: t0123, Worker: t0123}, nil)
|
|
|
|
|
|
|
|
ti := len(expect)
|
|
|
|
batch := false
|
|
|
|
if ti >= minBatch {
|
|
|
|
batch = true
|
|
|
|
ti = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if !aboveBalancer {
|
|
|
|
batch = false
|
|
|
|
ti = len(expect)
|
|
|
|
}
|
|
|
|
|
|
|
|
pciC := len(expect)
|
|
|
|
if failOnePCI {
|
|
|
|
s.EXPECT().StateSectorPreCommitInfo(gomock.Any(), gomock.Any(), abi.SectorNumber(1), gomock.Any()).Return(nil, nil).Times(1) // not found
|
|
|
|
pciC = len(expect) - 1
|
|
|
|
if !batch {
|
|
|
|
ti--
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.EXPECT().StateSectorPreCommitInfo(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&minertypes.SectorPreCommitOnChainInfo{
|
|
|
|
PreCommitDeposit: big.Zero(),
|
|
|
|
}, nil).Times(pciC)
|
|
|
|
s.EXPECT().StateMinerInitialPledgeCollateral(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(big.Zero(), nil).Times(pciC)
|
|
|
|
|
|
|
|
if batch {
|
|
|
|
s.EXPECT().StateNetworkVersion(gomock.Any(), gomock.Any()).Return(network.Version18, nil)
|
|
|
|
if gasOverLimit {
|
|
|
|
s.EXPECT().GasEstimateMessageGas(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, &api.ErrOutOfGas{})
|
|
|
|
} else {
|
|
|
|
s.EXPECT().GasEstimateMessageGas(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&types.Message{GasLimit: 100000}, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-01 11:51:11 +00:00
|
|
|
flush := func(expect []abi.SectorNumber, aboveBalancer, failOnePCI bool) action {
|
2022-06-14 18:31:17 +00:00
|
|
|
return func(t *testing.T, s *mocks.MockCommitBatcherApi, pcb *pipeline.CommitBatcher) promise {
|
2021-07-01 11:51:11 +00:00
|
|
|
_ = expectSend(expect, aboveBalancer, failOnePCI)(t, s, pcb)
|
2021-06-09 15:18:09 +00:00
|
|
|
|
2021-07-01 11:33:54 +00:00
|
|
|
batch := len(expect) >= minBatch && aboveBalancer
|
2021-06-09 15:18:09 +00:00
|
|
|
|
|
|
|
r, err := pcb.Flush(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
if batch {
|
|
|
|
require.Len(t, r, 1)
|
|
|
|
require.Empty(t, r[0].Error)
|
|
|
|
sort.Slice(r[0].Sectors, func(i, j int) bool {
|
|
|
|
return r[0].Sectors[i] < r[0].Sectors[j]
|
|
|
|
})
|
|
|
|
require.Equal(t, expect, r[0].Sectors)
|
2021-07-01 11:51:11 +00:00
|
|
|
if !failOnePCI {
|
|
|
|
require.Len(t, r[0].FailedSectors, 0)
|
|
|
|
} else {
|
|
|
|
require.Len(t, r[0].FailedSectors, 1)
|
|
|
|
_, found := r[0].FailedSectors[1]
|
|
|
|
require.True(t, found)
|
|
|
|
}
|
2021-06-09 15:18:09 +00:00
|
|
|
} else {
|
|
|
|
require.Len(t, r, len(expect))
|
|
|
|
for _, res := range r {
|
|
|
|
require.Len(t, res.Sectors, 1)
|
|
|
|
require.Empty(t, res.Error)
|
|
|
|
}
|
|
|
|
sort.Slice(r, func(i, j int) bool {
|
|
|
|
return r[i].Sectors[0] < r[j].Sectors[0]
|
|
|
|
})
|
|
|
|
for i, res := range r {
|
|
|
|
require.Equal(t, abi.SectorNumber(i), res.Sectors[0])
|
2021-07-01 11:51:11 +00:00
|
|
|
if failOnePCI && res.Sectors[0] == 1 {
|
|
|
|
require.Len(t, res.FailedSectors, 1)
|
|
|
|
_, found := res.FailedSectors[1]
|
|
|
|
require.True(t, found)
|
|
|
|
} else {
|
|
|
|
require.Empty(t, res.FailedSectors)
|
|
|
|
}
|
2021-06-09 15:18:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getSectors := func(n int) []abi.SectorNumber {
|
|
|
|
out := make([]abi.SectorNumber, n)
|
|
|
|
for i := range out {
|
|
|
|
out[i] = abi.SectorNumber(i)
|
|
|
|
}
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
|
|
|
tcs := map[string]struct {
|
|
|
|
actions []action
|
|
|
|
}{
|
2021-07-01 11:33:54 +00:00
|
|
|
"addSingle-aboveBalancer": {
|
|
|
|
actions: []action{
|
2022-06-16 12:00:37 +00:00
|
|
|
addSector(0, true),
|
2021-07-01 11:33:54 +00:00
|
|
|
waitPending(1),
|
2021-07-01 11:51:11 +00:00
|
|
|
flush([]abi.SectorNumber{0}, true, false),
|
2021-07-01 11:33:54 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
"addTwo-aboveBalancer": {
|
|
|
|
actions: []action{
|
2022-06-16 12:00:37 +00:00
|
|
|
addSectors(getSectors(2), true),
|
2021-07-01 11:33:54 +00:00
|
|
|
waitPending(2),
|
2021-07-01 11:51:11 +00:00
|
|
|
flush(getSectors(2), true, false),
|
2021-07-01 11:33:54 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
"addAte-aboveBalancer": {
|
|
|
|
actions: []action{
|
2022-06-16 12:00:37 +00:00
|
|
|
addSectors(getSectors(8), true),
|
2021-07-01 11:33:54 +00:00
|
|
|
waitPending(8),
|
2021-07-01 11:51:11 +00:00
|
|
|
flush(getSectors(8), true, false),
|
2021-07-01 11:33:54 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
"addMax-aboveBalancer": {
|
|
|
|
actions: []action{
|
2021-07-01 11:51:11 +00:00
|
|
|
expectSend(getSectors(maxBatch), true, false),
|
2022-06-16 12:00:37 +00:00
|
|
|
addSectors(getSectors(maxBatch), true),
|
2021-07-01 11:33:54 +00:00
|
|
|
},
|
|
|
|
},
|
2023-04-19 22:44:32 +00:00
|
|
|
"addMax-aboveBalancer-gasAboveLimit": {
|
|
|
|
actions: []action{
|
|
|
|
expectProcessBatch(getSectors(maxBatch), true, false, true),
|
|
|
|
expectSend(getSectors(maxBatch)[:maxBatch/2], true, false),
|
|
|
|
expectSend(getSectors(maxBatch)[maxBatch/2:], true, false),
|
|
|
|
addSectors(getSectors(maxBatch), true),
|
|
|
|
},
|
|
|
|
},
|
2021-07-01 11:33:54 +00:00
|
|
|
"addSingle-belowBalancer": {
|
2021-06-09 15:18:09 +00:00
|
|
|
actions: []action{
|
2022-06-16 12:00:37 +00:00
|
|
|
addSector(0, false),
|
2021-06-09 15:18:09 +00:00
|
|
|
waitPending(1),
|
2021-07-01 11:51:11 +00:00
|
|
|
flush([]abi.SectorNumber{0}, false, false),
|
2021-06-09 15:18:09 +00:00
|
|
|
},
|
|
|
|
},
|
2021-07-01 11:33:54 +00:00
|
|
|
"addTwo-belowBalancer": {
|
2021-06-09 15:18:09 +00:00
|
|
|
actions: []action{
|
2022-06-16 12:00:37 +00:00
|
|
|
addSectors(getSectors(2), false),
|
2021-06-09 15:18:09 +00:00
|
|
|
waitPending(2),
|
2021-07-01 11:51:11 +00:00
|
|
|
flush(getSectors(2), false, false),
|
2021-06-09 15:18:09 +00:00
|
|
|
},
|
|
|
|
},
|
2021-07-01 11:33:54 +00:00
|
|
|
"addAte-belowBalancer": {
|
2021-06-09 15:18:09 +00:00
|
|
|
actions: []action{
|
2022-06-16 12:00:37 +00:00
|
|
|
addSectors(getSectors(8), false),
|
2021-06-09 15:18:09 +00:00
|
|
|
waitPending(8),
|
2021-07-01 11:51:11 +00:00
|
|
|
flush(getSectors(8), false, false),
|
2021-06-09 15:18:09 +00:00
|
|
|
},
|
|
|
|
},
|
2021-07-01 11:33:54 +00:00
|
|
|
"addMax-belowBalancer": {
|
2021-06-09 15:18:09 +00:00
|
|
|
actions: []action{
|
2021-07-01 11:51:11 +00:00
|
|
|
expectSend(getSectors(maxBatch), false, false),
|
2022-06-16 12:00:37 +00:00
|
|
|
addSectors(getSectors(maxBatch), false),
|
2021-06-09 15:18:09 +00:00
|
|
|
},
|
|
|
|
},
|
2021-07-01 11:51:11 +00:00
|
|
|
|
|
|
|
"addAte-aboveBalancer-failOne": {
|
|
|
|
actions: []action{
|
2022-06-16 12:00:37 +00:00
|
|
|
addSectors(getSectors(8), true),
|
2021-07-01 11:51:11 +00:00
|
|
|
waitPending(8),
|
|
|
|
flush(getSectors(8), true, true),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"addAte-belowBalancer-failOne": {
|
|
|
|
actions: []action{
|
2022-06-16 12:00:37 +00:00
|
|
|
addSectors(getSectors(8), false),
|
2021-07-01 11:51:11 +00:00
|
|
|
waitPending(8),
|
|
|
|
flush(getSectors(8), false, true),
|
|
|
|
},
|
|
|
|
},
|
2021-06-09 15:18:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range tcs {
|
|
|
|
tc := tc
|
|
|
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
// create go mock controller here
|
|
|
|
mockCtrl := gomock.NewController(t)
|
|
|
|
// when test is done, assert expectations on all mock objects.
|
|
|
|
defer mockCtrl.Finish()
|
|
|
|
|
|
|
|
// create them mocks
|
|
|
|
pcapi := mocks.NewMockCommitBatcherApi(mockCtrl)
|
|
|
|
|
2022-06-14 18:31:17 +00:00
|
|
|
pcb := pipeline.NewCommitBatcher(ctx, t0123, pcapi, as, fc, cfg, &fakeProver{})
|
2021-06-09 15:18:09 +00:00
|
|
|
|
|
|
|
var promises []promise
|
|
|
|
|
|
|
|
for _, a := range tc.actions {
|
|
|
|
p := a(t, pcapi, pcb)
|
|
|
|
if p != nil {
|
|
|
|
promises = append(promises, p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, p := range promises {
|
|
|
|
p(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
err := pcb.Stop(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type fakeProver struct{}
|
|
|
|
|
2022-04-20 21:34:28 +00:00
|
|
|
func (f fakeProver) AggregateSealProofs(aggregateInfo prooftypes.AggregateSealVerifyProofAndInfos, proofs [][]byte) ([]byte, error) {
|
2021-06-09 15:18:09 +00:00
|
|
|
return []byte("Trust me, I'm a proof"), nil
|
|
|
|
}
|
|
|
|
|
2022-06-17 11:52:19 +00:00
|
|
|
var _ storiface.Prover = &fakeProver{}
|
2022-06-16 11:15:49 +00:00
|
|
|
|
2022-06-16 13:50:41 +00:00
|
|
|
var dummyAddr = func() address.Address {
|
2022-06-16 11:15:49 +00:00
|
|
|
a, _ := address.NewFromString("t00")
|
2022-06-16 13:50:41 +00:00
|
|
|
return a
|
|
|
|
}()
|
|
|
|
|
|
|
|
func makeBFTs(t *testing.T, basefee abi.TokenAmount, h abi.ChainEpoch) *types.TipSet {
|
2022-06-16 11:15:49 +00:00
|
|
|
dummyCid, _ := cid.Parse("bafkqaaa")
|
|
|
|
|
|
|
|
var ts, err = types.NewTipSet([]*types.BlockHeader{
|
|
|
|
{
|
|
|
|
Height: h,
|
2022-06-16 13:50:41 +00:00
|
|
|
Miner: dummyAddr,
|
2022-06-16 11:15:49 +00:00
|
|
|
|
|
|
|
Parents: []cid.Cid{},
|
|
|
|
|
|
|
|
Ticket: &types.Ticket{VRFProof: []byte{byte(h % 2)}},
|
|
|
|
|
|
|
|
ParentStateRoot: dummyCid,
|
|
|
|
Messages: dummyCid,
|
|
|
|
ParentMessageReceipts: dummyCid,
|
|
|
|
|
|
|
|
BlockSig: &crypto.Signature{Type: crypto.SigTypeBLS},
|
|
|
|
BLSAggregate: &crypto.Signature{Type: crypto.SigTypeBLS},
|
2022-06-16 12:00:37 +00:00
|
|
|
|
|
|
|
ParentBaseFee: basefee,
|
2022-06-16 11:15:49 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
if t != nil {
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ts
|
|
|
|
}
|
2022-06-16 12:00:37 +00:00
|
|
|
|
|
|
|
func makeTs(t *testing.T, h abi.ChainEpoch) *types.TipSet {
|
|
|
|
return makeBFTs(t, big.NewInt(0), h)
|
|
|
|
}
|
2022-06-16 13:50:41 +00:00
|
|
|
|
|
|
|
var dummySmsg = &types.SignedMessage{
|
|
|
|
Message: types.Message{
|
|
|
|
From: dummyAddr,
|
|
|
|
To: dummyAddr,
|
|
|
|
},
|
|
|
|
Signature: crypto.Signature{Type: crypto.SigTypeBLS},
|
|
|
|
}
|
2022-08-09 10:57:20 +00:00
|
|
|
|
|
|
|
type asel func(ctx context.Context, mi api.MinerInfo, use api.AddrUse, goodFunds, minFunds abi.TokenAmount) (address.Address, abi.TokenAmount, error)
|
|
|
|
|
|
|
|
func (s asel) AddressFor(ctx context.Context, _ ctladdr.NodeApi, mi api.MinerInfo, use api.AddrUse, goodFunds, minFunds abi.TokenAmount) (address.Address, abi.TokenAmount, error) {
|
|
|
|
return s(ctx, mi, use, goodFunds, minFunds)
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ pipeline.AddressSelector = asel(nil)
|