Documentation ¶
Index ¶
- Constants
- Variables
- func BlockEncodeBytes(blk *Block) []byte
- func Number(blockID meter.Bytes32) uint32
- func QCEncodeBytes(qc *QuorumCert) []byte
- type Block
- func (b *Block) Body() *Body
- func (b *Block) CompactString() string
- func (b *Block) DecodeRLP(s *rlp.Stream) error
- func (b *Block) EncodeRLP(w io.Writer) error
- func (b *Block) EvidenceDataHash() (hash meter.Bytes32)
- func (b *Block) GetBlockEpoch() (epoch uint64)
- func (b *Block) GetCanonicalName() string
- func (b *Block) GetCommitteeEpoch() uint64
- func (b *Block) GetCommitteeInfo() ([]CommitteeInfo, error)
- func (b *Block) GetKBlockData() (*KBlockData, error)
- func (b *Block) GetMagic() [4]byte
- func (b *Block) GetQC() *QuorumCert
- func (b *Block) Header() *Header
- func (b *Block) Oneliner() string
- func (b *Block) SetBlockSignature(sig []byte) error
- func (b *Block) SetCommitteeEpoch(epoch uint64)
- func (b *Block) SetCommitteeInfo(info []CommitteeInfo)
- func (b *Block) SetEvidenceDataHash(hash meter.Bytes32) error
- func (b *Block) SetKBlockData(data KBlockData) error
- func (b *Block) SetMagic(m [4]byte) *Block
- func (b *Block) SetQC(qc *QuorumCert) *Block
- func (b *Block) Size() metric.StorageSize
- func (b *Block) String() string
- func (b *Block) ToBytes() []byte
- func (b *Block) Transactions() tx.Transactions
- func (b *Block) WithSignature(sig []byte) *Block
- type Body
- type Builder
- func (b *Builder) Beneficiary(addr meter.Address) *Builder
- func (b *Builder) BlockType(t uint32) *Builder
- func (b *Builder) Build() *Block
- func (b *Builder) GasLimit(limit uint64) *Builder
- func (b *Builder) GasUsed(used uint64) *Builder
- func (b *Builder) LastKBlockHeight(height uint32) *Builder
- func (b *Builder) ParentID(id meter.Bytes32) *Builder
- func (b *Builder) ReceiptsRoot(hash meter.Bytes32) *Builder
- func (b *Builder) StateRoot(hash meter.Bytes32) *Builder
- func (b *Builder) Timestamp(ts uint64) *Builder
- func (b *Builder) TotalScore(score uint64) *Builder
- func (b *Builder) Transaction(tx *tx.Transaction) *Builder
- type CommitteeInfo
- type CommitteeInfos
- type Evidence
- type GasLimit
- type Header
- func (h *Header) Beneficiary() meter.Address
- func (h *Header) BlockType() uint32
- func (h *Header) EvidenceDataRoot() meter.Bytes32
- func (h *Header) GasLimit() uint64
- func (h *Header) GasUsed() uint64
- func (h *Header) ID() (id meter.Bytes32)
- func (h *Header) LastKBlockHeight() uint32
- func (h *Header) Number() uint32
- func (h *Header) ParentID() meter.Bytes32
- func (h *Header) ReceiptsRoot() meter.Bytes32
- func (h *Header) Signature() []byte
- func (h *Header) Signer() (signer meter.Address, err error)
- func (h *Header) SigningHash() (hash meter.Bytes32)
- func (h *Header) StateRoot() meter.Bytes32
- func (h *Header) String() string
- func (h *Header) Timestamp() uint64
- func (h *Header) TotalScore() uint64
- func (h *Header) TxsRoot() meter.Bytes32
- type HeaderBody
- type KBlockData
- type PowRawBlock
- type QuorumCert
- func (qc *QuorumCert) CompactString() string
- func (qc *QuorumCert) DecodeRLP(s *rlp.Stream) error
- func (qc *QuorumCert) EncodeRLP(w io.Writer) error
- func (qc *QuorumCert) GetViolation() []*Violation
- func (qc *QuorumCert) String() string
- func (qc *QuorumCert) ToBytes() []byte
- func (qc *QuorumCert) VoterBitArray() *cmn.BitArray
- type Raw
- type Violation
Constants ¶
const ( BLOCK_TYPE_K_BLOCK = uint32(1) BLOCK_TYPE_M_BLOCK = uint32(2) BLOCK_TYPE_S_BLOCK = uint32(255) // stop committee block )
const (
DoubleSign = int(1)
)
Variables ¶
var (
BlockMagicVersion1 [4]byte = [4]byte{0x76, 0x01, 0x00, 0x00} // version v.1.0.0
)
Functions ¶
Types ¶
type Block ¶
type Block struct { BlockHeader *Header Txs tx.Transactions QC *QuorumCert CommitteeInfos CommitteeInfos KBlockData KBlockData Magic [4]byte // contains filtered or unexported fields }
Block is an immutable block type.
func BlockDecodeFromBytes ¶
func Compose ¶
func Compose(header *Header, txs tx.Transactions) *Block
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) CompactString ¶
func (*Block) EvidenceDataHash ¶
func (*Block) GetBlockEpoch ¶
if the block is the first mblock, get epochID from committee otherwise get epochID from QC
func (*Block) GetCanonicalName ¶
func (*Block) GetCommitteeEpoch ¶
func (*Block) GetCommitteeInfo ¶
func (b *Block) GetCommitteeInfo() ([]CommitteeInfo, error)
func (*Block) GetKBlockData ¶
func (b *Block) GetKBlockData() (*KBlockData, error)
Serialization for KBlockData and ComitteeInfo
func (*Block) GetQC ¶
func (b *Block) GetQC() *QuorumCert
func (*Block) SetBlockSignature ¶
func (*Block) SetCommitteeEpoch ¶
func (*Block) SetCommitteeInfo ¶
func (b *Block) SetCommitteeInfo(info []CommitteeInfo)
func (*Block) SetKBlockData ¶
func (b *Block) SetKBlockData(data KBlockData) error
func (*Block) SetQC ¶
func (b *Block) SetQC(qc *QuorumCert) *Block
func (*Block) Transactions ¶
func (b *Block) Transactions() tx.Transactions
Transactions returns a copy of transactions.
func (*Block) WithSignature ¶
WithSignature create a new block object with signature set.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
XXX: Yang: Builder only build header and txs. evidence/committee info and kblock data built by app. Builder to make it easy to build a block object.
func (*Builder) Beneficiary ¶
Beneficiary set recipient of reward.
func (*Builder) LastKBlockHeight ¶
LastKBlockID set last KBlock id.
func (*Builder) ReceiptsRoot ¶
ReceiptsRoot set receipts root.
func (*Builder) TotalScore ¶
TotalScore set total score.
func (*Builder) Transaction ¶
func (b *Builder) Transaction(tx *tx.Transaction) *Builder
Transaction add a transaction.
type CommitteeInfo ¶
type CommitteeInfo struct { Name string CSIndex uint32 // Index, corresponding to the bitarray NetAddr types.NetAddress CSPubKey []byte // Bls pubkey PubKey []byte // ecdsa pubkey }
func NewCommitteeInfo ¶
func NewCommitteeInfo(name string, pubKey []byte, netAddr types.NetAddress, csPubKey []byte, csIndex uint32) *CommitteeInfo
Create new committee Info
func (CommitteeInfo) String ¶
func (ci CommitteeInfo) String() string
type CommitteeInfos ¶
type CommitteeInfos struct { Epoch uint64 CommitteeInfo []CommitteeInfo }
func (CommitteeInfos) String ¶
func (cis CommitteeInfos) String() string
type Evidence ¶
type Evidence struct { VotingSig []byte //serialized bls signature VotingMsgHash []byte //[][32]byte VotingBitArray cmn.BitArray VotingViolation []*Violation NotarizeSig []byte NotarizeMsgHash []byte //[][32]byte NotarizeBitArray cmn.BitArray NotarizeViolation []*Violation }
NewEvidence records the voting/notarization aggregated signatures and bitmap of validators. Validators info can get from 1st proposaed block meta data
type GasLimit ¶
type GasLimit uint64
GasLimit to support block gas limit validation and adjustment.
func (GasLimit) Adjust ¶
Adjust suppose the receiver is parent gas limit, and calculate a valid gas limit value by apply `delta`.
type Header ¶
type Header struct { Body HeaderBody // contains filtered or unexported fields }
Header contains almost all information about a block, except block body. It's immutable.
func (*Header) Beneficiary ¶
Beneficiary returns reward recipient.
func (*Header) EvidenceDataRoot ¶
EvidenceDataRoot returns merkle root of tx receipts.
func (*Header) ID ¶
ID computes id of block. The block ID is defined as: blockNumber + hash(signingHash, signer)[4:].
func (*Header) LastKBlockHeight ¶
LastBlocID returns id of parent block.
func (*Header) ReceiptsRoot ¶
ReceiptsRoot returns merkle root of tx receipts.
func (*Header) SigningHash ¶
SigningHash computes hash of all header fields excluding signature.
func (*Header) StateRoot ¶
StateRoot returns account state merkle root just afert this block being applied.
func (*Header) TotalScore ¶
TotalScore returns total score that cumulated from genesis block to this one.
type HeaderBody ¶
type HeaderBody struct { ParentID meter.Bytes32 Timestamp uint64 GasLimit uint64 LastKBlockHeight uint32 BlockType uint32 Beneficiary meter.Address Proposer meter.Address GasUsed uint64 TotalScore uint64 TxsRoot meter.Bytes32 StateRoot meter.Bytes32 ReceiptsRoot meter.Bytes32 EvidenceDataRoot meter.Bytes32 Signature []byte }
headerBody body of header
type KBlockData ¶
type KBlockData struct { Nonce uint64 // the last of the pow block Data []PowRawBlock }
func (KBlockData) ToString ¶
func (d KBlockData) ToString() string
type PowRawBlock ¶
type PowRawBlock []byte
type QuorumCert ¶
type QuorumCert struct { QCHeight uint32 QCRound uint32 EpochID uint64 VoterBitArrayStr string VoterMsgHash [32]byte // [][32]byte VoterAggSig []byte VoterViolation []*Violation // contains filtered or unexported fields }
func GenesisQC ¶
func GenesisQC() *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) GetViolation ¶
func (qc *QuorumCert) GetViolation() []*Violation
func (*QuorumCert) String ¶
func (qc *QuorumCert) String() string
func (*QuorumCert) ToBytes ¶
func (qc *QuorumCert) ToBytes() []byte
func (*QuorumCert) VoterBitArray ¶
func (qc *QuorumCert) VoterBitArray() *cmn.BitArray
type Raw ¶
type Raw []byte
Raw allows to partially decode components of a block.
func (Raw) DecodeBlockBody ¶
DecodeBlockBody decode block header & tx part.
func (Raw) DecodeHeader ¶
DecodeHeader decode only the header.