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

Backport tendermint-v0.34.23 into main #674

Merged
merged 15 commits into from
Jul 24, 2023
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
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