Merge pull request #81 from filecoin-project/feat/storminer-init

storageminer: Setup actor on init
This commit is contained in:
Whyrusleeping
2019-07-26 11:24:26 -07:00
committed by GitHub
5 changed files with 107 additions and 27 deletions
-22
View File
@@ -20,21 +20,6 @@ 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 (
@@ -42,13 +27,6 @@ var (
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 (
+1 -1
View File
@@ -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())
}
+1 -1
View File
@@ -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())
+1 -3
View File
@@ -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{
@@ -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")
}
+104
View File
@@ -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"
)
@@ -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?
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