block

package
v1.2.0-fork8 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 License: LGPL-3.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const (
	BLOCK_TYPE_K_BLOCK = uint32(1)
	BLOCK_TYPE_M_BLOCK = uint32(2)
	BLOCK_TYPE_S_BLOCK = uint32(255) // stop committee block
)
View Source
const (
	DoubleSign = int(1)
)

Variables

View Source
var (
	BlockMagicVersion1 [4]byte = [4]byte{0x76, 0x01, 0x00, 0x00} // version v.1.0.0
)

Functions

func BlockEncodeBytes

func BlockEncodeBytes(blk *Block) []byte

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

func Number

func Number(blockID meter.Bytes32) uint32

Number extract block number from block id.

func QCEncodeBytes

func QCEncodeBytes(qc *QuorumCert) []byte

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

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 BlockDecodeFromBytes(bytes []byte) (*Block, error)

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) Beneficiary added in v1.2.0

func (b *Block) Beneficiary() meter.Address

Beneficiary returns reward recipient.

func (*Block) BlockType added in v1.2.0

func (b *Block) BlockType() uint32

BlockType returns block type of this block.

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) EvidenceDataHash

func (b *Block) EvidenceDataHash() (hash meter.Bytes32)

func (*Block) EvidenceDataRoot added in v1.2.0

func (b *Block) EvidenceDataRoot() meter.Bytes32

EvidenceDataRoot returns merkle root of tx receipts.

func (*Block) GasLimit added in v1.2.0

func (b *Block) GasLimit() uint64

GasLimit returns gas limit of this block.

func (*Block) GasUsed added in v1.2.0

func (b *Block) GasUsed() uint64

GasUsed returns gas used by txs.

func (*Block) GetBlockEpoch

func (b *Block) GetBlockEpoch() (epoch uint64)

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

func (*Block) GetCanonicalName

func (b *Block) GetCanonicalName() string

func (*Block) GetCommitteeEpoch

func (b *Block) GetCommitteeEpoch() uint64

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) GetMagic

func (b *Block) GetMagic() [4]byte

func (*Block) GetQC

func (b *Block) GetQC() *QuorumCert

func (*Block) Header

func (b *Block) Header() *Header

Header returns the block header.

func (*Block) ID added in v1.2.0

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

func (*Block) IsKBlock added in v1.2.0

func (b *Block) IsKBlock() bool

func (*Block) IsSBlock

func (b *Block) IsSBlock() bool

func (*Block) LastKBlockHeight added in v1.2.0

func (b *Block) LastKBlockHeight() uint32

LastBlocID returns id of parent block.

func (*Block) Number added in v1.2.0

func (b *Block) Number() uint32

Number returns sequential number of this block.

func (*Block) Oneliner

func (b *Block) Oneliner() string

func (*Block) ParentID added in v1.2.0

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

ParentID returns id of parent block.

func (*Block) ReceiptsRoot added in v1.2.0

func (b *Block) ReceiptsRoot() meter.Bytes32

ReceiptsRoot returns merkle root of tx receipts.

func (*Block) SetBlockSignature

func (b *Block) SetBlockSignature(sig []byte) error

func (*Block) SetCommitteeEpoch

func (b *Block) SetCommitteeEpoch(epoch uint64)

func (*Block) SetCommitteeInfo

func (b *Block) SetCommitteeInfo(info []CommitteeInfo)

func (*Block) SetEvidenceDataHash

func (b *Block) SetEvidenceDataHash(hash meter.Bytes32) error

func (*Block) SetKBlockData

func (b *Block) SetKBlockData(data KBlockData) error

func (*Block) SetMagic

func (b *Block) SetMagic(m [4]byte) *Block

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

func (*Block) SetQC

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

func (*Block) Signer added in v1.2.0

func (b *Block) Signer() (signer meter.Address, err error)

func (*Block) Size

func (b *Block) Size() metric.StorageSize

Size returns block size in bytes.

func (*Block) StateRoot added in v1.2.0

func (b *Block) StateRoot() meter.Bytes32

StateRoot returns account state merkle root just afert this block being applied.

func (*Block) String

func (b *Block) String() string

func (*Block) Timestamp added in v1.2.0

func (b *Block) Timestamp() uint64

Timestamp returns timestamp of this block.

func (*Block) ToBytes

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

func (*Block) TotalScore added in v1.2.0

func (b *Block) TotalScore() uint64

TotalScore returns total score that cumulated from genesis block to this one.

func (*Block) Transactions

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

Transactions returns a copy of transactions.

func (*Block) TxsRoot added in v1.2.0

func (b *Block) TxsRoot() meter.Bytes32

TxsRoot returns merkle root of txs contained in this block.

