Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storageminer: Make worker key creation optional #235

Merged
merged 2 commits into from
Sep 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions cmd/lotus-storage-miner/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ var initCmd = &cli.Command{
&cli.BoolFlag{
Name: "genesis-miner",
Usage: "enable genesis mining (DON'T USE ON BOOTSTRAPPED NETWORK)",
Hidden: true,
},
&cli.BoolFlag{
Name: "create-worker-key",
Usage: "create separate worker key",
},
&cli.StringFlag{
Name: "worker",
Aliases: []string{"w"},
Usage: "worker key to use (overrides --create-worker-key)",
},
&cli.StringFlag{
Name: "owner",
Aliases: []string{"o"},
Usage: "owner key to use",
},
},
Action: func(cctx *cli.Context) error {
Expand Down Expand Up @@ -103,7 +118,7 @@ var initCmd = &cli.Command{

addr = a
} else {
a, err := createStorageMiner(ctx, api, peerid)
a, err := createStorageMiner(ctx, api, peerid, cctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -194,24 +209,35 @@ func configureStorageMiner(ctx context.Context, api api.FullNode, addr address.A
return nil
}

func createStorageMiner(ctx context.Context, api api.FullNode, peerid peer.ID) (address.Address, error) {
func createStorageMiner(ctx context.Context, api api.FullNode, peerid peer.ID, cctx *cli.Context) (addr address.Address, err error) {
log.Info("Creating StorageMarket.CreateStorageMiner message")

defOwner, err := api.WalletDefaultAddress(ctx)
var owner address.Address
if cctx.String("owner") != "" {
owner, err = address.NewFromString(cctx.String("owner"))
} else {
owner, err = api.WalletDefaultAddress(ctx)
}
if err != nil {
return address.Undef, err
}

k, err := api.WalletNew(ctx, types.KTBLS)
worker := owner
if cctx.String("worker") != "" {
worker, err = address.NewFromString(cctx.String("worker"))
} else if cctx.Bool("create-worker-key") { // TODO: Do we need to force this if owner is Secpk?
worker, err = api.WalletNew(ctx, types.KTBLS)
}
// TODO: Transfer some initial funds to worker
if err != nil {
return address.Undef, err
}

collateral := types.NewInt(1000) // TODO: Get this from params

params, err := actors.SerializeParams(&actors.CreateStorageMinerParams{
Owner: defOwner,
Worker: k,
Owner: owner,
Worker: worker,
SectorSize: types.NewInt(build.SectorSize),
PeerID: peerid,
})
Expand All @@ -221,7 +247,7 @@ func createStorageMiner(ctx context.Context, api api.FullNode, peerid peer.ID) (

createStorageMinerMsg := &types.Message{
To: actors.StorageMarketAddress,
From: defOwner,
From: owner,
Value: collateral,

Method: actors.SMAMethods.CreateStorageMiner,
Expand All @@ -244,7 +270,7 @@ func createStorageMiner(ctx context.Context, api api.FullNode, peerid peer.ID) (
return address.Undef, err
}

addr, err := address.NewFromBytes(mw.Receipt.Return)
addr, err = address.NewFromBytes(mw.Receipt.Return)
if err != nil {
return address.Undef, err
}
Expand Down