Skip to content

Commit

Permalink
storageminer: Setup actor on init
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Jul 25, 2019
1 parent 0569075 commit ae04dbf
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions cmd/lotus-storage-miner/init.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package main

import (
"github.com/libp2p/go-libp2p-core/peer"
"golang.org/x/xerrors"
"gopkg.in/urfave/cli.v2"

"github.com/filecoin-project/go-lotus/build"
"github.com/filecoin-project/go-lotus/chain"
"github.com/filecoin-project/go-lotus/chain/actors"
"github.com/filecoin-project/go-lotus/chain/address"
"github.com/filecoin-project/go-lotus/chain/types"
lcli "github.com/filecoin-project/go-lotus/cli"
"github.com/filecoin-project/go-lotus/node/repo"
)
Expand Down Expand Up @@ -54,8 +59,108 @@ var initCmd = &cli.Command{
return err
}

lr, err := r.Lock()
if err != nil {
return err
}
defer lr.Close()

log.Info("Initializing wallet")

ks, err := lr.KeyStore()
if err != nil {
return err
}

wallet, err := chain.NewWallet(ks)
if err != nil {
return err
}

log.Info("Initializing libp2p identity")

p2pSk, err := lr.Libp2pIdentity()
if err != nil {
return err
}

peerid, err := peer.IDFromPrivateKey(p2pSk)
if err != nil {
return err
}

log.Info("Creating StorageMarket.CreateStorageMiner message")

defOwner, err := api.WalletDefaultAddress(ctx)
if err != nil {
return err
}

nonce, err := api.MpoolGetNonce(ctx, defOwner)
if err != nil {
return err
}

k, err := wallet.GenerateKey(chain.KTSecp256k1) // TODO: review: is this right?
if err != nil {
return err
}

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

params, err := actors.SerializeParams(actors.CreateStorageMinerParams{
Owner: defOwner,
Worker: k,
SectorSize: types.NewInt(actors.SectorSize),
PeerID: peerid,
})
if err != nil {
return err
}

createStorageMinerMsg := types.Message{
To: address.StorageMarketAddress,
From: defOwner,

Nonce: nonce,

Value: collateral,

Method: 1, // TODO: Review: do we have a reverse index with these anywhere? (actor_storageminer.go)
Params: params,
}

unsigned, err := createStorageMinerMsg.Serialize()
if err != nil {
return err
}

log.Info("Signing StorageMarket.CreateStorageMiner")

sig, err := api.WalletSign(ctx, defOwner, unsigned)
if err != nil {
return err
}

signed := &chain.SignedMessage{
Message: createStorageMinerMsg,
Signature: *sig,
}

log.Infof("Pushing %s to Mpool", signed.Cid())

err = api.MpoolPush(ctx, signed)
if err != nil {
return err
}

log.Infof("Waiting for confirmation")

// TODO: Wait

// create actors and stuff

// TODO: Point to setting storage price, maybe do it interactively or something
log.Info("Storage miner successfully created, you can now start it with 'lotus-storage-miner run'")

return nil
Expand Down

0 comments on commit ae04dbf

Please sign in to comment.