Add flag to specify deal start epoch

This commit is contained in:
Jeromy 2020-04-30 10:42:16 -07:00
parent f16ae9dffb
commit e345525672
3 changed files with 21 additions and 7 deletions

View File

@ -331,6 +331,7 @@ type StartDealParams struct {
Miner address.Address
EpochPrice types.BigInt
MinBlocksDuration uint64
DealStartEpoch abi.ChainEpoch
}
type IpldObject struct {

View File

@ -173,6 +173,11 @@ var clientDealCmd = &cli.Command{
Name: "from",
Usage: "specify address to fund the deal with",
},
&cli.Int64Flag{
Name: "start-epoch",
Usage: "specify the epoch that the deal should start at",
Value: -1,
},
},
Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx)
@ -252,6 +257,7 @@ var clientDealCmd = &cli.Command{
Miner: miner,
EpochPrice: types.BigInt(price),
MinBlocksDuration: uint64(dur),
DealStartEpoch: abi.ChainEpoch(cctx.Int64("start-epoch")),
})
if err != nil {
return err

View File

@ -3,6 +3,7 @@ package client
import (
"context"
"errors"
"github.com/filecoin-project/go-fil-markets/pieceio"
ipldfree "github.com/ipld/go-ipld-prime/impl/free"
"github.com/ipld/go-ipld-prime/traversal/selector"
@ -66,9 +67,9 @@ type API struct {
Filestore dtypes.ClientFilestore `optional:"true"`
}
func calcDealExpiration(minDuration uint64, md *miner.DeadlineInfo, ts *types.TipSet) abi.ChainEpoch {
func calcDealExpiration(minDuration uint64, md *miner.DeadlineInfo, startEpoch abi.ChainEpoch) abi.ChainEpoch {
// Make sure we give some time for the miner to seal
minExp := ts.Height() + dealStartBuffer + abi.ChainEpoch(minDuration)
minExp := startEpoch + abi.ChainEpoch(minDuration)
// Align on miners ProvingPeriodBoundary
return minExp + miner.WPoStProvingPeriod - (minExp % miner.WPoStProvingPeriod) + (md.PeriodStart % miner.WPoStProvingPeriod) - 1
@ -103,18 +104,24 @@ func (a *API) ClientStartDeal(ctx context.Context, params *api.StartDealParams)
}
providerInfo := utils.NewStorageProviderInfo(params.Miner, mi.Worker, mi.SectorSize, mi.PeerId)
dealStart := params.DealStartEpoch
if dealStart <= 0 { // unset, or explicitly 'epoch undefined'
ts, err := a.ChainHead(ctx)
if err != nil {
return nil, xerrors.Errorf("failed getting chain height: %w", err)
}
dealStart = ts.Height() + dealStartBuffer
}
result, err := a.SMDealClient.ProposeStorageDeal(
ctx,
params.Wallet,
&providerInfo,
params.Data,
ts.Height()+dealStartBuffer,
calcDealExpiration(params.MinBlocksDuration, md, ts),
dealStart,
calcDealExpiration(params.MinBlocksDuration, md, dealStart),
params.EpochPrice,
big.Zero(),
rt,