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

Versioned protobuf files #495

Merged
merged 26 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fdcca78
proto: Add versioned cometbft proto files
mzabaluev Apr 6, 2023
784f976
Regenerate *.pb.go in the api folder
mzabaluev Apr 6, 2023
5a5beff
Move and adapt supporting code alongside *.pb.go
mzabaluev Apr 6, 2023
b1c79f9
Remove go_package directives from tendermint protos
mzabaluev Apr 6, 2023
ba3c574
Update proto imports in production code
mzabaluev Apr 6, 2023
9cbf604
Update proto imports in tests and examples
mzabaluev Apr 6, 2023
136791f
Update links to proto files in docs
mzabaluev Apr 6, 2023
a7ad099
Changelog entry for #495
mzabaluev Apr 6, 2023
32504b8
Bump govulncheck to use go 1.20.3
mzabaluev Apr 6, 2023
b431f7b
Suppress golangci lints on generated code/names
mzabaluev Apr 14, 2023
2c93cf3
Fix gofmt and goimports lints
mzabaluev Apr 14, 2023
b329316
Suppress more var-naming lints
mzabaluev Apr 14, 2023
5bf54e4
Update go.sum
mzabaluev Apr 14, 2023
ea29676
abci: fix structural literal lints
mzabaluev Apr 14, 2023
899eccb
Remove newline after file //nolint suppressions
mzabaluev Apr 14, 2023
40613ee
Suppress stylecheck linter on *.pb.go files
mzabaluev Apr 14, 2023
f78b19d
Suppress revive,stylecheck lints on alias files
mzabaluev Apr 14, 2023
9d41fd8
Fix an indent-error-flow lint in tests
mzabaluev Apr 14, 2023
5ee443d
Suppress style lints on SignedMsgType consts
mzabaluev Apr 14, 2023
c9ac8db
Edit changelog for #495
mzabaluev Apr 18, 2023
cc351d5
proto: fix the formatting
mzabaluev Apr 18, 2023
2b47221
proto: remove blockchain/v1
mzabaluev Apr 18, 2023
d2c36a9
proto: flatten VersionParams into a single version
mzabaluev Apr 18, 2023
cdf4e80
Regenerate protos for flattened VersionParams
mzabaluev Apr 18, 2023
fd54d1d
Merge branch 'mikhail/proto-version-suffixes' of github.com:cometbft/…
mzabaluev Apr 18, 2023
57e8a81
Revert SignedMsgProto member const names
mzabaluev Apr 18, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- `[proto]` Rename the proto packages to cometbft and introduce version suffixes.
Relocate generated Go code into the new `api` folder and change the import
paths accordingly.
mzabaluev marked this conversation as resolved.
Show resolved Hide resolved
([\#495](https://github.com/cometbft/cometbft/pull/495))
2 changes: 1 addition & 1 deletion .github/workflows/govulncheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/setup-go@v4
with:
go-version: "1.20.2"
go-version: "1.20.3"
- uses: actions/checkout@v3
- uses: technote-space/get-diff-action@v6
with:
Expand Down
6 changes: 6 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ issues:
- path: _test\.go
linters:
- gosec
- path: \.pb\.go
linters:
- gofmt
- goimports
- govet
- stylecheck
max-same-issues: 50

linters-settings:
Expand Down
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ endif

proto-gen: check-proto-deps
@echo "Generating Protobuf files"
@go run github.com/bufbuild/buf/cmd/buf generate
@mv ./proto/tendermint/abci/types.pb.go ./abci/types/
@cp ./proto/tendermint/rpc/grpc/types.pb.go ./rpc/grpc
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea why this generated Go file had to be copied while the one for abci above is moved. @julienbrt @thanethomson can you clarify why this duplication was needed in tendermint/tendermint#9356?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a legacy thing, it seems as though it was deemed best to have the generated ABCI proto code colocated with the rest of the ABCI code.

Similarly with the generated gRPC code.

The better approach is to have it all generated into an /api/ package in the root of the project, as per Buf's guidelines.

@go run github.com/bufbuild/buf/cmd/buf generate --path proto/cometbft
.PHONY: proto-gen

# These targets are provided for convenience and are intended for local
Expand Down
2 changes: 1 addition & 1 deletion abci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ To get up and running quickly, see the [getting started guide](../docs/app-dev/g
A detailed description of the ABCI methods and message types is contained in:

- [The main spec](https://github.com/cometbft/cometbft/blob/main/spec/abci/README.md)
- [A protobuf file](../proto/tendermint/types/types.proto)
- [A protobuf file](../proto/cometbft/types/v3/types.proto)
- [A Go interface](./types/application.go)

## Protocol Buffers
Expand Down
4 changes: 2 additions & 2 deletions abci/cmd/abci-cli/abci-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
servertest "github.com/cometbft/cometbft/abci/tests/server"
"github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/abci/version"
"github.com/cometbft/cometbft/proto/tendermint/crypto"
crypto "github.com/cometbft/cometbft/api/cometbft/crypto/v1"
)

// client is a global variable so it can be reused by the console
Expand Down Expand Up @@ -760,7 +760,7 @@ func printResponse(cmd *cobra.Command, args []string, rsps ...response) {
fmt.Printf("-> log: %s\n", rsp.Log)
}
if cmd.Use == "process_proposal" {
fmt.Printf("-> status: %s\n", types.ResponseProcessProposal_ProposalStatus_name[rsp.Status])
fmt.Printf("-> status: %s\n", types.ResponseProcessProposal_ProposalStatus(rsp.Status).String())
}

if rsp.Query != nil {
Expand Down
4 changes: 2 additions & 2 deletions abci/example/kvstore/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"strings"

"github.com/cometbft/cometbft/abci/types"
pbcrypto "github.com/cometbft/cometbft/api/cometbft/crypto/v1"
cryptoencoding "github.com/cometbft/cometbft/crypto/encoding"
cmtrand "github.com/cometbft/cometbft/libs/rand"
"github.com/cometbft/cometbft/proto/tendermint/crypto"
)

// RandVal creates one random validator, with a key derived
Expand Down Expand Up @@ -69,7 +69,7 @@ func NewTxFromID(i int) []byte {

// Create a transaction to add/remove/update a validator
// To remove, set power to 0.
func MakeValSetChangeTx(pubkey crypto.PublicKey, power int64) []byte {
func MakeValSetChangeTx(pubkey pbcrypto.PublicKey, power int64) []byte {
pk, err := cryptoencoding.PubKeyFromProto(pubkey)
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion abci/example/kvstore/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
dbm "github.com/cometbft/cometbft-db"

"github.com/cometbft/cometbft/abci/types"
cryptoproto "github.com/cometbft/cometbft/api/cometbft/crypto/v1"
cryptoencoding "github.com/cometbft/cometbft/crypto/encoding"
"github.com/cometbft/cometbft/libs/log"
cryptoproto "github.com/cometbft/cometbft/proto/tendermint/crypto"
"github.com/cometbft/cometbft/version"
)

Expand Down
67 changes: 34 additions & 33 deletions abci/types/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/cosmos/gogoproto/proto"

v3 "github.com/cometbft/cometbft/api/cometbft/abci/v3"
"github.com/cometbft/cometbft/libs/protoio"
)

Expand All @@ -29,200 +30,200 @@ func ReadMessage(r io.Reader, msg proto.Message) error {

func ToRequestEcho(message string) *Request {
return &Request{
Value: &Request_Echo{&RequestEcho{Message: message}},
Value: &v3.Request_Echo{Echo: &RequestEcho{Message: message}},
}
}

func ToRequestFlush() *Request {
return &Request{
Value: &Request_Flush{&RequestFlush{}},
Value: &v3.Request_Flush{Flush: &RequestFlush{}},
}
}

func ToRequestInfo(req *RequestInfo) *Request {
return &Request{
Value: &Request_Info{req},
Value: &v3.Request_Info{Info: req},
}
}

func ToRequestCheckTx(req *RequestCheckTx) *Request {
return &Request{
Value: &Request_CheckTx{req},
Value: &v3.Request_CheckTx{CheckTx: req},
}
}

func ToRequestCommit() *Request {
return &Request{
Value: &Request_Commit{&RequestCommit{}},
Value: &v3.Request_Commit{Commit: &RequestCommit{}},
}
}

func ToRequestQuery(req *RequestQuery) *Request {
return &Request{
Value: &Request_Query{req},
Value: &v3.Request_Query{Query: req},
}
}

func ToRequestInitChain(req *RequestInitChain) *Request {
return &Request{
Value: &Request_InitChain{req},
Value: &v3.Request_InitChain{InitChain: req},
}
}

func ToRequestListSnapshots(req *RequestListSnapshots) *Request {
return &Request{
Value: &Request_ListSnapshots{req},
Value: &v3.Request_ListSnapshots{ListSnapshots: req},
}
}

func ToRequestOfferSnapshot(req *RequestOfferSnapshot) *Request {
return &Request{
Value: &Request_OfferSnapshot{req},
Value: &v3.Request_OfferSnapshot{OfferSnapshot: req},
}
}

func ToRequestLoadSnapshotChunk(req *RequestLoadSnapshotChunk) *Request {
return &Request{
Value: &Request_LoadSnapshotChunk{req},
Value: &v3.Request_LoadSnapshotChunk{LoadSnapshotChunk: req},
}
}

func ToRequestApplySnapshotChunk(req *RequestApplySnapshotChunk) *Request {
return &Request{
Value: &Request_ApplySnapshotChunk{req},
Value: &v3.Request_ApplySnapshotChunk{ApplySnapshotChunk: req},
}
}

func ToRequestPrepareProposal(req *RequestPrepareProposal) *Request {
return &Request{
Value: &Request_PrepareProposal{req},
Value: &v3.Request_PrepareProposal{PrepareProposal: req},
}
}

func ToRequestProcessProposal(req *RequestProcessProposal) *Request {
return &Request{
Value: &Request_ProcessProposal{req},
Value: &v3.Request_ProcessProposal{ProcessProposal: req},
}
}

func ToRequestExtendVote(req *RequestExtendVote) *Request {
return &Request{
Value: &Request_ExtendVote{req},
Value: &v3.Request_ExtendVote{ExtendVote: req},
}
}

func ToRequestVerifyVoteExtension(req *RequestVerifyVoteExtension) *Request {
return &Request{
Value: &Request_VerifyVoteExtension{req},
Value: &v3.Request_VerifyVoteExtension{VerifyVoteExtension: req},
}
}

func ToRequestFinalizeBlock(req *RequestFinalizeBlock) *Request {
return &Request{
Value: &Request_FinalizeBlock{req},
Value: &v3.Request_FinalizeBlock{FinalizeBlock: req},
}
}

//----------------------------------------

func ToResponseException(errStr string) *Response {
return &Response{
Value: &Response_Exception{&ResponseException{Error: errStr}},
Value: &v3.Response_Exception{Exception: &ResponseException{Error: errStr}},
}
}

func ToResponseEcho(message string) *Response {
return &Response{
Value: &Response_Echo{&ResponseEcho{Message: message}},
Value: &v3.Response_Echo{Echo: &ResponseEcho{Message: message}},
}
}

func ToResponseFlush() *Response {
return &Response{
Value: &Response_Flush{&ResponseFlush{}},
Value: &v3.Response_Flush{Flush: &ResponseFlush{}},
}
}

func ToResponseInfo(res *ResponseInfo) *Response {
return &Response{
Value: &Response_Info{res},
Value: &v3.Response_Info{Info: res},
}
}

func ToResponseCheckTx(res *ResponseCheckTx) *Response {
return &Response{
Value: &Response_CheckTx{res},
Value: &v3.Response_CheckTx{CheckTx: res},
}
}

func ToResponseCommit(res *ResponseCommit) *Response {
return &Response{
Value: &Response_Commit{res},
Value: &v3.Response_Commit{Commit: res},
}
}

func ToResponseQuery(res *ResponseQuery) *Response {
return &Response{
Value: &Response_Query{res},
Value: &v3.Response_Query{Query: res},
}
}

func ToResponseInitChain(res *ResponseInitChain) *Response {
return &Response{
Value: &Response_InitChain{res},
Value: &v3.Response_InitChain{InitChain: res},
}
}

func ToResponseListSnapshots(res *ResponseListSnapshots) *Response {
return &Response{
Value: &Response_ListSnapshots{res},
Value: &v3.Response_ListSnapshots{ListSnapshots: res},
}
}

func ToResponseOfferSnapshot(res *ResponseOfferSnapshot) *Response {
return &Response{
Value: &Response_OfferSnapshot{res},
Value: &v3.Response_OfferSnapshot{OfferSnapshot: res},
}
}

func ToResponseLoadSnapshotChunk(res *ResponseLoadSnapshotChunk) *Response {
return &Response{
Value: &Response_LoadSnapshotChunk{res},
Value: &v3.Response_LoadSnapshotChunk{LoadSnapshotChunk: res},
}
}

func ToResponseApplySnapshotChunk(res *ResponseApplySnapshotChunk) *Response {
return &Response{
Value: &Response_ApplySnapshotChunk{res},
Value: &v3.Response_ApplySnapshotChunk{ApplySnapshotChunk: res},
}
}

func ToResponsePrepareProposal(res *ResponsePrepareProposal) *Response {
return &Response{
Value: &Response_PrepareProposal{res},
Value: &v3.Response_PrepareProposal{PrepareProposal: res},
}
}

func ToResponseProcessProposal(res *ResponseProcessProposal) *Response {
return &Response{
Value: &Response_ProcessProposal{res},
Value: &v3.Response_ProcessProposal{ProcessProposal: res},
}
}

func ToResponseExtendVote(res *ResponseExtendVote) *Response {
return &Response{
Value: &Response_ExtendVote{res},
Value: &v3.Response_ExtendVote{ExtendVote: res},
}
}

func ToResponseVerifyVoteExtension(res *ResponseVerifyVoteExtension) *Response {
return &Response{
Value: &Response_VerifyVoteExtension{res},
Value: &v3.Response_VerifyVoteExtension{VerifyVoteExtension: res},
}
}

func ToResponseFinalizeBlock(res *ResponseFinalizeBlock) *Response {
return &Response{
Value: &Response_FinalizeBlock{res},
Value: &v3.Response_FinalizeBlock{FinalizeBlock: res},
}
}
2 changes: 1 addition & 1 deletion abci/types/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/cosmos/gogoproto/proto"
"github.com/stretchr/testify/assert"

cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmtproto "github.com/cometbft/cometbft/api/cometbft/types"
)

func TestMarshalJSON(t *testing.T) {
Expand Down
Loading