diff --git a/cmd/lotus-storage-miner/actor.go b/cmd/lotus-storage-miner/actor.go index 21d09b5ac..70df1446a 100644 --- a/cmd/lotus-storage-miner/actor.go +++ b/cmd/lotus-storage-miner/actor.go @@ -3,6 +3,7 @@ package main import ( "fmt" "github.com/filecoin-project/specs-actors/actors/builtin" + "github.com/libp2p/go-libp2p-core/peer" "golang.org/x/xerrors" ma "github.com/multiformats/go-multiaddr" @@ -22,6 +23,7 @@ var actorCmd = &cli.Command{ Subcommands: []*cli.Command{ actorSetAddrsCmd, actorWithdrawCmd, + actorSetPeeridCmd, }, } @@ -82,7 +84,7 @@ var actorSetAddrsCmd = &cli.Command{ From: minfo.Worker, Value: types.NewInt(0), GasLimit: gasLimit, - Method: 18, + Method: builtin.MethodsMiner.ChangeMultiaddrs, Params: params, }, nil) if err != nil { @@ -95,6 +97,71 @@ var actorSetAddrsCmd = &cli.Command{ }, } +var actorSetPeeridCmd = &cli.Command{ + Name: "set-peer-id", + Usage: "set the peer id of your miner", + Flags: []cli.Flag{ + &cli.Int64Flag{ + Name: "gas-limit", + Usage: "set gas limit", + Value: 0, + }, + }, + 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) + + pid, err := peer.IDFromString(cctx.Args().Get(0)) + if err != nil { + return fmt.Errorf("failed to parse input as a peerId: %w", err) + } + + 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.ChangePeerIDParams{NewID: abi.PeerID(pid)}) + 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), + GasLimit: gasLimit, + Method: builtin.MethodsMiner.ChangePeerID, + Params: params, + }, nil) + if err != nil { + return err + } + + fmt.Printf("Requested peerid change in message %s\n", smsg.Cid()) + return nil + + }, +} + var actorWithdrawCmd = &cli.Command{ Name: "withdraw", Usage: "withdraw available balance",