chain

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound   = errors.New("not found")
	ErrBlockExist = errors.New("block already exists")
	ErrQCMismatch = errors.New("QC mismatch")
	ErrEmptyDraft = errors.New("empty draft")
)
View Source
var ErrInvalidGenesis = errors.New("invalid genesis")

Functions

func BlockMatchDraftQC

func BlockMatchDraftQC(b *block.DraftBlock, escortQC *block.QuorumCert) bool

qc is for that block? blk is derived from DraftBlock message. pass it in if already decoded

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 db.DB, verbose bool) (*Chain, error)

New create an instance of Chain.

func (*Chain) AddBlock

func (c *Chain) AddBlock(newBlock *block.Block, escortQC *block.QuorumCert) (*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) AddDraft

func (c *Chain) AddDraft(b *block.DraftBlock)

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

func (c *Chain) BuildLastCommitInfo(parent *block.Block, blk *block.Block) abci.CommitInfo

BuildLastCommitInfo builds a CommitInfo from the given block and validator set. If you want to load the validator set from the store instead of providing it, use buildLastCommitInfoFromStore.

func (*Chain) DraftLen

func (c *Chain) DraftLen() int

func (*Chain) FindEpochOnBlock

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 types.Bytes32, ancestorNum uint32) (types.Bytes32, error)

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

func (*Chain) GetBestNextValidatorSet

func (c *Chain) GetBestNextValidatorSet() *cmttypes.ValidatorSet

func (*Chain) GetBestValidatorSet

func (c *Chain) GetBestValidatorSet() *cmttypes.ValidatorSet

func (*Chain) GetBlock

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

GetBlock get block by id.

func (*Chain) GetBlockBody

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

GetBlockBody get block body by block id.

func (*Chain) GetBlockHeader

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

GetBlockHeader get block header by block id.

func (*Chain) GetBlockRaw

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

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

func (*Chain) GetDraft

func (c *Chain) GetDraft(blkID types.Bytes32) *block.DraftBlock

func (*Chain) GetDraftByEscortQC

func (c *Chain) GetDraftByEscortQC(qc *block.QuorumCert) *block.DraftBlock

func (*Chain) GetDraftByNum

func (c *Chain) GetDraftByNum(num uint32) *block.DraftBlock

func (*Chain) GetDraftByParentID

func (c *Chain) GetDraftByParentID(parentID types.Bytes32) *block.DraftBlock

func (*Chain) GetDraftsUpTo

func (c *Chain) GetDraftsUpTo(commitedBlkID types.Bytes32, qcHigh *block.QuorumCert) []*block.DraftBlock

func (*Chain) GetFinalizeBlockResponse added in v0.0.4

func (c *Chain) GetFinalizeBlockResponse(blockID types.Bytes32) (*v1.FinalizeBlockResponse, error)

func (*Chain) GetInitChainResponse added in v0.0.4

func (c *Chain) GetInitChainResponse() (*v1.InitChainResponse, error)

func (*Chain) GetNextValidatorSet

func (c *Chain) GetNextValidatorSet(num uint32) *cmttypes.ValidatorSet

func (*Chain) GetQCForBlock

func (c *Chain) GetQCForBlock(blkID types.Bytes32) (*block.QuorumCert, error)

func (*Chain) GetTransaction

func (c *Chain) GetTransaction(blockID types.Bytes32, index uint64) (cmttypes.Tx, error)

GetTransaction get transaction for given block and index.

func (*Chain) GetTransactionMeta

func (c *Chain) GetTransactionMeta(txID []byte, headBlockID types.Bytes32) (*TxMeta, error)

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

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) (types.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 []byte) (cmttypes.Tx, *TxMeta, error)

GetTrunkTransaction get transaction on trunk by given tx id.

func (*Chain) GetTrunkTransactionMeta

func (c *Chain) GetTrunkTransactionMeta(txID []byte) (*TxMeta, error)

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

func (*Chain) GetValidatorSet

func (c *Chain) GetValidatorSet(num uint32) *cmttypes.ValidatorSet

func (*Chain) GetValidatorsByHash

func (c *Chain) GetValidatorsByHash(hash cmtbytes.HexBytes) *cmttypes.ValidatorSet

FIXME: should add cache

func (*Chain) HasDraft

func (c *Chain) HasDraft(blkID types.Bytes32) bool

func (*Chain) HasTransactionMeta

func (c *Chain) HasTransactionMeta(txID []byte) (bool, error)

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

func (*Chain) Initialize added in v0.0.4

func (c *Chain) Initialize(gene *genesis.Genesis) error

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 types.Bytes32) bool

func (*Chain) IsNotFound

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

IsNotFound returns if an error means not found.

func (*Chain) NewBlockReader

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

NewBlockReader generate an object that implements the BlockReader interface

func (*Chain) NewSeeker

func (c *Chain) NewSeeker(headBlockID types.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) PruneDraftsUpTo

func (c *Chain) PruneDraftsUpTo(lastCommitted *block.DraftBlock)

func (*Chain) RawBlocksCacheLen

func (c *Chain) RawBlocksCacheLen() int

func (*Chain) SaveFinalizeBlockResponse added in v0.0.4

func (c *Chain) SaveFinalizeBlockResponse(blockID types.Bytes32, res *v1.FinalizeBlockResponse) error

func (*Chain) SaveInitChainResponse added in v0.0.4

func (c *Chain) SaveInitChainResponse(res *v1.InitChainResponse) error

func (*Chain) SaveValidatorSet

func (c *Chain) SaveValidatorSet(vset *cmttypes.ValidatorSet)

type Fork

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

Fork describes forked chain.

type ProposalMap

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

func NewProposalMap

func NewProposalMap(c *Chain) *ProposalMap

func (*ProposalMap) Add

func (p *ProposalMap) Add(blk *block.DraftBlock)

func (*ProposalMap) CleanAll

func (p *ProposalMap) CleanAll()

func (*ProposalMap) Get

func (p *ProposalMap) Get(blkID types.Bytes32) *block.DraftBlock

func (*ProposalMap) GetDraftsByNum

func (p *ProposalMap) GetDraftsByNum(num uint32) []*block.DraftBlock

func (*ProposalMap) GetDraftsByParentID

func (p *ProposalMap) GetDraftsByParentID(parentID types.Bytes32) []*block.DraftBlock

func (*ProposalMap) GetOneByEscortQC

func (p *ProposalMap) GetOneByEscortQC(qc *block.QuorumCert) *block.DraftBlock

func (*ProposalMap) GetProposalsUpTo

func (p *ProposalMap) GetProposalsUpTo(committedBlkID types.Bytes32, qcHigh *block.QuorumCert) []*block.DraftBlock

func (*ProposalMap) Has

func (p *ProposalMap) Has(blkID types.Bytes32) bool

func (*ProposalMap) Len

func (p *ProposalMap) Len() int

func (*ProposalMap) PruneUpTo

func (p *ProposalMap) PruneUpTo(lastCommitted *block.DraftBlock)

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() types.Bytes32

GenesisID get genesis block ID.

func (*Seeker) GetHeader

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

GetHeader returns block header by the given number.

func (*Seeker) GetID

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

GetID returns block ID by the given number.

type TxMeta

type TxMeta struct {
	BlockID types.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