work with bit-padded byte quantities, as per PR feedback

This commit is contained in:
laser 2020-06-17 08:42:30 -07:00
parent 139c3297ab
commit 5d4f1bb3f1

View File

@ -10,6 +10,7 @@ import (
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-fil-markets/storagemarket" "github.com/filecoin-project/go-fil-markets/storagemarket"
"github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/abi"
@ -59,20 +60,20 @@ var setAskCmd = &cli.Command{
}, },
&cli.Uint64Flag{ &cli.Uint64Flag{
Name: "duration", 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", DefaultText: "100000",
Value: 100000, Value: 100000,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "min-piece-size", Name: "min-piece-size",
Usage: "Set minimum piece size (without bit-padding, in bytes) in ask to `SIZE`", Usage: "Set minimum piece size (w/bit-padding, in bytes) in ask to `SIZE`",
DefaultText: "254B", DefaultText: "256B",
Value: "254B", Value: "256B",
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "max-piece-size", Name: "max-piece-size",
Usage: "Set maximum piece size (without bit-padding, in bytes) in ask to `SIZE`", Usage: "Set maximum piece size (w/bit-padding, in bytes) in ask to `SIZE`",
DefaultText: "miner sector size, without bit-padding", DefaultText: "miner sector size",
}, },
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
@ -92,8 +93,8 @@ var setAskCmd = &cli.Command{
return err return err
} }
if min < 254 { if min < 256 {
return errors.New("minimum piece size (unpadded) is 254 B") return xerrors.New("minimum piece size (w/bit-padding) is 256B")
} }
max, err := units.RAMInBytes(cctx.String("max-piece-size")) max, err := units.RAMInBytes(cctx.String("max-piece-size"))
@ -111,17 +112,17 @@ var setAskCmd = &cli.Command{
return err return err
} }
smax := int64(abi.PaddedPieceSize(ssize).Unpadded()) smax := int64(ssize)
if max == 0 { if max == 0 {
max = smax max = smax
} }
if 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) 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 { if ask == nil {
fmt.Fprintf(w, "<miner does not have an ask>\n") fmt.Fprintf(w, "<miner does not have an ask>\n")
} else { } 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() return w.Flush()