block

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DoubleSign = int(1)
)

Variables

This section is empty.

Functions

func EncodeMsg

func EncodeMsg(msg ConsensusMessage) (string, error)

func MajorityTwoThird

func MajorityTwoThird(voterNum, committeeSize uint32) bool

func Number

func Number(blockID types.Bytes32) uint32

Number extract block number from block id.

func QCEncodeBytes

func QCEncodeBytes(qc *QuorumCert) []byte

--------------

func RegisterConsensusMessages

func RegisterConsensusMessages(cdc *amino.Codec)

Types

type Block

type Block struct {
	BlockHeader *Header
	Txs         types.Transactions
	QC          *QuorumCert
	// contains filtered or unexported fields
}

Block is an immutable block type.

func BlockDecodeFromBytes

func BlockDecodeFromBytes(bytes []byte) (*Block, error)

func Compose

func Compose(header *Header, txs types.Transactions) *Block

Create new committee Info Compose compose a block with all needed components Note: This method is usually to recover a block by its portions, and the TxsRoot is not verified. To build up a block, use a Builder.

func (*Block) AppHash

func (b *Block) AppHash() cmtbytes.HexBytes

func (*Block) Body

func (b *Block) Body() *Body

Body returns body of a block.

func (*Block) CompactString

func (b *Block) CompactString() string

func (*Block) DecodeRLP

func (b *Block) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder.

func (*Block) EncodeRLP

func (b *Block) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder.

func (*Block) Epoch

func (b *Block) Epoch() uint64

if the block is the first mblock, get epoch from committee otherwise get epoch from QC

func (*Block) GetQC

func (b *Block) GetQC() *QuorumCert

func (*Block) Header

func (b *Block) Header() *Header

Header returns the block header.

func (*Block) ID

func (b *Block) ID() types.Bytes32

func (*Block) IsKBlock

func (b *Block) IsKBlock() bool

func (*Block) LastKBlock

func (b *Block) LastKBlock() uint32

LastBlocID returns id of parent block.

func (*Block) NextValidatorsHash

func (b *Block) NextValidatorsHash() cmtbytes.HexBytes

func (*Block) Nonce

func (b *Block) Nonce() uint64

func (*Block) Number

func (b *Block) Number() uint32

Number returns sequential number of this block.

func (*Block) Oneliner

func (b *Block) Oneliner() string

func (*Block) ParentID

func (b *Block) ParentID() types.Bytes32

ParentID returns id of parent block.

func (*Block) ProposerIndex

func (b *Block) ProposerIndex() uint32

func (*Block) SetQC

func (b *Block) SetQC(qc *QuorumCert) *Block

-----------------

func (*Block) Size

func (b *Block) Size() uint64

Size returns the true RLP encoded storage size of the block, either by encoding and returning it, or returning a previously cached value.

func (*Block) String

func (b *Block) String() string

func (*Block) Timestamp

func (b *Block) Timestamp() uint64

Timestamp returns timestamp of this block.

func (*Block) ToBytes

func (b *Block) ToBytes() []byte

func (*Block) Transactions

func (b *Block) Transactions() types.Transactions

Transactions returns a copy of transactions.

func (*Block) TxsRoot

func (b *Block) TxsRoot() cmtbytes.HexBytes

TxsRoot returns merkle root of txs contained in this block.

func (*Block) ValidatorsHash

func (b *Block) ValidatorsHash() cmtbytes.HexBytes

func (*Block) VerifyQC

func (b *Block) VerifyQC(escortQC *QuorumCert, blsMaster *types.BlsMaster, committee *types.ValidatorSet) (bool, error)

type Body

type Body struct {
	Txs types.Transactions
}

Body defines body of a block.

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder only build header and txs. committee info and kblock data built by app. Builder to make it easy to build a block object.

func (*Builder) Build

func (b *Builder) Build() *Block

Build build a block object.

func (*Builder) LastKBlock

func (b *Builder) LastKBlock(height uint32) *Builder

func (*Builder) NextValidatorsHash

func (b *Builder) NextValidatorsHash(hash []byte) *Builder

func (*Builder) Nonce

func (b *Builder) Nonce(nonce uint64) *Builder

func (*Builder) ParentID

func (b *Builder) ParentID(id types.Bytes32) *Builder

ParentID set parent id.

func (*Builder) ProposerIndex

func (b *Builder) ProposerIndex(index uint32) *Builder

func (*Builder) QC

func (b *Builder) QC(qc *QuorumCert) *Builder

func (*Builder) Timestamp

func (b *Builder) Timestamp(ts uint64) *Builder

Timestamp set timestamp.

func (*Builder) Transaction

func (b *Builder) Transaction(tx []byte) *Builder

Transaction add a transaction.

func (*Builder) Tx

func (b *Builder) Tx(tx cmttypes.Tx) *Builder

func (*Builder) ValidatorsHash

func (b *Builder) ValidatorsHash(hash []byte) *Builder

