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: Setup actor on init #81

Merged
merged 3 commits into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
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
22 changes: 0 additions & 22 deletions chain/address/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,13 @@ func init() {
if err != nil {
panic(err)
}

NetworkAddress, err = NewActorAddress([]byte("filecoin"))
if err != nil {
panic(err)
}

StorageMarketAddress, err = NewActorAddress([]byte("storage"))
if err != nil {
panic(err)
}

PaymentBrokerAddress, err = NewActorAddress([]byte("payments"))
if err != nil {
panic(err)
}
}

var (
// TestAddress is an account with some initial funds in it.
TestAddress Address
// TestAddress2 is an account with some initial funds in it.
TestAddress2 Address

// NetworkAddress is the filecoin network.
NetworkAddress Address
// StorageMarketAddress is the hard-coded address of the filecoin storage market.
StorageMarketAddress Address
// PaymentBrokerAddress is the hard-coded address of the filecoin storage market.
PaymentBrokerAddress Address
)

var (
Expand Down
2 changes: 1 addition & 1 deletion chain/vm/mkactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func makeActor(st *state.StateTree, addr address.Address) (*types.Actor, error)
case address.ID:
return nil, fmt.Errorf("no actor with given ID")
case address.Actor:
return nil, fmt.Errorf("no such actor")
return nil, fmt.Errorf("no such actor: %s", addr)
default:
return nil, fmt.Errorf("address has unsupported protocol: %d", addr.Protocol())
}
Expand Down
2 changes: 1 addition & 1 deletion chain/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (vm *VM) ApplyMessage(msg *types.Message) (*types.MessageReceipt, error) {
// reward miner gas fees
miner, err := st.GetActor(vm.blockMiner)
if err != nil {
return nil, xerrors.Errorf("getting block miner actor failed: %w", err)
return nil, xerrors.Errorf("getting block miner actor (%s) failed: %w", vm.blockMiner, err)
}

gasReward := types.BigMul(msg.GasPrice, vmctx.GasUsed())
Expand Down
4 changes: 1 addition & 3 deletions cli/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (

"github.com/pkg/errors"
"gopkg.in/urfave/cli.v2"

"github.com/filecoin-project/go-lotus/chain/address"
)

var minerCmd = &cli.Command{
Expand All @@ -29,7 +27,7 @@ var minerStart = &cli.Command{
ctx := ReqContext(cctx)

// TODO: this address needs to be the address of an actual miner
maddr, err := address.NewIDAddress(523423423)
maddr, err := api.WalletDefaultAddress(ctx)
if err != nil {
return errors.Wrap(err, "failed to create miner address")
}
Expand Down
104 changes: 104 additions & 0 deletions cmd/lotus-storage-miner/init.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
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/types"
lcli "github.com/filecoin-project/go-lotus/cli"
"github.com/filecoin-project/go-lotus/node/repo"
)
Expand Down Expand Up @@ -54,8 +58,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(types.KTSecp256k1) // TODO: review: is this right?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this works, though we will want to use BLS keys everywhere we can

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: actors.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 := &types.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