Browse Source

types: comments

pull/675/head
Ethan Buchman 7 years ago
parent
commit
d1a00c684e
9 changed files with 42 additions and 7 deletions
  1. +2
    -0
      types/block_meta.go
  2. +5
    -0
      types/heartbeat.go
  3. +1
    -0
      types/keys.go
  4. +9
    -1
      types/proposal.go
  5. +2
    -1
      types/protobuf.go
  6. +10
    -0
      types/services.go
  7. +9
    -5
      types/tx.go
  8. +2
    -0
      types/validator.go
  9. +2
    -0
      types/validator_set.go

+ 2
- 0
types/block_meta.go View File

@ -1,10 +1,12 @@
package types package types
// BlockMeta contains meta information about a block - namely, it's ID and Header.
type BlockMeta struct { type BlockMeta struct {
BlockID BlockID `json:"block_id"` // the block hash and partsethash BlockID BlockID `json:"block_id"` // the block hash and partsethash
Header *Header `json:"header"` // The block's Header Header *Header `json:"header"` // The block's Header
} }
// NewBlockMeta returns a new BlockMeta from the block and its blockParts.
func NewBlockMeta(block *Block, blockParts *PartSet) *BlockMeta { func NewBlockMeta(block *Block, blockParts *PartSet) *BlockMeta {
return &BlockMeta{ return &BlockMeta{
BlockID: BlockID{block.Hash(), blockParts.Header()}, BlockID: BlockID{block.Hash(), blockParts.Header()},


+ 5
- 0
types/heartbeat.go View File

@ -10,6 +10,8 @@ import (
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tmlibs/common"
) )
// Heartbeat is a simple vote-like structure so validators can alert others that
// they are alive and waiting for transactions.
type Heartbeat struct { type Heartbeat struct {
ValidatorAddress data.Bytes `json:"validator_address"` ValidatorAddress data.Bytes `json:"validator_address"`
ValidatorIndex int `json:"validator_index"` ValidatorIndex int `json:"validator_index"`
@ -19,6 +21,7 @@ type Heartbeat struct {
Signature crypto.Signature `json:"signature"` Signature crypto.Signature `json:"signature"`
} }
// WriteSignBytes writes the Heartbeat for signing.
func (heartbeat *Heartbeat) WriteSignBytes(chainID string, w io.Writer, n *int, err *error) { func (heartbeat *Heartbeat) WriteSignBytes(chainID string, w io.Writer, n *int, err *error) {
wire.WriteJSON(CanonicalJSONOnceHeartbeat{ wire.WriteJSON(CanonicalJSONOnceHeartbeat{
chainID, chainID,
@ -26,11 +29,13 @@ func (heartbeat *Heartbeat) WriteSignBytes(chainID string, w io.Writer, n *int,
}, w, n, err) }, w, n, err)
} }
// Copy makes a copy of the Heartbeat.
func (heartbeat *Heartbeat) Copy() *Heartbeat { func (heartbeat *Heartbeat) Copy() *Heartbeat {
heartbeatCopy := *heartbeat heartbeatCopy := *heartbeat
return &heartbeatCopy return &heartbeatCopy
} }
// String returns a string representation of the Heartbeat.
func (heartbeat *Heartbeat) String() string { func (heartbeat *Heartbeat) String() string {
if heartbeat == nil { if heartbeat == nil {
return "nil-heartbeat" return "nil-heartbeat"


+ 1
- 0
types/keys.go View File

@ -1,5 +1,6 @@
package types package types
// UNSTABLE
var ( var (
PeerStateKey = "ConsensusReactor.peerState" PeerStateKey = "ConsensusReactor.peerState"
PeerMempoolChKey = "MempoolReactor.peerMempoolCh" PeerMempoolChKey = "MempoolReactor.peerMempoolCh"


+ 9
- 1
types/proposal.go View File

@ -15,6 +15,11 @@ var (
ErrInvalidBlockPartHash = errors.New("Error invalid block part hash") ErrInvalidBlockPartHash = errors.New("Error invalid block part hash")
) )
// Proposal defines a block proposal for the consensus.
// It refers to the block only by its PartSetHeader.
// It must be signed by the correct proposer for the given Height/Round
// to be considered valid. It may depend on votes from a previous round,
// a so-called Proof-of-Lock (POL) round, as noted in the POLRound and POLBlockID.
type Proposal struct { type Proposal struct {
Height int `json:"height"` Height int `json:"height"`
Round int `json:"round"` Round int `json:"round"`
@ -24,7 +29,8 @@ type Proposal struct {
Signature crypto.Signature `json:"signature"` Signature crypto.Signature `json:"signature"`
} }
// polRound: -1 if no polRound.
// NewProposal returns a new Proposal.
// If there is no POLRound, polRound should be -1.
func NewProposal(height int, round int, blockPartsHeader PartSetHeader, polRound int, polBlockID BlockID) *Proposal { func NewProposal(height int, round int, blockPartsHeader PartSetHeader, polRound int, polBlockID BlockID) *Proposal {
return &Proposal{ return &Proposal{
Height: height, Height: height,
@ -35,11 +41,13 @@ func NewProposal(height int, round int, blockPartsHeader PartSetHeader, polRound
} }
} }
// String returns a string representation of the Proposal.
func (p *Proposal) String() string { func (p *Proposal) String() string {
return fmt.Sprintf("Proposal{%v/%v %v (%v,%v) %v}", p.Height, p.Round, return fmt.Sprintf("Proposal{%v/%v %v (%v,%v) %v}", p.Height, p.Round,
p.BlockPartsHeader, p.POLRound, p.POLBlockID, p.Signature) p.BlockPartsHeader, p.POLRound, p.POLBlockID, p.Signature)
} }
// WriteSignBytes writes the Proposal bytes for signing
func (p *Proposal) WriteSignBytes(chainID string, w io.Writer, n *int, err *error) { func (p *Proposal) WriteSignBytes(chainID string, w io.Writer, n *int, err *error) {
wire.WriteJSON(CanonicalJSONOnceProposal{ wire.WriteJSON(CanonicalJSONOnceProposal{
ChainID: chainID, ChainID: chainID,


+ 2
- 1
types/protobuf.go View File

@ -4,7 +4,8 @@ import (
"github.com/tendermint/abci/types" "github.com/tendermint/abci/types"
) )
// Convert tendermint types to protobuf types
// TM2PB is used for converting Tendermint types to protobuf types.
// UNSTABLE
var TM2PB = tm2pb{} var TM2PB = tm2pb{}
type tm2pb struct{} type tm2pb struct{}


+ 10
- 0
types/services.go View File

@ -4,6 +4,8 @@ import (
abci "github.com/tendermint/abci/types" abci "github.com/tendermint/abci/types"
) )
// NOTE: all types in this file are considered UNSTABLE
//------------------------------------------------------ //------------------------------------------------------
// blockchain services types // blockchain services types
// NOTE: Interfaces used by RPC must be thread safe! // NOTE: Interfaces used by RPC must be thread safe!
@ -12,8 +14,10 @@ import (
//------------------------------------------------------ //------------------------------------------------------
// mempool // mempool
// Mempool defines the mempool interface.
// Updates to the mempool need to be synchronized with committing a block // Updates to the mempool need to be synchronized with committing a block
// so apps can reset their transient state on Commit // so apps can reset their transient state on Commit
// UNSTABLE
type Mempool interface { type Mempool interface {
Lock() Lock()
Unlock() Unlock()
@ -28,6 +32,8 @@ type Mempool interface {
EnableTxsAvailable() EnableTxsAvailable()
} }
// MockMempool is an empty implementation of a Mempool, useful for testing.
// UNSTABLE
type MockMempool struct { type MockMempool struct {
} }
@ -44,6 +50,8 @@ func (m MockMempool) EnableTxsAvailable() {}
//------------------------------------------------------ //------------------------------------------------------
// blockstore // blockstore
// BlockStoreRPC is the block store interface used by the RPC.
// UNSTABLE
type BlockStoreRPC interface { type BlockStoreRPC interface {
Height() int Height() int
@ -55,6 +63,8 @@ type BlockStoreRPC interface {
LoadSeenCommit(height int) *Commit LoadSeenCommit(height int) *Commit
} }
// BlockStore defines the BlockStore interface.
// UNSTABLE
type BlockStore interface { type BlockStore interface {
BlockStoreRPC BlockStoreRPC
SaveBlock(block *Block, blockParts *PartSet, seenCommit *Commit) SaveBlock(block *Block, blockParts *PartSet, seenCommit *Commit)


+ 9
- 5
types/tx.go View File

@ -10,22 +10,26 @@ import (
"github.com/tendermint/tmlibs/merkle" "github.com/tendermint/tmlibs/merkle"
) )
// Tx represents a transaction, which may contain arbitrary bytes.
type Tx []byte type Tx []byte
// NOTE: this is the hash of the go-wire encoded Tx.
// Tx has no types at this level, so just length-prefixed.
// Alternatively, it may make sense to add types here and let
// []byte be type 0x1 so we can have versioned txs if need be in the future.
// Hash returns the hash of the go-wire encoded Tx.
// Tx has no types at this level, so go-wire encoding only adds length-prefix.
// NOTE: It may make sense to add types here one day and let []byte be type 0x1
// so we can have versioned txs if need be in the future.
func (tx Tx) Hash() []byte { func (tx Tx) Hash() []byte {
return merkle.SimpleHashFromBinary(tx) return merkle.SimpleHashFromBinary(tx)
} }
// String returns a string representation of the Tx.
func (tx Tx) String() string { func (tx Tx) String() string {
return fmt.Sprintf("Tx{%X}", []byte(tx)) return fmt.Sprintf("Tx{%X}", []byte(tx))
} }
// Txs is a slice of Tx.
type Txs []Tx type Txs []Tx
// Hash returns the simple Merkle root hash of the Txs.
func (txs Txs) Hash() []byte { func (txs Txs) Hash() []byte {
// Recursive impl. // Recursive impl.
// Copied from tmlibs/merkle to avoid allocations // Copied from tmlibs/merkle to avoid allocations
@ -51,7 +55,7 @@ func (txs Txs) Index(tx Tx) int {
return -1 return -1
} }
// Index returns the index of this transaction hash in the list, or -1 if not found
// IndexByHash returns the index of this transaction hash in the list, or -1 if not found
func (txs Txs) IndexByHash(hash []byte) int { func (txs Txs) IndexByHash(hash []byte) int {
for i := range txs { for i := range txs {
if bytes.Equal(txs[i].Hash(), hash) { if bytes.Equal(txs[i].Hash(), hash) {


+ 2
- 0
types/validator.go View File

@ -106,6 +106,8 @@ func (vc validatorCodec) Compare(o1 interface{}, o2 interface{}) int {
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// For testing... // For testing...
// RandValidator returns a randomized validator, useful for testing.
// UNSTABLE
func RandValidator(randPower bool, minPower int64) (*Validator, *PrivValidatorFS) { func RandValidator(randPower bool, minPower int64) (*Validator, *PrivValidatorFS) {
_, tempFilePath := cmn.Tempfile("priv_validator_") _, tempFilePath := cmn.Tempfile("priv_validator_")
privVal := GenPrivValidatorFS(tempFilePath) privVal := GenPrivValidatorFS(tempFilePath)


+ 2
- 0
types/validator_set.go View File

@ -368,7 +368,9 @@ func (ac accumComparable) Less(o interface{}) bool {
//---------------------------------------- //----------------------------------------
// For testing // For testing
// RandValidatorSet returns a randomized validator set, useful for testing.
// NOTE: PrivValidator are in order. // NOTE: PrivValidator are in order.
// UNSTABLE
func RandValidatorSet(numValidators int, votingPower int64) (*ValidatorSet, []*PrivValidatorFS) { func RandValidatorSet(numValidators int, votingPower int64) (*ValidatorSet, []*PrivValidatorFS) {
vals := make([]*Validator, numValidators) vals := make([]*Validator, numValidators)
privValidators := make([]*PrivValidatorFS, numValidators) privValidators := make([]*PrivValidatorFS, numValidators)


Loading…
Cancel
Save