iotex-core: github.com/iotexproject/iotex-core/blockchain Index | Files | Directories

package blockchain

import "github.com/iotexproject/iotex-core/blockchain"

Index

Package Files

blockchain.go blockcreationsubscriber.go blockvalidator.go

Variables

var (
    // ErrInvalidTipHeight is the error returned when the block height is not valid
    ErrInvalidTipHeight = errors.New("invalid tip height")
    // ErrInvalidBlock is the error returned when the block is not valid
    ErrInvalidBlock = errors.New("failed to validate the block")
    // ErrActionNonce is the error when the nonce of the action is wrong
    ErrActionNonce = errors.New("invalid action nonce")
    // ErrInsufficientGas indicates the error of insufficient gas value for data storage
    ErrInsufficientGas = errors.New("insufficient intrinsic gas value")
    // ErrBalance indicates the error of balance
    ErrBalance = errors.New("invalid balance")
)

func ProductivityByEpoch Uses

func ProductivityByEpoch(ctx context.Context, bc Blockchain, epochNum uint64) (uint64, map[string]uint64, error)

ProductivityByEpoch returns the map of the number of blocks produced per delegate in an epoch

type ActPoolManager Uses

type ActPoolManager interface {
    // GetActionByHash returns the pending action in pool given action's hash
    GetActionByHash(hash hash.Hash256) (action.SealedEnvelope, error)
}

ActPoolManager defines the actpool interface

type BlockCreationSubscriber Uses

type BlockCreationSubscriber interface {
    HandleBlock(*block.Block) error
}

BlockCreationSubscriber is an interface which will get notified when a block is created

type Blockchain Uses

type Blockchain interface {
    lifecycle.StartStopper

    // BlockHeaderByHeight return block header by height
    BlockHeaderByHeight(height uint64) (*block.Header, error)
    // BlockHeaderByHash return block header by hash
    BlockHeaderByHash(h hash.Hash256) (*block.Header, error)
    // BlockFooterByHeight return block footer by height
    BlockFooterByHeight(height uint64) (*block.Footer, error)
    // BlockFooterByHash return block footer by hash
    BlockFooterByHash(h hash.Hash256) (*block.Footer, error)
    // BlockDAO returns the block dao
    BlockDAO() blockdao.BlockDAO
    // ChainID returns the chain ID
    ChainID() uint32
    // ChainAddress returns chain address on parent chain, the root chain return empty.
    ChainAddress() string
    // TipHash returns tip block's hash
    TipHash() hash.Hash256
    // TipHeight returns tip block's height
    TipHeight() uint64
    // Genesis returns the genesis
    Genesis() genesis.Genesis
    // Context returns current context
    Context() (context.Context, error)

    // For block operations
    // MintNewBlock creates a new block with given actions
    // Note: the coinbase transfer will be added to the given transfers when minting a new block
    MintNewBlock(
        actionMap map[string][]action.SealedEnvelope,
        timestamp time.Time,
    ) (*block.Block, error)
    // CommitBlock validates and appends a block to the chain
    CommitBlock(blk *block.Block) error
    // ValidateBlock validates a new block before adding it to the blockchain
    ValidateBlock(blk *block.Block) error

    // For action operations
    // Validator returns the current validator object
    Validator() Validator
    // SetValidator sets the current validator object
    SetValidator(val Validator)

    // AddSubscriber make you listen to every single produced block
    AddSubscriber(BlockCreationSubscriber) error

    // RemoveSubscriber make you listen to every single produced block
    RemoveSubscriber(BlockCreationSubscriber) error
}

Blockchain represents the blockchain data structure and hosts the APIs to access it

func NewBlockchain Uses

func NewBlockchain(cfg config.Config, dao blockdao.BlockDAO, sf factory.Factory, opts ...Option) Blockchain

NewBlockchain creates a new blockchain and DB instance

type Option Uses

type Option func(*blockchain, config.Config) error

Option sets blockchain construction parameter

func BoltDBDaoOption Uses

func BoltDBDaoOption() Option

BoltDBDaoOption sets blockchain's dao with BoltDB from config.Chain.ChainDBPath

func ClockOption Uses

func ClockOption(clk clock.Clock) Option

ClockOption overrides the default clock

func InMemDaoOption Uses

func InMemDaoOption() Option

InMemDaoOption sets blockchain's dao with MemKVStore

func RegistryOption Uses

func RegistryOption(registry *protocol.Registry) Option

RegistryOption sets the blockchain with the protocol registry

type Validator Uses

type Validator interface {
    // Validate validates the given block's content
    Validate(ctx context.Context, block *block.Block) error
    // AddActionEnvelopeValidators add validators
    AddActionEnvelopeValidators(...protocol.ActionEnvelopeValidator)

    // SetActPool set ActPoolManager
    SetActPool(actPool ActPoolManager)
}

Validator is the interface of validator

Directories

PathSynopsis
block
blockdao
genesis

Package blockchain imports 31 packages (graph) and is imported by 10 packages. Updated 2019-12-08. Refresh now. Tools for package owners.