diff --git a/api/api_storage.go b/api/api_storage.go index 6d8fe384e..27f42df9d 100644 --- a/api/api_storage.go +++ b/api/api_storage.go @@ -35,6 +35,9 @@ type StorageMiner interface { 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 SectorRemove(context.Context, abi.SectorNumber) error diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index cf88e514a..e5986bbe0 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -205,7 +205,8 @@ type StorageMinerStruct struct { SectorsStatus func(context.Context, abi.SectorNumber) (api.SectorInfo, error) `perm:"read"` SectorsList func(context.Context) ([]abi.SectorNumber, 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"` 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) } +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 { return c.Internal.SectorsUpdate(ctx, id, state) } diff --git a/api/test/deals.go b/api/test/deals.go index 22152d7ab..0bf869818 100644 --- a/api/test/deals.go +++ b/api/test/deals.go @@ -12,8 +12,9 @@ import ( "testing" "time" - "github.com/ipfs/go-cid" + "github.com/stretchr/testify/require" + "github.com/ipfs/go-cid" files "github.com/ipfs/go-ipfs-files" logging "github.com/ipfs/go-log/v2" "github.com/ipld/go-car" @@ -21,6 +22,7 @@ import ( "github.com/filecoin-project/go-fil-markets/storagemarket" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" + sealing "github.com/filecoin-project/storage-fsm" dag "github.com/ipfs/go-merkledag" dstest "github.com/ipfs/go-merkledag/test" 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 time.Sleep(time.Second) - waitDealSealed(t, ctx, client, deal) + waitDealSealed(t, ctx, miner, client, deal) // Retrieval @@ -157,7 +159,7 @@ func startDeal(t *testing.T, ctx context.Context, miner TestStorageNode, client 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: for { di, err := client.ClientGetDealInfo(ctx, *deal) @@ -165,6 +167,8 @@ loop: t.Fatal(err) } switch di.State { + case storagemarket.StorageDealSealing: + startSealingWaiting(t, ctx, miner) case storagemarket.StorageDealProposalRejected: t.Fatal("deal rejected") 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) { offers, err := client.ClientFindData(ctx, fcid) if err != nil { diff --git a/api/test/mining.go b/api/test/mining.go index d9b16fd1f..f23baeb8d 100644 --- a/api/test/mining.go +++ b/api/test/mining.go @@ -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 time.Sleep(time.Second) - waitDealSealed(t, ctx, client, deal) + waitDealSealed(t, ctx, provider, client, deal) <-minedTwo diff --git a/node/impl/storminer.go b/node/impl/storminer.go index b993d1b46..a69c37071 100644 --- a/node/impl/storminer.go +++ b/node/impl/storminer.go @@ -171,6 +171,10 @@ func (sm *StorageMinerAPI) StorageStat(ctx context.Context, id stores.ID) (store 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 { return sm.Miner.ForceSectorState(ctx, id, sealing.SectorState(state)) } diff --git a/node/node_test.go b/node/node_test.go index a3a37bdd3..edac3f38d 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -202,7 +202,7 @@ func builder(t *testing.T, nFull int, storage []test.StorageMiner) ([]test.TestN genaccs = append(genaccs, genesis.Actor{ 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(), }) @@ -336,7 +336,7 @@ func mockSbBuilder(t *testing.T, nFull int, storage []test.StorageMiner) ([]test genaccs = append(genaccs, genesis.Actor{ 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(), }) diff --git a/storage/sealing.go b/storage/sealing.go index d0009431a..75a1c5011 100644 --- a/storage/sealing.go +++ b/storage/sealing.go @@ -20,6 +20,10 @@ func (m *Miner) AddPieceToAnySector(ctx context.Context, size abi.UnpaddedPieceS 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) { return m.sealing.ListSectors() }