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

perf: fix to use easyjson instead of amino when marshal abci logs #208

Merged
merged 7 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,15 @@ devdoc-update:

.PHONY: devdoc devdoc-clean devdoc-init devdoc-save devdoc-update

###############################################################################
### easyjson ###
###############################################################################
# easyjson must be used for types that are not registered in amino by RegisterConcrete.
easyjson-gen:
@echo "Generating easyjson files"
go get github.com/mailru/[email protected]
easyjson ./types/result.go

###############################################################################
### Protobuf ###
###############################################################################
Expand Down
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ ignore:
- "*.sh"
- "*.png"
- "*_test.go"
- "**/*_easyjson.go"
- "x/**/*.pb.go"
- "x/**/*.pb.gw.go"
- "scripts/"
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ require (
github.com/line/tm-db/v2 v2.0.0-init.1.0.20210413083915-5bb60e117524
github.com/line/wasmvm v0.14.0-0.5.0
github.com/magiconair/properties v1.8.4
github.com/mailru/easyjson v0.7.7
github.com/mattn/go-isatty v0.0.12
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/nxadm/tail v1.4.8 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht
github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U=
github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
Expand Down Expand Up @@ -347,6 +349,8 @@ github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czP
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.4 h1:8KGKTcQQGm0Kv7vEbKFErAoAOFyyacLStRtQSeYtvkY=
github.com/magiconair/properties v1.8.4/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
Expand Down
3 changes: 3 additions & 0 deletions types/decimal_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"math/big"
"testing"

"github.com/line/lbm-sdk/v2/codec"
"github.com/stretchr/testify/suite"
)

Expand All @@ -22,6 +23,7 @@ func (s *decimalInternalTestSuite) TestPrecisionMultiplier() {
}

func (s *decimalInternalTestSuite) TestZeroDeserializationJSON() {
var cdc = codec.NewLegacyAmino()
d := Dec{new(big.Int)}
err := cdc.UnmarshalJSON([]byte(`"0"`), &d)
s.Require().Nil(err)
Expand All @@ -30,6 +32,7 @@ func (s *decimalInternalTestSuite) TestZeroDeserializationJSON() {
}

func (s *decimalInternalTestSuite) TestSerializationGocodecJSON() {
var cdc = codec.NewLegacyAmino()
d := MustNewDecFromStr("0.333")

bz, err := cdc.MarshalJSON(d)
Expand Down
18 changes: 8 additions & 10 deletions types/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ import (

"github.com/gogo/protobuf/proto"

yaml "gopkg.in/yaml.v2"
"gopkg.in/yaml.v2"

abci "github.com/line/ostracon/abci/types"
ctypes "github.com/line/ostracon/rpc/core/types"

"github.com/line/lbm-sdk/v2/codec"
codectypes "github.com/line/lbm-sdk/v2/codec/types"
)

var cdc = codec.NewLegacyAmino()

func (gi GasInfo) String() string {
bz, _ := yaml.Marshal(gi)
return string(bz)
Expand All @@ -40,6 +37,7 @@ func (r Result) GetEvents() Events {
}

// ABCIMessageLogs represents a slice of ABCIMessageLog.
//easyjson:json
type ABCIMessageLogs []ABCIMessageLog

func NewABCIMessageLog(i uint32, log string, events Events) ABCIMessageLog {
Expand All @@ -51,15 +49,15 @@ func NewABCIMessageLog(i uint32, log string, events Events) ABCIMessageLog {
}

// String implements the fmt.Stringer interface for the ABCIMessageLogs type.
func (logs ABCIMessageLogs) String() (str string) {
func (logs ABCIMessageLogs) String() string {
if logs != nil {
raw, err := cdc.MarshalJSON(logs)
if err == nil {
str = string(raw)
res, err := logs.MarshalJSON()
if err != nil {
panic(err)
}
return string(res)
}

return str
return ""
}

// NewResponseResultTx returns a TxResponse given a ResultTx from ostracon
Expand Down
Loading