get and set storage deal acceptance through CLI
This commit is contained in:
parent
67110ce739
commit
7587e6c08b
@ -54,6 +54,7 @@ type StorageMiner interface {
|
|||||||
|
|
||||||
DealsImportData(ctx context.Context, dealPropCid cid.Cid, file string) error
|
DealsImportData(ctx context.Context, dealPropCid cid.Cid, file string) error
|
||||||
DealsList(ctx context.Context) ([]storagemarket.StorageDeal, error)
|
DealsList(ctx context.Context) ([]storagemarket.StorageDeal, error)
|
||||||
|
DealsSetIsAcceptingStorageDeals(ctx context.Context, b bool) error
|
||||||
|
|
||||||
StorageAddLocal(ctx context.Context, path string) error
|
StorageAddLocal(ctx context.Context, path string) error
|
||||||
}
|
}
|
||||||
|
@ -222,6 +222,7 @@ type StorageMinerStruct struct {
|
|||||||
|
|
||||||
DealsImportData func(ctx context.Context, dealPropCid cid.Cid, file string) error `perm:"write"`
|
DealsImportData func(ctx context.Context, dealPropCid cid.Cid, file string) error `perm:"write"`
|
||||||
DealsList func(ctx context.Context) ([]storagemarket.StorageDeal, error) `perm:"read"`
|
DealsList func(ctx context.Context) ([]storagemarket.StorageDeal, error) `perm:"read"`
|
||||||
|
DealsSetIsAcceptingStorageDeals func(ctx context.Context, b bool) error `perm:"admin"`
|
||||||
|
|
||||||
StorageAddLocal func(ctx context.Context, path string) error `perm:"admin"`
|
StorageAddLocal func(ctx context.Context, path string) error `perm:"admin"`
|
||||||
}
|
}
|
||||||
@ -852,6 +853,10 @@ func (c *StorageMinerStruct) DealsList(ctx context.Context) ([]storagemarket.Sto
|
|||||||
return c.Internal.DealsList(ctx)
|
return c.Internal.DealsList(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *StorageMinerStruct) DealsSetIsAcceptingStorageDeals(ctx context.Context, b bool) error {
|
||||||
|
return c.Internal.DealsSetIsAcceptingStorageDeals(ctx, b)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *StorageMinerStruct) StorageAddLocal(ctx context.Context, path string) error {
|
func (c *StorageMinerStruct) StorageAddLocal(ctx context.Context, path string) error {
|
||||||
return c.Internal.StorageAddLocal(ctx, path)
|
return c.Internal.StorageAddLocal(ctx, path)
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,6 @@ func main() {
|
|||||||
setPriceCmd,
|
setPriceCmd,
|
||||||
workersCmd,
|
workersCmd,
|
||||||
provingCmd,
|
provingCmd,
|
||||||
enableCmd,
|
|
||||||
disableCmd,
|
|
||||||
}
|
}
|
||||||
jaeger := tracing.SetupJaegerTracing("lotus")
|
jaeger := tracing.SetupJaegerTracing("lotus")
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -15,7 +15,13 @@ var enableCmd = &cli.Command{
|
|||||||
Usage: "Configure the miner to consider storage deal proposals",
|
Usage: "Configure the miner to consider storage deal proposals",
|
||||||
Flags: []cli.Flag{},
|
Flags: []cli.Flag{},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
panic("enable storage deals")
|
api, closer, err := lcli.GetStorageMinerAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer closer()
|
||||||
|
|
||||||
|
return api.DealsSetIsAcceptingStorageDeals(lcli.DaemonContext(cctx), true)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,7 +30,13 @@ var disableCmd = &cli.Command{
|
|||||||
Usage: "Configure the miner to reject all storage deal proposals",
|
Usage: "Configure the miner to reject all storage deal proposals",
|
||||||
Flags: []cli.Flag{},
|
Flags: []cli.Flag{},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
panic("disable storage deals")
|
api, closer, err := lcli.GetStorageMinerAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer closer()
|
||||||
|
|
||||||
|
return api.DealsSetIsAcceptingStorageDeals(lcli.DaemonContext(cctx), false)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,6 +72,8 @@ var dealsCmd = &cli.Command{
|
|||||||
Subcommands: []*cli.Command{
|
Subcommands: []*cli.Command{
|
||||||
dealsImportDataCmd,
|
dealsImportDataCmd,
|
||||||
dealsListCmd,
|
dealsListCmd,
|
||||||
|
enableCmd,
|
||||||
|
disableCmd,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,6 +314,7 @@ func Online() Option {
|
|||||||
Override(new(gen.WinningPoStProver), storage.NewWinningPoStProver),
|
Override(new(gen.WinningPoStProver), storage.NewWinningPoStProver),
|
||||||
Override(new(*miner.Miner), modules.SetupBlockProducer),
|
Override(new(*miner.Miner), modules.SetupBlockProducer),
|
||||||
Override(new(dtypes.IsAcceptingStorageDealsFunc), modules.NewIsAcceptingStorageDealsFunc),
|
Override(new(dtypes.IsAcceptingStorageDealsFunc), modules.NewIsAcceptingStorageDealsFunc),
|
||||||
|
Override(new(dtypes.SetAcceptingStorageDealsFunc), modules.NewSetAcceptingStorageDealsFunc),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/miner"
|
"github.com/filecoin-project/lotus/miner"
|
||||||
"github.com/filecoin-project/lotus/node/impl/common"
|
"github.com/filecoin-project/lotus/node/impl/common"
|
||||||
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||||
"github.com/filecoin-project/lotus/storage"
|
"github.com/filecoin-project/lotus/storage"
|
||||||
"github.com/filecoin-project/lotus/storage/sectorblocks"
|
"github.com/filecoin-project/lotus/storage/sectorblocks"
|
||||||
)
|
)
|
||||||
@ -41,6 +42,8 @@ type StorageMinerAPI struct {
|
|||||||
Full api.FullNode
|
Full api.FullNode
|
||||||
StorageMgr *sectorstorage.Manager `optional:"true"`
|
StorageMgr *sectorstorage.Manager `optional:"true"`
|
||||||
*stores.Index
|
*stores.Index
|
||||||
|
|
||||||
|
SetAcceptingStorageDealsFunc dtypes.SetAcceptingStorageDealsFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *StorageMinerAPI) ServeRemote(w http.ResponseWriter, r *http.Request) {
|
func (sm *StorageMinerAPI) ServeRemote(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -206,6 +209,10 @@ func (sm *StorageMinerAPI) DealsList(ctx context.Context) ([]storagemarket.Stora
|
|||||||
return sm.StorageProvider.ListDeals(ctx)
|
return sm.StorageProvider.ListDeals(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sm *StorageMinerAPI) DealsSetIsAcceptingStorageDeals(ctx context.Context, b bool) error {
|
||||||
|
return sm.SetAcceptingStorageDealsFunc(b)
|
||||||
|
}
|
||||||
|
|
||||||
func (sm *StorageMinerAPI) DealsImportData(ctx context.Context, deal cid.Cid, fname string) error {
|
func (sm *StorageMinerAPI) DealsImportData(ctx context.Context, deal cid.Cid, fname string) error {
|
||||||
fi, err := os.Open(fname)
|
fi, err := os.Open(fname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -11,3 +11,7 @@ type MinerID abi.ActorID
|
|||||||
// IsAcceptingStorageDealsFunc is a function which reads from miner config to
|
// IsAcceptingStorageDealsFunc is a function which reads from miner config to
|
||||||
// determine if the user has disabled storage deals (or not).
|
// determine if the user has disabled storage deals (or not).
|
||||||
type IsAcceptingStorageDealsFunc func() (bool, error)
|
type IsAcceptingStorageDealsFunc func() (bool, error)
|
||||||
|
|
||||||
|
// SetAcceptingStorageDealsFunc is a function which is used to disable or enable
|
||||||
|
// storage deal acceptance.
|
||||||
|
type SetAcceptingStorageDealsFunc func(bool) error
|
||||||
|
@ -2,6 +2,7 @@ package modules
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/ipfs/go-bitswap"
|
"github.com/ipfs/go-bitswap"
|
||||||
@ -17,6 +18,7 @@ import (
|
|||||||
"github.com/libp2p/go-libp2p-core/host"
|
"github.com/libp2p/go-libp2p-core/host"
|
||||||
"github.com/libp2p/go-libp2p-core/routing"
|
"github.com/libp2p/go-libp2p-core/routing"
|
||||||
"go.uber.org/fx"
|
"go.uber.org/fx"
|
||||||
|
"go.uber.org/multierr"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
@ -392,3 +394,21 @@ func NewIsAcceptingStorageDealsFunc(r repo.LockedRepo) (dtypes.IsAcceptingStorag
|
|||||||
return cfg.Dealmaking.IsAcceptingStorageDeals, nil
|
return cfg.Dealmaking.IsAcceptingStorageDeals, nil
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewSetAcceptingStorageDealsFunc(r repo.LockedRepo) (dtypes.SetAcceptingStorageDealsFunc, error) {
|
||||||
|
return func(b bool) error {
|
||||||
|
var typeErr error
|
||||||
|
|
||||||
|
setConfigErr := r.SetConfig(func(raw interface{}) {
|
||||||
|
cfg, ok := raw.(*config.StorageMiner)
|
||||||
|
if !ok {
|
||||||
|
typeErr = errors.New("expected storage miner config")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg.Dealmaking.IsAcceptingStorageDeals = b
|
||||||
|
})
|
||||||
|
|
||||||
|
return multierr.Combine(typeErr, setConfigErr)
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user