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 1 commit
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
Prev Previous commit
Next Next commit
Update proto imports in tests and examples
  • Loading branch information
mzabaluev committed Apr 6, 2023
commit 9cbf604994cb79a8454cdf78e6019cb8cc575de2
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
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
2 changes: 1 addition & 1 deletion blocksync/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

bcproto "github.com/cometbft/cometbft/api/cometbft/blocksync"
"github.com/cometbft/cometbft/blocksync"
bcproto "github.com/cometbft/cometbft/proto/tendermint/blocksync"
"github.com/cometbft/cometbft/types"
)

Expand Down
3 changes: 1 addition & 2 deletions blocksync/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/cometbft/cometbft/libs/log"
mpmocks "github.com/cometbft/cometbft/mempool/mocks"
"github.com/cometbft/cometbft/p2p"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cometbft/cometbft/proxy"
sm "github.com/cometbft/cometbft/state"
"github.com/cometbft/cometbft/store"
Expand Down Expand Up @@ -140,7 +139,7 @@ func newReactor(
idx,
thisBlock.Header.Height,
0,
cmtproto.PrecommitType,
types.SignedMsgType_PRECOMMIT,
blockID,
time.Now(),
)
Expand Down
11 changes: 5 additions & 6 deletions consensus/byzantine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ import (
mempl "github.com/cometbft/cometbft/mempool"
"github.com/cometbft/cometbft/proxy"

cmtcons "github.com/cometbft/cometbft/api/cometbft/consensus"
"github.com/cometbft/cometbft/p2p"
cmtcons "github.com/cometbft/cometbft/proto/tendermint/consensus"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
sm "github.com/cometbft/cometbft/state"
"github.com/cometbft/cometbft/store"
"github.com/cometbft/cometbft/types"
Expand Down Expand Up @@ -145,9 +144,9 @@ func TestByzantinePrevoteEquivocation(t *testing.T) {
// allow first height to happen normally so that byzantine validator is no longer proposer
if height == prevoteHeight {
bcs.Logger.Info("Sending two votes")
prevote1, err := bcs.signVote(cmtproto.PrevoteType, bcs.ProposalBlock.Hash(), bcs.ProposalBlockParts.Header())
prevote1, err := bcs.signVote(types.SignedMsgType_PREVOTE, bcs.ProposalBlock.Hash(), bcs.ProposalBlockParts.Header())
require.NoError(t, err)
prevote2, err := bcs.signVote(cmtproto.PrevoteType, nil, types.PartSetHeader{})
prevote2, err := bcs.signVote(types.SignedMsgType_PREVOTE, nil, types.PartSetHeader{})
require.NoError(t, err)
peerList := reactors[byzantineNode].Switch.Peers().List()
bcs.Logger.Info("Getting peer list", "peers", peerList)
Expand Down Expand Up @@ -542,8 +541,8 @@ func sendProposalAndParts(

// votes
cs.mtx.Lock()
prevote, _ := cs.signVote(cmtproto.PrevoteType, blockHash, parts.Header())
precommit, _ := cs.signVote(cmtproto.PrecommitType, blockHash, parts.Header())
prevote, _ := cs.signVote(types.SignedMsgType_PREVOTE, blockHash, parts.Header())
precommit, _ := cs.signVote(types.SignedMsgType_PRECOMMIT, blockHash, parts.Header())
cs.mtx.Unlock()
peer.Send(p2p.Envelope{
ChannelID: VoteChannel,
Expand Down
24 changes: 12 additions & 12 deletions consensus/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
abcicli "github.com/cometbft/cometbft/abci/client"
"github.com/cometbft/cometbft/abci/example/kvstore"
abci "github.com/cometbft/cometbft/abci/types"
cmtproto "github.com/cometbft/cometbft/api/cometbft/types"
cfg "github.com/cometbft/cometbft/config"
cstypes "github.com/cometbft/cometbft/consensus/types"
"github.com/cometbft/cometbft/internal/test"
Expand All @@ -32,7 +33,6 @@ import (
mempl "github.com/cometbft/cometbft/mempool"
"github.com/cometbft/cometbft/p2p"
"github.com/cometbft/cometbft/privval"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cometbft/cometbft/proxy"
sm "github.com/cometbft/cometbft/state"
"github.com/cometbft/cometbft/store"
Expand Down Expand Up @@ -88,7 +88,7 @@ func newValidatorStub(privValidator types.PrivValidator, valIndex int32) *valida
}

func (vs *validatorStub) signVote(
voteType cmtproto.SignedMsgType,
voteType types.SignedMsgType,
hash []byte,
header types.PartSetHeader,
voteExtension []byte,
Expand Down Expand Up @@ -132,11 +132,11 @@ func (vs *validatorStub) signVote(
}

// Sign vote for type/hash/header
func signVote(vs *validatorStub, voteType cmtproto.SignedMsgType, hash []byte, header types.PartSetHeader, extEnabled bool) *types.Vote {
func signVote(vs *validatorStub, voteType types.SignedMsgType, hash []byte, header types.PartSetHeader, extEnabled bool) *types.Vote {
var ext []byte
// Only non-nil precommits are allowed to carry vote extensions.
if extEnabled {
if voteType != cmtproto.PrecommitType {
if voteType != types.SignedMsgType_PRECOMMIT {
panic(fmt.Errorf("vote type is not precommit but extensions enabled"))
}
if len(hash) != 0 || !header.IsZero() {
Expand All @@ -155,7 +155,7 @@ func signVote(vs *validatorStub, voteType cmtproto.SignedMsgType, hash []byte, h
}

func signVotes(
voteType cmtproto.SignedMsgType,
voteType types.SignedMsgType,
hash []byte,
header types.PartSetHeader,
extEnabled bool,
Expand Down Expand Up @@ -260,7 +260,7 @@ func addVotes(to *State, votes ...*types.Vote) {

func signAddVotes(
to *State,
voteType cmtproto.SignedMsgType,
voteType types.SignedMsgType,
hash []byte,
header types.PartSetHeader,
extEnabled bool,
Expand Down Expand Up @@ -668,15 +668,15 @@ func ensureProposal(proposalCh <-chan cmtpubsub.Message, height int64, round int
}

func ensurePrecommit(voteCh <-chan cmtpubsub.Message, height int64, round int32) {
ensureVote(voteCh, height, round, cmtproto.PrecommitType)
ensureVote(voteCh, height, round, types.SignedMsgType_PRECOMMIT)
}

func ensurePrevote(voteCh <-chan cmtpubsub.Message, height int64, round int32) {
ensureVote(voteCh, height, round, cmtproto.PrevoteType)
ensureVote(voteCh, height, round, types.SignedMsgType_PREVOTE)
}

func ensureVote(voteCh <-chan cmtpubsub.Message, height int64, round int32,
voteType cmtproto.SignedMsgType,
voteType types.SignedMsgType,
) {
select {
case <-time.After(ensureTimeout):
Expand All @@ -702,15 +702,15 @@ func ensureVote(voteCh <-chan cmtpubsub.Message, height int64, round int32,

func ensurePrevoteMatch(t *testing.T, voteCh <-chan cmtpubsub.Message, height int64, round int32, hash []byte) {
t.Helper()
ensureVoteMatch(t, voteCh, height, round, hash, cmtproto.PrevoteType)
ensureVoteMatch(t, voteCh, height, round, hash, types.SignedMsgType_PREVOTE)
}

func ensurePrecommitMatch(t *testing.T, voteCh <-chan cmtpubsub.Message, height int64, round int32, hash []byte) {
t.Helper()
ensureVoteMatch(t, voteCh, height, round, hash, cmtproto.PrecommitType)
ensureVoteMatch(t, voteCh, height, round, hash, types.SignedMsgType_PRECOMMIT)
}

func ensureVoteMatch(t *testing.T, voteCh <-chan cmtpubsub.Message, height int64, round int32, hash []byte, voteType cmtproto.SignedMsgType) {
func ensureVoteMatch(t *testing.T, voteCh <-chan cmtpubsub.Message, height int64, round int32, hash []byte, voteType types.SignedMsgType) {
t.Helper()
select {
case <-time.After(ensureTimeout):
Expand Down
5 changes: 2 additions & 3 deletions consensus/invalid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"testing"
"time"

cmtcons "github.com/cometbft/cometbft/api/cometbft/consensus"
cfg "github.com/cometbft/cometbft/config"
"github.com/cometbft/cometbft/libs/bytes"
"github.com/cometbft/cometbft/libs/log"
cmtrand "github.com/cometbft/cometbft/libs/rand"
"github.com/cometbft/cometbft/p2p"
cmtcons "github.com/cometbft/cometbft/proto/tendermint/consensus"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cometbft/cometbft/types"
)

Expand Down Expand Up @@ -86,7 +85,7 @@ func invalidDoPrevoteFunc(t *testing.T, height int64, round int32, cs *State, sw
Height: cs.Height,
Round: cs.Round,
Timestamp: cs.voteTime(),
Type: cmtproto.PrecommitType,
Type: types.SignedMsgType_PRECOMMIT,
BlockID: types.BlockID{
Hash: blockHash,
PartSetHeader: types.PartSetHeader{Total: 1, Hash: cmtrand.Bytes(32)}},
Expand Down
28 changes: 16 additions & 12 deletions consensus/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

cmtcons "github.com/cometbft/cometbft/api/cometbft/consensus"
cmtproto "github.com/cometbft/cometbft/api/cometbft/types"
"github.com/cometbft/cometbft/crypto/merkle"
"github.com/cometbft/cometbft/libs/bits"
cmtrand "github.com/cometbft/cometbft/libs/rand"
"github.com/cometbft/cometbft/p2p"
cmtcons "github.com/cometbft/cometbft/proto/tendermint/consensus"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cometbft/cometbft/types"
)

Expand Down Expand Up @@ -47,7 +47,7 @@ func TestMsgToProto(t *testing.T) {
require.NoError(t, err)

proposal := types.Proposal{
Type: cmtproto.ProposalType,
Type: types.SignedMsgType_PROPOSAL,
Height: 1,
Round: 1,
POLRound: 1,
Expand All @@ -64,7 +64,7 @@ func TestMsgToProto(t *testing.T) {
0,
1,
0,
cmtproto.PrecommitType,
types.SignedMsgType_PRECOMMIT,
bi,
time.Now(),
)
Expand Down Expand Up @@ -175,11 +175,15 @@ func TestMsgToProto(t *testing.T) {
for _, tt := range testsCases {
tt := tt
t.Run(tt.testName, func(t *testing.T) {
pb, err := MsgToProto(tt.msg)
if tt.wantErr == true {
wpb, err := MsgToWrappedProto(tt.msg)
if tt.wantErr {
assert.Equal(t, err != nil, tt.wantErr)
return
} else {
mzabaluev marked this conversation as resolved.
Show resolved Hide resolved
require.NoError(t, err)
}
pb, err := wpb.Unwrap()
require.NoError(t, err)
assert.EqualValues(t, tt.want, pb, tt.testName)

msg, err := MsgFromProto(pb)
Expand Down Expand Up @@ -331,7 +335,7 @@ func TestConsMsgsVectors(t *testing.T) {
require.NoError(t, err)

proposal := types.Proposal{
Type: cmtproto.ProposalType,
Type: types.SignedMsgType_PROPOSAL,
Height: 1,
Round: 1,
POLRound: 1,
Expand All @@ -347,7 +351,7 @@ func TestConsMsgsVectors(t *testing.T) {
Height: 1,
Round: 0,
Timestamp: date,
Type: cmtproto.PrecommitType,
Type: types.SignedMsgType_PRECOMMIT,
BlockID: bi,
}
vpb := v.ToProto()
Expand Down Expand Up @@ -392,17 +396,17 @@ func TestConsMsgsVectors(t *testing.T) {
Vote: &cmtcons.Vote{Vote: vextPb}}},
"327b0a790802100122480a206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d1224080112206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d2a0608c0b89fdc0532146164645f6d6f72655f6578636c616d6174696f6e38014a09657874656e73696f6e"},
{"HasVote", &cmtcons.Message{Sum: &cmtcons.Message_HasVote{
HasVote: &cmtcons.HasVote{Height: 1, Round: 1, Type: cmtproto.PrevoteType, Index: 1}}},
HasVote: &cmtcons.HasVote{Height: 1, Round: 1, Type: types.SignedMsgType_PREVOTE, Index: 1}}},
"3a080801100118012001"},
{"HasVote", &cmtcons.Message{Sum: &cmtcons.Message_HasVote{
HasVote: &cmtcons.HasVote{Height: math.MaxInt64, Round: math.MaxInt32,
Type: cmtproto.PrevoteType, Index: math.MaxInt32}}},
Type: types.SignedMsgType_PREVOTE, Index: math.MaxInt32}}},
"3a1808ffffffffffffffff7f10ffffffff07180120ffffffff07"},
{"VoteSetMaj23", &cmtcons.Message{Sum: &cmtcons.Message_VoteSetMaj23{
VoteSetMaj23: &cmtcons.VoteSetMaj23{Height: 1, Round: 1, Type: cmtproto.PrevoteType, BlockID: pbBi}}},
VoteSetMaj23: &cmtcons.VoteSetMaj23{Height: 1, Round: 1, Type: types.SignedMsgType_PREVOTE, BlockID: pbBi}}},
"425008011001180122480a206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d1224080112206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d"},
{"VoteSetBits", &cmtcons.Message{Sum: &cmtcons.Message_VoteSetBits{
VoteSetBits: &cmtcons.VoteSetBits{Height: 1, Round: 1, Type: cmtproto.PrevoteType, BlockID: pbBi, Votes: *pbBits}}},
VoteSetBits: &cmtcons.VoteSetBits{Height: 1, Round: 1, Type: types.SignedMsgType_PREVOTE, BlockID: pbBi, Votes: *pbBits}}},
"4a5708011001180122480a206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d1224080112206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d2a050801120100"},
}

Expand Down
Loading