From 6253c39100f4fcc16099e6f4fbcd620aad11c13c Mon Sep 17 00:00:00 2001 From: laser Date: Tue, 16 Jun 2020 15:38:48 -0700 Subject: [PATCH 01/13] replace "set-price" with "set-ask" Fixes #2027 --- api/api_storage.go | 2 +- api/apistruct/struct.go | 12 +++--- cmd/lotus-storage-miner/main.go | 1 - cmd/lotus-storage-miner/market.go | 67 ++++++++++++++++++++++++++----- node/impl/storminer.go | 9 ++++- 5 files changed, 70 insertions(+), 21 deletions(-) diff --git a/api/api_storage.go b/api/api_storage.go index 04ff8311c94..e07505e3fb4 100644 --- a/api/api_storage.go +++ b/api/api_storage.go @@ -50,7 +50,7 @@ type StorageMiner interface { MarketImportDealData(ctx context.Context, propcid cid.Cid, path string) error MarketListDeals(ctx context.Context) ([]storagemarket.StorageDeal, error) MarketListIncompleteDeals(ctx context.Context) ([]storagemarket.MinerDeal, error) - MarketSetPrice(context.Context, types.BigInt) error + MarketSetAsk(ctx context.Context, price types.BigInt, duration abi.ChainEpoch, minPieceSize abi.PaddedPieceSize, maxPieceSize abi.PaddedPieceSize) error DealsImportData(ctx context.Context, dealPropCid cid.Cid, file string) error DealsList(ctx context.Context) ([]storagemarket.StorageDeal, error) diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index 02d9e515553..55c87dbd413 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -192,10 +192,10 @@ type StorageMinerStruct struct { MiningBase func(context.Context) (*types.TipSet, error) `perm:"read"` - MarketImportDealData func(context.Context, cid.Cid, string) error `perm:"write"` - MarketListDeals func(ctx context.Context) ([]storagemarket.StorageDeal, error) `perm:"read"` - MarketListIncompleteDeals func(ctx context.Context) ([]storagemarket.MinerDeal, error) `perm:"read"` - MarketSetPrice func(context.Context, types.BigInt) error `perm:"admin"` + MarketImportDealData func(context.Context, cid.Cid, string) error `perm:"write"` + MarketListDeals func(ctx context.Context) ([]storagemarket.StorageDeal, error) `perm:"read"` + MarketListIncompleteDeals func(ctx context.Context) ([]storagemarket.MinerDeal, error) `perm:"read"` + MarketSetAsk func(ctx context.Context, price types.BigInt, duration abi.ChainEpoch, minPieceSize abi.PaddedPieceSize, maxPieceSize abi.PaddedPieceSize) error `perm:"admin"` PledgeSector func(context.Context) error `perm:"write"` @@ -841,8 +841,8 @@ func (c *StorageMinerStruct) MarketListIncompleteDeals(ctx context.Context) ([]s return c.Internal.MarketListIncompleteDeals(ctx) } -func (c *StorageMinerStruct) MarketSetPrice(ctx context.Context, p types.BigInt) error { - return c.Internal.MarketSetPrice(ctx, p) +func (c *StorageMinerStruct) MarketSetAsk(ctx context.Context, price types.BigInt, duration abi.ChainEpoch, minPieceSize abi.PaddedPieceSize, maxPieceSize abi.PaddedPieceSize) error { + return c.Internal.MarketSetAsk(ctx, price, duration, minPieceSize, maxPieceSize) } func (c *StorageMinerStruct) DealsImportData(ctx context.Context, dealPropCid cid.Cid, file string) error { diff --git a/cmd/lotus-storage-miner/main.go b/cmd/lotus-storage-miner/main.go index ba7722e4e9e..dc6de70292e 100644 --- a/cmd/lotus-storage-miner/main.go +++ b/cmd/lotus-storage-miner/main.go @@ -30,7 +30,6 @@ func main() { stopCmd, sectorsCmd, storageCmd, - setPriceCmd, workersCmd, provingCmd, } diff --git a/cmd/lotus-storage-miner/market.go b/cmd/lotus-storage-miner/market.go index c2f2555fa37..74a42d85d7f 100644 --- a/cmd/lotus-storage-miner/market.go +++ b/cmd/lotus-storage-miner/market.go @@ -4,10 +4,13 @@ import ( "encoding/json" "fmt" - "github.com/filecoin-project/lotus/chain/types" - lcli "github.com/filecoin-project/lotus/cli" + "github.com/docker/go-units" + "github.com/filecoin-project/specs-actors/actors/abi" "github.com/ipfs/go-cid" "github.com/urfave/cli/v2" + + "github.com/filecoin-project/lotus/chain/types" + lcli "github.com/filecoin-project/lotus/cli" ) var enableCmd = &cli.Command{ @@ -40,29 +43,70 @@ var disableCmd = &cli.Command{ }, } -var setPriceCmd = &cli.Command{ - Name: "set-price", - Usage: "Set price that miner will accept storage deals at (FIL / GiB / Epoch)", - Flags: []cli.Flag{}, +var setAskCmd = &cli.Command{ + Name: "set-ask", + Usage: "Configure the miner's ask", + Flags: []cli.Flag{ + &cli.Uint64Flag{ + Name: "price", + Usage: "Set the price of the ask (specified as FIL / GiB / Epoch) to `PRICE`", + Required: true, + }, + &cli.Uint64Flag{ + Name: "duration", + Usage: "Set the duration (specified as epochs) of the ask to `DURATION`", + DefaultText: "8640000", + Value: 8640000, + }, + &cli.StringFlag{ + Name: "min-piece-size", + Usage: "Set minimum piece size (without bit-padding, in bytes) in ask to `SIZE`", + DefaultText: "254B", + Value: "254B", + }, + &cli.StringFlag{ + Name: "max-piece-size", + Usage: "Set maximum piece size (without bit-padding, in bytes) in ask to `SIZE`", + DefaultText: "miner sector size, without bit-padding", + }, + }, Action: func(cctx *cli.Context) error { + ctx := lcli.DaemonContext(cctx) + api, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.DaemonContext(cctx) + pri := types.NewInt(cctx.Uint64("price")) + dur := abi.ChainEpoch(cctx.Uint64("duration")) - if !cctx.Args().Present() { - return fmt.Errorf("must specify price to set") + min, err := units.RAMInBytes(cctx.String("min-piece-size")) + if err != nil { + return err } - fp, err := types.ParseFIL(cctx.Args().First()) + max, err := units.RAMInBytes(cctx.String("max-piece-size")) if err != nil { return err } - return api.MarketSetPrice(ctx, types.BigInt(fp)) + if max == 0 { + maddr, err := api.ActorAddress(ctx) + if err != nil { + return err + } + + ssize, err := api.ActorSectorSize(ctx, maddr) + if err != nil { + return err + } + + max = int64(abi.PaddedPieceSize(ssize).Unpadded()) + } + + return api.MarketSetAsk(ctx, pri, dur, abi.UnpaddedPieceSize(min).Padded(), abi.UnpaddedPieceSize(max).Padded()) }, } @@ -74,6 +118,7 @@ var dealsCmd = &cli.Command{ dealsListCmd, enableCmd, disableCmd, + setAskCmd, }, } diff --git a/node/impl/storminer.go b/node/impl/storminer.go index 0cc13177eb7..7ece10ac02a 100644 --- a/node/impl/storminer.go +++ b/node/impl/storminer.go @@ -201,8 +201,13 @@ func (sm *StorageMinerAPI) MarketListIncompleteDeals(ctx context.Context) ([]sto return sm.StorageProvider.ListLocalDeals() } -func (sm *StorageMinerAPI) MarketSetPrice(ctx context.Context, p types.BigInt) error { - return sm.StorageProvider.SetAsk(p, 60*60*24*100) // lasts for 100 days? +func (sm *StorageMinerAPI) MarketSetAsk(ctx context.Context, price types.BigInt, duration abi.ChainEpoch, minPieceSize abi.PaddedPieceSize, maxPieceSize abi.PaddedPieceSize) error { + options := []storagemarket.StorageAskOption{ + storagemarket.MinPieceSize(minPieceSize), + storagemarket.MaxPieceSize(maxPieceSize), + } + + return sm.StorageProvider.SetAsk(price, duration, options...) } func (sm *StorageMinerAPI) DealsList(ctx context.Context) ([]storagemarket.StorageDeal, error) { From 5eceed81e192a9aca66dbe06e6ae64d28e0c264e Mon Sep 17 00:00:00 2001 From: laser Date: Tue, 16 Jun 2020 17:18:54 -0700 Subject: [PATCH 02/13] add "get-ask" command --- api/api_storage.go | 1 + api/apistruct/struct.go | 5 ++++ cmd/lotus-storage-miner/market.go | 46 +++++++++++++++++++++++++++++-- node/impl/storminer.go | 4 +++ 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/api/api_storage.go b/api/api_storage.go index e07505e3fb4..90de01fb9ad 100644 --- a/api/api_storage.go +++ b/api/api_storage.go @@ -51,6 +51,7 @@ type StorageMiner interface { MarketListDeals(ctx context.Context) ([]storagemarket.StorageDeal, error) MarketListIncompleteDeals(ctx context.Context) ([]storagemarket.MinerDeal, error) MarketSetAsk(ctx context.Context, price types.BigInt, duration abi.ChainEpoch, minPieceSize abi.PaddedPieceSize, maxPieceSize abi.PaddedPieceSize) error + MarketGetAsk(ctx context.Context) (*storagemarket.SignedStorageAsk, error) DealsImportData(ctx context.Context, dealPropCid cid.Cid, file string) error DealsList(ctx context.Context) ([]storagemarket.StorageDeal, error) diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index 55c87dbd413..a1fe69f065c 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -196,6 +196,7 @@ type StorageMinerStruct struct { MarketListDeals func(ctx context.Context) ([]storagemarket.StorageDeal, error) `perm:"read"` MarketListIncompleteDeals func(ctx context.Context) ([]storagemarket.MinerDeal, error) `perm:"read"` MarketSetAsk func(ctx context.Context, price types.BigInt, duration abi.ChainEpoch, minPieceSize abi.PaddedPieceSize, maxPieceSize abi.PaddedPieceSize) error `perm:"admin"` + MarketGetAsk func(ctx context.Context) (*storagemarket.SignedStorageAsk, error) `perm:"read"` PledgeSector func(context.Context) error `perm:"write"` @@ -845,6 +846,10 @@ func (c *StorageMinerStruct) MarketSetAsk(ctx context.Context, price types.BigIn return c.Internal.MarketSetAsk(ctx, price, duration, minPieceSize, maxPieceSize) } +func (c *StorageMinerStruct) MarketGetAsk(ctx context.Context) (*storagemarket.SignedStorageAsk, error) { + return c.Internal.MarketGetAsk(ctx) +} + func (c *StorageMinerStruct) DealsImportData(ctx context.Context, dealPropCid cid.Cid, file string) error { return c.Internal.DealsImportData(ctx, dealPropCid, file) } diff --git a/cmd/lotus-storage-miner/market.go b/cmd/lotus-storage-miner/market.go index 74a42d85d7f..b2b7155c344 100644 --- a/cmd/lotus-storage-miner/market.go +++ b/cmd/lotus-storage-miner/market.go @@ -3,12 +3,16 @@ package main import ( "encoding/json" "fmt" + "os" + "text/tabwriter" "github.com/docker/go-units" - "github.com/filecoin-project/specs-actors/actors/abi" "github.com/ipfs/go-cid" "github.com/urfave/cli/v2" + "github.com/filecoin-project/go-fil-markets/storagemarket" + "github.com/filecoin-project/specs-actors/actors/abi" + "github.com/filecoin-project/lotus/chain/types" lcli "github.com/filecoin-project/lotus/cli" ) @@ -55,8 +59,8 @@ var setAskCmd = &cli.Command{ &cli.Uint64Flag{ Name: "duration", Usage: "Set the duration (specified as epochs) of the ask to `DURATION`", - DefaultText: "8640000", - Value: 8640000, + DefaultText: "100000", + Value: 100000, }, &cli.StringFlag{ Name: "min-piece-size", @@ -110,6 +114,41 @@ var setAskCmd = &cli.Command{ }, } +var getAskCmd = &cli.Command{ + Name: "get-ask", + Usage: "Print the miner's ask", + Flags: []cli.Flag{}, + Action: func(cctx *cli.Context) error { + ctx := lcli.DaemonContext(cctx) + + api, closer, err := lcli.GetStorageMinerAPI(cctx) + if err != nil { + return err + } + defer closer() + + sask, err := api.MarketGetAsk(ctx) + if err != nil { + return err + } + + var ask *storagemarket.StorageAsk + if sask != nil && sask.Ask != nil { + ask = sask.Ask + } + + w := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0) + fmt.Fprintf(w, "Price per GiB / Epoch\tMin. Piece Size (bytes, unpadded)\tMax. Piece Size (bytes, unpadded)\tExpiry\tSeq. No.\n") + if ask == nil { + fmt.Fprintf(w, "\n") + } else { + fmt.Fprintf(w, "%s\t%d\t%d\t%d\t%d\n", ask.Price, ask.MinPieceSize.Unpadded(), ask.MaxPieceSize.Unpadded(), ask.Expiry, ask.SeqNo) + } + + return w.Flush() + }, +} + var dealsCmd = &cli.Command{ Name: "deals", Usage: "interact with your deals", @@ -119,6 +158,7 @@ var dealsCmd = &cli.Command{ enableCmd, disableCmd, setAskCmd, + getAskCmd, }, } diff --git a/node/impl/storminer.go b/node/impl/storminer.go index 7ece10ac02a..ed94e173d7e 100644 --- a/node/impl/storminer.go +++ b/node/impl/storminer.go @@ -210,6 +210,10 @@ func (sm *StorageMinerAPI) MarketSetAsk(ctx context.Context, price types.BigInt, return sm.StorageProvider.SetAsk(price, duration, options...) } +func (sm *StorageMinerAPI) MarketGetAsk(ctx context.Context) (*storagemarket.SignedStorageAsk, error) { + return sm.StorageProvider.GetAsk(), nil +} + func (sm *StorageMinerAPI) DealsList(ctx context.Context) ([]storagemarket.StorageDeal, error) { return sm.StorageProvider.ListDeals(ctx) } From 4ba1846c11d031716ec0d336d8593d20736559c4 Mon Sep 17 00:00:00 2001 From: laser Date: Tue, 16 Jun 2020 17:32:45 -0700 Subject: [PATCH 03/13] format the piece sizes --- cmd/lotus-storage-miner/market.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/lotus-storage-miner/market.go b/cmd/lotus-storage-miner/market.go index b2b7155c344..60c53bff887 100644 --- a/cmd/lotus-storage-miner/market.go +++ b/cmd/lotus-storage-miner/market.go @@ -138,11 +138,11 @@ var getAskCmd = &cli.Command{ } w := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0) - fmt.Fprintf(w, "Price per GiB / Epoch\tMin. Piece Size (bytes, unpadded)\tMax. Piece Size (bytes, unpadded)\tExpiry\tSeq. No.\n") + fmt.Fprintf(w, "Price per GiB / Epoch\tMin. Piece Size (unpadded)\tMax. Piece Size (unpadded)\tExpiry\tSeq. No.\n") if ask == nil { fmt.Fprintf(w, "\n") } else { - fmt.Fprintf(w, "%s\t%d\t%d\t%d\t%d\n", ask.Price, ask.MinPieceSize.Unpadded(), ask.MaxPieceSize.Unpadded(), ask.Expiry, ask.SeqNo) + fmt.Fprintf(w, "%s\t%s\t%s\t%d\t%d\n", ask.Price, types.SizeStr(types.NewInt(uint64(ask.MinPieceSize.Unpadded()))), types.SizeStr(types.NewInt(uint64(ask.MaxPieceSize.Unpadded()))), ask.Expiry, ask.SeqNo) } return w.Flush() From 5acf5bf102d9f11eb63f49eaecaeb8604d202380 Mon Sep 17 00:00:00 2001 From: laser Date: Tue, 16 Jun 2020 17:45:11 -0700 Subject: [PATCH 04/13] upper and lower bounds checking --- cmd/lotus-storage-miner/market.go | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/cmd/lotus-storage-miner/market.go b/cmd/lotus-storage-miner/market.go index 60c53bff887..84465f60d32 100644 --- a/cmd/lotus-storage-miner/market.go +++ b/cmd/lotus-storage-miner/market.go @@ -8,6 +8,7 @@ import ( "github.com/docker/go-units" "github.com/ipfs/go-cid" + "github.com/pkg/errors" "github.com/urfave/cli/v2" "github.com/filecoin-project/go-fil-markets/storagemarket" @@ -91,23 +92,33 @@ var setAskCmd = &cli.Command{ return err } + if min < 254 { + return errors.New("minimum piece size (unpadded) is 254 B") + } + max, err := units.RAMInBytes(cctx.String("max-piece-size")) if err != nil { return err } - if max == 0 { - maddr, err := api.ActorAddress(ctx) - if err != nil { - return err - } + maddr, err := api.ActorAddress(ctx) + if err != nil { + return err + } - ssize, err := api.ActorSectorSize(ctx, maddr) - if err != nil { - return err - } + ssize, err := api.ActorSectorSize(ctx, maddr) + if err != nil { + return err + } + + smax := int64(abi.PaddedPieceSize(ssize).Unpadded()) + + if max == 0 { + max = smax + } - max = int64(abi.PaddedPieceSize(ssize).Unpadded()) + if max > smax { + return errors.Errorf("max piece size (unpadded) %s cannot exceed miner sector size (unpadded) %s", types.SizeStr(types.NewInt(uint64(max))), types.SizeStr(types.NewInt(uint64(smax)))) } return api.MarketSetAsk(ctx, pri, dur, abi.UnpaddedPieceSize(min).Padded(), abi.UnpaddedPieceSize(max).Padded()) From 2676892886cf674528528b46432fa80a76baaefa Mon Sep 17 00:00:00 2001 From: laser Date: Tue, 16 Jun 2020 17:47:04 -0700 Subject: [PATCH 05/13] go mod tidy --- go.mod | 1 + 1 file changed, 1 insertion(+) diff --git a/go.mod b/go.mod index d5e684e46d1..cb94ad0559b 100644 --- a/go.mod +++ b/go.mod @@ -103,6 +103,7 @@ require ( github.com/multiformats/go-multibase v0.0.2 github.com/multiformats/go-multihash v0.0.13 github.com/opentracing/opentracing-go v1.1.0 + github.com/pkg/errors v0.9.1 github.com/stretchr/objx v0.2.0 // indirect github.com/stretchr/testify v1.5.1 github.com/syndtr/goleveldb v1.0.0 From 139c3297ab59939285842baea007276019add121 Mon Sep 17 00:00:00 2001 From: laser Date: Wed, 17 Jun 2020 08:34:50 -0700 Subject: [PATCH 06/13] change "duration" help text --- cmd/lotus-storage-miner/market.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/lotus-storage-miner/market.go b/cmd/lotus-storage-miner/market.go index 84465f60d32..1163e09e832 100644 --- a/cmd/lotus-storage-miner/market.go +++ b/cmd/lotus-storage-miner/market.go @@ -59,7 +59,7 @@ var setAskCmd = &cli.Command{ }, &cli.Uint64Flag{ Name: "duration", - Usage: "Set the duration (specified as epochs) of the ask to `DURATION`", + Usage: "Set the number of epochs (from now) that the ask will expire `DURATION`", DefaultText: "100000", Value: 100000, }, From 5d4f1bb3f1b8004ce75cff2e3154d501014ea0a3 Mon Sep 17 00:00:00 2001 From: laser Date: Wed, 17 Jun 2020 08:42:30 -0700 Subject: [PATCH 07/13] work with bit-padded byte quantities, as per PR feedback --- cmd/lotus-storage-miner/market.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/cmd/lotus-storage-miner/market.go b/cmd/lotus-storage-miner/market.go index 1163e09e832..8d677a55cc6 100644 --- a/cmd/lotus-storage-miner/market.go +++ b/cmd/lotus-storage-miner/market.go @@ -10,6 +10,7 @@ import ( "github.com/ipfs/go-cid" "github.com/pkg/errors" "github.com/urfave/cli/v2" + "golang.org/x/xerrors" "github.com/filecoin-project/go-fil-markets/storagemarket" "github.com/filecoin-project/specs-actors/actors/abi" @@ -59,20 +60,20 @@ var setAskCmd = &cli.Command{ }, &cli.Uint64Flag{ Name: "duration", - Usage: "Set the number of epochs (from now) that the ask will expire `DURATION`", + Usage: "Set the number of epochs from the current chain head that the ask will expire `DURATION`", DefaultText: "100000", Value: 100000, }, &cli.StringFlag{ Name: "min-piece-size", - Usage: "Set minimum piece size (without bit-padding, in bytes) in ask to `SIZE`", - DefaultText: "254B", - Value: "254B", + Usage: "Set minimum piece size (w/bit-padding, in bytes) in ask to `SIZE`", + DefaultText: "256B", + Value: "256B", }, &cli.StringFlag{ Name: "max-piece-size", - Usage: "Set maximum piece size (without bit-padding, in bytes) in ask to `SIZE`", - DefaultText: "miner sector size, without bit-padding", + Usage: "Set maximum piece size (w/bit-padding, in bytes) in ask to `SIZE`", + DefaultText: "miner sector size", }, }, Action: func(cctx *cli.Context) error { @@ -92,8 +93,8 @@ var setAskCmd = &cli.Command{ return err } - if min < 254 { - return errors.New("minimum piece size (unpadded) is 254 B") + if min < 256 { + return xerrors.New("minimum piece size (w/bit-padding) is 256B") } max, err := units.RAMInBytes(cctx.String("max-piece-size")) @@ -111,17 +112,17 @@ var setAskCmd = &cli.Command{ return err } - smax := int64(abi.PaddedPieceSize(ssize).Unpadded()) + smax := int64(ssize) if max == 0 { max = smax } if max > smax { - return errors.Errorf("max piece size (unpadded) %s cannot exceed miner sector size (unpadded) %s", types.SizeStr(types.NewInt(uint64(max))), types.SizeStr(types.NewInt(uint64(smax)))) + return errors.Errorf("max piece size (w/bit-padding) %s cannot exceed miner sector size %s", types.SizeStr(types.NewInt(uint64(max))), types.SizeStr(types.NewInt(uint64(smax)))) } - return api.MarketSetAsk(ctx, pri, dur, abi.UnpaddedPieceSize(min).Padded(), abi.UnpaddedPieceSize(max).Padded()) + return api.MarketSetAsk(ctx, pri, dur, abi.PaddedPieceSize(min), abi.PaddedPieceSize(max)) }, } @@ -149,11 +150,11 @@ var getAskCmd = &cli.Command{ } w := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0) - fmt.Fprintf(w, "Price per GiB / Epoch\tMin. Piece Size (unpadded)\tMax. Piece Size (unpadded)\tExpiry\tSeq. No.\n") + fmt.Fprintf(w, "Price per GiB / Epoch\tMin. Piece Size (w/bit-padding)\tMax. Piece Size (w/bit-padding)\tExpiry\tSeq. No.\n") if ask == nil { fmt.Fprintf(w, "\n") } else { - fmt.Fprintf(w, "%s\t%s\t%s\t%d\t%d\n", ask.Price, types.SizeStr(types.NewInt(uint64(ask.MinPieceSize.Unpadded()))), types.SizeStr(types.NewInt(uint64(ask.MaxPieceSize.Unpadded()))), ask.Expiry, ask.SeqNo) + fmt.Fprintf(w, "%s\t%s\t%s\t%d\t%d\n", ask.Price, types.SizeStr(types.NewInt(uint64(ask.MinPieceSize))), types.SizeStr(types.NewInt(uint64(ask.MaxPieceSize))), ask.Expiry, ask.SeqNo) } return w.Flush() From 673a64318426dda40ca3244f82c7e9af662c8ceb Mon Sep 17 00:00:00 2001 From: laser Date: Wed, 17 Jun 2020 08:57:18 -0700 Subject: [PATCH 08/13] use xerrors, as per feedback in PR --- cmd/lotus-storage-miner/market.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/lotus-storage-miner/market.go b/cmd/lotus-storage-miner/market.go index 8d677a55cc6..71be988e953 100644 --- a/cmd/lotus-storage-miner/market.go +++ b/cmd/lotus-storage-miner/market.go @@ -8,7 +8,6 @@ import ( "github.com/docker/go-units" "github.com/ipfs/go-cid" - "github.com/pkg/errors" "github.com/urfave/cli/v2" "golang.org/x/xerrors" @@ -119,7 +118,7 @@ var setAskCmd = &cli.Command{ } if max > smax { - return errors.Errorf("max piece size (w/bit-padding) %s cannot exceed miner sector size %s", types.SizeStr(types.NewInt(uint64(max))), types.SizeStr(types.NewInt(uint64(smax)))) + return xerrors.Errorf("max piece size (w/bit-padding) %s cannot exceed miner sector size %s", types.SizeStr(types.NewInt(uint64(max))), types.SizeStr(types.NewInt(uint64(smax)))) } return api.MarketSetAsk(ctx, pri, dur, abi.PaddedPieceSize(min), abi.PaddedPieceSize(max)) From 9d7be5dcbfac3e6cdb90e9ac5a33effa8b6c879c Mon Sep 17 00:00:00 2001 From: laser Date: Wed, 17 Jun 2020 09:20:43 -0700 Subject: [PATCH 09/13] modify set-ask to work with human-readable clock time/duration --- cmd/lotus-storage-miner/market.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/cmd/lotus-storage-miner/market.go b/cmd/lotus-storage-miner/market.go index 71be988e953..a189706f3b8 100644 --- a/cmd/lotus-storage-miner/market.go +++ b/cmd/lotus-storage-miner/market.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "text/tabwriter" + "time" "github.com/docker/go-units" "github.com/ipfs/go-cid" @@ -14,6 +15,7 @@ import ( "github.com/filecoin-project/go-fil-markets/storagemarket" "github.com/filecoin-project/specs-actors/actors/abi" + "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" lcli "github.com/filecoin-project/lotus/cli" ) @@ -57,11 +59,11 @@ var setAskCmd = &cli.Command{ Usage: "Set the price of the ask (specified as FIL / GiB / Epoch) to `PRICE`", Required: true, }, - &cli.Uint64Flag{ + &cli.StringFlag{ Name: "duration", - Usage: "Set the number of epochs from the current chain head that the ask will expire `DURATION`", - DefaultText: "100000", - Value: 100000, + Usage: "Set duration of ask (a quantity of time after which the ask expires) `DURATION`", + DefaultText: "30d0h0m0s", + Value: "30d0h0m0s", }, &cli.StringFlag{ Name: "min-piece-size", @@ -85,11 +87,17 @@ var setAskCmd = &cli.Command{ defer closer() pri := types.NewInt(cctx.Uint64("price")) - dur := abi.ChainEpoch(cctx.Uint64("duration")) + + dur, err := time.ParseDuration(cctx.String("duration")) + if err != nil { + return xerrors.Errorf("cannot parse duration: %w", err) + } + + qty := dur.Seconds() / build.BlockDelay min, err := units.RAMInBytes(cctx.String("min-piece-size")) if err != nil { - return err + return xerrors.Errorf("cannot parse min-piece-size to quantity of bytes: %w", err) } if min < 256 { @@ -98,7 +106,7 @@ var setAskCmd = &cli.Command{ max, err := units.RAMInBytes(cctx.String("max-piece-size")) if err != nil { - return err + return xerrors.Errorf("cannot parse max-piece-size to quantity of bytes: %w", err) } maddr, err := api.ActorAddress(ctx) @@ -121,7 +129,7 @@ var setAskCmd = &cli.Command{ return xerrors.Errorf("max piece size (w/bit-padding) %s cannot exceed miner sector size %s", types.SizeStr(types.NewInt(uint64(max))), types.SizeStr(types.NewInt(uint64(smax)))) } - return api.MarketSetAsk(ctx, pri, dur, abi.PaddedPieceSize(min), abi.PaddedPieceSize(max)) + return api.MarketSetAsk(ctx, pri, abi.ChainEpoch(qty), abi.PaddedPieceSize(min), abi.PaddedPieceSize(max)) }, } From 402cd8be1903bb50eff997ad1272e5810178aeb3 Mon Sep 17 00:00:00 2001 From: laser Date: Wed, 17 Jun 2020 10:20:42 -0700 Subject: [PATCH 10/13] get-ask output should use durations, too --- cmd/lotus-storage-miner/market.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/cmd/lotus-storage-miner/market.go b/cmd/lotus-storage-miner/market.go index a189706f3b8..977ae22de6b 100644 --- a/cmd/lotus-storage-miner/market.go +++ b/cmd/lotus-storage-miner/market.go @@ -62,8 +62,8 @@ var setAskCmd = &cli.Command{ &cli.StringFlag{ Name: "duration", Usage: "Set duration of ask (a quantity of time after which the ask expires) `DURATION`", - DefaultText: "30d0h0m0s", - Value: "30d0h0m0s", + DefaultText: "720h0m0s", + Value: "720h0m0s", }, &cli.StringFlag{ Name: "min-piece-size", @@ -157,13 +157,22 @@ var getAskCmd = &cli.Command{ } w := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0) - fmt.Fprintf(w, "Price per GiB / Epoch\tMin. Piece Size (w/bit-padding)\tMax. Piece Size (w/bit-padding)\tExpiry\tSeq. No.\n") + fmt.Fprintf(w, "Price per GiB / Epoch\tMin. Piece Size (w/bit-padding)\tMax. Piece Size (w/bit-padding)\tExpiry (Epoch)\tExpiry (Appx. Rem. Time)\tSeq. No.\n") if ask == nil { fmt.Fprintf(w, "\n") - } else { - fmt.Fprintf(w, "%s\t%s\t%s\t%d\t%d\n", ask.Price, types.SizeStr(types.NewInt(uint64(ask.MinPieceSize))), types.SizeStr(types.NewInt(uint64(ask.MaxPieceSize))), ask.Expiry, ask.SeqNo) + + return w.Flush() } + miningBaseTs, err := api.MiningBase(ctx) + if err != nil { + return err + } + + rem := time.Second * time.Duration((ask.Expiry-miningBaseTs.Height())*build.BlockDelay) + + fmt.Fprintf(w, "%s\t%s\t%s\t%d\t%s\t%d\n", ask.Price, types.SizeStr(types.NewInt(uint64(ask.MinPieceSize))), types.SizeStr(types.NewInt(uint64(ask.MaxPieceSize))), ask.Expiry, rem, ask.SeqNo) + return w.Flush() }, } From 791dff5a8712c3291a67f1977a08d27bfbdb27ba Mon Sep 17 00:00:00 2001 From: laser Date: Wed, 17 Jun 2020 10:30:16 -0700 Subject: [PATCH 11/13] don't go into negative remaining time --- cmd/lotus-storage-miner/market.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/lotus-storage-miner/market.go b/cmd/lotus-storage-miner/market.go index 977ae22de6b..dd99a375c64 100644 --- a/cmd/lotus-storage-miner/market.go +++ b/cmd/lotus-storage-miner/market.go @@ -169,7 +169,11 @@ var getAskCmd = &cli.Command{ return err } - rem := time.Second * time.Duration((ask.Expiry-miningBaseTs.Height())*build.BlockDelay) + dlt := ask.Expiry - miningBaseTs.Height() + rem := "" + if dlt > 0 { + rem = (time.Second * time.Duration(dlt*build.BlockDelay)).String() + } fmt.Fprintf(w, "%s\t%s\t%s\t%d\t%s\t%d\n", ask.Price, types.SizeStr(types.NewInt(uint64(ask.MinPieceSize))), types.SizeStr(types.NewInt(uint64(ask.MaxPieceSize))), ask.Expiry, rem, ask.SeqNo) From ed5b74b1ae377910aaf4398b5af885412142f806 Mon Sep 17 00:00:00 2001 From: laser Date: Wed, 17 Jun 2020 10:42:09 -0700 Subject: [PATCH 12/13] tidy up --- go.mod | 1 - 1 file changed, 1 deletion(-) diff --git a/go.mod b/go.mod index cb94ad0559b..d5e684e46d1 100644 --- a/go.mod +++ b/go.mod @@ -103,7 +103,6 @@ require ( github.com/multiformats/go-multibase v0.0.2 github.com/multiformats/go-multihash v0.0.13 github.com/opentracing/opentracing-go v1.1.0 - github.com/pkg/errors v0.9.1 github.com/stretchr/objx v0.2.0 // indirect github.com/stretchr/testify v1.5.1 github.com/syndtr/goleveldb v1.0.0 From fcdfda8ba2eb2e994d26eabe8be759c947f60ad7 Mon Sep 17 00:00:00 2001 From: laser Date: Wed, 17 Jun 2020 10:56:42 -0700 Subject: [PATCH 13/13] use chain head instead of mining base --- cmd/lotus-storage-miner/market.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cmd/lotus-storage-miner/market.go b/cmd/lotus-storage-miner/market.go index dd99a375c64..4dac236e46c 100644 --- a/cmd/lotus-storage-miner/market.go +++ b/cmd/lotus-storage-miner/market.go @@ -140,13 +140,19 @@ var getAskCmd = &cli.Command{ Action: func(cctx *cli.Context) error { ctx := lcli.DaemonContext(cctx) - api, closer, err := lcli.GetStorageMinerAPI(cctx) + fnapi, closer, err := lcli.GetFullNodeAPI(cctx) + if err != nil { + return err + } + defer closer() + + smapi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - sask, err := api.MarketGetAsk(ctx) + sask, err := smapi.MarketGetAsk(ctx) if err != nil { return err } @@ -164,12 +170,12 @@ var getAskCmd = &cli.Command{ return w.Flush() } - miningBaseTs, err := api.MiningBase(ctx) + head, err := fnapi.ChainHead(ctx) if err != nil { return err } - dlt := ask.Expiry - miningBaseTs.Height() + dlt := ask.Expiry - head.Height() rem := "" if dlt > 0 { rem = (time.Second * time.Duration(dlt*build.BlockDelay)).String()