Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Integrate tendermint Block endpoints into the cli #14659

Merged
merged 66 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
7365588
idiot check
cipherzzz Jan 17, 2023
ddc0edd
cleaned up
cipherzzz Jan 17, 2023
38a6468
updated BlockResponse proto and got the BlockSearch working
cipherzzz Jan 20, 2023
bdd2ba7
Merge branch 'main' of github.com:cosmos/cosmos-sdk into cipherz/1370…
cipherzzz Jan 21, 2023
7d0330c
merged latest
cipherzzz Jan 21, 2023
9842706
fixing int overflow? and some proto issues
cipherzzz Jan 21, 2023
252f354
fixing int overflow paging calculation
cipherzzz Jan 22, 2023
639120d
gofumpt
cipherzzz Jan 22, 2023
f492408
added tests
cipherzzz Jan 23, 2023
e04a843
fixed merge
cipherzzz Jan 23, 2023
73aad2d
gofumpt and lint
cipherzzz Jan 23, 2023
2218ef7
Merge branch 'main' into cipherz/13703-query-block-event
cipherzzz Jan 23, 2023
ad78cde
Merge branch 'main' into cipherz/13703-query-block-event
cipherzzz Jan 25, 2023
89eb164
Merge branch 'main' into cipherz/13703-query-block-event
cipherzzz Jan 25, 2023
984b252
fixes per review
cipherzzz Jan 26, 2023
7b1d4b6
Merge branch 'main' of github.com:cosmos/cosmos-sdk into cipherz/1370…
cipherzzz Jan 26, 2023
25091e2
Merge branch 'cipherz/13703-query-block-event' of github.com:cipherzz…
cipherzzz Jan 26, 2023
261ff39
refactor based on pr feedback
cipherzzz Jan 26, 2023
24aea0f
Merge branch 'main' of github.com:cosmos/cosmos-sdk into cipherz/1370…
cipherzzz Jan 26, 2023
1c30838
fix test
cipherzzz Jan 26, 2023
89314ab
Merge branch 'main' into cipherz/13703-query-block-event
cipherzzz Jan 27, 2023
ff7b290
fix test
cipherzzz Jan 27, 2023
cffd5c2
Merge branch 'main' of github.com:cosmos/cosmos-sdk into cipherz/1370…
cipherzzz Jan 27, 2023
0bdf087
Merge branch 'cipherz/13703-query-block-event' of github.com:cipherzz…
cipherzzz Jan 27, 2023
012164a
Merge branch 'main' into cipherz/13703-query-block-event
cipherzzz Jan 30, 2023
58c65ba
Merge branch 'main' of github.com:cosmos/cosmos-sdk into cipherz/1370…
cipherzzz Jan 30, 2023
2b21718
Merge branch 'cipherz/13703-query-block-event' of github.com:cipherzz…
cipherzzz Jan 30, 2023
22544c3
moved block query from auth module to tendermint server
cipherzzz Jan 30, 2023
ec412d4
fixes per PR
cipherzzz Jan 31, 2023
1845a21
extracted to method
cipherzzz Jan 31, 2023
85d1b54
Merge branch 'main' of github.com:cosmos/cosmos-sdk into cipherz/1370…
cipherzzz Jan 31, 2023
5488e94
fixes per pr feedback
cipherzzz Jan 31, 2023
5bcad2a
pass query directly to Tendermint
cipherzzz Jan 31, 2023
adae794
Merge branch 'main' of github.com:cosmos/cosmos-sdk into cipherz/1370…
cipherzzz Jan 31, 2023
8288c38
fumpt
cipherzzz Jan 31, 2023
4fbcb12
Merge branch 'main' into cipherz/13703-query-block-event
cipherzzz Feb 1, 2023
b197b7b
Update client/rpc/block.go
cipherzzz Feb 2, 2023
589de79
Merge branch 'main' of github.com:cosmos/cosmos-sdk into cipherz/1370…
cipherzzz Feb 2, 2023
1833618
Merge branch 'cipherz/13703-query-block-event' of github.com:cipherzz…
cipherzzz Feb 2, 2023
ead688e
fixed merge
cipherzzz Feb 3, 2023
266803e
changes per PR feedback
cipherzzz Feb 3, 2023
63634aa
Merge branch 'main' into cipherz/13703-query-block-event
cipherzzz Feb 4, 2023
8c4e000
Update client/rpc/block.go
cipherzzz Feb 4, 2023
4c27245
differentiate errors
cipherzzz Feb 4, 2023
8d1ace4
Merge branch 'main' of github.com:cosmos/cosmos-sdk into cipherz/1370…
cipherzzz Feb 4, 2023
e514413
fixed merge
cipherzzz Feb 4, 2023
d8d5136
changes per PR review
cipherzzz Feb 7, 2023
80d4071
fixed merge
cipherzzz Feb 7, 2023
cbff045
fixed test
cipherzzz Feb 7, 2023
763119e
Merge branch 'main' of github.com:cosmos/cosmos-sdk into cipherz/1370…
cipherzzz Feb 9, 2023
4bea8b3
Update types/result.go
cipherzzz Feb 9, 2023
4310491
Update client/rpc/block.go
cipherzzz Feb 9, 2023
bedce2d
Update server/cmt_cmds.go
cipherzzz Feb 9, 2023
01bdbe3
Update server/cmt_cmds.go
cipherzzz Feb 9, 2023
4af5760
Update server/cmt_cmds.go
cipherzzz Feb 9, 2023
fb5857d
Update server/cmt_cmds.go
cipherzzz Feb 9, 2023
1b3eb73
updates per pr feedback
cipherzzz Feb 9, 2023
1e1cf9d
Merge branch 'cipherz/13703-query-block-event' of github.com:cipherzz…
cipherzzz Feb 9, 2023
35669ab
updates per PR feedback
cipherzzz Feb 9, 2023
7b2fb55
Merge branch 'main' into cipherz/13703-query-block-event
JeancarloBarrios Feb 9, 2023
0a34801
Merge branch 'main' into cipherz/13703-query-block-event
cipherzzz Feb 13, 2023
f178e0f
Merge branch 'main' into cipherz/13703-query-block-event
alexanderbez Feb 13, 2023
35f605f
Merge branch 'main' of github.com:cosmos/cosmos-sdk into cipherz/1370…
cipherzzz Feb 14, 2023
12d51da
implemented PR change requests
cipherzzz Feb 14, 2023
1cc27a3
Merge branch 'main' of github.com:cosmos/cosmos-sdk into cipherz/1370…
cipherzzz Feb 14, 2023
39c9179
Merge branch 'cipherz/13703-query-block-event' of github.com:cipherzz…
cipherzzz Feb 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
751 changes: 604 additions & 147 deletions api/cosmos/base/abci/v1beta1/abci.pulsar.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions client/tendermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type TendermintRPC interface {
Validators(ctx context.Context, height *int64, page, perPage *int) (*coretypes.ResultValidators, error)
Status(context.Context) (*coretypes.ResultStatus, error)
Block(ctx context.Context, height *int64) (*coretypes.ResultBlock, error)
BlockByHash(ctx context.Context, hash []byte) (*coretypes.ResultBlock, error)
cipherzzz marked this conversation as resolved.
Show resolved Hide resolved
BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*coretypes.ResultBlockchainInfo, error)
Commit(ctx context.Context, height *int64) (*coretypes.ResultCommit, error)
Tx(ctx context.Context, hash []byte, prove bool) (*coretypes.ResultTx, error)
Expand Down
7 changes: 7 additions & 0 deletions proto/cosmos/base/abci/v1beta1/abci.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ message TxResponse {
repeated tendermint.abci.Event events = 13 [(gogoproto.nullable) = false];
}

