Documentation
¶
Index ¶
Constants ¶
This section is empty.
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") )
Functions ¶
func ProductivityByEpoch ¶ added in v0.11.0
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 TODO: move to poll protocol and implement reading current epoch meta from state factory -- now only reading current epoch productivity
Types ¶
type ActPoolManager ¶ added in v0.10.0
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 ¶ added in v0.11.0
type BlockBuilderFactory interface {
// NewBlockBuilder creates block builder
NewBlockBuilder(context.Context, map[string][]action.SealedEnvelope, []action.SealedEnvelope) (*block.Builder, error)
}
BlockBuilderFactory is the factory interface of block builder
type BlockCreationSubscriber ¶ added in v0.4.4
BlockCreationSubscriber is an interface which will get notified when a block is created
type Blockchain ¶
type Blockchain interface {
lifecycle.StartStopper
// For exposing blockchain states
// BlockHeaderByHeight return block header by height
BlockHeaderByHeight(height uint64) (*block.Header, error)
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 ¶
func NewBlockchain(cfg config.Config, dao blockdao.BlockDAO, sf factory.Factory, opts ...Option) Blockchain
NewBlockchain creates a new blockchain and DB instance TODO: replace sf with blockbuilderfactory
type Option ¶ added in v0.3.0
Option sets blockchain construction parameter
func BlockValidatorOption ¶ added in v0.11.0
BlockValidatorOption sets block validator
func BoltDBDaoOption ¶ added in v0.3.0
func BoltDBDaoOption() Option
BoltDBDaoOption sets blockchain's dao with BoltDB from config.Chain.ChainDBPath
func ClockOption ¶ added in v0.3.0
ClockOption overrides the default clock
func InMemDaoOption ¶ added in v0.3.0
func InMemDaoOption() Option
InMemDaoOption sets blockchain's dao with MemKVStore
func RegistryOption ¶ added in v0.5.0
RegistryOption sets the blockchain with the protocol registry
type PubSubManager ¶ added in v0.11.0
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 ¶ added in v0.11.0
func NewPubSub(bufferSize uint64) PubSubManager
NewPubSub creates new pubSub struct with buffersize for pendingBlock buffer channel