chain

package
v1.2.0-fork5-fix5 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2022 License: LGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBlockExist = errors.New("block already exists")

Functions

This section is empty.

Types

type Block

type Block struct {
	*block.Block
	Obsolete bool
}

Block expanded block.Block to indicate whether it is obsolete

type BlockReader

type BlockReader interface {
	Read() ([]*Block, error)
}

BlockReader defines the interface to read Block

type Chain

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

Chain describes a persistent block chain. It's thread-safe.

func New

func New(kv kv.GetPutter, genesisBlock *block.Block, verbose bool) (*Chain, error)

New create an instance of Chain.

func (*Chain) AddBlock

func (c *Chain) AddBlock(newBlock *block.Block, receipts tx.Receipts, finalize bool) (*Fork, error)

AddBlock add a new block into block chain. Once reorg happened (len(Trunk) > 0 && len(Branch) >0), Fork.Branch will be the chain transitted from trunk to branch. Reorg happens when isTrunk is true.

func (*Chain) BestBlock

func (c *Chain) BestBlock() *block.Block

BestBlock returns the newest block on trunk.

func (*Chain) BestKBlock

func (c *Chain) BestKBlock() (*block.Block, error)

func (*Chain) BestQC

func (c *Chain) BestQC() *block.QuorumCert

func (*Chain) BestQCCandidate

func (c *Chain) BestQCCandidate() *block.QuorumCert

func (*Chain) BestQCOrCandidate

func (c *Chain) BestQCOrCandidate() *block.QuorumCert

func (*Chain) FindEpochOnBlock added in v1.2.0

func (c *Chain) FindEpochOnBlock(num uint32) (uint64, error)

func (*Chain) GenesisBlock

func (c *Chain) GenesisBlock() *block.Block

GenesisBlock returns genesis block.

func (*Chain) GetAncestorBlockID

func (c *Chain) GetAncestorBlockID(descendantID meter.Bytes32, ancestorNum uint32) (meter.Bytes32, error)

GetAncestorBlockID get ancestor block ID of descendant for given ancestor block.

func (*Chain) GetBestQCCandidate

func (c *Chain) GetBestQCCandidate() *block.QuorumCert

func (*Chain) GetBlock

func (c *Chain) GetBlock(id meter.Bytes32) (*block.Block, error)

GetBlock get block by id.

func (*Chain) GetBlockBody

func (c *Chain) GetBlockBody(id meter.Bytes32) (*block.Body, error)

GetBlockBody get block body by block id.

func (*Chain) GetBlockHeader

func (c *Chain) GetBlockHeader(id meter.Bytes32) (*block.Header, error)

GetBlockHeader get block header by block id.

func (*Chain) GetBlockRaw

func (c *Chain) GetBlockRaw(id meter.Bytes32) (block.Raw, error)

GetBlockRaw get block rlp encoded bytes for given id. Never modify the returned raw block.

func (*Chain) GetBlockReceipts

func (c *Chain) GetBlockReceipts(id meter.Bytes32) (tx.Receipts, error)

GetBlockReceipts get all tx receipts in the block for given block id.

func (*Chain) GetTransaction

func (c *Chain) GetTransaction(blockID meter.Bytes32, index uint64) (*tx.Transaction, error)

GetTransaction get transaction for given block and index.

func (*Chain) GetTransactionMeta

func (c *Chain) GetTransactionMeta(txID meter.Bytes32, headBlockID meter.Bytes32) (*TxMeta, error)

GetTransactionMeta get transaction meta info, on the chain defined by head block ID.

func (*Chain) GetTransactionReceipt

func (c *Chain) GetTransactionReceipt(blockID meter.Bytes32, index uint64) (*tx.Receipt, error)

GetTransactionReceipt get tx receipt for given block and index.

func (*Chain) GetTrunkBlock

func (c *Chain) GetTrunkBlock(num uint32) (*block.Block, error)

GetTrunkBlock get block on trunk by given block number.

func (*Chain) GetTrunkBlockHeader

func (c *Chain) GetTrunkBlockHeader(num uint32) (*block.Header, error)

GetTrunkBlockHeader get block header on trunk by given block number.

