Skip to content

Commit

Permalink
Backport tendermint-v0.34.23 into main (#674)
Browse files Browse the repository at this point in the history
* ci: Fix linter complaint (backport #9645) (#9647)

* ci: Fix linter complaint (#9645)

Fixes a very silly linter complaint that makes absolutely no sense and is blocking the merging of several PRs.

---

- [x] Tests written/updated, or no tests needed
- [x] `CHANGELOG_PENDING.md` updated, or no changelog entry needed
- [x] Updated relevant documentation (`docs/`) and code comments, or no
      documentation updates needed

(cherry picked from commit 83b7f4ad5bc77a56fdb51ec39ae13c1204dde6e0)

* Resolve conflicts

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* ci: Sync golangci-lint config with main

Minus the spelling configuration that restricts spelling to US English
only.

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* make format

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Remove usage of deprecated io/ioutil package

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Remove unused mockBlockStore

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* blockchain/v2: Remove unused method

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Bulk fix lints

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* lint: Ignore auto-generated query PEG

Signed-off-by: Thane Thomson <connect@thanethomson.com>

Signed-off-by: Thane Thomson <connect@thanethomson.com>
Co-authored-by: Thane Thomson <connect@thanethomson.com>

* ci: Remove unused Markdown link checker from v0.34.x branch (#9643)

Signed-off-by: Thane Thomson <connect@thanethomson.com>

Signed-off-by: Thane Thomson <connect@thanethomson.com>

Co-authored-by: Thane Thomson <connect@thanethomson.com>

* p2p: add a per-message type send and receive metric (backport #9622) (#9641)

* p2p: add a per-message type send and receive metric (#9622)

* p2p: ressurrect the p2p envelope and use to calculate message metric

Add new SendEnvelope, TrySendEnvelope, BroadcastEnvelope, and ReceiveEnvelope methods in the p2p package to work with the new envelope type.

Care was taken to ensure this was performed in a non-breaking manner.

Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com>
Co-authored-by: William Banfield <wbanfield@gmail.com>

* (fixup) Upgrade to tendermint-v0.34.23 for proto-go files

* (fixup) Remove unnecessary files and adjust to Ostracon

* (fixup) Remove logging PeerState with fixing conflict

* (fixup) Ajust RecvAsync with EnvelopeReceiver

* (fixup) Add ErrInMap for bugfix

* (fixup) Ajust TestSyncReactor/TestAsyncReactor to Ostracon

* (fixup) Generate EnvelopeSender mock and use it for improving test

* (fixup) Improve coverage peer.go

* add allocate in Receive calls (#9667)

Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com>

* rpc: Add caching support (backport #9650) (#9666)

* rpc: Add caching support (#9650)

* Set cache control in the HTTP-RPC response header

* Add a simply cache policy to the RPC routes

* add a condition to check the RPC request has default height settings

* fix cherry pick error

* update pending log

* use options struct intead of single parameter

* refacor FuncOptions to functional options

* add functional options in WebSocket RPC function

* revert doc

* replace deprecated function call

* revise functional options

* remove unuse comment

* fix revised error

* adjust cache-control settings

* Update rpc/jsonrpc/server/http_json_handler.go

Co-authored-by: Thane Thomson <connect@thanethomson.com>

* linter: Fix false positive

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* rpc: Separate cacheable and non-cacheable HTTP response writers

Allows us to roll this change out in a non-API-breaking way, since this
is an additive change.

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* rpc: Ensure consistent caching strategy

Ensure a consistent caching strategy across both JSONRPC- and URI-based
requests.

This requires a bit of a refactor of the previous caching logic, which
is complicated a little by the complex reflection-based approach taken
in the Tendermint RPC.

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* rpc: Add more tests for caching

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Update CHANGELOG_PENDING

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* light: Sync routes config with RPC core

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* rpc: Update OpenAPI docs

Signed-off-by: Thane Thomson <connect@thanethomson.com>

Signed-off-by: Thane Thomson <connect@thanethomson.com>
Co-authored-by: jayt106 <jaytseng106@gmail.com>
Co-authored-by: jay tseng <jay.tseng@crypto.com>
Co-authored-by: JayT106 <JayT106@users.noreply.github.com>
(cherry picked from commit 816c6bac00c63a421a1bdaeccbc081c5346cb0d8)

* Fix conflict in CHANGELOG_PENDING

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Resolve remaining conflicts

Signed-off-by: Thane Thomson <connect@thanethomson.com>

Signed-off-by: Thane Thomson <connect@thanethomson.com>
Co-authored-by: Thane Thomson <connect@thanethomson.com>

* Update p2p/peer.go

Co-authored-by: Shogo Hyodo <mmoshg8u@gmail.com>

* (fixup) Refactor to ProtoMsg

---------

Signed-off-by: Thane Thomson <connect@thanethomson.com>
Co-authored-by: Thane Thomson <connect@thanethomson.com>
Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com>
Co-authored-by: William Banfield <wbanfield@gmail.com>
Co-authored-by: Shogo Hyodo <mmoshg8u@gmail.com>
  • Loading branch information
5 people authored Jul 24, 2023
1 parent 949633b commit 1cab268
Show file tree
Hide file tree
Showing 121 changed files with 2,551 additions and 1,483 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/linkchecker.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ format:

lint:
@echo "--> Running linter"
@golangci-lint run
@go run github.com/golangci/golangci-lint/cmd/golangci-lint run
.PHONY: lint

DESTINATION = ./index.html.md
Expand Down
39 changes: 6 additions & 33 deletions abci/example/kvstore/kvstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package kvstore

import (
"fmt"
"io/ioutil"
"os"
"sort"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -73,7 +72,7 @@ func TestKVStoreKV(t *testing.T) {
}

func TestPersistentKVStoreKV(t *testing.T) {
dir, err := ioutil.TempDir("/tmp", "abci-kvstore-test") // TODO
dir, err := os.MkdirTemp("/tmp", "abci-kvstore-test") // TODO
if err != nil {
t.Fatal(err)
}
Expand All @@ -89,7 +88,7 @@ func TestPersistentKVStoreKV(t *testing.T) {
}

func TestPersistentKVStoreInfo(t *testing.T) {
dir, err := ioutil.TempDir("/tmp", "abci-kvstore-test") // TODO
dir, err := os.MkdirTemp("/tmp", "abci-kvstore-test") // TODO
if err != nil {
t.Fatal(err)
}
Expand All @@ -116,12 +115,11 @@ func TestPersistentKVStoreInfo(t *testing.T) {
if resInfo.LastBlockHeight != height {
t.Fatalf("expected height of %d, got %d", height, resInfo.LastBlockHeight)
}

}

// add a validator, remove a validator, update a validator
func TestValUpdates(t *testing.T) {
dir, err := ioutil.TempDir("/tmp", "abci-kvstore-test") // TODO
dir, err := os.MkdirTemp("/tmp", "abci-kvstore-test") // TODO
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -183,18 +181,15 @@ func TestValUpdates(t *testing.T) {
vals1 = append([]types.ValidatorUpdate{v1}, vals1[1:]...)
vals2 = kvstore.Validators()
valsEqual(t, vals1, vals2)

for _, v := range vals2 {
existInPersistStore(t, kvstore, v)
}
}

func makeApplyBlock(
t *testing.T,
kvstore ocabci.Application,
heightInt int,
diff []types.ValidatorUpdate,
txs ...[]byte) {
txs ...[]byte,
) {
// make and apply block
height := int64(heightInt)
hash := []byte("foo")
Expand All @@ -212,28 +207,6 @@ func makeApplyBlock(
kvstore.Commit()

valsEqual(t, diff, resEndBlock.ValidatorUpdates)

}

func existInPersistStore(t *testing.T, kvstore ocabci.Application, v types.ValidatorUpdate) {
// success
pubkeyStr, _ := MakeValSetChangeTxAndMore(v.PubKey, v.Power)
resQuery := kvstore.Query(types.RequestQuery{Path: "/val", Data: []byte(pubkeyStr)})
assert.False(t, resQuery.IsErr(), resQuery)
assert.Equal(t, "", resQuery.Log)
// failures
{
// default Query: does not exist
r := kvstore.Query(types.RequestQuery{Path: "/val_", Data: []byte(pubkeyStr)})
assert.False(t, r.IsErr(), r)
assert.Contains(t, r.Log, "does not exist")
}
{
// Query: does not exist
r := kvstore.Query(types.RequestQuery{Path: "/val", Data: []byte{}})
assert.False(t, r.IsErr(), r)
assert.Equal(t, "", resQuery.Log)
}
}

// order doesn't matter
Expand Down
82 changes: 30 additions & 52 deletions blockchain/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"

"github.com/gogo/protobuf/proto"

"github.com/tendermint/tendermint/p2p"
bcproto "github.com/tendermint/tendermint/proto/tendermint/blockchain"

ocbcproto "github.com/Finschia/ostracon/proto/ostracon/blockchain"
Expand All @@ -20,58 +22,6 @@ const (
BlockResponseMessageFieldKeySize
)

// EncodeMsg encodes a Protobuf message
func EncodeMsg(pb proto.Message) ([]byte, error) {
msg := ocbcproto.Message{}

switch pb := pb.(type) {
case *bcproto.BlockRequest:
msg.Sum = &ocbcproto.Message_BlockRequest{BlockRequest: pb}
case *ocbcproto.BlockResponse:
msg.Sum = &ocbcproto.Message_BlockResponse{BlockResponse: pb}
case *bcproto.NoBlockResponse:
msg.Sum = &ocbcproto.Message_NoBlockResponse{NoBlockResponse: pb}
case *bcproto.StatusRequest:
msg.Sum = &ocbcproto.Message_StatusRequest{StatusRequest: pb}
case *bcproto.StatusResponse:
msg.Sum = &ocbcproto.Message_StatusResponse{StatusResponse: pb}
default:
return nil, fmt.Errorf("unknown message type %T", pb)
}

bz, err := proto.Marshal(&msg)
if err != nil {
return nil, fmt.Errorf("unable to marshal %T: %w", pb, err)
}

return bz, nil
}

// DecodeMsg decodes a Protobuf message.
func DecodeMsg(bz []byte) (proto.Message, error) {
pb := &ocbcproto.Message{}

err := proto.Unmarshal(bz, pb)
if err != nil {
return nil, err
}

switch msg := pb.Sum.(type) {
case *ocbcproto.Message_BlockRequest:
return msg.BlockRequest, nil
case *ocbcproto.Message_BlockResponse:
return msg.BlockResponse, nil
case *ocbcproto.Message_NoBlockResponse:
return msg.NoBlockResponse, nil
case *ocbcproto.Message_StatusRequest:
return msg.StatusRequest, nil
case *ocbcproto.Message_StatusResponse:
return msg.StatusResponse, nil
default:
return nil, fmt.Errorf("unknown message type %T", msg)
}
}

// ValidateMsg validates a message.
func ValidateMsg(pb proto.Message) error {
if pb == nil {
Expand Down Expand Up @@ -109,3 +59,31 @@ func ValidateMsg(pb proto.Message) error {
}
return nil
}

// EncodeMsg encodes a Protobuf message
//
// Deprecated: Will be removed in v0.37.
func EncodeMsg(pb proto.Message) ([]byte, error) {
if um, ok := pb.(p2p.Wrapper); ok {
pb = um.Wrap()
}
bz, err := proto.Marshal(pb)
if err != nil {
return nil, fmt.Errorf("unable to marshal %T: %w", pb, err)
}

return bz, nil
}

// DecodeMsg decodes a Protobuf message.
//
// Deprecated: Will be removed in v0.37.
func DecodeMsg(bz []byte) (proto.Message, error) {
pb := &ocbcproto.Message{}

err := proto.Unmarshal(bz, pb)
if err != nil {
return nil, err
}
return pb.Unwrap()
}
Loading

0 comments on commit 1cab268

Please sign in to comment.