func (*Block) WithSignature

func (b *Block) WithSignature(sig []byte) *Block

WithSignature create a new block object with signature set.

type Body

type Body struct {
	Txs tx.Transactions
}

Body defines body of a block.

type Builder

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

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

func (b *Builder) Beneficiary(addr meter.Address) *Builder

Beneficiary set recipient of reward.

func (*Builder) BlockType

func (b *Builder) BlockType(t uint32) *Builder

BlockType set block type BLOCK_TYPE_K_BLOCK/BLOCK_TYPE_M_BLOCK.

func (*Builder) Build

func (b *Builder) Build() *Block

Build build a block object.

func (*Builder) GasLimit

func (b *Builder) GasLimit(limit uint64) *Builder

GasLimit set gas limit.

func (*Builder) GasUsed

func (b *Builder) GasUsed(used uint64) *Builder

GasUsed set gas used.

func (*Builder) LastKBlockHeight

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

LastKBlockID set last KBlock id.

func (*Builder) ParentID

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

ParentID set parent id.

func (*Builder) ReceiptsRoot

func (b *Builder) ReceiptsRoot(hash meter.Bytes32) *Builder

ReceiptsRoot set receipts root.

func (*Builder) StateRoot

func (b *Builder) StateRoot(hash meter.Bytes32) *Builder

StateRoot set state root.

func (*Builder) Timestamp

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

Timestamp set timestamp.

func (*Builder) TotalScore

func (b *Builder) TotalScore(score uint64) *Builder

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

func NewEvidence

func NewEvidence(votingSig []byte, votingMsgHash [][32]byte, votingBA cmn.BitArray,
	notarizeSig []byte, notarizeMsgHash [][32]byte, notarizeBA cmn.BitArray) *Evidence

Create new Evidence

type GasLimit

type GasLimit uint64

GasLimit to support block gas limit validation and adjustment.

func (GasLimit) Adjust

func (gl GasLimit) Adjust(delta int64) uint64

Adjust suppose the receiver is parent gas limit, and calculate a valid gas limit value by apply `delta`.

func (GasLimit) IsValid

func (gl GasLimit) IsValid(parentGasLimit uint64) bool

IsValid returns if the receiver is valid according to parent gas limit.

func (GasLimit) Qualify

func (gl GasLimit) Qualify(parentGasLimit uint64) uint64

Qualify qualify the receiver according to parent gas limit, and returns the qualified gas limit value.

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

func (h *Header) Beneficiary() meter.Address

Beneficiary returns reward recipient.

func (*Header) BlockType

func (h *Header) BlockType() uint32

BlockType returns block type of this block.

func (*Header) EvidenceDataRoot

func (h *Header) EvidenceDataRoot() meter.Bytes32

EvidenceDataRoot returns merkle root of tx receipts.

func (*Header) GasLimit

func (h *Header) GasLimit() uint64

GasLimit returns gas limit of this block.

func (*Header) GasUsed

func (h *Header) GasUsed() uint64

GasUsed returns gas used by txs.

func (*Header) ID

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

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

func (*Header) LastKBlockHeight

func (h *Header) LastKBlockHeight() uint32

LastBlocID returns id of parent block.

func (*Header) Number

func (h *Header) Number() uint32

Number returns sequential number of this block.

func (*Header) ParentID

func (h *Header) ParentID() meter.Bytes32

ParentID returns id of parent block.

func (*Header) ReceiptsRoot

func (h *Header) ReceiptsRoot() meter.Bytes32

ReceiptsRoot returns merkle root of tx receipts.

func (*Header) Signature

func (h *Header) Signature() []byte

Signature returns signature.

func (*Header) Signer

func (h *Header) Signer() (signer meter.Address, err error)

Signer extract signer of the block from signature.

func (*Header) SigningHash

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

SigningHash computes hash of all header fields excluding signature.

func (*Header) StateRoot

func (h *Header) StateRoot() meter.Bytes32

StateRoot returns account state merkle root just afert this block being applied.

func (*Header) String

func (h *Header) String() string

func (*Header) Timestamp

func (h *Header) Timestamp() uint64

Timestamp returns timestamp of this block.

func (*Header) TotalScore

func (h *Header) TotalScore() uint64

TotalScore returns total score that cumulated from genesis block to this one.

func (*Header) TxsRoot

func (h *Header) TxsRoot() meter.Bytes32

TxsRoot returns merkle root of txs contained in this block.

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

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.

type Violation

type Violation struct {
	Type       int
	Index      int
	Address    meter.Address
	MsgHash    [32]byte
	Signature1 []byte
	Signature2 []byte
}

Jump to

Keyboard shortcuts

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