diff --git a/cmd/lotus-shed/blockmsgid.go b/cmd/lotus-shed/blockmsgid.go new file mode 100644 index 000000000..85b786ec0 --- /dev/null +++ b/cmd/lotus-shed/blockmsgid.go @@ -0,0 +1,70 @@ +package main + +import ( + "encoding/base64" + "fmt" + + blake2b "github.com/minio/blake2b-simd" + "github.com/urfave/cli/v2" + + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/lotus/chain/types" + lcli "github.com/filecoin-project/lotus/cli" +) + +var blockmsgidCmd = &cli.Command{ + Name: "blockmsgid", + Usage: "Print a block's pubsub message ID", + ArgsUsage: " ...", + Action: func(cctx *cli.Context) error { + api, closer, err := lcli.GetFullNodeAPI(cctx) + if err != nil { + return err + } + + defer closer() + ctx := lcli.ReqContext(cctx) + + for _, arg := range cctx.Args().Slice() { + blkcid, err := cid.Decode(arg) + if err != nil { + return fmt.Errorf("error decoding block cid: %w", err) + } + + blkhdr, err := api.ChainGetBlock(ctx, blkcid) + if err != nil { + return fmt.Errorf("error retrieving block header: %w", err) + } + + blkmsgs, err := api.ChainGetBlockMessages(ctx, blkcid) + if err != nil { + return fmt.Errorf("error retrieving block messages: %w", err) + } + + blkmsg := &types.BlockMsg{ + Header: blkhdr, + } + + for _, m := range blkmsgs.BlsMessages { + blkmsg.BlsMessages = append(blkmsg.BlsMessages, m.Cid()) + } + + for _, m := range blkmsgs.SecpkMessages { + blkmsg.SecpkMessages = append(blkmsg.SecpkMessages, m.Cid()) + } + + bytes, err := blkmsg.Serialize() + if err != nil { + return fmt.Errorf("error serializing BlockMsg: %w", err) + } + + msgId := blake2b.Sum256(bytes) + msgId64 := base64.StdEncoding.EncodeToString(msgId[:]) + + fmt.Println(msgId64) + } + + return nil + }, +} diff --git a/cmd/lotus-shed/main.go b/cmd/lotus-shed/main.go index 19067f8c9..10b2b4d89 100644 --- a/cmd/lotus-shed/main.go +++ b/cmd/lotus-shed/main.go @@ -50,6 +50,7 @@ func main() { electionCmd, rpcCmd, cidCmd, + blockmsgidCmd, } app := &cli.App{