Skip to content

Commit

Permalink
feat: include transactions in QueryBlockByHeight (backport cosmos#10880
Browse files Browse the repository at this point in the history
…) (cosmos#11248)

* feat: include transactions in QueryBlockByHeight  (cosmos#10880)

## Description

Closes: cosmos#3729

- adds a new query to the tx service in Auth, which gets block information + decoded txs
- added a new function to get the protoBlock from the node.

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)

(cherry picked from commit dd65ef8)

# Conflicts:
#	CHANGELOG.md
#	api/cosmos/group/v1beta1/types.pulsar.go
#	api/cosmos/tx/v1beta1/service.pulsar.go
#	api/cosmos/tx/v1beta1/service_grpc.pb.go
#	client/grpc/tmservice/block.go
#	testutil/testdata_pulsar/query.pulsar.go
#	testutil/testdata_pulsar/testdata.pulsar.go
#	testutil/testdata_pulsar/tx.pulsar.go
#	testutil/testdata_pulsar/unknonwnproto.pulsar.go
#	types/tx/service.pb.go

* fix conflicts

* remove pulsar

Co-authored-by: Tyler <[email protected]>
Co-authored-by: marbar3778 <[email protected]>
  • Loading branch information
3 people authored and JeancarloBarrios committed Sep 28, 2024
1 parent 1824b81 commit cde7a3f
Show file tree
Hide file tree
Showing 9 changed files with 878 additions and 565 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/bank) [\#10771](https://github.com/cosmos/cosmos-sdk/pull/10771) Add safety check on bank module perms to allow module-specific mint restrictions (e.g. only minting a certain denom).
* (x/bank) [\#10771](https://github.com/cosmos/cosmos-sdk/pull/10771) Add `bank.BankKeeper.WithMintCoinsRestriction` function to restrict use of bank `MintCoins` usage. This function is not on the bank `Keeper` interface, so it's not API-breaking, but only additive on the keeper implementation.
* [\#11124](https://github.com/cosmos/cosmos-sdk/pull/11124) Add `GetAllVersions` to application store
* (x/auth) [\#10880](https://github.com/cosmos/cosmos-sdk/pull/10880) Added a new query to the tx query service that returns a block with transactions fully decoded.


### Bug Fixes

Expand Down
7 changes: 1 addition & 6 deletions client/grpc/cmtservice/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,7 @@ func (s queryServer) GetBlockByHeight(ctx context.Context, req *GetBlockByHeight
return nil, status.Error(codes.InvalidArgument, "requested block height is bigger then the chain length")
}

protoBlockID, protoBlock, err := GetProtoBlock(ctx, s.rpc, &req.Height)
if err != nil {
return nil, err
}

sdkBlock, err := convertBlock(protoBlock, s.consensusCodec)
protoBlockID, protoBlock, err := GetProtoBlock(ctx, s.clientCtx, &req.Height)
if err != nil {
return nil, err
}
Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ require (
github.com/coinbase/rosetta-sdk-go v0.7.0
github.com/confio/ics23/go v0.6.6
github.com/cosmos/btcutil v1.0.4
github.com/cosmos/cosmos-proto v1.0.0-alpha7
github.com/cosmos/cosmos-sdk/api v0.1.0-alpha4
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/iavl v0.17.3
github.com/cosmos/ledger-cosmos-go v0.11.1
Expand Down Expand Up @@ -49,8 +51,8 @@ require (
github.com/tendermint/tendermint v0.34.14
github.com/tendermint/tm-db v0.6.4
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71
google.golang.org/grpc v1.42.0
google.golang.org/genproto v0.0.0-20211223182754-3ac035c7e7cb
google.golang.org/grpc v1.44.0
google.golang.org/protobuf v1.27.1
gopkg.in/yaml.v2 v2.4.0
)
Expand Down
15 changes: 9 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfc
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cosmos/btcutil v1.0.4 h1:n7C2ngKXo7UC9gNyMNLbzqz7Asuf+7Qv4gnX/rOdQ44=
github.com/cosmos/btcutil v1.0.4/go.mod h1:Ffqc8Hn6TJUdDgHBwIZLtrLQC1KdJ9jGJl/TvgUaxbU=
github.com/cosmos/cosmos-proto v1.0.0-alpha7 h1:yqYUOHF2jopwZh4dVQp3xgqwftE5/2hkrwIV6vkUbO0=
github.com/cosmos/cosmos-proto v1.0.0-alpha7/go.mod h1:dosO4pSAbJF8zWCzCoTWP7nNsjcvSUBQmniFxDg5daw=
github.com/cosmos/cosmos-sdk/api v0.1.0-alpha4 h1:z2si9sQNUTj2jw+24SujuUxcoNS3TVga/fdYsS4rJII=
github.com/cosmos/cosmos-sdk/api v0.1.0-alpha4/go.mod h1:gZu6sOu2vl4Fd7I+BjDSx2bxndwPgFLGfOegek3SQQo=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
Expand Down Expand Up @@ -327,11 +331,10 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
Expand Down Expand Up @@ -1012,7 +1015,6 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down Expand Up @@ -1091,8 +1093,8 @@ google.golang.org/genproto v0.0.0-20210310155132-4ce2db91004e/go.mod h1:FWY/as6D
google.golang.org/genproto v0.0.0-20210319143718-93e7006c17a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaEmUacj36I+k7YKbEc5CXzPIeORRgDAUOu28A=
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0=
google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71 h1:z+ErRPu0+KS02Td3fOAgdX+lnPDh/VyaABEJPD4JRQs=
google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71/go.mod h1:eFjDcFEctNawg4eG61bRv87N7iHBWyVhJu7u1kqDUXY=
google.golang.org/genproto v0.0.0-20211223182754-3ac035c7e7cb h1:ZrsicilzPCS/Xr8qtBZZLpy4P9TYXAfl49ctG1/5tgw=
google.golang.org/genproto v0.0.0-20211223182754-3ac035c7e7cb/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc=
google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o=
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
Expand Down Expand Up @@ -1144,6 +1146,7 @@ honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
nhooyr.io/websocket v1.8.6 h1:s+C3xAMLwGmlI31Nyn/eAehUlZPwfYZu2JXM621Q5/k=
nhooyr.io/websocket v1.8.6/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0=
pgregory.net/rapid v0.4.7/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
Expand Down
147 changes: 18 additions & 129 deletions proto/cosmos/tx/v1beta1/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import "google/api/annotations.proto";
import "cosmos/base/abci/v1beta1/abci.proto";
import "cosmos/tx/v1beta1/tx.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "cometbft/types/v1/block.proto";
import "cometbft/types/v1/types.proto";
import "cosmos_proto/cosmos.proto";
import "tendermint/types/block.proto";
import "tendermint/types/types.proto";

option go_package = "github.com/cosmos/cosmos-sdk/types/tx";

Expand Down Expand Up @@ -36,69 +35,21 @@ service Service {
option (google.api.http).get = "/cosmos/tx/v1beta1/txs";
}
// GetBlockWithTxs fetches a block with decoded txs.
//
// Since: cosmos-sdk 0.45.2
rpc GetBlockWithTxs(GetBlockWithTxsRequest) returns (GetBlockWithTxsResponse) {
option (google.api.http).get = "/cosmos/tx/v1beta1/txs/block/{height}";
option (cosmos_proto.method_added_in) = "cosmos-sdk 0.45.2";
}
// TxDecode decodes the transaction.
rpc TxDecode(TxDecodeRequest) returns (TxDecodeResponse) {
option (google.api.http) = {
post: "/cosmos/tx/v1beta1/decode"
body: "*"
};
option (cosmos_proto.method_added_in) = "cosmos-sdk 0.47";
}
// TxEncode encodes the transaction.
rpc TxEncode(TxEncodeRequest) returns (TxEncodeResponse) {
option (google.api.http) = {
post: "/cosmos/tx/v1beta1/encode"
body: "*"
};
option (cosmos_proto.method_added_in) = "cosmos-sdk 0.47";
}
// TxEncodeAmino encodes an Amino transaction from JSON to encoded bytes.
rpc TxEncodeAmino(TxEncodeAminoRequest) returns (TxEncodeAminoResponse) {
option (google.api.http) = {
post: "/cosmos/tx/v1beta1/encode/amino"
body: "*"
};
option (cosmos_proto.method_added_in) = "cosmos-sdk 0.47";
}
// TxDecodeAmino decodes an Amino transaction from encoded bytes to JSON.
rpc TxDecodeAmino(TxDecodeAminoRequest) returns (TxDecodeAminoResponse) {
option (google.api.http) = {
post: "/cosmos/tx/v1beta1/decode/amino"
body: "*"
};
option (cosmos_proto.method_added_in) = "cosmos-sdk 0.47";
option (google.api.http).get = "/cosmos/tx/v1beta1/txs/block/{height}";
}
}

// GetTxsEventRequest is the request type for the Service.TxsByEvents
// RPC method.
message GetTxsEventRequest {
// events is the list of transaction event type.
// Deprecated: post v0.47.x use query instead, which should contain a valid
// events query.
repeated string events = 1 [deprecated = true];

repeated string events = 1;
// pagination defines a pagination for the request.
// Deprecated: post v0.46.x use page and limit instead.
cosmos.base.query.v1beta1.PageRequest pagination = 2 [deprecated = true];

OrderBy order_by = 3;

// page is the page number to query, starts at 1. If not provided, will
// default to first page.
uint64 page = 4;

// limit is the total number of results to be returned in the result page.
// If left empty it will default to a value to be set by each app.
uint64 limit = 5;

// query defines the transaction event query that is proxied to Tendermint's
// TxSearch RPC method. The query must be valid.
string query = 6 [(cosmos_proto.field_added_in) = "cosmos-sdk 0.50"];
cosmos.base.query.v1beta1.PageRequest pagination = 2;
OrderBy order_by = 3;
}

// OrderBy defines the sorting order
Expand All @@ -120,10 +71,7 @@ message GetTxsEventResponse {
// tx_responses is the list of queried TxResponses.
repeated cosmos.base.abci.v1beta1.TxResponse tx_responses = 2;
// pagination defines a pagination for the response.
// Deprecated: post v0.46.x use total instead.
cosmos.base.query.v1beta1.PageResponse pagination = 3 [deprecated = true];
// total is total number of results available
uint64 total = 4;
cosmos.base.query.v1beta1.PageResponse pagination = 3;
}

// BroadcastTxRequest is the request type for the Service.BroadcastTxRequest
Expand Down Expand Up @@ -195,82 +143,23 @@ message GetTxResponse {

// GetBlockWithTxsRequest is the request type for the Service.GetBlockWithTxs
// RPC method.
//
// Since: cosmos-sdk 0.45.2
message GetBlockWithTxsRequest {
// height is the height of the block to query.
int64 height = 1;
// pagination defines a pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 2;
option (cosmos_proto.message_added_in) = "cosmos-sdk 0.45.2";
}

// GetBlockWithTxsResponse is the response type for the Service.GetBlockWithTxs
// method.
// GetBlockWithTxsResponse is the response type for the Service.GetBlockWithTxs method.
//
// Since: cosmos-sdk 0.45.2
message GetBlockWithTxsResponse {
// txs are the transactions in the block.
repeated cosmos.tx.v1beta1.Tx txs = 1;
.cometbft.types.v1.BlockID block_id = 2;
.cometbft.types.v1.Block block = 3;
repeated cosmos.tx.v1beta1.Tx txs = 1;
.tendermint.types.BlockID block_id = 2;
.tendermint.types.Block block = 3;
// pagination defines a pagination for the response.
cosmos.base.query.v1beta1.PageResponse pagination = 4;
option (cosmos_proto.message_added_in) = "cosmos-sdk 0.45.2";
}

// TxDecodeRequest is the request type for the Service.TxDecode
// RPC method.
message TxDecodeRequest {
// tx_bytes is the raw transaction.
bytes tx_bytes = 1;
option (cosmos_proto.message_added_in) = "cosmos-sdk 0.47";
}

// TxDecodeResponse is the response type for the
// Service.TxDecode method.
message TxDecodeResponse {
// tx is the decoded transaction.
cosmos.tx.v1beta1.Tx tx = 1;
option (cosmos_proto.message_added_in) = "cosmos-sdk 0.47";
}

// TxEncodeRequest is the request type for the Service.TxEncode
// RPC method.
message TxEncodeRequest {
// tx is the transaction to encode.
cosmos.tx.v1beta1.Tx tx = 1;
option (cosmos_proto.message_added_in) = "cosmos-sdk 0.47";
}

// TxEncodeResponse is the response type for the
// Service.TxEncode method.
message TxEncodeResponse {
// tx_bytes is the encoded transaction bytes.
bytes tx_bytes = 1;
option (cosmos_proto.message_added_in) = "cosmos-sdk 0.47";
}

// TxEncodeAminoRequest is the request type for the Service.TxEncodeAmino
// RPC method.
message TxEncodeAminoRequest {
string amino_json = 1;
option (cosmos_proto.message_added_in) = "cosmos-sdk 0.47";
}

// TxEncodeAminoResponse is the response type for the Service.TxEncodeAmino
// RPC method.
message TxEncodeAminoResponse {
bytes amino_binary = 1;
option (cosmos_proto.message_added_in) = "cosmos-sdk 0.47";
}

// TxDecodeAminoRequest is the request type for the Service.TxDecodeAmino
// RPC method.
message TxDecodeAminoRequest {
bytes amino_binary = 1;
option (cosmos_proto.message_added_in) = "cosmos-sdk 0.47";
}

// TxDecodeAminoResponse is the response type for the Service.TxDecodeAmino
// RPC method.
message TxDecodeAminoResponse {
string amino_json = 1;
option (cosmos_proto.message_added_in) = "cosmos-sdk 0.47";
}
}
Loading

0 comments on commit cde7a3f

Please sign in to comment.