Skip to content

Commit

Permalink
Update proto imports in production code
Browse files Browse the repository at this point in the history
Anything I understand to be production code, anyway.
  • Loading branch information
mzabaluev committed Apr 6, 2023
1 parent b1c79f9 commit ba3c574
Show file tree
Hide file tree
Showing 59 changed files with 238 additions and 231 deletions.
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
2 changes: 1 addition & 1 deletion blocksync/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/cosmos/gogoproto/proto"

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

Expand Down
2 changes: 1 addition & 1 deletion blocksync/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/cometbft/cometbft/libs/log"
"github.com/cometbft/cometbft/p2p"
bcproto "github.com/cometbft/cometbft/proto/tendermint/blocksync"
bcproto "github.com/cometbft/cometbft/api/cometbft/blocksync"
sm "github.com/cometbft/cometbft/state"
"github.com/cometbft/cometbft/store"
"github.com/cometbft/cometbft/types"
Expand Down
10 changes: 5 additions & 5 deletions consensus/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/go-kit/kit/metrics"

cstypes "github.com/cometbft/cometbft/consensus/types"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cometbft/cometbft/types"
)

const (
Expand Down Expand Up @@ -134,7 +134,7 @@ func (m *Metrics) MarkVoteExtensionReceived(accepted bool) {
m.VoteExtensionReceiveCount.With("status", status).Add(1)
}

func (m *Metrics) MarkVoteReceived(vt cmtproto.SignedMsgType, power, totalPower int64) {
func (m *Metrics) MarkVoteReceived(vt types.SignedMsgType, power, totalPower int64) {
p := float64(power) / float64(totalPower)
n := strings.ToLower(strings.TrimPrefix(vt.String(), "SIGNED_MSG_TYPE_"))
m.RoundVotingPowerPercent.With("vote_type", n).Add(p)
Expand All @@ -145,16 +145,16 @@ func (m *Metrics) MarkRound(r int32, st time.Time) {
roundTime := time.Since(st).Seconds()
m.RoundDurationSeconds.Observe(roundTime)

pvt := cmtproto.PrevoteType
pvt := types.SignedMsgType_PREVOTE
pvn := strings.ToLower(strings.TrimPrefix(pvt.String(), "SIGNED_MSG_TYPE_"))
m.RoundVotingPowerPercent.With("vote_type", pvn).Set(0)

pct := cmtproto.PrecommitType
pct := types.SignedMsgType_PRECOMMIT
pcn := strings.ToLower(strings.TrimPrefix(pct.String(), "SIGNED_MSG_TYPE_"))
m.RoundVotingPowerPercent.With("vote_type", pcn).Set(0)
}

func (m *Metrics) MarkLateVote(vt cmtproto.SignedMsgType) {
func (m *Metrics) MarkLateVote(vt types.SignedMsgType) {
n := strings.ToLower(strings.TrimPrefix(vt.String(), "SIGNED_MSG_TYPE_"))
m.LateVotes.With("vote_type", n).Add(1)
}
Expand Down
61 changes: 28 additions & 33 deletions consensus/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,88 +10,87 @@ import (
"github.com/cometbft/cometbft/libs/bits"
cmtmath "github.com/cometbft/cometbft/libs/math"
"github.com/cometbft/cometbft/p2p"
cmtcons "github.com/cometbft/cometbft/proto/tendermint/consensus"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmtcons "github.com/cometbft/cometbft/api/cometbft/consensus"
cmtproto "github.com/cometbft/cometbft/api/cometbft/types"
"github.com/cometbft/cometbft/types"
)

// MsgToProto takes a consensus message type and returns the proto defined consensus message.
//
// TODO: This needs to be removed, but WALToProto depends on this.
func MsgToProto(msg Message) (proto.Message, error) {
// Takes a consensus message type and returns the proto defined consensus message,
// wrapped in the discriminating Message container.
func MsgToWrappedProto(msg Message) (cmtcons.Message, error) {
pb := cmtcons.Message{}
if msg == nil {
return nil, errors.New("consensus: message is nil")
return pb, errors.New("consensus: message is nil")
}
var pb proto.Message

switch msg := msg.(type) {
case *NewRoundStepMessage:
pb = &cmtcons.NewRoundStep{
pb.Sum = &cmtcons.Message_NewRoundStep{NewRoundStep: &cmtcons.NewRoundStep {
Height: msg.Height,
Round: msg.Round,
Step: uint32(msg.Step),
SecondsSinceStartTime: msg.SecondsSinceStartTime,
LastCommitRound: msg.LastCommitRound,
}
}}

case *NewValidBlockMessage:
pbPartSetHeader := msg.BlockPartSetHeader.ToProto()
pbBits := msg.BlockParts.ToProto()
pb = &cmtcons.NewValidBlock{
pb.Sum = &cmtcons.Message_NewValidBlock{NewValidBlock: &cmtcons.NewValidBlock{
Height: msg.Height,
Round: msg.Round,
BlockPartSetHeader: pbPartSetHeader,
BlockParts: pbBits,
IsCommit: msg.IsCommit,
}
}}

case *ProposalMessage:
pbP := msg.Proposal.ToProto()
pb = &cmtcons.Proposal{
pb.Sum = &cmtcons.Message_Proposal{Proposal: &cmtcons.Proposal{
Proposal: *pbP,
}
}}

case *ProposalPOLMessage:
pbBits := msg.ProposalPOL.ToProto()
pb = &cmtcons.ProposalPOL{
pb.Sum = &cmtcons.Message_ProposalPol{ProposalPol: &cmtcons.ProposalPOL{
Height: msg.Height,
ProposalPolRound: msg.ProposalPOLRound,
ProposalPol: *pbBits,
}
}}

case *BlockPartMessage:
parts, err := msg.Part.ToProto()
if err != nil {
return nil, fmt.Errorf("msg to proto error: %w", err)
return pb, fmt.Errorf("msg to proto error: %w", err)
}
pb = &cmtcons.BlockPart{
pb.Sum = &cmtcons.Message_BlockPart{BlockPart: &cmtcons.BlockPart{
Height: msg.Height,
Round: msg.Round,
Part: *parts,
}
}}

case *VoteMessage:
vote := msg.Vote.ToProto()
pb = &cmtcons.Vote{
pb.Sum = &cmtcons.Message_Vote{Vote: &cmtcons.Vote{
Vote: vote,
}
}}

case *HasVoteMessage:
pb = &cmtcons.HasVote{
pb.Sum = &cmtcons.Message_HasVote{HasVote: &cmtcons.HasVote{
Height: msg.Height,
Round: msg.Round,
Type: msg.Type,
Index: msg.Index,
}
}}

case *VoteSetMaj23Message:
bi := msg.BlockID.ToProto()
pb = &cmtcons.VoteSetMaj23{
pb.Sum = &cmtcons.Message_VoteSetMaj23{VoteSetMaj23: &cmtcons.VoteSetMaj23{
Height: msg.Height,
Round: msg.Round,
Type: msg.Type,
BlockID: bi,
}
}}

case *VoteSetBitsMessage:
bi := msg.BlockID.ToProto()
Expand All @@ -108,10 +107,10 @@ func MsgToProto(msg Message) (proto.Message, error) {
vsb.Votes = *bits
}

pb = vsb
pb.Sum = &cmtcons.Message_VoteSetBits{VoteSetBits: vsb}

default:
return nil, fmt.Errorf("consensus: message not recognized: %T", msg)
return pb, fmt.Errorf("consensus: message not recognized: %T", msg)
}

return pb, nil
Expand Down Expand Up @@ -252,18 +251,14 @@ func WALToProto(msg WALMessage) (*cmtcons.WALMessage, error) {
},
}
case msgInfo:
consMsg, err := MsgToProto(msg.Msg)
cm, err := MsgToWrappedProto(msg.Msg)
if err != nil {
return nil, err
}
if w, ok := consMsg.(p2p.Wrapper); ok {
consMsg = w.Wrap()
}
cm := consMsg.(*cmtcons.Message)
pb = cmtcons.WALMessage{
Sum: &cmtcons.WALMessage_MsgInfo{
MsgInfo: &cmtcons.MsgInfo{
Msg: *cm,
Msg: cm,
PeerID: string(msg.PeerID),
},
},
Expand Down
47 changes: 23 additions & 24 deletions consensus/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import (
"github.com/cometbft/cometbft/libs/log"
cmtsync "github.com/cometbft/cometbft/libs/sync"
"github.com/cometbft/cometbft/p2p"
cmtcons "github.com/cometbft/cometbft/proto/tendermint/consensus"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmtcons "github.com/cometbft/cometbft/api/cometbft/consensus"
sm "github.com/cometbft/cometbft/state"
"github.com/cometbft/cometbft/types"
cmttime "github.com/cometbft/cometbft/types/time"
Expand Down Expand Up @@ -284,9 +283,9 @@ func (conR *Reactor) Receive(e p2p.Envelope) {
// (and consequently shows which we don't have)
var ourVotes *bits.BitArray
switch msg.Type {
case cmtproto.PrevoteType:
case types.SignedMsgType_PREVOTE:
ourVotes = votes.Prevotes(msg.Round).BitArrayByBlockID(msg.BlockID)
case cmtproto.PrecommitType:
case types.SignedMsgType_PRECOMMIT:
ourVotes = votes.Precommits(msg.Round).BitArrayByBlockID(msg.BlockID)
default:
panic("Bad VoteSetBitsMessage field Type. Forgot to add a check in ValidateBasic?")
Expand Down Expand Up @@ -364,9 +363,9 @@ func (conR *Reactor) Receive(e p2p.Envelope) {
if height == msg.Height {
var ourVotes *bits.BitArray
switch msg.Type {
case cmtproto.PrevoteType:
case types.SignedMsgType_PREVOTE:
ourVotes = votes.Prevotes(msg.Round).BitArrayByBlockID(msg.BlockID)
case cmtproto.PrecommitType:
case types.SignedMsgType_PRECOMMIT:
ourVotes = votes.Precommits(msg.Round).BitArrayByBlockID(msg.BlockID)
default:
panic("Bad VoteSetBitsMessage field Type. Forgot to add a check in ValidateBasic?")
Expand Down Expand Up @@ -852,7 +851,7 @@ OUTER_LOOP:
Message: &cmtcons.VoteSetMaj23{
Height: prs.Height,
Round: prs.Round,
Type: cmtproto.PrevoteType,
Type: types.SignedMsgType_PREVOTE,
BlockID: maj23.ToProto(),
},
})
Expand All @@ -872,7 +871,7 @@ OUTER_LOOP:
Message: &cmtcons.VoteSetMaj23{
Height: prs.Height,
Round: prs.Round,
Type: cmtproto.PrecommitType,
Type: types.SignedMsgType_PRECOMMIT,
BlockID: maj23.ToProto(),
},
})
Expand All @@ -893,7 +892,7 @@ OUTER_LOOP:
Message: &cmtcons.VoteSetMaj23{
Height: prs.Height,
Round: prs.ProposalPOLRound,
Type: cmtproto.PrevoteType,
Type: types.SignedMsgType_PREVOTE,
BlockID: maj23.ToProto(),
},
})
Expand All @@ -916,7 +915,7 @@ OUTER_LOOP:
Message: &cmtcons.VoteSetMaj23{
Height: prs.Height,
Round: commit.Round,
Type: cmtproto.PrecommitType,
Type: types.SignedMsgType_PRECOMMIT,
BlockID: commit.BlockID.ToProto(),
},
})
Expand Down Expand Up @@ -1160,7 +1159,7 @@ func (ps *PeerState) PickVoteToSend(votes types.VoteSetReader) (vote *types.Vote
}

height, round, votesType, size :=
votes.GetHeight(), votes.GetRound(), cmtproto.SignedMsgType(votes.Type()), votes.Size()
votes.GetHeight(), votes.GetRound(), types.SignedMsgType(votes.Type()), votes.Size()

// Lazily set data using 'votes'.
if votes.IsCommit() {
Expand All @@ -1178,33 +1177,33 @@ func (ps *PeerState) PickVoteToSend(votes types.VoteSetReader) (vote *types.Vote
return nil, false
}

func (ps *PeerState) getVoteBitArray(height int64, round int32, votesType cmtproto.SignedMsgType) *bits.BitArray {
func (ps *PeerState) getVoteBitArray(height int64, round int32, votesType types.SignedMsgType) *bits.BitArray {
if !types.IsVoteTypeValid(votesType) {
return nil
}

if ps.PRS.Height == height {
if ps.PRS.Round == round {
switch votesType {
case cmtproto.PrevoteType:
case types.SignedMsgType_PREVOTE:
return ps.PRS.Prevotes
case cmtproto.PrecommitType:
case types.SignedMsgType_PRECOMMIT:
return ps.PRS.Precommits
}
}
if ps.PRS.CatchupCommitRound == round {
switch votesType {
case cmtproto.PrevoteType:
case types.SignedMsgType_PREVOTE:
return nil
case cmtproto.PrecommitType:
case types.SignedMsgType_PRECOMMIT:
return ps.PRS.CatchupCommit
}
}
if ps.PRS.ProposalPOLRound == round {
switch votesType {
case cmtproto.PrevoteType:
case types.SignedMsgType_PREVOTE:
return ps.PRS.ProposalPOL
case cmtproto.PrecommitType:
case types.SignedMsgType_PRECOMMIT:
return nil
}
}
Expand All @@ -1213,9 +1212,9 @@ func (ps *PeerState) getVoteBitArray(height int64, round int32, votesType cmtpro
if ps.PRS.Height == height+1 {
if ps.PRS.LastCommitRound == round {
switch votesType {
case cmtproto.PrevoteType:
case types.SignedMsgType_PREVOTE:
return nil
case cmtproto.PrecommitType:
case types.SignedMsgType_PRECOMMIT:
return ps.PRS.LastCommit
}
}
Expand Down Expand Up @@ -1330,7 +1329,7 @@ func (ps *PeerState) SetHasVote(vote *types.Vote) {
ps.setHasVote(vote.Height, vote.Round, vote.Type, vote.ValidatorIndex)
}

func (ps *PeerState) setHasVote(height int64, round int32, voteType cmtproto.SignedMsgType, index int32) {
func (ps *PeerState) setHasVote(height int64, round int32, voteType types.SignedMsgType, index int32) {
ps.logger.Debug("setHasVote",
"peerH/R",
log.NewLazySprintf("%d/%d", ps.PRS.Height, ps.PRS.Round),
Expand Down Expand Up @@ -1708,7 +1707,7 @@ func (m *VoteMessage) String() string {
type HasVoteMessage struct {
Height int64
Round int32
Type cmtproto.SignedMsgType
Type types.SignedMsgType
Index int32
}

Expand Down Expand Up @@ -1740,7 +1739,7 @@ func (m *HasVoteMessage) String() string {
type VoteSetMaj23Message struct {
Height int64
Round int32
Type cmtproto.SignedMsgType
Type types.SignedMsgType
BlockID types.BlockID
}

Expand Down Expand Up @@ -1772,7 +1771,7 @@ func (m *VoteSetMaj23Message) String() string {
type VoteSetBitsMessage struct {
Height int64
Round int32
Type cmtproto.SignedMsgType
Type types.SignedMsgType
BlockID types.BlockID
Votes *bits.BitArray
}
Expand Down
Loading

0 comments on commit ba3c574

Please sign in to comment.