Skip to content

Commit

Permalink
[part 3] "miner create" command must accept "sectorsize" flag (#2874)
Browse files Browse the repository at this point in the history
* remove Pledge from storage miner actor

* drop pledge from "miner create" + don't require minimum collateral

* modify "miner create" to accept a sector size, in bytes
  • Loading branch information
laser authored Jun 4, 2019
1 parent 9616abd commit 4e53198
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 15 deletions.
24 changes: 15 additions & 9 deletions commands/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"math/big"
"strconv"
"strings"

"github.com/ipfs/go-cid"
"github.com/ipfs/go-ipfs-cmdkit"
Expand Down Expand Up @@ -50,10 +51,11 @@ miner's collateral drops below 0.001FIL, the miner will not be able to commit
additional sectors.`,
},
Arguments: []cmdkit.Argument{
cmdkit.StringArg("collateral", true, false, "The amount of collateral, in FIL"),
cmdkit.StringArg("collateral", true, false, "The amount of collateral, in FIL."),
},
Options: []cmdkit.Option{
cmdkit.StringOption("from", "Address to send from"),
cmdkit.StringOption("sectorsize", "size of the sectors which this miner will commit, in bytes"),
cmdkit.StringOption("from", "address to send from"),
cmdkit.StringOption("peerid", "Base58-encoded libp2p peer ID that the miner will operate"),
priceOption,
limitOption,
Expand All @@ -67,18 +69,22 @@ additional sectors.`,
return err
}

// TODO: Modify this command to accept a sector size as an argument,
// ensuring that the provided sector size is supported by the network.
// https://github.com/filecoin-project/go-filecoin/issues/2530
//
sectorSize, err := optionalSectorSizeWithDefault(req.Options["sectorsize"], pp.SupportedSectorSizes[0])
if err != nil {
return err
}

// TODO: It may become the case that the protocol does not specify an
// enumeration of supported sector sizes, but rather that any sector
// size for which a miner has Groth parameters and a verifying key is
// supported.
// https://github.com/filecoin-project/specs/pull/318
sectorSize := types.OneKiBSectorSize
if pp.ProofsMode == types.LiveProofsMode {
sectorSize = types.TwoHundredFiftySixMiBSectorSize
if !pp.IsSupportedSectorSize(sectorSize) {
supportedStrs := make([]string, len(pp.SupportedSectorSizes))
for i, ss := range pp.SupportedSectorSizes {
supportedStrs[i] = ss.String()
}
return fmt.Errorf("unsupported sector size: %s (supported sizes: %s)", sectorSize, strings.Join(supportedStrs, ", "))
}

fromAddr, err := optionalAddr(req.Options["from"])
Expand Down
16 changes: 16 additions & 0 deletions commands/miner_daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,29 @@ func TestMinerCreate(t *testing.T) {
tf(testAddr, th.RequireRandomPeerID(t))
})

t.Run("unsupported sector size", func(t *testing.T) {
d := th.NewDaemon(t).Start()
defer d.ShutdownSuccess()

d.CreateAddress()

d.RunFail("unsupported sector size",
"miner", "create", "20",
"--sectorsize", "42",
)
})

t.Run("validation failure", func(t *testing.T) {

d := th.NewDaemon(t).Start()
defer d.ShutdownSuccess()

d.CreateAddress()

d.RunFail("invalid sector size",
"miner", "create", "20",
"--sectorsize", "ninetybillion",
)
d.RunFail("invalid peer id",
"miner", "create",
"--from", testAddr.String(), "--gas-price", "1", "--gas-limit", "300", "--peerid", "flarp", "20",
Expand Down
21 changes: 21 additions & 0 deletions commands/opt_sector_size.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package commands

import (
"fmt"
"strconv"

"github.com/filecoin-project/go-filecoin/types"
)

func optionalSectorSizeWithDefault(o interface{}, def *types.BytesAmount) (*types.BytesAmount, error) {
if o != nil {
n, err := strconv.ParseUint(o.(string), 10, 64)
if err != nil || n == 0 {
return nil, fmt.Errorf("invalid sector size: %s", o.(string))
}

return types.NewBytesAmount(n), nil
}

return def, nil
}
27 changes: 23 additions & 4 deletions porcelain/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (

// ProtocolParams TODO(rosa)
type ProtocolParams struct {
AutoSealInterval uint
ProofsMode types.ProofsMode
AutoSealInterval uint
ProofsMode types.ProofsMode
SupportedSectorSizes []*types.BytesAmount
}

type protocolParamsPlumbing interface {
Expand All @@ -38,12 +39,30 @@ func ProtocolParameters(ctx context.Context, plumbing protocolParamsPlumbing) (*
return nil, errors.Wrap(err, "could not retrieve proofs mode")
}

supportedSectorSizes := []*types.BytesAmount{types.OneKiBSectorSize}
if proofsMode == types.LiveProofsMode {
supportedSectorSizes[0] = types.TwoHundredFiftySixMiBSectorSize
}

return &ProtocolParams{
AutoSealInterval: autoSealInterval,
ProofsMode: proofsMode,
AutoSealInterval: autoSealInterval,
ProofsMode: proofsMode,
SupportedSectorSizes: supportedSectorSizes,
}, nil
}

// IsSupportedSectorSize returns true if the given sector size is supported by
// the network.
func (pp *ProtocolParams) IsSupportedSectorSize(sectorSize *types.BytesAmount) bool {
for _, size := range pp.SupportedSectorSizes {
if size.Equal(sectorSize) {
return true
}
}

return false
}

func getProofsMode(ctx context.Context, plumbing protocolParamsPlumbing) (types.ProofsMode, error) {
var proofsMode types.ProofsMode
values, err := plumbing.MessageQuery(ctx, address.Address{}, address.StorageMarketAddress, "getProofsMode")
Expand Down
5 changes: 3 additions & 2 deletions porcelain/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ func TestProtocolParams(t *testing.T) {
}

expected := &porcelain.ProtocolParams{
AutoSealInterval: 120,
ProofsMode: types.TestProofsMode,
AutoSealInterval: 120,
ProofsMode: types.TestProofsMode,
SupportedSectorSizes: []*types.BytesAmount{types.OneKiBSectorSize},
}

out, err := porcelain.ProtocolParameters(context.TODO(), plumbing)
Expand Down

0 comments on commit 4e53198

Please sign in to comment.