github.com/supragya/TendermintConnector@v0.0.0-20210619045051-113e32b84fb1/chains/tm34/structsTendermint.go (about)

     1  package tm34
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/supragya/TendermintConnector/chains/tm34/crypto"
     7  	"github.com/supragya/TendermintConnector/chains/tm34/crypto/merkle"
     8  	"github.com/supragya/TendermintConnector/chains/tm34/libs/bits"
     9  	tmjson "github.com/supragya/TendermintConnector/chains/tm34/libs/json"
    10  	tmproto "github.com/supragya/TendermintConnector/chains/tm34/proto/tendermint/types"
    11  )
    12  
    13  const (
    14  	channelBc   = byte(0x40) //bc.BlockchainChannel,
    15  	channelCsSt = byte(0x20) //cs.StateChannel,
    16  	channelCsDc = byte(0x21) //cs.DataChannel,
    17  	channelCsVo = byte(0x22) //cs.VoteChannel,
    18  	channelCsVs = byte(0x23) //cs.VoteSetBitsChannel,
    19  	channelMm   = byte(0x30) //mempl.MempoolChannel,
    20  	channelEv   = byte(0x38) //evidence.EvidenceChannel,
    21  )
    22  
    23  func init() {
    24  	tmjson.RegisterType(&NewRoundStepMessage{}, "tendermint/NewRoundStepMessage")
    25  	tmjson.RegisterType(&NewValidBlockMessage{}, "tendermint/NewValidBlockMessage")
    26  	tmjson.RegisterType(&ProposalMessage{}, "tendermint/Proposal")
    27  	tmjson.RegisterType(&ProposalPOLMessage{}, "tendermint/ProposalPOL")
    28  	tmjson.RegisterType(&BlockPartMessage{}, "tendermint/BlockPart")
    29  	tmjson.RegisterType(&VoteMessage{}, "tendermint/Vote")
    30  	tmjson.RegisterType(&HasVoteMessage{}, "tendermint/HasVote")
    31  	tmjson.RegisterType(&VoteSetMaj23Message{}, "tendermint/VoteSetMaj23")
    32  	tmjson.RegisterType(&VoteSetBitsMessage{}, "tendermint/VoteSetBits")
    33  }
    34  
    35  //-------------------------------------
    36  
    37  // NewRoundStepMessage is sent for every step taken in the ConsensusState.
    38  // For every height/round/step transition
    39  type NewRoundStepMessage struct {
    40  	Height                int64
    41  	Round                 int32
    42  	Step                  int8
    43  	SecondsSinceStartTime int64
    44  	LastCommitRound       int32
    45  }
    46  
    47  //-------------------------------------
    48  type PartSetHeader struct {
    49  	Total uint32 `json:"total"`
    50  	Hash  []byte `json:"hash"`
    51  }
    52  
    53  // NewValidBlockMessage is sent when a validator observes a valid block B in some round r,
    54  // i.e., there is a Proposal for block B and 2/3+ prevotes for the block B in the round r.
    55  // In case the block is also committed, then IsCommit flag is set to true.
    56  type NewValidBlockMessage struct {
    57  	Height             int64
    58  	Round              int32
    59  	BlockPartSetHeader PartSetHeader
    60  	BlockParts         *bits.BitArray
    61  	IsCommit           bool
    62  }
    63  
    64  //-------------------------------------
    65  type BlockID struct {
    66  	Hash          []byte        `json:"hash"`
    67  	PartSetHeader PartSetHeader `json:"parts"`
    68  }
    69  
    70  type Proposal struct {
    71  	Type      tmproto.SignedMsgType
    72  	Height    int64     `json:"height"`
    73  	Round     int32     `json:"round"`     // there can not be greater than 2_147_483_647 rounds
    74  	POLRound  int32     `json:"pol_round"` // -1 if null.
    75  	BlockID   BlockID   `json:"block_id"`
    76  	Timestamp time.Time `json:"timestamp"`
    77  	Signature []byte    `json:"signature"`
    78  }
    79  
    80  // ProposalMessage is sent when a new block is proposed.
    81  type ProposalMessage struct {
    82  	Proposal *Proposal
    83  }
    84  
    85  //-------------------------------------
    86  
    87  // ProposalPOLMessage is sent when a previous proposal is re-proposed.
    88  type ProposalPOLMessage struct {
    89  	Height           int64
    90  	ProposalPOLRound int32
    91  	ProposalPOL      *bits.BitArray
    92  }
    93  
    94  //-------------------------------------
    95  type Part struct {
    96  	Index uint32       `json:"index"`
    97  	Bytes []byte       `json:"bytes"`
    98  	Proof merkle.Proof `json:"proof"`
    99  }
   100  
   101  // BlockPartMessage is sent when gossipping a piece of the proposed block.
   102  type BlockPartMessage struct {
   103  	Height int64
   104  	Round  int32
   105  	Part   *Part
   106  }
   107  
   108  //-------------------------------------
   109  type Vote struct {
   110  	Type             tmproto.SignedMsgType `json:"type"`
   111  	Height           int64                 `json:"height"`
   112  	Round            int32                 `json:"round"`    // assume there will not be greater than 2_147_483_647 rounds
   113  	BlockID          BlockID               `json:"block_id"` // zero if vote is nil.
   114  	Timestamp        time.Time             `json:"timestamp"`
   115  	ValidatorAddress crypto.Address        `json:"validator_address"`
   116  	ValidatorIndex   int32                 `json:"validator_index"`
   117  	Signature        []byte                `json:"signature"`
   118  }
   119  
   120  // VoteMessage is sent when voting for a proposal (or lack thereof).
   121  type VoteMessage struct {
   122  	Vote *Vote
   123  }
   124  
   125  //-------------------------------------
   126  
   127  // HasVoteMessage is sent to indicate that a particular vote has been received.
   128  type HasVoteMessage struct {
   129  	Height int64
   130  	Round  int32
   131  	Type   tmproto.SignedMsgType
   132  	Index  int32
   133  }
   134  
   135  //-------------------------------------
   136  
   137  // VoteSetMaj23Message is sent to indicate that a given BlockID has seen +2/3 votes.
   138  type VoteSetMaj23Message struct {
   139  	Height  int64
   140  	Round   int32
   141  	Type    tmproto.SignedMsgType
   142  	BlockID BlockID
   143  }
   144  
   145  //-------------------------------------
   146  
   147  // VoteSetBitsMessage is sent to communicate the bit-array of votes seen for the BlockID.
   148  type VoteSetBitsMessage struct {
   149  	Height  int64
   150  	Round   int32
   151  	Type    tmproto.SignedMsgType
   152  	BlockID BlockID
   153  	Votes   *bits.BitArray
   154  }
   155  
   156  //-------------------------------------