apitest: auto-start sealing precoss
This commit is contained in:
parent
6893dbb657
commit
24f4c96fc3
@ -35,6 +35,9 @@ type StorageMiner interface {
|
|||||||
|
|
||||||
SectorsRefs(context.Context) (map[string][]SealedRef, error)
|
SectorsRefs(context.Context) (map[string][]SealedRef, error)
|
||||||
|
|
||||||
|
// SectorStartSealing can be called on sectors in Empty on WaitDeals states
|
||||||
|
// to trigger sealing early
|
||||||
|
SectorStartSealing(context.Context, abi.SectorNumber) error
|
||||||
SectorsUpdate(context.Context, abi.SectorNumber, SectorState) error
|
SectorsUpdate(context.Context, abi.SectorNumber, SectorState) error
|
||||||
SectorRemove(context.Context, abi.SectorNumber) error
|
SectorRemove(context.Context, abi.SectorNumber) error
|
||||||
|
|
||||||
|
@ -205,7 +205,8 @@ type StorageMinerStruct struct {
|
|||||||
SectorsStatus func(context.Context, abi.SectorNumber) (api.SectorInfo, error) `perm:"read"`
|
SectorsStatus func(context.Context, abi.SectorNumber) (api.SectorInfo, error) `perm:"read"`
|
||||||
SectorsList func(context.Context) ([]abi.SectorNumber, error) `perm:"read"`
|
SectorsList func(context.Context) ([]abi.SectorNumber, error) `perm:"read"`
|
||||||
SectorsRefs func(context.Context) (map[string][]api.SealedRef, error) `perm:"read"`
|
SectorsRefs func(context.Context) (map[string][]api.SealedRef, error) `perm:"read"`
|
||||||
SectorsUpdate func(context.Context, abi.SectorNumber, api.SectorState) error `perm:"write"`
|
SectorStartSealing func(context.Context, abi.SectorNumber) error`perm:"write"`
|
||||||
|
SectorsUpdate func(context.Context, abi.SectorNumber, api.SectorState) error `perm:"admin"`
|
||||||
SectorRemove func(context.Context, abi.SectorNumber) error `perm:"admin"`
|
SectorRemove func(context.Context, abi.SectorNumber) error `perm:"admin"`
|
||||||
|
|
||||||
WorkerConnect func(context.Context, string) error `perm:"admin"` // TODO: worker perm
|
WorkerConnect func(context.Context, string) error `perm:"admin"` // TODO: worker perm
|
||||||
@ -786,6 +787,10 @@ func (c *StorageMinerStruct) SectorsRefs(ctx context.Context) (map[string][]api.
|
|||||||
return c.Internal.SectorsRefs(ctx)
|
return c.Internal.SectorsRefs(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *StorageMinerStruct) SectorStartSealing(ctx context.Context, number abi.SectorNumber) error {
|
||||||
|
return c.Internal.SectorStartSealing(ctx, number)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *StorageMinerStruct) SectorsUpdate(ctx context.Context, id abi.SectorNumber, state api.SectorState) error {
|
func (c *StorageMinerStruct) SectorsUpdate(ctx context.Context, id abi.SectorNumber, state api.SectorState) error {
|
||||||
return c.Internal.SectorsUpdate(ctx, id, state)
|
return c.Internal.SectorsUpdate(ctx, id, state)
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,9 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/ipfs/go-cid"
|
||||||
files "github.com/ipfs/go-ipfs-files"
|
files "github.com/ipfs/go-ipfs-files"
|
||||||
logging "github.com/ipfs/go-log/v2"
|
logging "github.com/ipfs/go-log/v2"
|
||||||
"github.com/ipld/go-car"
|
"github.com/ipld/go-car"
|
||||||
@ -21,6 +22,7 @@ import (
|
|||||||
"github.com/filecoin-project/go-fil-markets/storagemarket"
|
"github.com/filecoin-project/go-fil-markets/storagemarket"
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
|
sealing "github.com/filecoin-project/storage-fsm"
|
||||||
dag "github.com/ipfs/go-merkledag"
|
dag "github.com/ipfs/go-merkledag"
|
||||||
dstest "github.com/ipfs/go-merkledag/test"
|
dstest "github.com/ipfs/go-merkledag/test"
|
||||||
unixfile "github.com/ipfs/go-unixfs/file"
|
unixfile "github.com/ipfs/go-unixfs/file"
|
||||||
@ -127,7 +129,7 @@ func makeDeal(t *testing.T, ctx context.Context, rseed int, client *impl.FullNod
|
|||||||
|
|
||||||
// TODO: this sleep is only necessary because deals don't immediately get logged in the dealstore, we should fix this
|
// TODO: this sleep is only necessary because deals don't immediately get logged in the dealstore, we should fix this
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
waitDealSealed(t, ctx, client, deal)
|
waitDealSealed(t, ctx, miner, client, deal)
|
||||||
|
|
||||||
// Retrieval
|
// Retrieval
|
||||||
|
|
||||||
@ -157,7 +159,7 @@ func startDeal(t *testing.T, ctx context.Context, miner TestStorageNode, client
|
|||||||
return deal
|
return deal
|
||||||
}
|
}
|
||||||
|
|
||||||
func waitDealSealed(t *testing.T, ctx context.Context, client *impl.FullNodeAPI, deal *cid.Cid) {
|
func waitDealSealed(t *testing.T, ctx context.Context, miner TestStorageNode, client *impl.FullNodeAPI, deal *cid.Cid) {
|
||||||
loop:
|
loop:
|
||||||
for {
|
for {
|
||||||
di, err := client.ClientGetDealInfo(ctx, *deal)
|
di, err := client.ClientGetDealInfo(ctx, *deal)
|
||||||
@ -165,6 +167,8 @@ loop:
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
switch di.State {
|
switch di.State {
|
||||||
|
case storagemarket.StorageDealSealing:
|
||||||
|
startSealingWaiting(t, ctx, miner)
|
||||||
case storagemarket.StorageDealProposalRejected:
|
case storagemarket.StorageDealProposalRejected:
|
||||||
t.Fatal("deal rejected")
|
t.Fatal("deal rejected")
|
||||||
case storagemarket.StorageDealFailing:
|
case storagemarket.StorageDealFailing:
|
||||||
@ -180,6 +184,20 @@ loop:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func startSealingWaiting(t *testing.T, ctx context.Context, miner TestStorageNode) {
|
||||||
|
snums, err := miner.SectorsList(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
for _, snum := range snums {
|
||||||
|
si, err := miner.SectorsStatus(ctx, snum)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
if si.State == api.SectorState(sealing.WaitDeals) {
|
||||||
|
require.NoError(t, miner.SectorStartSealing(ctx, snum))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testRetrieval(t *testing.T, ctx context.Context, err error, client *impl.FullNodeAPI, fcid cid.Cid, carExport bool, data []byte) {
|
func testRetrieval(t *testing.T, ctx context.Context, err error, client *impl.FullNodeAPI, fcid cid.Cid, carExport bool, data []byte) {
|
||||||
offers, err := client.ClientFindData(ctx, fcid)
|
offers, err := client.ClientFindData(ctx, fcid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -194,7 +194,7 @@ func TestDealMining(t *testing.T, b APIBuilder, blocktime time.Duration, carExpo
|
|||||||
// TODO: this sleep is only necessary because deals don't immediately get logged in the dealstore, we should fix this
|
// TODO: this sleep is only necessary because deals don't immediately get logged in the dealstore, we should fix this
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
|
|
||||||
waitDealSealed(t, ctx, client, deal)
|
waitDealSealed(t, ctx, provider, client, deal)
|
||||||
|
|
||||||
<-minedTwo
|
<-minedTwo
|
||||||
|
|
||||||
|
@ -171,6 +171,10 @@ func (sm *StorageMinerAPI) StorageStat(ctx context.Context, id stores.ID) (store
|
|||||||
return sm.StorageMgr.FsStat(ctx, id)
|
return sm.StorageMgr.FsStat(ctx, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sm *StorageMinerAPI) SectorStartSealing(ctx context.Context, number abi.SectorNumber) error {
|
||||||
|
return sm.Miner.StartPackingSector(number)
|
||||||
|
}
|
||||||
|
|
||||||
func (sm *StorageMinerAPI) SectorsUpdate(ctx context.Context, id abi.SectorNumber, state api.SectorState) error {
|
func (sm *StorageMinerAPI) SectorsUpdate(ctx context.Context, id abi.SectorNumber, state api.SectorState) error {
|
||||||
return sm.Miner.ForceSectorState(ctx, id, sealing.SectorState(state))
|
return sm.Miner.ForceSectorState(ctx, id, sealing.SectorState(state))
|
||||||
}
|
}
|
||||||
|
@ -202,7 +202,7 @@ func builder(t *testing.T, nFull int, storage []test.StorageMiner) ([]test.TestN
|
|||||||
|
|
||||||
genaccs = append(genaccs, genesis.Actor{
|
genaccs = append(genaccs, genesis.Actor{
|
||||||
Type: genesis.TAccount,
|
Type: genesis.TAccount,
|
||||||
Balance: big.Mul(big.NewInt(50000), types.NewInt(build.FilecoinPrecision)),
|
Balance: big.Mul(big.NewInt(400_000_000), types.NewInt(build.FilecoinPrecision)),
|
||||||
Meta: (&genesis.AccountMeta{Owner: wk.Address}).ActorMeta(),
|
Meta: (&genesis.AccountMeta{Owner: wk.Address}).ActorMeta(),
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -336,7 +336,7 @@ func mockSbBuilder(t *testing.T, nFull int, storage []test.StorageMiner) ([]test
|
|||||||
|
|
||||||
genaccs = append(genaccs, genesis.Actor{
|
genaccs = append(genaccs, genesis.Actor{
|
||||||
Type: genesis.TAccount,
|
Type: genesis.TAccount,
|
||||||
Balance: big.Mul(big.NewInt(50000), types.NewInt(build.FilecoinPrecision)),
|
Balance: big.Mul(big.NewInt(400_000_000), types.NewInt(build.FilecoinPrecision)),
|
||||||
Meta: (&genesis.AccountMeta{Owner: wk.Address}).ActorMeta(),
|
Meta: (&genesis.AccountMeta{Owner: wk.Address}).ActorMeta(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -20,6 +20,10 @@ func (m *Miner) AddPieceToAnySector(ctx context.Context, size abi.UnpaddedPieceS
|
|||||||
return m.sealing.AddPieceToAnySector(ctx, size, r, d)
|
return m.sealing.AddPieceToAnySector(ctx, size, r, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Miner) StartPackingSector(sectorNum abi.SectorNumber) error {
|
||||||
|
return m.sealing.StartPacking(sectorNum)
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Miner) ListSectors() ([]sealing.SectorInfo, error) {
|
func (m *Miner) ListSectors() ([]sealing.SectorInfo, error) {
|
||||||
return m.sealing.ListSectors()
|
return m.sealing.ListSectors()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user