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

Fix TODOs in #546 #575

Merged
merged 7 commits into from
Mar 7, 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
29 changes: 14 additions & 15 deletions abci/example/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ import (

"golang.org/x/net/context"

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

"github.com/line/ostracon/libs/log"
tmnet "github.com/line/ostracon/libs/net"
"github.com/tendermint/tendermint/abci/types"

abcicli "github.com/line/ostracon/abci/client"
"github.com/line/ostracon/abci/example/code"
"github.com/line/ostracon/abci/example/kvstore"
abciserver "github.com/line/ostracon/abci/server"
"github.com/line/ostracon/abci/types"
ocabci "github.com/line/ostracon/abci/types"
"github.com/line/ostracon/libs/log"
tmnet "github.com/line/ostracon/libs/net"
)

func init() {
Expand All @@ -38,15 +37,15 @@ func TestKVStore(t *testing.T) {

func TestBaseApp(t *testing.T) {
fmt.Println("### Testing BaseApp")
testStream(t, types.NewBaseApplication())
testStream(t, ocabci.NewBaseApplication())
}

func TestGRPC(t *testing.T) {
fmt.Println("### Testing GRPC")
testGRPCSync(t, types.NewGRPCApplication(types.NewBaseApplication()))
testGRPCSync(t, ocabci.NewGRPCApplication(ocabci.NewBaseApplication()))
}

func testStream(t *testing.T, app types.Application) {
func testStream(t *testing.T, app ocabci.Application) {
numDeliverTxs := 20000
socketFile := fmt.Sprintf("test-%08x.sock", rand.Int31n(1<<30))
defer os.Remove(socketFile)
Expand Down Expand Up @@ -78,10 +77,10 @@ func testStream(t *testing.T, app types.Application) {

done := make(chan struct{})
counter := 0
client.SetGlobalCallback(func(req *types.Request, res *types.Response) {
client.SetGlobalCallback(func(req *ocabci.Request, res *ocabci.Response) {
// Process response
switch r := res.Value.(type) {
case *types.Response_DeliverTx:
case *ocabci.Response_DeliverTx:
counter++
if r.DeliverTx.Code != code.CodeTypeOK {
t.Error("DeliverTx failed with ret_code", r.DeliverTx.Code)
Expand All @@ -96,7 +95,7 @@ func testStream(t *testing.T, app types.Application) {
}()
return
}
case *types.Response_Flush:
case *ocabci.Response_Flush:
// ignore
default:
t.Error("Unexpected response type", reflect.TypeOf(res.Value))
Expand All @@ -106,7 +105,7 @@ func testStream(t *testing.T, app types.Application) {
// Write requests
for counter := 0; counter < numDeliverTxs; counter++ {
// Send request
reqRes := client.DeliverTxAsync(abci.RequestDeliverTx{Tx: []byte("test")}, nil)
reqRes := client.DeliverTxAsync(types.RequestDeliverTx{Tx: []byte("test")}, nil)
_ = reqRes
// check err ?

Expand All @@ -130,7 +129,7 @@ func dialerFunc(ctx context.Context, addr string) (net.Conn, error) {
return tmnet.Connect(addr)
}

func testGRPCSync(t *testing.T, app types.ABCIApplicationServer) {
func testGRPCSync(t *testing.T, app ocabci.ABCIApplicationServer) {
numDeliverTxs := 2000
socketFile := fmt.Sprintf("/tmp/test-%08x.sock", rand.Int31n(1<<30))
defer os.Remove(socketFile)
Expand Down Expand Up @@ -162,12 +161,12 @@ func testGRPCSync(t *testing.T, app types.ABCIApplicationServer) {
}
})

client := types.NewABCIApplicationClient(conn)
client := ocabci.NewABCIApplicationClient(conn)

// Write requests
for counter := 0; counter < numDeliverTxs; counter++ {
// Send request
response, err := client.DeliverTx(context.Background(), &abci.RequestDeliverTx{Tx: []byte("test")})
response, err := client.DeliverTx(context.Background(), &types.RequestDeliverTx{Tx: []byte("test")})
if err != nil {
t.Fatalf("Error in GRPC DeliverTx: %v", err.Error())
}
Expand Down
50 changes: 25 additions & 25 deletions blockchain/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"fmt"

"github.com/gogo/protobuf/proto"
tmbcproto "github.com/tendermint/tendermint/proto/tendermint/blockchain"
bcproto "github.com/tendermint/tendermint/proto/tendermint/blockchain"

bcproto "github.com/line/ostracon/proto/ostracon/blockchain"
ocbcproto "github.com/line/ostracon/proto/ostracon/blockchain"
"github.com/line/ostracon/types"
)

const (
// NOTE: keep up to date with bcproto.BlockResponse
// NOTE: keep up to date with ocbcproto.BlockResponse
BlockResponseMessagePrefixSize = 4
BlockResponseMessageFieldKeySize = 1
MaxMsgSize = types.MaxBlockSizeBytes +
Expand All @@ -22,19 +22,19 @@ const (

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

switch pb := pb.(type) {
case *tmbcproto.BlockRequest:
msg.Sum = &bcproto.Message_BlockRequest{BlockRequest: pb}
case *bcproto.BlockResponse:
msg.Sum = &bcproto.Message_BlockResponse{BlockResponse: pb}
case *tmbcproto.NoBlockResponse:
msg.Sum = &bcproto.Message_NoBlockResponse{NoBlockResponse: pb}
case *tmbcproto.StatusRequest:
msg.Sum = &bcproto.Message_StatusRequest{StatusRequest: pb}
case *tmbcproto.StatusResponse:
msg.Sum = &bcproto.Message_StatusResponse{StatusResponse: pb}
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)
}
Expand All @@ -49,23 +49,23 @@ func EncodeMsg(pb proto.Message) ([]byte, error) {

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

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

switch msg := pb.Sum.(type) {
case *bcproto.Message_BlockRequest:
case *ocbcproto.Message_BlockRequest:
return msg.BlockRequest, nil
case *bcproto.Message_BlockResponse:
case *ocbcproto.Message_BlockResponse:
return msg.BlockResponse, nil
case *bcproto.Message_NoBlockResponse:
case *ocbcproto.Message_NoBlockResponse:
return msg.NoBlockResponse, nil
case *bcproto.Message_StatusRequest:
case *ocbcproto.Message_StatusRequest:
return msg.StatusRequest, nil
case *bcproto.Message_StatusResponse:
case *ocbcproto.Message_StatusResponse:
return msg.StatusResponse, nil
default:
return nil, fmt.Errorf("unknown message type %T", msg)
Expand All @@ -79,20 +79,20 @@ func ValidateMsg(pb proto.Message) error {
}

switch msg := pb.(type) {
case *tmbcproto.BlockRequest:
case *bcproto.BlockRequest:
if msg.Height < 0 {
return errors.New("negative Height")
}
case *bcproto.BlockResponse:
case *ocbcproto.BlockResponse:
_, err := types.BlockFromProto(msg.Block)
if err != nil {
return err
}
case *tmbcproto.NoBlockResponse:
case *bcproto.NoBlockResponse:
if msg.Height < 0 {
return errors.New("negative Height")
}
case *tmbcproto.StatusResponse:
case *bcproto.StatusResponse:
if msg.Base < 0 {
return errors.New("negative Base")
}
Expand All @@ -102,7 +102,7 @@ func ValidateMsg(pb proto.Message) error {
if msg.Base > msg.Height {
return fmt.Errorf("base %v cannot be greater than height %v", msg.Base, msg.Height)
}
case *tmbcproto.StatusRequest:
case *bcproto.StatusRequest:
return nil
default:
return fmt.Errorf("unknown message type %T", msg)
Expand Down
Loading