From d77f0c26eb157b11da9cf966a1d65daf8ef112b6 Mon Sep 17 00:00:00 2001 From: Toshimasa Nasu Date: Mon, 24 Jul 2023 22:18:00 +0900 Subject: [PATCH] Backport tendermint-v0.34.24 into main (#678) * rpc: fix check_tx cache problem (backport #9690) (#9692) * fix check_tx cache problem (#9690) (cherry picked from commit ffae184b62942219e8f16c8d5d68882b43d7ad24) * Resolve conflicts Signed-off-by: Thane Thomson * Add changelog entry Signed-off-by: Thane Thomson Signed-off-by: Thane Thomson Co-authored-by: JayT106 Co-authored-by: Thane Thomson * Remove useless whitespace in Websocket output (backport #9720) (#9724) * Remove useless whitespace in Websocket output (#9720) * First try at #9696 * Brief explanation * Removed all prettified JSON RPC responses * Fixes for failing tests. Adapted the assertions in - TestWriteRPCResponseHTTP - TestWriteRPCResponseHTTPError to work with non-pretty JSON-RPC output * Added changelog pending entry * Update CHANGELOG_PENDING.md Co-authored-by: Thane Thomson * Add pending changelog and upgrading entries Signed-off-by: Thane Thomson Signed-off-by: Thane Thomson Co-authored-by: Adi Seredinschi Co-authored-by: Thane Thomson * Upgrade to tendermint-v0.34.24 --------- Signed-off-by: Thane Thomson Co-authored-by: JayT106 Co-authored-by: Thane Thomson --- go.mod | 3 +-- go.sum | 4 +-- rpc/core/routes.go | 2 +- rpc/jsonrpc/server/http_server.go | 4 +-- rpc/jsonrpc/server/http_server_test.go | 35 +++----------------------- rpc/jsonrpc/server/ws_handler.go | 5 +++- 6 files changed, 13 insertions(+), 40 deletions(-) diff --git a/go.mod b/go.mod index 8621ffffb..c434edc40 100644 --- a/go.mod +++ b/go.mod @@ -46,7 +46,7 @@ require ( github.com/oasisprotocol/curve25519-voi v0.0.0-20230110094441-db37f07504ce github.com/rs/zerolog v1.29.1 github.com/tendermint/go-amino v0.16.0 - github.com/tendermint/tendermint v0.34.23 + github.com/tendermint/tendermint v0.34.24 gopkg.in/natefinch/lumberjack.v2 v2.2.1 gopkg.in/yaml.v3 v3.0.1 ) @@ -64,7 +64,6 @@ require ( require github.com/vektra/mockery/v2 v2.32.0 require ( - github.com/gogo/protobuf v1.3.2 github.com/informalsystems/tm-load-test v1.0.0 gonum.org/v1/gonum v0.13.0 google.golang.org/protobuf v1.31.0 diff --git a/go.sum b/go.sum index f6d273f60..7cf1ae459 100644 --- a/go.sum +++ b/go.sum @@ -1101,8 +1101,8 @@ github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c/go.mod h1:ahpPrc7 github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E= github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= github.com/tendermint/tendermint v0.34.14/go.mod h1:FrwVm3TvsVicI9Z7FlucHV6Znfd5KBc/Lpp69cCwtk0= -github.com/tendermint/tendermint v0.34.23 h1:JZYsdc59aOiT5efou+BHILJv8x6FlRyvlor84Xq9Tb0= -github.com/tendermint/tendermint v0.34.23/go.mod h1:rXVrl4OYzmIa1I91av3iLv2HS0fGSiucyW9J4aMTpKI= +github.com/tendermint/tendermint v0.34.24 h1:879MKKJWYYPJEMMKME+DWUTY4V9f/FBpnZDI82ky+4k= +github.com/tendermint/tendermint v0.34.24/go.mod h1:rXVrl4OYzmIa1I91av3iLv2HS0fGSiucyW9J4aMTpKI= github.com/tendermint/tm-db v0.6.4/go.mod h1:dptYhIpJ2M5kUuenLr+Yyf3zQOv1SgBZcl8/BmWlMBw= github.com/tendermint/tm-db v0.6.7 h1:fE00Cbl0jayAoqlExN6oyQJ7fR/ZtoVOmvPJ//+shu8= github.com/tendermint/tm-db v0.6.7/go.mod h1:byQDzFkZV1syXr/ReXS808NxA2xvyuuVgXOJ/088L6I= diff --git a/rpc/core/routes.go b/rpc/core/routes.go index 4fd4581c5..4d75850f8 100644 --- a/rpc/core/routes.go +++ b/rpc/core/routes.go @@ -24,7 +24,7 @@ var Routes = map[string]*rpc.RPCFunc{ "block_by_hash": rpc.NewRPCFunc(BlockByHash, "hash", rpc.Cacheable()), "block_results": rpc.NewRPCFunc(BlockResults, "height", rpc.Cacheable("height")), "commit": rpc.NewRPCFunc(Commit, "height", rpc.Cacheable("height")), - "check_tx": rpc.NewRPCFunc(CheckTx, "tx", rpc.Cacheable()), + "check_tx": rpc.NewRPCFunc(CheckTx, "tx"), "tx": rpc.NewRPCFunc(Tx, "hash,prove", rpc.Cacheable()), "tx_search": rpc.NewRPCFunc(TxSearch, "query,prove,page,per_page,order_by"), "block_search": rpc.NewRPCFunc(BlockSearch, "query,page,per_page,order_by"), diff --git a/rpc/jsonrpc/server/http_server.go b/rpc/jsonrpc/server/http_server.go index 5fad8e239..3783806e2 100644 --- a/rpc/jsonrpc/server/http_server.go +++ b/rpc/jsonrpc/server/http_server.go @@ -109,7 +109,7 @@ func WriteRPCResponseHTTPError( panic("tried to write http error response without RPC error") } - jsonBytes, err := json.MarshalIndent(res, "", " ") + jsonBytes, err := json.Marshal(res) if err != nil { return fmt.Errorf("json marshal: %w", err) } @@ -145,7 +145,7 @@ func writeRPCResponseHTTP(w http.ResponseWriter, headers []httpHeader, res ...ty v = res } - jsonBytes, err := json.MarshalIndent(v, "", " ") + jsonBytes, err := json.Marshal(v) if err != nil { return fmt.Errorf("json marshal: %w", err) } diff --git a/rpc/jsonrpc/server/http_server_test.go b/rpc/jsonrpc/server/http_server_test.go index 6204c9ff4..fb2a2711f 100644 --- a/rpc/jsonrpc/server/http_server_test.go +++ b/rpc/jsonrpc/server/http_server_test.go @@ -123,13 +123,7 @@ func TestWriteRPCResponseHTTP(t *testing.T) { assert.Equal(t, 200, resp.StatusCode) assert.Equal(t, "application/json", resp.Header.Get("Content-Type")) assert.Equal(t, "public, max-age=86400", resp.Header.Get("Cache-control")) - assert.Equal(t, `{ - "jsonrpc": "2.0", - "id": -1, - "result": { - "value": "hello" - } -}`, string(body)) + assert.Equal(t, `{"jsonrpc":"2.0","id":-1,"result":{"value":"hello"}}`, string(body)) // multiple arguments w = httptest.NewRecorder() @@ -144,22 +138,7 @@ func TestWriteRPCResponseHTTP(t *testing.T) { assert.Equal(t, 200, resp.StatusCode) assert.Equal(t, "application/json", resp.Header.Get("Content-Type")) - assert.Equal(t, `[ - { - "jsonrpc": "2.0", - "id": -1, - "result": { - "value": "hello" - } - }, - { - "jsonrpc": "2.0", - "id": -1, - "result": { - "value": "world" - } - } -]`, string(body)) + assert.Equal(t, `[{"jsonrpc":"2.0","id":-1,"result":{"value":"hello"}},{"jsonrpc":"2.0","id":-1,"result":{"value":"world"}}]`, string(body)) } func TestWriteRPCResponseHTTPError(t *testing.T) { @@ -175,15 +154,7 @@ func TestWriteRPCResponseHTTPError(t *testing.T) { require.NoError(t, err) assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) assert.Equal(t, "application/json", resp.Header.Get("Content-Type")) - assert.Equal(t, `{ - "jsonrpc": "2.0", - "id": -1, - "error": { - "code": -32603, - "message": "Internal error", - "data": "foo" - } -}`, string(body)) + assert.Equal(t, `{"jsonrpc":"2.0","id":-1,"error":{"code":-32603,"message":"Internal error","data":"foo"}}`, string(body)) } func TestWriteRPCResponseHTTP_MarshalIndent_error(t *testing.T) { w := NewFailedWriteResponseWriter() diff --git a/rpc/jsonrpc/server/ws_handler.go b/rpc/jsonrpc/server/ws_handler.go index 2a8569e29..d46bbfa9d 100644 --- a/rpc/jsonrpc/server/ws_handler.go +++ b/rpc/jsonrpc/server/ws_handler.go @@ -431,7 +431,10 @@ func (wsc *wsConnection) writeRoutine() { return } case msg := <-wsc.writeChan: - jsonBytes, err := json.MarshalIndent(msg, "", " ") + // Use json.MarshalIndent instead of Marshal for pretty output. + // Pretty output not necessary, since most consumers of WS events are + // automated processes, not humans. + jsonBytes, err := json.Marshal(msg) if err != nil { wsc.Logger.Error("Failed to marshal RPCResponse to JSON", "err", err) continue