Skip to content

Commit

Permalink
Versioned protobuf files (cometbft#495)
Browse files Browse the repository at this point in the history
* proto: Add versioned cometbft proto files

Rename the packages, placing them under the top-level cometbft package.
The version suffixes denote evolution of message types across
successive CometBFT releases, without binding versioned packages
to any particular release. I.e. messages that have not evolved from
the baseline remain located in .v1 even as other messages' definitions
are taken from .v2 and onwards.
The source releases for versioning as of this commit are the following:
- v0.34.27
- v0.37.0
- main, to become v0.38.x

* Regenerate *.pb.go in the api folder

Replace the *.pb.go files generated from tendermint domain protos
with those generated from the versioned protos under cometbft.

* Move and adapt supporting code alongside *.pb.go

Two types of changes here:
- Adapted manually-written files adding methods to generated Go types.
- Added aliases for multi-versioned type definitions in their
  "parent" domain package that gets the importer the latest definition
   of each message type in the domain.

* Remove go_package directives from tendermint protos

---------

Co-authored-by: Thane Thomson <connect@thanethomson.com>
  • Loading branch information
mzabaluev and thanethomson authored Apr 21, 2023
1 parent 4790ea3 commit f1d41a6
Show file tree
Hide file tree
Showing 253 changed files with 44,005 additions and 10,933 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- `[proto]` Rename the package from `tendermint` to `cometbft` and introduce version suffixes.
Relocate generated Go code into a new `api` folder and change the import
paths accordingly.
([\#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
@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

0 comments on commit f1d41a6

Please sign in to comment.