type ConsensusMessage

type ConsensusMessage interface {
	GetSignerIndex() uint32
	GetEpoch() uint64
	GetType() string
	GetRound() uint32

	String() string
	GetMsgHash() types.Bytes32
	SetMsgSignature(signature []byte)
	VerifyMsgSignature(pubkey bls.PublicKey) bool
}

ConsensusMessage is a message that can be sent and received on the Reactor

func DecodeMsg

func DecodeMsg(rawHex string) (ConsensusMessage, error)

type DraftBlock

type DraftBlock struct {
	Msg           ConsensusMessage
	Height        uint32
	Round         uint32
	Parent        *DraftBlock
	Justify       *DraftQC
	Committed     bool // used for DraftBlock created from database
	ProposedBlock *Block

	SuccessProcessed bool
	ProcessError     error
}

definition for DraftBlock

func (*DraftBlock) ToString

func (pb *DraftBlock) ToString() string

type DraftQC

type DraftQC struct {
	//Height/QCround must be the same with QCNode.Height/QCnode.Round
	QCNode *DraftBlock // this is the QCed block
	QC     *QuorumCert // this is the actual QC that goes into the next block
}

definition for DraftQC

func NewDraftQC

func NewDraftQC(qc *QuorumCert, qcNode *DraftBlock) *DraftQC

func (*DraftQC) ToString

func (qc *DraftQC) ToString() string

type EscortedBlock

type EscortedBlock struct {
	Block    *Block
	EscortQC *QuorumCert
}
type Header struct {
	ParentID      types.Bytes32
	Timestamp     uint64
	ProposerIndex uint32
	TxsRoot       cmtbytes.HexBytes
	LastKBlock    uint32
	Nonce         uint64 //

	QCHash             cmtbytes.HexBytes // hash of QC
	ValidatorsHash     cmtbytes.HexBytes // hash of validator set
	NextValidatorsHash cmtbytes.HexBytes // hash of next validator set
	AppHash            cmtbytes.HexBytes //
	// contains filtered or unexported fields
}

Header contains almost all information about a block, except block body. It's immutable.

func (*Header) ID

func (h *Header) ID() (id types.Bytes32)

ID computes id of block. The block ID is defined as: blockNumber + hash(signingHash, proposerIndex)[4:].

func (*Header) Number

func (h *Header) Number() uint32

Number returns sequential number of this block.

func (*Header) SigningHash

func (h *Header) SigningHash() (hash types.Bytes32)

SigningHash computes hash of all header fields excluding signature.

func (*Header) String

func (h *Header) String() string

type PMProposalMessage

type PMProposalMessage struct {
	Timestamp   time.Time
	Epoch       uint64
	Round       uint32
	RawBlock    []byte
	TimeoutCert *types.TimeoutCert

	MsgSignature []byte
	// contains filtered or unexported fields
}

PMProposalMessage is sent when a new block is proposed

func (*PMProposalMessage) DecodeBlock

func (m *PMProposalMessage) DecodeBlock() *Block

func (*PMProposalMessage) GetEpoch

func (m *PMProposalMessage) GetEpoch() uint64

func (*PMProposalMessage) GetMsgHash

func (m *PMProposalMessage) GetMsgHash() types.Bytes32

GetMsgHash computes hash of all header fields excluding signature.

func (*PMProposalMessage) GetRound

func (m *PMProposalMessage) GetRound() uint32

func (*PMProposalMessage) GetSignerIndex

func (m *PMProposalMessage) GetSignerIndex() uint32

func (*PMProposalMessage) GetType

func (m *PMProposalMessage) GetType() string

func (*PMProposalMessage) SetMsgSignature

func (m *PMProposalMessage) SetMsgSignature(msgSignature []byte)

func (*PMProposalMessage) String

func (m *PMProposalMessage) String() string

String returns a string representation.

func (*PMProposalMessage) VerifyMsgSignature

func (m *PMProposalMessage) VerifyMsgSignature(pubkey bls.PublicKey) bool

type PMQueryMessage

type PMQueryMessage struct {
	Timestamp   time.Time
	Epoch       uint64
	SignerIndex uint32

	LastCommitted types.Bytes32

	MsgSignature []byte
}

func (*PMQueryMessage) GetEpoch

func (m *PMQueryMessage) GetEpoch() uint64

func (*PMQueryMessage) GetMsgHash

func (m *PMQueryMessage) GetMsgHash() types.Bytes32

GetMsgHash computes hash of all header fields excluding signature.

func (*PMQueryMessage) GetRound

func (m *PMQueryMessage) GetRound() uint32

func (*PMQueryMessage) GetSignerIndex

func (m *PMQueryMessage) GetSignerIndex() uint32

func (*PMQueryMessage) GetType

func (m *PMQueryMessage) GetType() string

func (*PMQueryMessage) SetMsgSignature

