Skip to content

Commit

Permalink
add protojson
Browse files Browse the repository at this point in the history
Signed-off-by: senthil <[email protected]>
  • Loading branch information
cendhu committed Aug 25, 2022
1 parent c54b3e1 commit efc15d6
Show file tree
Hide file tree
Showing 43 changed files with 9,844 additions and 5,519 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ GO = go
DOCKER = docker
DOCKER_IMAGE = orionbcdb/orion-server
DOCKERFILE = images/Dockerfile
PROTO_COMPILER_IMAGE = orionbcdb/protobuf
PROTO_COMPILER_DOCKERFILE = images/Proto
PKGS = $(or $(PKG),$(shell env GO111MODULE=on $(GO) list ./...))
TESTPKGS = $(shell env GO111MODULE=on $(GO) list -f \
'{{ if or .TestGoFiles .XTestGoFiles }}{{ .ImportPath }}{{ end }}' \
Expand Down Expand Up @@ -69,7 +71,8 @@ docker-clean:

.PHONY: protos
protos:
docker run -it -v `pwd`:`pwd` -w `pwd` sykesm/fabric-protos:0.2 scripts/compile_go_protos.sh
$(DOCKER) build -t $(PROTO_COMPILER_IMAGE) --no-cache -f $(PROTO_COMPILER_DOCKERFILE) .
docker run -it -v `pwd`:`pwd` -w `pwd` $(PROTO_COMPILER_IMAGE) scripts/compile_go_protos.sh

TEST_TARGETS := test-default test-bench test-short test-verbose test-race
test-bench: ARGS=-run=__absolutelynothing__ -bench=.
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ go 1.16
require (
github.com/cayleygraph/cayley v0.7.7
github.com/cayleygraph/quad v1.1.0
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.2
github.com/golang/snappy v0.0.1
github.com/google/go-cmp v0.5.5 // indirect
github.com/google/uuid v1.1.1
github.com/gorilla/mux v1.7.4
github.com/hidal-go/hidalgo v0.0.0-20201109092204-05749a6d73df
Expand All @@ -19,5 +21,6 @@ require (
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2
go.etcd.io/etcd v0.5.0-alpha.5.0.20210226220824-aa7126864d82 // indirect git tag v3.4.15
go.uber.org/zap v1.18.1
google.golang.org/protobuf v1.26.0
gopkg.in/yaml.v2 v2.4.0
)
13 changes: 13 additions & 0 deletions images/Proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM golang

RUN go install google.golang.org/protobuf/cmd/[email protected]
RUN apt-get update && apt-get install -y unzip

ENV PROTOC_ZIP=protoc-3.15.8-linux-x86_64.zip
RUN curl -OL https://github.com/google/protobuf/releases/download/v3.15.8/${PROTOC_ZIP}
RUN unzip -o ${PROTOC_ZIP} -d ./proto
RUN chmod 755 -R ./proto/bin
ENV BASE=/usr/local
# Copy into path
RUN cp ./proto/bin/protoc ${BASE}/bin
RUN cp -R ./proto/include/* ${BASE}/include
8 changes: 4 additions & 4 deletions internal/bcdb/config_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ func TestGetClusterStatus(t *testing.T) {
require.Equal(t, "node2", status.Response.Nodes[1].Id)
require.NotNil(t, status.Response.Nodes[1].Certificate)

require.Equal(t, &types.Version{BlockNum: 10}, status.Response.Version)
require.True(t, proto.Equal(&types.Version{BlockNum: 10}, status.Response.Version))
require.Equal(t, "node1", status.Response.Leader)
require.Equal(t, []string{"node1", "node2"}, status.Response.Active)
})
Expand All @@ -445,7 +445,7 @@ func TestGetClusterStatus(t *testing.T) {
require.Equal(t, "node2", status.Response.Nodes[1].Id)
require.NotNil(t, status.Response.Nodes[1].Certificate)

require.Equal(t, &types.Version{BlockNum: 10}, status.Response.Version)
require.True(t, proto.Equal(&types.Version{BlockNum: 10}, status.Response.Version))
require.Equal(t, "", status.Response.Leader)
require.Equal(t, []string{"node1"}, status.Response.Active)
})
Expand All @@ -469,7 +469,7 @@ func TestGetClusterStatus(t *testing.T) {
require.Equal(t, "node2", status.Response.Nodes[1].Id)
require.Nil(t, status.Response.Nodes[1].Certificate)

require.Equal(t, &types.Version{BlockNum: 10}, status.Response.Version)
require.True(t, proto.Equal(&types.Version{BlockNum: 10}, status.Response.Version))
require.Equal(t, "node1", status.Response.Leader)
require.Equal(t, []string{"node1", "node2"}, status.Response.Active)
})
Expand All @@ -494,7 +494,7 @@ func TestGetClusterStatus(t *testing.T) {
require.Equal(t, "node2", status.Response.Nodes[1].Id)
require.NotNil(t, "node2", status.Response.Nodes[1].Certificate)

require.Equal(t, &types.Version{BlockNum: 10}, status.Response.Version)
require.True(t, proto.Equal(&types.Version{BlockNum: 10}, status.Response.Version))
require.Equal(t, "", status.Response.Leader)
require.Equal(t, []string{"node1", "node2"}, status.Response.Active)
})
Expand Down
5 changes: 3 additions & 2 deletions internal/bcdb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package bcdb
import (
"context"
"crypto/x509"
"encoding/json"
"encoding/pem"
"io/ioutil"
"time"
Expand All @@ -22,8 +21,10 @@ import (
"github.com/hyperledger-labs/orion-server/pkg/certificateauthority"
"github.com/hyperledger-labs/orion-server/pkg/crypto"
"github.com/hyperledger-labs/orion-server/pkg/logger"
"github.com/hyperledger-labs/orion-server/pkg/marshal"
"github.com/hyperledger-labs/orion-server/pkg/types"
"github.com/pkg/errors"
"google.golang.org/protobuf/proto"
)

//go:generate mockery --dir . --name DB --case underscore --output mocks/
Expand Down Expand Up @@ -966,7 +967,7 @@ func (d *db) responseHeader() *types.ResponseHeader {
}

func (d *db) signature(response interface{}) ([]byte, error) {
responseBytes, err := json.Marshal(response)
responseBytes, err := marshal.DefaultMarshaler().Marshal(response.(proto.Message))
if err != nil {
return nil, err
}
Expand Down
14 changes: 4 additions & 10 deletions internal/blockprocessor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,17 @@ func newTestEnv(t *testing.T) *testEnv {
Algorithm: "raft",
Members: []*types.PeerConfig{
{
NodeId: "node1",
RaftId: 1,
PeerHost: "127.0.0.1",
PeerPort: 7090,
XXX_unrecognized: nil,
XXX_sizecache: 0,
NodeId: "node1",
RaftId: 1,
PeerHost: "127.0.0.1",
PeerPort: 7090,
},
},
RaftConfig: &types.RaftConfig{
TickInterval: "100ms",
ElectionTicks: 100,
HeartbeatTicks: 10,
},
XXX_NoUnkeyedLiteral: struct{}{},
XXX_unrecognized: nil,
XXX_sizecache: 0,
},
}
genesisBlock := &types.Block{
Expand Down Expand Up @@ -626,7 +621,6 @@ func TestBlockCommitListener(t *testing.T) {
},
}
expectedBlock := proto.Clone(block2).(*types.Block)
expectedBlock.XXX_sizecache = 0
genesisHash, err := env.blockStore.GetHash(uint64(1))
expectedBlock.Header.SkipchainHashes = calculateBlockHashes(t, genesisHash, []*types.Block{block2}, 2)
root, err := mtree.BuildTreeForBlockTx(block2)
Expand Down
12 changes: 9 additions & 3 deletions internal/blockstore/block_file_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"encoding/binary"
"testing"

"github.com/hyperledger-labs/orion-server/pkg/types"
"github.com/golang/protobuf/proto"
"github.com/hyperledger-labs/orion-server/pkg/types"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -84,7 +84,10 @@ func TestBlockFileStream(t *testing.T) {
blockEndOffset: location.Offset + location.Length,
}

require.Equal(t, expectedBlockWithLocation, blockWithLocation)
require.True(t, proto.Equal(expectedBlockWithLocation.block, blockWithLocation.block))
require.Equal(t, expectedBlockWithLocation.fileChunkNum, blockWithLocation.fileChunkNum)
require.Equal(t, expectedBlockWithLocation.blockStartOffset, blockWithLocation.blockStartOffset)
require.Equal(t, expectedBlockWithLocation.blockEndOffset, blockWithLocation.blockEndOffset)
i++
}
blockWithLocation, err := stream.nextBlockWithLocation()
Expand Down Expand Up @@ -164,7 +167,10 @@ func TestBlockFileStream(t *testing.T) {
blockEndOffset: location.Offset + location.Length,
}

require.Equal(t, expectedBlockWithLocation, blockWithLocation)
require.True(t, proto.Equal(expectedBlockWithLocation.block, blockWithLocation.block))
require.Equal(t, expectedBlockWithLocation.fileChunkNum, blockWithLocation.fileChunkNum)
require.Equal(t, expectedBlockWithLocation.blockStartOffset, blockWithLocation.blockStartOffset)
require.Equal(t, expectedBlockWithLocation.blockEndOffset, blockWithLocation.blockEndOffset)
}
blockWithLocation, err := stream.nextBlockWithLocation()
require.Nil(t, blockWithLocation)
Expand Down
Loading

0 comments on commit efc15d6

Please sign in to comment.