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 pubsubmanager.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 Productivity Uses

func Productivity(bc Blockchain, startHeight uint64, endHeight uint64) (map[string]uint64, error)

Productivity returns the map of the number of blocks produced per delegate in given epoch TODO: implement reading current epoch meta from state factory

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 BlockBuilderFactory Uses

type BlockBuilderFactory interface {
    // NewBlockBuilder creates block builder
    NewBlockBuilder(context.Context, map[string][]action.SealedEnvelope, func(action.Envelope) (action.SealedEnvelope, error)) (*block.Builder, error)
}

BlockBuilderFactory is the factory interface of block builder

type BlockCreationSubscriber Uses

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

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

type Blockchain Uses

type Blockchain interface {
    lifecycle.StartStopper

    // For exposing blockchain states
    // BlockHeaderByHeight return block header by height
    BlockHeaderByHeight(height uint64) (*block.Header, error)
    // BlockFooterByHeight return block footer by height
    BlockFooterByHeight(height uint64) (*block.Footer, error)
    // 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

    // 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, bbf BlockBuilderFactory, opts ...Option) Blockchain

NewBlockchain creates a new blockchain and DB instance TODO: replace sf with blockbuilderfactory

type Option Uses

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

Option sets blockchain construction parameter

func BlockValidatorOption Uses

func BlockValidatorOption(blockValidator block.Validator) Option

BlockValidatorOption sets block validator

func BoltDBDaoOption Uses

func BoltDBDaoOption(indexers ...blockdao.BlockIndexer) 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(indexers ...blockdao.BlockIndexer) Option

InMemDaoOption sets blockchain's dao with MemKVStore

type PubSubManager Uses

type PubSubManager interface {
    AddBlockListener(BlockCreationSubscriber) error
    RemoveBlockListener(BlockCreationSubscriber) error
    SendBlockToSubscribers(*block.Block)
}

PubSubManager is an interface which handles multi-thread publisher and subscribers

func NewPubSub Uses

func NewPubSub(bufferSize uint64) PubSubManager

NewPubSub creates new pubSub struct with buffersize for pendingBlock buffer channel

Directories

PathSynopsis
block
blockdao
genesis

Package blockchain imports 21 packages (graph) and is imported by 9 packages. Updated 2020-04-05. Refresh now. Tools for package owners.