func (*Chain) GetTrunkBlockID

func (c *Chain) GetTrunkBlockID(num uint32) (meter.Bytes32, error)

GetTrunkBlockID get block id on trunk by given block number.

func (*Chain) GetTrunkBlockRaw

func (c *Chain) GetTrunkBlockRaw(num uint32) (block.Raw, error)

GetTrunkBlockRaw get block raw on trunk by given block number.

func (*Chain) GetTrunkTransaction

func (c *Chain) GetTrunkTransaction(txID meter.Bytes32) (*tx.Transaction, *TxMeta, error)

GetTrunkTransaction get transaction on trunk by given tx id.

func (*Chain) GetTrunkTransactionMeta

func (c *Chain) GetTrunkTransactionMeta(txID meter.Bytes32) (*TxMeta, error)

GetTrunkTransactionMeta get transaction meta info on trunk by given tx id.

func (*Chain) IsBlockExist

func (c *Chain) IsBlockExist(err error) bool

IsBlockExist returns if the error means block was already in the chain.

func (*Chain) IsBlockFinalized

func (c *Chain) IsBlockFinalized(id meter.Bytes32) bool

func (*Chain) IsNotFound

func (c *Chain) IsNotFound(err error) bool

IsNotFound returns if an error means not found.

func (*Chain) LeafBlock

func (c *Chain) LeafBlock() *block.Block

func (*Chain) NewBlockReader

func (c *Chain) NewBlockReader(position meter.Bytes32) BlockReader

NewBlockReader generate an object that implements the BlockReader interface

func (*Chain) NewSeeker

func (c *Chain) NewSeeker(headBlockID meter.Bytes32) *Seeker

NewSeeker returns a new seeker instance.

func (*Chain) NewTicker

func (c *Chain) NewTicker() co.Waiter

NewTicker create a signal Waiter to receive event of head block change.

func (*Chain) RemoveBlock

func (c *Chain) RemoveBlock(blockID meter.Bytes32) error

func (*Chain) SetBestQCCandidate

func (c *Chain) SetBestQCCandidate(qc *block.QuorumCert) bool

func (*Chain) SetBestQCCandidateWithChainLock

func (c *Chain) SetBestQCCandidateWithChainLock(qc *block.QuorumCert) bool

func (*Chain) Tag

func (c *Chain) Tag() byte

Tag returns chain tag, which is the last byte of genesis id.

func (*Chain) UpdateBestQC

func (c *Chain) UpdateBestQC(qc *block.QuorumCert, source QCSource) (bool, error)

func (*Chain) UpdateBestQCWithChainLock

func (c *Chain) UpdateBestQCWithChainLock(qc *block.QuorumCert, source QCSource) (bool, error)

func (*Chain) UpdateLeafBlock

func (c *Chain) UpdateLeafBlock() error

type Fork

type Fork struct {
	Ancestor *block.Header
	Trunk    []*block.Header
	Branch   []*block.Header
}

Fork describes forked chain.

type QCSource

type QCSource int
const (
	None           QCSource = 0
	RcvedQC        QCSource = 1
	LocalCommit    QCSource = 2
	LocalBestQC    QCSource = 3
	LocalBestBlock QCSource = 4
	LocalCandidate QCSource = 5
)

func (QCSource) String

func (s QCSource) String() string

type QCWrap

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

type Seeker

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

Seeker to seek block by given number on the chain defined by head block ID.

func (*Seeker) Err

func (s *Seeker) Err() error

Err returns error occurred.

func (*Seeker) GenesisID

func (s *Seeker) GenesisID() meter.Bytes32

GenesisID get genesis block ID.

func (*Seeker) GetHeader

func (s *Seeker) GetHeader(id meter.Bytes32) *block.Header

GetHeader returns block header by the given number.

func (*Seeker) GetID

func (s *Seeker) GetID(num uint32) meter.Bytes32

GetID returns block ID by the given number.

type TxMeta

type TxMeta struct {
	BlockID meter.Bytes32

	// Index the position of the tx in block's txs.
	Index uint64 // rlp require uint64.

	Reverted bool
}

TxMeta contains information about a tx is settled.

Jump to

Keyboard shortcuts

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