Merge pull request #5196 from filecoin-project/feat/shed-block-pubsub-id

lotus-shed blockmsgid command
This commit is contained in:
Łukasz Magiera 2020-12-15 19:36:02 +01:00 committed by GitHub
commit 884e20f637
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 71 additions and 0 deletions

View File

@ -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: "<blockCid> ...",
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
},
}

View File

@ -50,6 +50,7 @@ func main() {
electionCmd,
rpcCmd,
cidCmd,
blockmsgidCmd,
}
app := &cli.App{