wire up lotus side of make deal for manual commP

This commit is contained in:
whyrusleeping 2020-03-02 16:36:01 -08:00
parent 99c842e027
commit 2be2891647
5 changed files with 57 additions and 24 deletions

View File

@ -89,7 +89,7 @@ type FullNode interface {
// ClientImport imports file under the specified path into filestore // ClientImport imports file under the specified path into filestore
ClientImport(ctx context.Context, path string) (cid.Cid, error) ClientImport(ctx context.Context, path string) (cid.Cid, error)
ClientStartDeal(ctx context.Context, data *storagemarket.DataRef, addr address.Address, miner address.Address, epochPrice types.BigInt, blocksDuration uint64) (*cid.Cid, error) ClientStartDeal(ctx context.Context, params *StartDealParams) (*cid.Cid, error)
ClientGetDealInfo(context.Context, cid.Cid) (*DealInfo, error) ClientGetDealInfo(context.Context, cid.Cid) (*DealInfo, error)
ClientListDeals(ctx context.Context) ([]DealInfo, error) ClientListDeals(ctx context.Context) ([]DealInfo, error)
ClientHasLocal(ctx context.Context, root cid.Cid) (bool, error) ClientHasLocal(ctx context.Context, root cid.Cid) (bool, error)
@ -303,6 +303,16 @@ type MethodCall struct {
Error string Error string
} }
type StartDealParams struct {
Data *storagemarket.DataRef
Wallet address.Address
Miner address.Address
EpochPrice types.BigInt
BlocksDuration uint64
PieceCommitment *cid.Cid
}
type ActiveSync struct { type ActiveSync struct {
Base *types.TipSet Base *types.TipSet
Target *types.TipSet Target *types.TipSet

View File

@ -93,15 +93,15 @@ type FullNodeStruct struct {
WalletExport func(context.Context, address.Address) (*types.KeyInfo, error) `perm:"admin"` WalletExport func(context.Context, address.Address) (*types.KeyInfo, error) `perm:"admin"`
WalletImport func(context.Context, *types.KeyInfo) (address.Address, error) `perm:"admin"` WalletImport func(context.Context, *types.KeyInfo) (address.Address, error) `perm:"admin"`
ClientImport func(ctx context.Context, path string) (cid.Cid, error) `perm:"admin"` ClientImport func(ctx context.Context, path string) (cid.Cid, error) `perm:"admin"`
ClientListImports func(ctx context.Context) ([]api.Import, error) `perm:"write"` ClientListImports func(ctx context.Context) ([]api.Import, error) `perm:"write"`
ClientHasLocal func(ctx context.Context, root cid.Cid) (bool, error) `perm:"write"` ClientHasLocal func(ctx context.Context, root cid.Cid) (bool, error) `perm:"write"`
ClientFindData func(ctx context.Context, root cid.Cid) ([]api.QueryOffer, error) `perm:"read"` ClientFindData func(ctx context.Context, root cid.Cid) ([]api.QueryOffer, error) `perm:"read"`
ClientStartDeal func(ctx context.Context, data *storagemarket.DataRef, addr address.Address, miner address.Address, price types.BigInt, blocksDuration uint64) (*cid.Cid, error) `perm:"admin"` ClientStartDeal func(ctx context.Context, params *api.StartDealParams) (*cid.Cid, error) `perm:"admin"`
ClientGetDealInfo func(context.Context, cid.Cid) (*api.DealInfo, error) `perm:"read"` ClientGetDealInfo func(context.Context, cid.Cid) (*api.DealInfo, error) `perm:"read"`
ClientListDeals func(ctx context.Context) ([]api.DealInfo, error) `perm:"write"` ClientListDeals func(ctx context.Context) ([]api.DealInfo, error) `perm:"write"`
ClientRetrieve func(ctx context.Context, order api.RetrievalOrder, path string) error `perm:"admin"` ClientRetrieve func(ctx context.Context, order api.RetrievalOrder, path string) error `perm:"admin"`
ClientQueryAsk func(ctx context.Context, p peer.ID, miner address.Address) (*storagemarket.SignedStorageAsk, error) `perm:"read"` ClientQueryAsk func(ctx context.Context, p peer.ID, miner address.Address) (*storagemarket.SignedStorageAsk, error) `perm:"read"`
StateMinerSectors func(context.Context, address.Address, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"` StateMinerSectors func(context.Context, address.Address, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"`
StateMinerProvingSet func(context.Context, address.Address, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"` StateMinerProvingSet func(context.Context, address.Address, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"`
@ -247,8 +247,8 @@ func (c *FullNodeStruct) ClientFindData(ctx context.Context, root cid.Cid) ([]ap
return c.Internal.ClientFindData(ctx, root) return c.Internal.ClientFindData(ctx, root)
} }
func (c *FullNodeStruct) ClientStartDeal(ctx context.Context, data *storagemarket.DataRef, addr address.Address, miner address.Address, price types.BigInt, blocksDuration uint64) (*cid.Cid, error) { func (c *FullNodeStruct) ClientStartDeal(ctx context.Context, params *api.StartDealParams) (*cid.Cid, error) {
return c.Internal.ClientStartDeal(ctx, data, addr, miner, price, blocksDuration) return c.Internal.ClientStartDeal(ctx, params)
} }
func (c *FullNodeStruct) ClientGetDealInfo(ctx context.Context, deal cid.Cid) (*api.DealInfo, error) { func (c *FullNodeStruct) ClientGetDealInfo(ctx context.Context, deal cid.Cid) (*api.DealInfo, error) {
return c.Internal.ClientGetDealInfo(ctx, deal) return c.Internal.ClientGetDealInfo(ctx, deal)

View File

@ -3,6 +3,7 @@ package stmgr
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"

View File

@ -15,6 +15,7 @@ import (
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-fil-markets/storagemarket" "github.com/filecoin-project/go-fil-markets/storagemarket"
lapi "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
) )
@ -86,6 +87,10 @@ var clientDealCmd = &cli.Command{
Name: "manual-transfer", Name: "manual-transfer",
Usage: "data will be transferred out of band", Usage: "data will be transferred out of band",
}, },
&cli.StringFlag{
Name: "manual-piece-cid",
Usage: "manually specify piece commitment for data",
},
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx) api, closer, err := GetFullNodeAPI(cctx)
@ -134,7 +139,24 @@ var clientDealCmd = &cli.Command{
ref.TransferType = storagemarket.TTManual ref.TransferType = storagemarket.TTManual
} }
proposal, err := api.ClientStartDeal(ctx, ref, a, miner, types.BigInt(price), uint64(dur)) var pcid *cid.Cid
if mpc := cctx.String("manual-piece-cid"); mpc != "" {
c, err := cid.Parse(mpc)
if err != nil {
return xerrors.Errorf("failed to parse provided manual piece cid: %w", err)
}
pcid = &c
}
proposal, err := api.ClientStartDeal(ctx, &lapi.StartDealParams{
Data: ref,
Wallet: a,
Miner: miner,
EpochPrice: types.BigInt(price),
BlocksDuration: uint64(dur),
PieceCommitment: pcid,
})
if err != nil { if err != nil {
return err return err
} }

View File

@ -58,26 +58,26 @@ type API struct {
Filestore dtypes.ClientFilestore `optional:"true"` Filestore dtypes.ClientFilestore `optional:"true"`
} }
func (a *API) ClientStartDeal(ctx context.Context, data *storagemarket.DataRef, addr address.Address, miner address.Address, epochPrice types.BigInt, blocksDuration uint64) (*cid.Cid, error) { func (a *API) ClientStartDeal(ctx context.Context, params *api.StartDealParams) (*cid.Cid, error) {
exist, err := a.WalletHas(ctx, addr) exist, err := a.WalletHas(ctx, params.Wallet)
if err != nil { if err != nil {
return nil, xerrors.Errorf("failed getting addr from wallet: %w", addr) return nil, xerrors.Errorf("failed getting addr from wallet: %w", params.Wallet)
} }
if !exist { if !exist {
return nil, xerrors.Errorf("provided address doesn't exist in wallet") return nil, xerrors.Errorf("provided address doesn't exist in wallet")
} }
pid, err := a.StateMinerPeerID(ctx, miner, types.EmptyTSK) pid, err := a.StateMinerPeerID(ctx, params.Miner, types.EmptyTSK)
if err != nil { if err != nil {
return nil, xerrors.Errorf("failed getting peer ID: %w", err) return nil, xerrors.Errorf("failed getting peer ID: %w", err)
} }
mw, err := a.StateMinerWorker(ctx, miner, types.EmptyTSK) mw, err := a.StateMinerWorker(ctx, params.Miner, types.EmptyTSK)
if err != nil { if err != nil {
return nil, xerrors.Errorf("failed getting miner worker: %w", err) return nil, xerrors.Errorf("failed getting miner worker: %w", err)
} }
ssize, err := a.StateMinerSectorSize(ctx, miner, types.EmptyTSK) ssize, err := a.StateMinerSectorSize(ctx, params.Miner, types.EmptyTSK)
if err != nil { if err != nil {
return nil, xerrors.Errorf("failed checking miners sector size: %w", err) return nil, xerrors.Errorf("failed checking miners sector size: %w", err)
} }
@ -87,19 +87,19 @@ func (a *API) ClientStartDeal(ctx context.Context, data *storagemarket.DataRef,
return nil, xerrors.Errorf("bad sector size: %w", err) return nil, xerrors.Errorf("bad sector size: %w", err)
} }
providerInfo := utils.NewStorageProviderInfo(miner, mw, 0, pid) providerInfo := utils.NewStorageProviderInfo(params.Miner, mw, 0, pid)
ts, err := a.ChainHead(ctx) ts, err := a.ChainHead(ctx)
if err != nil { if err != nil {
return nil, xerrors.Errorf("failed getting chain height: %w", err) return nil, xerrors.Errorf("failed getting chain height: %w", err)
} }
result, err := a.SMDealClient.ProposeStorageDeal( result, err := a.SMDealClient.ProposeStorageDeal(
ctx, ctx,
addr, params.Wallet,
&providerInfo, &providerInfo,
data, params.Data,
ts.Height()+dealStartBuffer, ts.Height()+dealStartBuffer,
ts.Height()+dealStartBuffer+abi.ChainEpoch(blocksDuration), ts.Height()+dealStartBuffer+abi.ChainEpoch(params.BlocksDuration),
epochPrice, params.EpochPrice,
big.Zero(), big.Zero(),
rt, rt,
) )