lotus/itests/batch_deal_test.go

97 lines
2.7 KiB
Go
Raw Normal View History

package itests
import (
2021-05-20 15:12:42 +00:00
"context"
"testing"
"time"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/extern/storage-sealing/sealiface"
2021-05-18 21:01:10 +00:00
"github.com/filecoin-project/lotus/itests/kit"
"github.com/filecoin-project/lotus/markets/storageadapter"
"github.com/filecoin-project/lotus/node"
"github.com/filecoin-project/lotus/node/impl"
"github.com/filecoin-project/lotus/node/modules/dtypes"
"github.com/stretchr/testify/require"
)
func TestBatchDealInput(t *testing.T) {
2021-05-18 21:01:10 +00:00
kit.QuietMiningLogs()
var (
blockTime = 10 * time.Millisecond
// For these tests where the block time is artificially short, just use
// a deal start epoch that is guaranteed to be far enough in the future
// so that the deal starts sealing in time
dealStartEpoch = abi.ChainEpoch(2 << 12)
publishPeriod = 10 * time.Second
maxDealsPerMsg = uint64(4)
)
// Set max deals per publish deals message to maxDealsPerMsg
2021-05-18 21:01:10 +00:00
minerDef := []kit.StorageMiner{{
Full: 0,
Opts: node.Options(
node.Override(
new(*storageadapter.DealPublisher),
storageadapter.NewDealPublisher(nil, storageadapter.PublishMsgConfig{
Period: publishPeriod,
MaxDealsPerMsg: maxDealsPerMsg,
})),
node.Override(new(dtypes.GetSealingConfigFunc), func() (dtypes.GetSealingConfigFunc, error) {
return func() (sealiface.Config, error) {
return sealiface.Config{
MaxWaitDealsSectors: 1,
MaxSealingSectors: 1,
MaxSealingSectorsForDeals: 2,
AlwaysKeepUnsealedCopy: true,
}, nil
}, nil
}),
),
2021-05-18 21:01:10 +00:00
Preseal: kit.PresealGenesis,
}}
// Create a connect client and miner node
2021-05-20 11:17:41 +00:00
n, sn := kit.MockMinerBuilder(t, kit.OneFull, minerDef)
client := n[0].FullNode.(*impl.FullNodeAPI)
miner := sn[0]
2021-05-20 15:12:42 +00:00
blockMiner := kit.ConnectAndStartMining(t, blockTime, miner, client)
t.Cleanup(blockMiner.Stop)
dh := kit.NewDealHarness(t, client, miner)
ctx := context.Background()
// Starts a deal and waits until it's published
runDealTillSeal := func(rseed int) {
2021-05-20 15:12:42 +00:00
res, _, err := kit.CreateImportFile(ctx, client, rseed)
require.NoError(t, err)
2021-05-20 15:12:42 +00:00
deal := dh.StartDeal(ctx, res.Root, false, dealStartEpoch)
dh.WaitDealSealed(ctx, deal, false)
}
// Run maxDealsPerMsg+1 deals in parallel
done := make(chan struct{}, maxDealsPerMsg+1)
for rseed := 1; rseed <= int(maxDealsPerMsg+1); rseed++ {
rseed := rseed
go func() {
runDealTillSeal(rseed)
done <- struct{}{}
}()
}
// Wait for maxDealsPerMsg of the deals to be published
for i := 0; i < int(maxDealsPerMsg); i++ {
<-done
}
2021-05-20 15:12:42 +00:00
sl, err := sn[0].SectorsList(ctx)
require.NoError(t, err)
require.GreaterOrEqual(t, len(sl), 4)
require.LessOrEqual(t, len(sl), 5)
}