Merge pull request #1994 from laser/feat/1920-toggle-accepting-storage-deals
allow miner to disable/enable consideration of received storage deal proposals
This commit is contained in:
commit
01f0bb3124
@ -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)
|
||||||
|
DealsSetAcceptingStorageDeals(context.Context, 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"`
|
||||||
|
DealsSetAcceptingStorageDeals func(context.Context, 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) DealsSetAcceptingStorageDeals(ctx context.Context, b bool) error {
|
||||||
|
return c.Internal.DealsSetAcceptingStorageDeals(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)
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,36 @@ import (
|
|||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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 disableCmd = &cli.Command{
|
||||||
|
Name: "disable",
|
||||||
|
Usage: "Configure the miner to reject all 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), false)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
var setPriceCmd = &cli.Command{
|
var setPriceCmd = &cli.Command{
|
||||||
Name: "set-price",
|
Name: "set-price",
|
||||||
Usage: "Set price that miner will accept storage deals at (FIL / GiB / Epoch)",
|
Usage: "Set price that miner will accept storage deals at (FIL / GiB / Epoch)",
|
||||||
@ -42,6 +72,8 @@ var dealsCmd = &cli.Command{
|
|||||||
Subcommands: []*cli.Command{
|
Subcommands: []*cli.Command{
|
||||||
dealsImportDataCmd,
|
dealsImportDataCmd,
|
||||||
dealsListCmd,
|
dealsListCmd,
|
||||||
|
enableCmd,
|
||||||
|
disableCmd,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,6 +313,9 @@ func Online() Option {
|
|||||||
Override(HandleDealsKey, modules.HandleDeals),
|
Override(HandleDealsKey, modules.HandleDeals),
|
||||||
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.AcceptingStorageDealsConfigFunc), modules.NewAcceptingStorageDealsConfigFunc),
|
||||||
|
Override(new(dtypes.SetAcceptingStorageDealsConfigFunc), modules.NewSetAcceptingStorageDealsConfigFunc),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -27,9 +27,14 @@ type FullNode struct {
|
|||||||
type StorageMiner struct {
|
type StorageMiner struct {
|
||||||
Common
|
Common
|
||||||
|
|
||||||
|
Dealmaking DealmakingConfig
|
||||||
Storage sectorstorage.SealerConfig
|
Storage sectorstorage.SealerConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DealmakingConfig struct {
|
||||||
|
AcceptingStorageDeals bool
|
||||||
|
}
|
||||||
|
|
||||||
// API contains configs for API endpoint
|
// API contains configs for API endpoint
|
||||||
type API struct {
|
type API struct {
|
||||||
ListenAddress string
|
ListenAddress string
|
||||||
@ -113,6 +118,10 @@ func DefaultStorageMiner() *StorageMiner {
|
|||||||
AllowCommit: true,
|
AllowCommit: true,
|
||||||
AllowUnseal: true,
|
AllowUnseal: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Dealmaking: DealmakingConfig{
|
||||||
|
AcceptingStorageDeals: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
cfg.Common.API.ListenAddress = "/ip4/127.0.0.1/tcp/2345/http"
|
cfg.Common.API.ListenAddress = "/ip4/127.0.0.1/tcp/2345/http"
|
||||||
cfg.Common.API.RemoteListenAddress = "127.0.0.1:2345"
|
cfg.Common.API.RemoteListenAddress = "127.0.0.1:2345"
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
SetAcceptingStorageDealsConfigFunc dtypes.SetAcceptingStorageDealsConfigFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
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) DealsSetAcceptingStorageDeals(ctx context.Context, b bool) error {
|
||||||
|
return sm.SetAcceptingStorageDealsConfigFunc(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 {
|
||||||
|
@ -7,3 +7,11 @@ import (
|
|||||||
|
|
||||||
type MinerAddress address.Address
|
type MinerAddress address.Address
|
||||||
type MinerID abi.ActorID
|
type MinerID abi.ActorID
|
||||||
|
|
||||||
|
// AcceptingStorageDealsFunc is a function which reads from miner config to
|
||||||
|
// determine if the user has disabled storage deals (or not).
|
||||||
|
type AcceptingStorageDealsConfigFunc func() (bool, error)
|
||||||
|
|
||||||
|
// SetAcceptingStorageDealsFunc is a function which is used to disable or enable
|
||||||
|
// storage deal acceptance.
|
||||||
|
type SetAcceptingStorageDealsConfigFunc 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"
|
||||||
@ -35,6 +37,7 @@ import (
|
|||||||
paramfetch "github.com/filecoin-project/go-paramfetch"
|
paramfetch "github.com/filecoin-project/go-paramfetch"
|
||||||
"github.com/filecoin-project/go-statestore"
|
"github.com/filecoin-project/go-statestore"
|
||||||
"github.com/filecoin-project/go-storedcounter"
|
"github.com/filecoin-project/go-storedcounter"
|
||||||
|
"github.com/filecoin-project/lotus/node/config"
|
||||||
sectorstorage "github.com/filecoin-project/sector-storage"
|
sectorstorage "github.com/filecoin-project/sector-storage"
|
||||||
"github.com/filecoin-project/sector-storage/ffiwrapper"
|
"github.com/filecoin-project/sector-storage/ffiwrapper"
|
||||||
"github.com/filecoin-project/sector-storage/stores"
|
"github.com/filecoin-project/sector-storage/stores"
|
||||||
@ -304,14 +307,28 @@ func NewStorageAsk(ctx helpers.MetricsCtx, fapi lapi.FullNode, ds dtypes.Metadat
|
|||||||
return storedAsk, nil
|
return storedAsk, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func StorageProvider(minerAddress dtypes.MinerAddress, ffiConfig *ffiwrapper.Config, storedAsk *storedask.StoredAsk, h host.Host, ds dtypes.MetadataDS, ibs dtypes.StagingBlockstore, r repo.LockedRepo, pieceStore dtypes.ProviderPieceStore, dataTransfer dtypes.ProviderDataTransfer, spn storagemarket.StorageProviderNode) (storagemarket.StorageProvider, error) {
|
func StorageProvider(minerAddress dtypes.MinerAddress, ffiConfig *ffiwrapper.Config, storedAsk *storedask.StoredAsk, h host.Host, ds dtypes.MetadataDS, ibs dtypes.StagingBlockstore, r repo.LockedRepo, pieceStore dtypes.ProviderPieceStore, dataTransfer dtypes.ProviderDataTransfer, spn storagemarket.StorageProviderNode, isAcceptingFunc dtypes.AcceptingStorageDealsConfigFunc) (storagemarket.StorageProvider, error) {
|
||||||
net := smnet.NewFromLibp2pHost(h)
|
net := smnet.NewFromLibp2pHost(h)
|
||||||
store, err := piecefilestore.NewLocalFileStore(piecefilestore.OsPath(r.Path()))
|
store, err := piecefilestore.NewLocalFileStore(piecefilestore.OsPath(r.Path()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
p, err := storageimpl.NewProvider(net, namespace.Wrap(ds, datastore.NewKey("/deals/provider")), ibs, store, pieceStore, dataTransfer, spn, address.Address(minerAddress), ffiConfig.SealProofType, storedAsk)
|
opt := storageimpl.CustomDealDecisionLogic(func(ctx context.Context, deal storagemarket.MinerDeal) (bool, string, error) {
|
||||||
|
b, err := isAcceptingFunc()
|
||||||
|
if err != nil {
|
||||||
|
return false, "miner error", err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !b {
|
||||||
|
log.Warnf("storage deal acceptance disabled; rejecting storage deal proposal from client: %s", deal.Client.String())
|
||||||
|
return false, "miner is not accepting storage deals", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, "", nil
|
||||||
|
})
|
||||||
|
|
||||||
|
p, err := storageimpl.NewProvider(net, namespace.Wrap(ds, datastore.NewKey("/deals/provider")), ibs, store, pieceStore, dataTransfer, spn, address.Address(minerAddress), ffiConfig.SealProofType, storedAsk, opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return p, err
|
return p, err
|
||||||
}
|
}
|
||||||
@ -361,3 +378,37 @@ func StorageAuth(ctx helpers.MetricsCtx, ca lapi.Common) (sectorstorage.StorageA
|
|||||||
headers.Add("Authorization", "Bearer "+string(token))
|
headers.Add("Authorization", "Bearer "+string(token))
|
||||||
return sectorstorage.StorageAuth(headers), nil
|
return sectorstorage.StorageAuth(headers), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewAcceptingStorageDealsConfigFunc(r repo.LockedRepo) (dtypes.AcceptingStorageDealsConfigFunc, error) {
|
||||||
|
return func() (bool, error) {
|
||||||
|
raw, err := r.Config()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg, ok := raw.(*config.StorageMiner)
|
||||||
|
if !ok {
|
||||||
|
return false, xerrors.New("expected address of config.StorageMiner")
|
||||||
|
}
|
||||||
|
|
||||||
|
return cfg.Dealmaking.AcceptingStorageDeals, nil
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSetAcceptingStorageDealsConfigFunc(r repo.LockedRepo) (dtypes.SetAcceptingStorageDealsConfigFunc, 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.AcceptingStorageDeals = b
|
||||||
|
})
|
||||||
|
|
||||||
|
return multierr.Combine(typeErr, setConfigErr)
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user