replace enable/disable commands with selection commands

This commit is contained in:
laser 2020-06-26 10:33:06 -07:00
parent 4af9a20903
commit 5d9a775699
5 changed files with 136 additions and 34 deletions

View File

@ -56,7 +56,9 @@ type StorageMiner interface {
DealsImportData(ctx context.Context, dealPropCid cid.Cid, file string) error
DealsList(ctx context.Context) ([]storagemarket.StorageDeal, error)
DealsAcceptingStorageDeals(context.Context) (bool, error)
DealsSetAcceptingStorageDeals(context.Context, bool) error
DealsAcceptingRetrievalDeals(context.Context) (bool, error)
DealsSetAcceptingRetrievalDeals(context.Context, bool) error
DealsPieceCidBlocklist(context.Context) ([]cid.Cid, error)
DealsSetPieceCidBlocklist(context.Context, []cid.Cid) error

View File

@ -226,7 +226,9 @@ type StorageMinerStruct struct {
DealsImportData func(ctx context.Context, dealPropCid cid.Cid, file string) error `perm:"write"`
DealsList func(ctx context.Context) ([]storagemarket.StorageDeal, error) `perm:"read"`
DealsAcceptingStorageDeals func(context.Context) (bool, error) `perm:"admin"`
DealsSetAcceptingStorageDeals func(context.Context, bool) error `perm:"admin"`
DealsAcceptingRetrievalDeals func(context.Context) (bool, error) `perm:"admin"`
DealsSetAcceptingRetrievalDeals func(context.Context, bool) error `perm:"admin"`
DealsPieceCidBlocklist func(context.Context) ([]cid.Cid, error) `perm:"admin"`
DealsSetPieceCidBlocklist func(context.Context, []cid.Cid) error `perm:"read"`
@ -878,10 +880,18 @@ func (c *StorageMinerStruct) DealsList(ctx context.Context) ([]storagemarket.Sto
return c.Internal.DealsList(ctx)
}
func (c *StorageMinerStruct) DealsAcceptingStorageDeals(ctx context.Context) (bool, error) {
return c.Internal.DealsAcceptingStorageDeals(ctx)
}
func (c *StorageMinerStruct) DealsSetAcceptingStorageDeals(ctx context.Context, b bool) error {
return c.Internal.DealsSetAcceptingStorageDeals(ctx, b)
}
func (c *StorageMinerStruct) DealsAcceptingRetrievalDeals(ctx context.Context) (bool, error) {
return c.Internal.DealsAcceptingRetrievalDeals(ctx)
}
func (c *StorageMinerStruct) DealsSetAcceptingRetrievalDeals(ctx context.Context, b bool) error {
return c.Internal.DealsSetAcceptingRetrievalDeals(ctx, b)
}

View File

@ -50,33 +50,73 @@ func GetCidEncoder(cctx *cli.Context) (cidenc.Encoder, error) {
return e, nil
}
var enableCmd = &cli.Command{
Name: "enable",
Usage: "Configure the miner to consider storage deal proposals",
Flags: []cli.Flag{},
Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()
return api.DealsSetAcceptingStorageDeals(lcli.DaemonContext(cctx), true)
var storageDealSelectionCmd = &cli.Command{
Name: "selection",
Usage: "Configure acceptance criteria for storage deal proposals",
Subcommands: []*cli.Command{
storageDealSelectionShowCmd,
storageDealSelectionResetCmd,
storageDealSelectionRejectCmd,
},
}
var disableCmd = &cli.Command{
Name: "disable",
Usage: "Configure the miner to reject all storage deal proposals",
Flags: []cli.Flag{},
var storageDealSelectionShowCmd = &cli.Command{
Name: "list",
Usage: "List storage deal proposal selection criteria",
Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetStorageMinerAPI(cctx)
smapi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()
return api.DealsSetAcceptingStorageDeals(lcli.DaemonContext(cctx), false)
isAcceptingStorageDeals, err := smapi.DealsAcceptingStorageDeals(lcli.DaemonContext(cctx))
if err != nil {
return err
}
fmt.Printf("offline storage deals: %t\n", isAcceptingStorageDeals)
fmt.Printf("online storage deals: %t\n", isAcceptingStorageDeals)
return nil
},
}
var storageDealSelectionResetCmd = &cli.Command{
Name: "reset",
Usage: "Reset storage deal proposal selection criteria to default values",
Action: func(cctx *cli.Context) error {
smapi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()
err = smapi.DealsSetAcceptingStorageDeals(lcli.DaemonContext(cctx), true)
if err != nil {
return err
}
return nil
},
}
var storageDealSelectionRejectCmd = &cli.Command{
Name: "reject",
Usage: "Configure criteria which necessitate automatic rejection",
Action: func(cctx *cli.Context) error {
smapi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()
err = smapi.DealsSetAcceptingStorageDeals(lcli.DaemonContext(cctx), false)
if err != nil {
return err
}
return nil
},
}
@ -223,8 +263,7 @@ var storageDealsCmd = &cli.Command{
Subcommands: []*cli.Command{
dealsImportDataCmd,
dealsListCmd,
enableCmd,
disableCmd,
storageDealSelectionCmd,
setAskCmd,
getAskCmd,
setBlocklistCmd,

View File

@ -1,6 +1,8 @@
package main
import (
"fmt"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/urfave/cli/v2"
)
@ -9,37 +11,76 @@ var retrievalDealsCmd = &cli.Command{
Name: "retrieval-deals",
Usage: "Manage retrieval deals and related configuration",
Subcommands: []*cli.Command{
enableRetrievalCmd,
disableRetrievalCmd,
retrievalDealSelectionCmd,
},
}
var enableRetrievalCmd = &cli.Command{
Name: "enable",
Usage: "Configure the miner to consider retrieval deal proposals",
Flags: []cli.Flag{},
var retrievalDealSelectionCmd = &cli.Command{
Name: "selection",
Usage: "Configure acceptance criteria for retrieval deal proposals",
Subcommands: []*cli.Command{
retrievalDealSelectionShowCmd,
retrievalDealSelectionResetCmd,
retrievalDealSelectionRejectCmd,
},
}
var retrievalDealSelectionShowCmd = &cli.Command{
Name: "list",
Usage: "List retrieval deal proposal selection criteria",
Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetStorageMinerAPI(cctx)
smapi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()
return api.DealsSetAcceptingRetrievalDeals(lcli.DaemonContext(cctx), true)
isAcceptingRetrievalDeals, err := smapi.DealsAcceptingRetrievalDeals(lcli.DaemonContext(cctx))
if err != nil {
return err
}
fmt.Printf("offline retrieval deals: %t\n", isAcceptingRetrievalDeals)
fmt.Printf("online retrieval deals: %t\n", isAcceptingRetrievalDeals)
return nil
},
}
var disableRetrievalCmd = &cli.Command{
Name: "disable",
Usage: "Configure the miner to reject all retrieval deal proposals",
Flags: []cli.Flag{},
var retrievalDealSelectionResetCmd = &cli.Command{
Name: "reset",
Usage: "Reset retrieval deal proposal selection criteria to default values",
Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetStorageMinerAPI(cctx)
smapi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()
return api.DealsSetAcceptingRetrievalDeals(lcli.DaemonContext(cctx), false)
err = smapi.DealsSetAcceptingRetrievalDeals(lcli.DaemonContext(cctx), true)
if err != nil {
return err
}
return nil
},
}
var retrievalDealSelectionRejectCmd = &cli.Command{
Name: "reject",
Usage: "Configure criteria which necessitate automatic rejection",
Action: func(cctx *cli.Context) error {
smapi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()
err = smapi.DealsSetAcceptingRetrievalDeals(lcli.DaemonContext(cctx), false)
if err != nil {
return err
}
return nil
},
}

View File

@ -43,7 +43,9 @@ type StorageMinerAPI struct {
StorageMgr *sectorstorage.Manager `optional:"true"`
*stores.Index
AcceptingStorageDealsConfigFunc dtypes.AcceptingStorageDealsConfigFunc
SetAcceptingStorageDealsConfigFunc dtypes.SetAcceptingStorageDealsConfigFunc
AcceptingRetrievalDealsConfigFunc dtypes.AcceptingRetrievalDealsConfigFunc
SetAcceptingRetrievalDealsConfigFunc dtypes.SetAcceptingRetrievalDealsConfigFunc
StorageDealPieceCidBlocklistConfigFunc dtypes.StorageDealPieceCidBlocklistConfigFunc
SetStorageDealPieceCidBlocklistConfigFunc dtypes.SetStorageDealPieceCidBlocklistConfigFunc
@ -225,10 +227,18 @@ func (sm *StorageMinerAPI) DealsList(ctx context.Context) ([]storagemarket.Stora
return sm.StorageProvider.ListDeals(ctx)
}
func (sm *StorageMinerAPI) DealsAcceptingStorageDeals(ctx context.Context) (bool, error) {
return sm.AcceptingStorageDealsConfigFunc()
}
func (sm *StorageMinerAPI) DealsSetAcceptingStorageDeals(ctx context.Context, b bool) error {
return sm.SetAcceptingStorageDealsConfigFunc(b)
}
func (sm *StorageMinerAPI) DealsAcceptingRetrievalDeals(ctx context.Context) (bool, error) {
return sm.AcceptingRetrievalDealsConfigFunc()
}
func (sm *StorageMinerAPI) DealsSetAcceptingRetrievalDeals(ctx context.Context, b bool) error {
return sm.SetAcceptingRetrievalDealsConfigFunc(b)
}