diff --git a/chain/address/constants.go b/chain/address/constants.go index 1da2488c3..8fc66c678 100644 --- a/chain/address/constants.go +++ b/chain/address/constants.go @@ -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 ( diff --git a/chain/vm/mkactor.go b/chain/vm/mkactor.go index 52e8cd7f2..4ce8ff994 100644 --- a/chain/vm/mkactor.go +++ b/chain/vm/mkactor.go @@ -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()) } diff --git a/chain/vm/vm.go b/chain/vm/vm.go index d1d7c3f38..9de1d5a85 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -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()) diff --git a/cli/miner.go b/cli/miner.go index 607f26512..d4ed66b9c 100644 --- a/cli/miner.go +++ b/cli/miner.go @@ -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") } diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index c997e3062..f3ce44d17 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -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