// BlockResponse placeholder - still needs work
cipherzzz marked this conversation as resolved.
Show resolved Hide resolved
message BlockResponse {
cipherzzz marked this conversation as resolved.
Show resolved Hide resolved
option (gogoproto.goproto_getters) = false;
// The block height
int64 height = 1;
}

// ABCIMessageLog defines a structure containing an indexed tx ABCI message log.
message ABCIMessageLog {
option (gogoproto.stringer) = true;
Expand Down
2 changes: 1 addition & 1 deletion simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func queryCommand() *cobra.Command {
cmd.AddCommand(
authcmd.GetAccountCmd(),
rpc.ValidatorCommand(),
rpc.BlockCommand(),
cipherzzz marked this conversation as resolved.
Show resolved Hide resolved
authcmd.QueryBlockCmd(),
cipherzzz marked this conversation as resolved.
Show resolved Hide resolved
authcmd.QueryTxsByEventsCmd(),
authcmd.QueryTxCmd(),
)
Expand Down
281 changes: 216 additions & 65 deletions types/abci.pb.go

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions types/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ func NewResponseResultTx(res *coretypes.ResultTx, anyTx *codectypes.Any, timesta
}
}

// NewResponseResultBlock returns a BlockResponse given a ResultBlock from tendermint
cipherzzz marked this conversation as resolved.
Show resolved Hide resolved
func NewResponseResultBlock(res *coretypes.ResultBlock) *BlockResponse {
if res == nil {
return nil
}

return &BlockResponse{
Height: res.Block.Height,
}
}

// NewResponseFormatBroadcastTx returns a TxResponse given a ResultBroadcastTx from tendermint
func NewResponseFormatBroadcastTx(res *coretypes.ResultBroadcastTx) *TxResponse {
if res == nil {
Expand Down
64 changes: 64 additions & 0 deletions x/auth/block/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package block

import (
"context"
"encoding/hex"

"github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
coretypes "github.com/tendermint/tendermint/rpc/core/types"
)

// get block by height
func GetBlockByHeight(clientCtx client.Context, height *int64) (*sdk.BlockResponse, error) {
cipherzzz marked this conversation as resolved.
Show resolved Hide resolved
// get the node
node, err := clientCtx.GetNode()
if err != nil {
return nil, err
}

// header -> BlockchainInfo
// header, tx -> Block
// results -> BlockResults
resBlock, err := node.Block(context.Background(), height)
if err != nil {
return nil, err
}

out, err := mkBlockResult(resBlock)
if err != nil {
return out, err
}

return out, nil
}

func GetBlockByHash(clientCtx client.Context, hashHexString string) (*sdk.BlockResponse, error) {

hash, err := hex.DecodeString(hashHexString)
if err != nil {
return nil, err
}

// get the node
node, err := clientCtx.GetNode()
if err != nil {
return nil, err
}

resBlock, err := node.BlockByHash(context.Background(), hash)
if err != nil {
return nil, err
}

out, err := mkBlockResult(resBlock)
if err != nil {
return out, err
}

return out, nil
}

func mkBlockResult(resBlock *coretypes.ResultBlock) (*sdk.BlockResponse, error) {
return sdk.NewResponseResultBlock(resBlock), nil
}
97 changes: 97 additions & 0 deletions x/auth/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/version"
authblock "github.com/cosmos/cosmos-sdk/x/auth/block"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
"github.com/cosmos/cosmos-sdk/x/auth/types"
)
Expand All @@ -26,6 +27,7 @@ const (
typeHash = "hash"
typeAccSeq = "acc_seq"
typeSig = "signature"
typeHeight = "height"

eventFormat = "{eventType}.{eventAttribute}={value}"
)
Expand Down Expand Up @@ -429,6 +431,101 @@ $ %s query tx --%s=%s <sig1_base64>,<sig2_base64...>
return cmd
}

// QueryTxCmd implements the default command for a tx query.
cipherzzz marked this conversation as resolved.
Show resolved Hide resolved
func QueryBlockCmd() *cobra.Command {
cipherzzz marked this conversation as resolved.
Show resolved Hide resolved
cmd := &cobra.Command{
Use: "block --type=[height|hash] [height|hash]",
Short: "Query for a committed block by height or hash",
Long: strings.TrimSpace(fmt.Sprintf(`
Example:
$ %s query block <height>
$ %s query block --%s=%s <hash>
`,
version.AppName,
version.AppName, flagType, typeHeight)),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

typ, _ := cmd.Flags().GetString(flagType)
Fixed Show fixed Hide fixed

switch typ {
case typeHeight:
{
if args[0] == "" {
return fmt.Errorf("argument should be a block height")
}

var height *int64

// optional height
if len(args) > 0 {
h, err := strconv.Atoi(args[0])
if err != nil {
return err
}
if h > 0 {
tmp := int64(h)
height = &tmp
}
}

output, err := authblock.GetBlockByHeight(clientCtx, height)
if err != nil {
return err
}

if output.Empty() {
return fmt.Errorf("no transaction found with hash %s", args[0])
}

return clientCtx.PrintProto(output)
}
case typeHash:
{
if args[0] == "" {
return fmt.Errorf("argument should be a tx hash")
}

// If hash is given, then query the tx by hash.
output, err := authblock.GetBlockByHash(clientCtx, args[0])
if err != nil {
return err
}

if output.Empty() {
return fmt.Errorf("no transaction found with hash %s", args[0])
}

return clientCtx.PrintProto(output)

// // If hash is given, then query the tx by hash.
// output, err := authtx.QueryTx(clientCtx, args[0])
// if err != nil {
// return err
// }

// if output.Empty() {
// return fmt.Errorf("no transaction found with hash %s", args[0])
// }

// return clientCtx.PrintProto(output)
}
default:
return fmt.Errorf("unknown --%s value %s", flagType, typ)
}
},
}

flags.AddQueryFlagsToCmd(cmd)
cmd.Flags().String(flagType, typeHash, fmt.Sprintf("The type to be used when querying tx, can be one of \"%s\", \"%s\"", typeHeight, typeHash))

return cmd
}

// ParseSigArgs parses comma-separated signatures from the CLI arguments.
func ParseSigArgs(args []string) ([]string, error) {
if len(args) != 1 || args[0] == "" {
Expand Down