Skip to content

Commit

Permalink
fix: Add Events to TxResponse (cosmos#10630)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored Nov 30, 2021
1 parent 4a12983 commit c4bedf8
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 117 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

* (deps) [\#10210](https://github.com/cosmos/cosmos-sdk/pull/10210) Bump Tendermint to [v0.35.0](https://github.com/tendermint/tendermint/releases/tag/v0.35.0).
* [\#10486](https://github.com/cosmos/cosmos-sdk/pull/10486) store/cachekv's `Store.Write` conservatively looks up keys, but also uses the [map clearing idiom](https://bencher.orijtech.com/perfclinic/mapclearing/) to reduce the RAM usage, CPU time usage, and garbage collection pressure from clearing maps, instead of allocating new maps.
* (types) [\#10630](https://github.com/cosmos/cosmos-sdk/pull/10630) Add an `Events` field to the `TxResponse` type that captures _all_ events emitted by a transaction, unlike `Logs` which only contains events emitted during message execution.

### API Breaking Changes

Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f/go.mod h1:xH/i4TFM
github.com/dgraph-io/badger/v2 v2.2007.2/go.mod h1:26P/7fbL4kUZVEVKLAKXkBXKOydDmM2p1e+NhhnBCAE=
github.com/dgraph-io/badger/v2 v2.2007.4 h1:TRWBQg8UrlUhaFdco01nO2uXwzKS7zd+HVdwV/GHc4o=
github.com/dgraph-io/badger/v2 v2.2007.4/go.mod h1:vSw/ax2qojzbN6eXHIx6KPKtCSHJN/Uz0X0VPruTIhk=
github.com/dgraph-io/badger/v3 v3.2103.2/go.mod h1:RHo4/GmYcKKh5Lxu63wLEMHJ70Pac2JqZRYGhlyAo2M=
github.com/dgraph-io/ristretto v0.0.3-0.20200630154024-f66de99634de/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E=
github.com/dgraph-io/ristretto v0.0.3/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E=
github.com/dgraph-io/ristretto v0.1.0 h1:Jv3CGQHp9OjuMBSne1485aDpUkTKEcUqF+jm/LuerPI=
Expand Down Expand Up @@ -498,8 +497,6 @@ github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9
github.com/google/certificate-transparency-go v1.0.21/go.mod h1:QeJfpSbVSfYc7RgB3gJFj9cbuQMMchQxrWXz8Ruopmg=
github.com/google/certificate-transparency-go v1.1.1/go.mod h1:FDKqPvSXawb2ecErVRrD+nfy23RCzyl7eqVCEmlT1Zs=
github.com/google/flatbuffers v1.11.0/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
github.com/google/flatbuffers v1.12.1/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
github.com/google/flatbuffers v2.0.0+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
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 @@ -39,6 +39,13 @@ message TxResponse {
// the timestamps of the valid votes in the block.LastCommit. For height == 1,
// it's genesis time.
string timestamp = 12;
// Events defines all the events emitted by processing a transaction. Note,
// these events include those emitted by processing all the messages and those
// emitted from the ante handler. Whereas Logs contains the events, with
// additional metadata, emitted only by processing the messages.
//
// Since: cosmos-sdk 0.42.11, 0.44.5, 0.45
repeated tendermint.abci.Event events = 13 [(gogoproto.nullable) = false];
}

// ABCIMessageLog defines a structure containing an indexed tx ABCI message log.
Expand Down
174 changes: 118 additions & 56 deletions types/abci.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 7 additions & 44 deletions types/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ package types
import (
"encoding/hex"
"encoding/json"
"fmt"
"math"
"strings"

"github.com/gogo/protobuf/proto"

"sigs.k8s.io/yaml"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/rpc/coretypes"

Expand All @@ -21,12 +17,12 @@ import (
var cdc = codec.NewLegacyAmino()

func (gi GasInfo) String() string {
bz, _ := yaml.Marshal(gi)
bz, _ := codec.MarshalYAML(codec.NewProtoCodec(nil), &gi)
return string(bz)
}

func (r Result) String() string {
bz, _ := yaml.Marshal(r)
bz, _ := codec.MarshalYAML(codec.NewProtoCodec(nil), &r)
return string(bz)
}

Expand Down Expand Up @@ -83,6 +79,7 @@ func NewResponseResultTx(res *coretypes.ResultTx, anyTx *codectypes.Any, timesta
GasUsed: res.TxResult.GasUsed,
Tx: anyTx,
Timestamp: timestamp,
Events: res.TxResult.Events,
}
}

Expand Down Expand Up @@ -123,6 +120,7 @@ func newTxResponseCheckTx(res *coretypes.ResultBroadcastTxCommit) *TxResponse {
Info: res.CheckTx.Info,
GasWanted: res.CheckTx.GasWanted,
GasUsed: res.CheckTx.GasUsed,
Events: res.CheckTx.Events,
}
}

Expand All @@ -149,6 +147,7 @@ func newTxResponseDeliverTx(res *coretypes.ResultBroadcastTxCommit) *TxResponse
Info: res.DeliverTx.Info,
GasWanted: res.DeliverTx.GasWanted,
GasUsed: res.DeliverTx.GasUsed,
Events: res.DeliverTx.Events,
}
}

Expand All @@ -171,44 +170,8 @@ func NewResponseFormatBroadcastTx(res *coretypes.ResultBroadcastTx) *TxResponse
}

func (r TxResponse) String() string {
var sb strings.Builder
sb.WriteString("Response:\n")

if r.Height > 0 {
sb.WriteString(fmt.Sprintf(" Height: %d\n", r.Height))
}
if r.TxHash != "" {
sb.WriteString(fmt.Sprintf(" TxHash: %s\n", r.TxHash))
}
if r.Code > 0 {
sb.WriteString(fmt.Sprintf(" Code: %d\n", r.Code))
}
if r.Data != "" {
sb.WriteString(fmt.Sprintf(" Data: %s\n", r.Data))
}
if r.RawLog != "" {
sb.WriteString(fmt.Sprintf(" Raw Log: %s\n", r.RawLog))
}
if r.Logs != nil {
sb.WriteString(fmt.Sprintf(" Logs: %s\n", r.Logs))
}
if r.Info != "" {
sb.WriteString(fmt.Sprintf(" Info: %s\n", r.Info))
}
if r.GasWanted != 0 {
sb.WriteString(fmt.Sprintf(" GasWanted: %d\n", r.GasWanted))
}
if r.GasUsed != 0 {
sb.WriteString(fmt.Sprintf(" GasUsed: %d\n", r.GasUsed))
}
if r.Codespace != "" {
sb.WriteString(fmt.Sprintf(" Codespace: %s\n", r.Codespace))
}
if r.Timestamp != "" {
sb.WriteString(fmt.Sprintf(" Timestamp: %s\n", r.Timestamp))
}

return strings.TrimSpace(sb.String())
bz, _ := codec.MarshalYAML(codec.NewProtoCodec(nil), &r)
return string(bz)
}

// Empty returns true if the response is empty
Expand Down
Loading

0 comments on commit c4bedf8

Please sign in to comment.