Merge pull request #2120 from filecoin-project/feat/change-addrs-cmd
add command to change registered multiaddrs for miner
This commit is contained in:
commit
4037d707c9
94
cmd/lotus-storage-miner/actor.go
Normal file
94
cmd/lotus-storage-miner/actor.go
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
ma "github.com/multiformats/go-multiaddr"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||||
|
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
|
lcli "github.com/filecoin-project/lotus/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
var actorCmd = &cli.Command{
|
||||||
|
Name: "actor",
|
||||||
|
Usage: "manipulate the miner actor",
|
||||||
|
Subcommands: []*cli.Command{
|
||||||
|
actorSetAddrsCmd,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var actorSetAddrsCmd = &cli.Command{
|
||||||
|
Name: "set-addrs",
|
||||||
|
Usage: "set addresses that your miner can be publically dialed on",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.Int64Flag{
|
||||||
|
Name: "gas-limit",
|
||||||
|
Usage: "set gas limit",
|
||||||
|
Value: 100000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: func(cctx *cli.Context) error {
|
||||||
|
nodeAPI, closer, err := lcli.GetStorageMinerAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer closer()
|
||||||
|
|
||||||
|
api, acloser, err := lcli.GetFullNodeAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer acloser()
|
||||||
|
|
||||||
|
ctx := lcli.ReqContext(cctx)
|
||||||
|
|
||||||
|
var addrs []abi.Multiaddrs
|
||||||
|
for _, a := range cctx.Args().Slice() {
|
||||||
|
maddr, err := ma.NewMultiaddr(a)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to parse %q as a multiaddr: %w", a, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
addrs = append(addrs, maddr.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
maddr, err := nodeAPI.ActorAddress(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
minfo, err := api.StateMinerInfo(ctx, maddr, types.EmptyTSK)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
params, err := actors.SerializeParams(&miner.ChangeMultiaddrsParams{NewMultiaddrs: addrs})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
gasLimit := cctx.Int64("gas-limit")
|
||||||
|
|
||||||
|
smsg, err := api.MpoolPushMessage(ctx, &types.Message{
|
||||||
|
To: maddr,
|
||||||
|
From: minfo.Worker,
|
||||||
|
Value: types.NewInt(0),
|
||||||
|
GasPrice: types.NewInt(1),
|
||||||
|
GasLimit: gasLimit,
|
||||||
|
Method: 18,
|
||||||
|
Params: params,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Requested multiaddrs change in message %s\n", smsg.Cid())
|
||||||
|
return nil
|
||||||
|
|
||||||
|
},
|
||||||
|
}
|
@ -4,7 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/filecoin-project/specs-actors/actors/builtin/power"
|
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -13,6 +12,7 @@ import (
|
|||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
||||||
|
"github.com/filecoin-project/specs-actors/actors/builtin/power"
|
||||||
sealing "github.com/filecoin-project/storage-fsm"
|
sealing "github.com/filecoin-project/storage-fsm"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
|
@ -22,6 +22,7 @@ func main() {
|
|||||||
lotuslog.SetupLogLevels()
|
lotuslog.SetupLogLevels()
|
||||||
|
|
||||||
local := []*cli.Command{
|
local := []*cli.Command{
|
||||||
|
actorCmd,
|
||||||
dealsCmd,
|
dealsCmd,
|
||||||
infoCmd,
|
infoCmd,
|
||||||
initCmd,
|
initCmd,
|
||||||
|
Loading…
Reference in New Issue
Block a user