func (m *PMQueryMessage) SetMsgSignature(msgSignature []byte)

func (*PMQueryMessage) String

func (m *PMQueryMessage) String() string

String returns a string representation.

func (*PMQueryMessage) VerifyMsgSignature

func (m *PMQueryMessage) VerifyMsgSignature(pubkey bls.PublicKey) bool

type PMTimeoutMessage

type PMTimeoutMessage struct {
	Timestamp   time.Time
	Epoch       uint64
	SignerIndex uint32
	WishRound   uint32

	// local QCHigh
	QCHigh []byte

	// timeout vote
	WishVoteHash [32]byte
	WishVoteSig  []byte // signature

	// last vote for proposal
	LastVoteRound     uint32
	LastVoteBlockID   types.Bytes32
	LastVoteSignature []byte

	MsgSignature []byte
	// contains filtered or unexported fields
}

PMTimeoutMessage is sent to the next leader in these two senarios

func (*PMTimeoutMessage) DecodeQCHigh

func (m *PMTimeoutMessage) DecodeQCHigh() *QuorumCert

func (*PMTimeoutMessage) GetEpoch

func (m *PMTimeoutMessage) GetEpoch() uint64

func (*PMTimeoutMessage) GetMsgHash

func (m *PMTimeoutMessage) GetMsgHash() types.Bytes32

GetMsgHash computes hash of all header fields excluding signature.

func (*PMTimeoutMessage) GetRound

func (m *PMTimeoutMessage) GetRound() uint32

func (*PMTimeoutMessage) GetSignerIndex

func (m *PMTimeoutMessage) GetSignerIndex() uint32

func (*PMTimeoutMessage) GetType

func (m *PMTimeoutMessage) GetType() string

func (*PMTimeoutMessage) SetMsgSignature

func (m *PMTimeoutMessage) SetMsgSignature(msgSignature []byte)

func (*PMTimeoutMessage) String

func (m *PMTimeoutMessage) String() string

String returns a string representation.

func (*PMTimeoutMessage) VerifyMsgSignature

func (m *PMTimeoutMessage) VerifyMsgSignature(pubkey bls.PublicKey) bool

type PMVoteMessage

type PMVoteMessage struct {
	Timestamp     time.Time
	Epoch         uint64
	SignerIndex   uint32
	VoteRound     uint32
	VoteBlockID   types.Bytes32
	VoteSignature []byte //bls.Signature

	MsgSignature []byte
}

PMVoteMessage is sent when voting for a proposal (or lack thereof).

func (*PMVoteMessage) GetEpoch

func (m *PMVoteMessage) GetEpoch() uint64

func (*PMVoteMessage) GetMsgHash

func (m *PMVoteMessage) GetMsgHash() types.Bytes32

GetMsgHash computes hash of all header fields excluding signature.

func (*PMVoteMessage) GetRound

func (m *PMVoteMessage) GetRound() uint32

func (*PMVoteMessage) GetSignerIndex

func (m *PMVoteMessage) GetSignerIndex() uint32

func (*PMVoteMessage) GetType

func (m *PMVoteMessage) GetType() string

func (*PMVoteMessage) SetMsgSignature

func (m *PMVoteMessage) SetMsgSignature(msgSignature []byte)

func (*PMVoteMessage) String

func (m *PMVoteMessage) String() string

String returns a string representation.

func (*PMVoteMessage) VerifyMsgSignature

func (m *PMVoteMessage) VerifyMsgSignature(pubkey bls.PublicKey) bool

type QuorumCert

type QuorumCert struct {
	Epoch   uint64
	Round   uint32
	BlockID types.Bytes32

	AggSig   []byte
	BitArray *cmn.BitArray
}

func GenesisEscortQC

func GenesisEscortQC(b *Block) *QuorumCert

func QCDecodeFromBytes

func QCDecodeFromBytes(bytes []byte) (*QuorumCert, error)

func (*QuorumCert) CompactString

func (qc *QuorumCert) CompactString() string

func (*QuorumCert) DecodeRLP

func (qc *QuorumCert) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder.

func (*QuorumCert) EncodeRLP

func (qc *QuorumCert) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder.

func (*QuorumCert) Hash

func (qc *QuorumCert) Hash() []byte

func (*QuorumCert) Number

func (qc *QuorumCert) Number() uint32

func (*QuorumCert) String

func (qc *QuorumCert) String() string

func (*QuorumCert) ToBytes

func (qc *QuorumCert) ToBytes() []byte

type Raw

type Raw []byte

Raw allows to partially decode components of a block.

func (Raw) DecodeBlockBody

func (r Raw) DecodeBlockBody() (*Block, error)

DecodeBlockBody decode block header & tx part.

func (Raw) DecodeBody

func (r Raw) DecodeBody() (*Body, error)

DecodeBody decode only the body.

func (Raw) DecodeHeader

func (r Raw) DecodeHeader() (*Header, error)

DecodeHeader decode only the header.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL