Delete the custom libs/json (tmjson) package. (#7673)

There are no further uses of this package anywhere in Tendermint.
All the uses in the Cosmos SDK are for types that now work correctly with the
standard encoding/json package.
This commit is contained in:
M. J. Fromberger
2022-01-24 08:15:34 -08:00
committed by GitHub
parent f6ebd84ee2
commit 7878ca6a8a
20 changed files with 104 additions and 1216 deletions

View File

@@ -5,8 +5,8 @@ import (
"fmt"
cstypes "github.com/tendermint/tendermint/internal/consensus/types"
"github.com/tendermint/tendermint/internal/jsontypes"
"github.com/tendermint/tendermint/libs/bits"
tmjson "github.com/tendermint/tendermint/libs/json"
tmmath "github.com/tendermint/tendermint/libs/math"
tmcons "github.com/tendermint/tendermint/proto/tendermint/consensus"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
@@ -18,30 +18,34 @@ import (
// converted to a Message via MsgFromProto.
type Message interface {
ValidateBasic() error
jsontypes.Tagged
}
func init() {
tmjson.RegisterType(&NewRoundStepMessage{}, "tendermint/NewRoundStepMessage")
tmjson.RegisterType(&NewValidBlockMessage{}, "tendermint/NewValidBlockMessage")
tmjson.RegisterType(&ProposalMessage{}, "tendermint/Proposal")
tmjson.RegisterType(&ProposalPOLMessage{}, "tendermint/ProposalPOL")
tmjson.RegisterType(&BlockPartMessage{}, "tendermint/BlockPart")
tmjson.RegisterType(&VoteMessage{}, "tendermint/Vote")
tmjson.RegisterType(&HasVoteMessage{}, "tendermint/HasVote")
tmjson.RegisterType(&VoteSetMaj23Message{}, "tendermint/VoteSetMaj23")
tmjson.RegisterType(&VoteSetBitsMessage{}, "tendermint/VoteSetBits")
jsontypes.MustRegister(&NewRoundStepMessage{})
jsontypes.MustRegister(&NewValidBlockMessage{})
jsontypes.MustRegister(&ProposalMessage{})
jsontypes.MustRegister(&ProposalPOLMessage{})
jsontypes.MustRegister(&BlockPartMessage{})
jsontypes.MustRegister(&VoteMessage{})
jsontypes.MustRegister(&HasVoteMessage{})
jsontypes.MustRegister(&VoteSetMaj23Message{})
jsontypes.MustRegister(&VoteSetBitsMessage{})
}
// NewRoundStepMessage is sent for every step taken in the ConsensusState.
// For every height/round/step transition
type NewRoundStepMessage struct {
Height int64
Height int64 `json:",string"`
Round int32
Step cstypes.RoundStepType
SecondsSinceStartTime int64
SecondsSinceStartTime int64 `json:",string"`
LastCommitRound int32
}
func (*NewRoundStepMessage) TypeTag() string { return "tendermint/NewRoundStepMessage" }
// ValidateBasic performs basic validation.
func (m *NewRoundStepMessage) ValidateBasic() error {
if m.Height < 0 {
@@ -93,13 +97,15 @@ func (m *NewRoundStepMessage) String() string {
// i.e., there is a Proposal for block B and 2/3+ prevotes for the block B in the round r.
// In case the block is also committed, then IsCommit flag is set to true.
type NewValidBlockMessage struct {
Height int64
Height int64 `json:",string"`
Round int32
BlockPartSetHeader types.PartSetHeader
BlockParts *bits.BitArray
IsCommit bool
}
func (*NewValidBlockMessage) TypeTag() string { return "tendermint/NewValidBlockMessage" }
// ValidateBasic performs basic validation.
func (m *NewValidBlockMessage) ValidateBasic() error {
if m.Height < 0 {
@@ -136,6 +142,8 @@ type ProposalMessage struct {
Proposal *types.Proposal
}
func (*ProposalMessage) TypeTag() string { return "tendermint/Proposal" }
// ValidateBasic performs basic validation.
func (m *ProposalMessage) ValidateBasic() error {
return m.Proposal.ValidateBasic()
@@ -148,11 +156,13 @@ func (m *ProposalMessage) String() string {
// ProposalPOLMessage is sent when a previous proposal is re-proposed.
type ProposalPOLMessage struct {
Height int64
Height int64 `json:",string"`
ProposalPOLRound int32
ProposalPOL *bits.BitArray
}
func (*ProposalPOLMessage) TypeTag() string { return "tendermint/ProposalPOL" }
// ValidateBasic performs basic validation.
func (m *ProposalPOLMessage) ValidateBasic() error {
if m.Height < 0 {
@@ -177,11 +187,13 @@ func (m *ProposalPOLMessage) String() string {
// BlockPartMessage is sent when gossipping a piece of the proposed block.
type BlockPartMessage struct {
Height int64
Height int64 `json:",string"`
Round int32
Part *types.Part
}
func (*BlockPartMessage) TypeTag() string { return "tendermint/BlockPart" }
// ValidateBasic performs basic validation.
func (m *BlockPartMessage) ValidateBasic() error {
if m.Height < 0 {
@@ -206,6 +218,8 @@ type VoteMessage struct {
Vote *types.Vote
}
func (*VoteMessage) TypeTag() string { return "tendermint/Vote" }
// ValidateBasic performs basic validation.
func (m *VoteMessage) ValidateBasic() error {
return m.Vote.ValidateBasic()
@@ -218,12 +232,14 @@ func (m *VoteMessage) String() string {
// HasVoteMessage is sent to indicate that a particular vote has been received.
type HasVoteMessage struct {
Height int64
Height int64 `json:",string"`
Round int32
Type tmproto.SignedMsgType
Index int32
}
func (*HasVoteMessage) TypeTag() string { return "tendermint/HasVote" }
// ValidateBasic performs basic validation.
func (m *HasVoteMessage) ValidateBasic() error {
if m.Height < 0 {
@@ -248,12 +264,14 @@ func (m *HasVoteMessage) String() string {
// VoteSetMaj23Message is sent to indicate that a given BlockID has seen +2/3 votes.
type VoteSetMaj23Message struct {
Height int64
Height int64 `json:",string"`
Round int32
Type tmproto.SignedMsgType
BlockID types.BlockID
}
func (*VoteSetMaj23Message) TypeTag() string { return "tendermint/VoteSetMaj23" }
// ValidateBasic performs basic validation.
func (m *VoteSetMaj23Message) ValidateBasic() error {
if m.Height < 0 {
@@ -280,13 +298,15 @@ func (m *VoteSetMaj23Message) String() string {
// VoteSetBitsMessage is sent to communicate the bit-array of votes seen for the
// BlockID.
type VoteSetBitsMessage struct {
Height int64
Height int64 `json:",string"`
Round int32
Type tmproto.SignedMsgType
BlockID types.BlockID
Votes *bits.BitArray
}
func (*VoteSetBitsMessage) TypeTag() string { return "tendermint/VoteSetBits" }
// ValidateBasic performs basic validation.
func (m *VoteSetBitsMessage) ValidateBasic() error {
if m.Height < 0 {

View File

@@ -19,6 +19,7 @@ import (
"github.com/tendermint/tendermint/crypto"
cstypes "github.com/tendermint/tendermint/internal/consensus/types"
"github.com/tendermint/tendermint/internal/eventbus"
"github.com/tendermint/tendermint/internal/jsontypes"
sm "github.com/tendermint/tendermint/internal/state"
tmevents "github.com/tendermint/tendermint/libs/events"
"github.com/tendermint/tendermint/libs/log"
@@ -46,18 +47,47 @@ var msgQueueSize = 1000
// msgs from the reactor which may update the state
type msgInfo struct {
Msg Message `json:"msg"`
PeerID types.NodeID `json:"peer_key"`
Msg Message
PeerID types.NodeID
}
func (msgInfo) TypeTag() string { return "tendermint/wal/MsgInfo" }
type msgInfoJSON struct {
Msg json.RawMessage `json:"msg"`
PeerID types.NodeID `json:"peer_key"`
}
func (m msgInfo) MarshalJSON() ([]byte, error) {
msg, err := jsontypes.Marshal(m.Msg)
if err != nil {
return nil, err
}
return json.Marshal(msgInfoJSON{Msg: msg, PeerID: m.PeerID})
}
func (m *msgInfo) UnmarshalJSON(data []byte) error {
var msg msgInfoJSON
if err := json.Unmarshal(data, &msg); err != nil {
return err
}
if err := jsontypes.Unmarshal(msg.Msg, &m.Msg); err != nil {
return err
}
m.PeerID = msg.PeerID
return nil
}
// internally generated messages which may update the state
type timeoutInfo struct {
Duration time.Duration `json:"duration"`
Height int64 `json:"height"`
Duration time.Duration `json:"duration,string"`
Height int64 `json:"height,string"`
Round int32 `json:"round"`
Step cstypes.RoundStepType `json:"step"`
}
func (timeoutInfo) TypeTag() string { return "tendermint/wal/TimeoutInfo" }
func (ti *timeoutInfo) String() string {
return fmt.Sprintf("%v ; %d/%d %v", ti.Duration, ti.Height, ti.Round, ti.Step)
}

View File

@@ -65,7 +65,7 @@ func (rs RoundStepType) String() string {
// NOTE: Not thread safe. Should only be manipulated by functions downstream
// of the cs.receiveRoutine
type RoundState struct {
Height int64 `json:"height"` // Height we are working on
Height int64 `json:"height,string"` // Height we are working on
Round int32 `json:"round"`
Step RoundStepType `json:"step"`
StartTime time.Time `json:"start_time"`

View File

@@ -12,8 +12,8 @@ import (
"github.com/gogo/protobuf/proto"
"github.com/tendermint/tendermint/internal/jsontypes"
auto "github.com/tendermint/tendermint/internal/libs/autofile"
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
"github.com/tendermint/tendermint/libs/service"
@@ -41,15 +41,17 @@ type TimedWALMessage struct {
// EndHeightMessage marks the end of the given height inside WAL.
// @internal used by scripts/wal2json util.
type EndHeightMessage struct {
Height int64 `json:"height"`
Height int64 `json:"height,string"`
}
func (EndHeightMessage) TypeTag() string { return "tendermint/wal/EndHeightMessage" }
type WALMessage interface{}
func init() {
tmjson.RegisterType(msgInfo{}, "tendermint/wal/MsgInfo")
tmjson.RegisterType(timeoutInfo{}, "tendermint/wal/TimeoutInfo")
tmjson.RegisterType(EndHeightMessage{}, "tendermint/wal/EndHeightMessage")
jsontypes.MustRegister(msgInfo{})
jsontypes.MustRegister(timeoutInfo{})
jsontypes.MustRegister(EndHeightMessage{})
}
//--------------------------------------------------------