From eb2879ca2244eef2d9d663e629534456c264bfd6 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Thu, 13 Aug 2020 17:08:46 -0700 Subject: [PATCH 1/5] allow client to specify provider collateral --- api/api_full.go | 17 +++++++++-------- cli/client.go | 30 ++++++++++++++++++++++-------- node/impl/client/client.go | 3 +-- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index 55e958850..fe61afa26 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -609,14 +609,15 @@ type MethodCall struct { } type StartDealParams struct { - Data *storagemarket.DataRef - Wallet address.Address - Miner address.Address - EpochPrice types.BigInt - MinBlocksDuration uint64 - DealStartEpoch abi.ChainEpoch - FastRetrieval bool - VerifiedDeal bool + Data *storagemarket.DataRef + Wallet address.Address + Miner address.Address + EpochPrice types.BigInt + MinBlocksDuration uint64 + ProviderCollateral big.Int + DealStartEpoch abi.ChainEpoch + FastRetrieval bool + VerifiedDeal bool } type IpldObject struct { diff --git a/cli/client.go b/cli/client.go index 0e70a6faa..968146cc4 100644 --- a/cli/client.go +++ b/cli/client.go @@ -311,6 +311,10 @@ var clientDealCmd = &cli.Command{ Usage: "indicate that the deal counts towards verified client total", Value: false, }, + &cli.StringFlag{ + Name: "provider-collateral", + Usage: "specify the requested provider collateral the miner should put up", + }, &CidBaseFlag, }, Action: func(cctx *cli.Context) error { @@ -351,6 +355,15 @@ var clientDealCmd = &cli.Command{ return err } + var provCol big.Int + if pcs := cctx.String("provider-collateral"); pc != "" { + pc, err := big.FromString(pc) + if err != nil { + return fmt.Errorf("failed to parse provider-collateral: %w", err) + } + provCol = pc + } + if abi.ChainEpoch(dur) < build.MinDealDuration { return xerrors.Errorf("minimum deal duration is %d blocks", build.MinDealDuration) } @@ -415,14 +428,15 @@ var clientDealCmd = &cli.Command{ } proposal, err := api.ClientStartDeal(ctx, &lapi.StartDealParams{ - Data: ref, - Wallet: a, - Miner: miner, - EpochPrice: types.BigInt(price), - MinBlocksDuration: uint64(dur), - DealStartEpoch: abi.ChainEpoch(cctx.Int64("start-epoch")), - FastRetrieval: cctx.Bool("fast-retrieval"), - VerifiedDeal: isVerified, + Data: ref, + Wallet: a, + Miner: miner, + EpochPrice: types.BigInt(price), + MinBlocksDuration: uint64(dur), + DealStartEpoch: abi.ChainEpoch(cctx.Int64("start-epoch")), + FastRetrieval: cctx.Bool("fast-retrieval"), + VerifiedDeal: isVerified, + ProviderCollateral: provCol, }) if err != nil { return err diff --git a/node/impl/client/client.go b/node/impl/client/client.go index 404487859..df9febe75 100644 --- a/node/impl/client/client.go +++ b/node/impl/client/client.go @@ -36,7 +36,6 @@ import ( "github.com/filecoin-project/go-multistore" "github.com/filecoin-project/go-padreader" "github.com/filecoin-project/specs-actors/actors/abi" - "github.com/filecoin-project/specs-actors/actors/abi/big" "github.com/filecoin-project/specs-actors/actors/builtin/miner" marketevents "github.com/filecoin-project/lotus/markets/loggers" @@ -157,7 +156,7 @@ func (a *API) ClientStartDeal(ctx context.Context, params *api.StartDealParams) StartEpoch: dealStart, EndEpoch: calcDealExpiration(params.MinBlocksDuration, md, dealStart), Price: params.EpochPrice, - Collateral: big.Zero(), + Collateral: params.ProviderCollateral, Rt: rt, FastRetrieval: params.FastRetrieval, VerifiedDeal: params.VerifiedDeal, From b49276ef4768086421c7538a5a4ad5b44acad4ee Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Thu, 13 Aug 2020 21:54:39 -0400 Subject: [PATCH 2/5] Double provider collateral estimates in the client atadpter --- markets/storageadapter/client.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/markets/storageadapter/client.go b/markets/storageadapter/client.go index f7627fa7a..31a63fb65 100644 --- a/markets/storageadapter/client.go +++ b/markets/storageadapter/client.go @@ -5,6 +5,7 @@ package storageadapter import ( "bytes" "context" + "github.com/filecoin-project/specs-actors/actors/abi/big" "golang.org/x/xerrors" @@ -230,7 +231,7 @@ func (c *ClientNodeAdapter) DealProviderCollateralBounds(ctx context.Context, si return abi.TokenAmount{}, abi.TokenAmount{}, err } - return bounds.Min, bounds.Max, nil + return big.Mul(bounds.Min, big.NewInt(2)), bounds.Max, nil } func (c *ClientNodeAdapter) OnDealSectorCommitted(ctx context.Context, provider address.Address, dealId abi.DealID, cb storagemarket.DealSectorCommittedCallback) error { From c2a24b7b4ce6116d204dfd6d6296380e7f27e032 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Thu, 13 Aug 2020 22:13:31 -0400 Subject: [PATCH 3/5] Update markets --- go.mod | 2 +- go.sum | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 7a6d84fe5..13b154c26 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,7 @@ require ( github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03 github.com/filecoin-project/go-data-transfer v0.6.1 github.com/filecoin-project/go-fil-commcid v0.0.0-20200716160307-8f644712406f - github.com/filecoin-project/go-fil-markets v0.5.5 + github.com/filecoin-project/go-fil-markets v0.5.6-0.20200814021159-7be996ed8ccb github.com/filecoin-project/go-jsonrpc v0.1.1-0.20200602181149-522144ab4e24 github.com/filecoin-project/go-multistore v0.0.3 github.com/filecoin-project/go-padreader v0.0.0-20200210211231-548257017ca6 diff --git a/go.sum b/go.sum index 95304002d..808632267 100644 --- a/go.sum +++ b/go.sum @@ -240,8 +240,8 @@ github.com/filecoin-project/go-data-transfer v0.6.1 h1:EA6X8fSiBRNVVwKm5pA7+njZn github.com/filecoin-project/go-data-transfer v0.6.1/go.mod h1:uRYBRKVBVM12CSusBtVrzDHkVw/3DKZpkxKJVP1Ydas= github.com/filecoin-project/go-fil-commcid v0.0.0-20200716160307-8f644712406f h1:GxJzR3oRIMTPtpZ0b7QF8FKPK6/iPAc7trhlL5k/g+s= github.com/filecoin-project/go-fil-commcid v0.0.0-20200716160307-8f644712406f/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ= -github.com/filecoin-project/go-fil-markets v0.5.5 h1:6bDUXXWgMfhHLdp6KJJGfffOwM4lA7I8yJ9bSFLgnbQ= -github.com/filecoin-project/go-fil-markets v0.5.5/go.mod h1:9Sbm+N/WW2QpcmeDgEcQo7BJMPDbDpfHOvsYS9kT7zs= +github.com/filecoin-project/go-fil-markets v0.5.6-0.20200814021159-7be996ed8ccb h1:eCLqJb1tmhMCWUFAfJuSyyv/qLrqiAhICLjhUcbi4x8= +github.com/filecoin-project/go-fil-markets v0.5.6-0.20200814021159-7be996ed8ccb/go.mod h1:SJApXAKr5jyGpbzDEOhvemui0pih7hhT8r2MXJxCP1E= github.com/filecoin-project/go-jsonrpc v0.1.1-0.20200602181149-522144ab4e24 h1:Jc7vkplmZYVuaEcSXGHDwefvZIdoyyaoGDLqSr8Svms= github.com/filecoin-project/go-jsonrpc v0.1.1-0.20200602181149-522144ab4e24/go.mod h1:j6zV//WXIIY5kky873Q3iIKt/ViOE8rcijovmpxrXzM= github.com/filecoin-project/go-multistore v0.0.3 h1:vaRBY4YiA2UZFPK57RNuewypB8u0DzzQwqsL0XarpnI= @@ -254,6 +254,8 @@ github.com/filecoin-project/go-paramfetch v0.0.2-0.20200701152213-3e0f0afdc261/g github.com/filecoin-project/go-statemachine v0.0.0-20200714194326-a77c3ae20989/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig= github.com/filecoin-project/go-statemachine v0.0.0-20200730031800-c3336614d2a7 h1:KAF3WM/xSnl6G6RHX8vDJthg4+e4PSgBh72//6c6Qvc= github.com/filecoin-project/go-statemachine v0.0.0-20200730031800-c3336614d2a7/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig= +github.com/filecoin-project/go-statemachine v0.0.0-20200813232949-df9b130df370 h1:Jbburj7Ih2iaJ/o5Q9A+EAeTabME6YII7FLi9SKUf5c= +github.com/filecoin-project/go-statemachine v0.0.0-20200813232949-df9b130df370/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig= github.com/filecoin-project/go-statestore v0.1.0 h1:t56reH59843TwXHkMcwyuayStBIiWBRilQjQ+5IiwdQ= github.com/filecoin-project/go-statestore v0.1.0/go.mod h1:LFc9hD+fRxPqiHiaqUEZOinUJB4WARkRfNl10O7kTnI= github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b h1:fkRZSPrYpk42PV3/lIXiL0LHetxde7vyYYvSsttQtfg= From 2d90bcff3c8fecce01ddd274ba6f04bc2430a564 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Thu, 13 Aug 2020 22:14:45 -0400 Subject: [PATCH 4/5] jeromy is a bad software engineer --- cli/client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/client.go b/cli/client.go index 968146cc4..41f0f8f8f 100644 --- a/cli/client.go +++ b/cli/client.go @@ -356,8 +356,8 @@ var clientDealCmd = &cli.Command{ } var provCol big.Int - if pcs := cctx.String("provider-collateral"); pc != "" { - pc, err := big.FromString(pc) + if pcs := cctx.String("provider-collateral"); pcs != "" { + pc, err := big.FromString(pcs) if err != nil { return fmt.Errorf("failed to parse provider-collateral: %w", err) } From 5ca410ae99c03de53bf80c3c9d298929a9ff62bd Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Thu, 13 Aug 2020 22:21:20 -0400 Subject: [PATCH 5/5] extract overestimation factor into a constant --- markets/storageadapter/client.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/markets/storageadapter/client.go b/markets/storageadapter/client.go index 31a63fb65..f621c3838 100644 --- a/markets/storageadapter/client.go +++ b/markets/storageadapter/client.go @@ -225,13 +225,15 @@ func (c *ClientNodeAdapter) ValidatePublishedDeal(ctx context.Context, deal stor return res.IDs[dealIdx], nil } +const clientOverestimation = 2 + func (c *ClientNodeAdapter) DealProviderCollateralBounds(ctx context.Context, size abi.PaddedPieceSize, isVerified bool) (abi.TokenAmount, abi.TokenAmount, error) { bounds, err := c.StateDealProviderCollateralBounds(ctx, size, isVerified, types.EmptyTSK) if err != nil { return abi.TokenAmount{}, abi.TokenAmount{}, err } - return big.Mul(bounds.Min, big.NewInt(2)), bounds.Max, nil + return big.Mul(bounds.Min, big.NewInt(clientOverestimation)), bounds.Max, nil } func (c *ClientNodeAdapter) OnDealSectorCommitted(ctx context.Context, provider address.Address, dealId abi.DealID, cb storagemarket.DealSectorCommittedCallback) error {