Documentation
¶
Index ¶
- type DeleteCallback
- type HeaderTree
- func (t *HeaderTree) AddHeader(node types.HeaderIntf) bool
- func (t *HeaderTree) Children() *list.List
- func (t *HeaderTree) FindHeader(node types.HeaderIntf, compare func(n1, n2 types.HeaderIntf) bool) *HeaderTree
- func (t *HeaderTree) GetCount() int
- func (t *HeaderTree) GetMaxTdPath(node types.HeaderIntf) *HeaderTree
- func (t *HeaderTree) Header() types.HeaderIntf
- func (t *HeaderTree) Iterator(deepFirst bool, proc func(node types.HeaderIntf) bool)
- func (t *HeaderTree) MergeTree(newT *HeaderTree) bool
- func (t *HeaderTree) Parent() *HeaderTree
- func (t *HeaderTree) Remove(node types.HeaderIntf, removeHeader bool)
- func (t *HeaderTree) RemoveByHash(hash common.Hash, deleteSelf bool)
- func (t *HeaderTree) ShrinkToBranch(node types.HeaderIntf) *HeaderTree
- type HeaderTreeManager
- func (t *HeaderTreeManager) AddNewHead(node types.HeaderIntf)
- func (t *HeaderTreeManager) AddNewHeads(nodes []types.HeaderIntf) []types.HeaderIntf
- func (t *HeaderTreeManager) GetMaxTd() (*types.ShardBlockInfo, error)
- func (t *HeaderTreeManager) GetPendingCount() int
- func (t *HeaderTreeManager) GetTd(header types.HeaderIntf) uint64
- func (t *HeaderTreeManager) Pending() []types.HeaderIntf
- func (t *HeaderTreeManager) ReduceTo(node types.HeaderIntf) error
- func (t *HeaderTreeManager) RemoveHead(node types.HeaderIntf)
- func (t *HeaderTreeManager) RemoveHeadByHash(hash common.Hash)
- func (t *HeaderTreeManager) SetConfirmed(head types.HeaderIntf) []types.HeaderIntf
- func (t *HeaderTreeManager) SetRootHash(hash common.Hash)
- func (t *HeaderTreeManager) TreeOf(hash common.Hash) *HeaderTree
- func (t *HeaderTreeManager) Trees() map[common.Hash]*HeaderTree
- type PendingShard
- type QHeaderChain
- func (hc *QHeaderChain) Config() *params.ChainConfig
- func (hc *QHeaderChain) CurrentHeader() types.HeaderIntf
- func (hc *QHeaderChain) Engine() consensus.Engine
- func (hc *QHeaderChain) GetAncestor(hash common.Hash, number, ancestor uint64, maxNonCanonical *uint64) (common.Hash, uint64)
- func (hc *QHeaderChain) GetBlock(hash common.Hash, number uint64) types.BlockIntf
- func (hc *QHeaderChain) GetBlockHashesFromHash(hash common.Hash, max uint64) []common.Hash
- func (hc *QHeaderChain) GetBlockNumber(hash common.Hash) *uint64
- func (hc *QHeaderChain) GetHeader(hash common.Hash, number uint64) types.HeaderIntf
- func (hc *QHeaderChain) GetHeaderByHash(hash common.Hash) types.HeaderIntf
- func (hc *QHeaderChain) GetHeaderByNumber(number uint64) types.HeaderIntf
- func (hc *QHeaderChain) GetTd(hash common.Hash, number uint64) *big.Int
- func (hc *QHeaderChain) GetTdByHash(hash common.Hash) *big.Int
- func (hc *QHeaderChain) HasHeader(hash common.Hash, number uint64) bool
- func (hc *QHeaderChain) InsertHeaderChain(chain []types.HeaderIntf, start time.Time) ([]types.HeaderIntf, error)
- func (hc *QHeaderChain) SetCacheHeader(header types.HeaderIntf)
- func (hc *QHeaderChain) SetCurrentHeader(head types.HeaderIntf)
- func (hc *QHeaderChain) SetGenesis(head types.HeaderIntf)
- func (hc *QHeaderChain) SetHead(head uint64, delFn DeleteCallback)
- func (hc *QHeaderChain) ShardId() uint16
- func (hc *QHeaderChain) ValidateHeader(chain []types.HeaderIntf, checkFreq int) (int, error)
- func (hc *QHeaderChain) WriteConfirmedHeader(header types.HeaderIntf) error
- func (hc *QHeaderChain) WriteHeaderToDb(header types.HeaderIntf) error
- func (hc *QHeaderChain) WriteTd(hash common.Hash, number uint64, td *big.Int) error
- type ShardChainPool
- func (scp *ShardChainPool) GetAncestor(hash common.Hash, number, ancestor uint64, maxNonCanonical *uint64, ...) (common.Hash, uint64)
- func (scp *ShardChainPool) GetBlock(hash common.Hash, number uint64) *types.SBlock
- func (scp *ShardChainPool) GetBlockByHash(hash common.Hash, shardId uint16) *types.SBlock
- func (scp *ShardChainPool) GetHeaderByHash(hash common.Hash, shardId uint16) types.HeaderIntf
- func (scp *ShardChainPool) GetHeaderByNumber(number uint64, shardId uint16) types.HeaderIntf
- func (scp *ShardChainPool) GetMaxTds() map[uint16]types.ShardBlockInfo
- func (scp *ShardChainPool) InsertChain(blocks types.BlockIntfs) error
- func (scp *ShardChainPool) Pending() (map[uint16]PendingShard, error)
- func (scp *ShardChainPool) Stop()
- func (scp *ShardChainPool) SubscribeChainShardsEvent(newShardCh chan *core.ChainsShardEvent) event.Subscription
- func (scp *ShardChainPool) SubscribeMasterHeadProcsEvent(newMasterProcCh chan core.ChainHeadEvent) event.Subscription
- type SortHead
- type WhCallback
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DeleteCallback ¶
type DeleteCallback func(rawdb.DatabaseDeleter, common.Hash, uint64)
DeleteCallback is a callback function that is called by SetHead before each header is deleted.
type HeaderTree ¶
type HeaderTree struct {
// contains filtered or unexported fields
}
func NewHeaderTree ¶
func NewHeaderTree(root types.HeaderIntf, owner *HeaderTreeManager) *HeaderTree
func (*HeaderTree) AddHeader ¶
func (t *HeaderTree) AddHeader(node types.HeaderIntf) bool
func (*HeaderTree) Children ¶
func (t *HeaderTree) Children() *list.List
func (*HeaderTree) FindHeader ¶
func (t *HeaderTree) FindHeader(node types.HeaderIntf, compare func(n1, n2 types.HeaderIntf) bool) *HeaderTree
func (*HeaderTree) GetCount ¶
func (t *HeaderTree) GetCount() int
func (*HeaderTree) GetMaxTdPath ¶
func (t *HeaderTree) GetMaxTdPath(node types.HeaderIntf) *HeaderTree
find a max td path on node's branch, if node is nil find max of all
func (*HeaderTree) Header ¶
func (t *HeaderTree) Header() types.HeaderIntf
func (*HeaderTree) Iterator ¶
func (t *HeaderTree) Iterator(deepFirst bool, proc func(node types.HeaderIntf) bool)
using routine "proc" to iterate all node, it breaks when "proc" return true
func (*HeaderTree) MergeTree ¶
func (t *HeaderTree) MergeTree(newT *HeaderTree) bool
func (*HeaderTree) Parent ¶
func (t *HeaderTree) Parent() *HeaderTree
func (*HeaderTree) Remove ¶
func (t *HeaderTree) Remove(node types.HeaderIntf, removeHeader bool)
func (*HeaderTree) RemoveByHash ¶
func (t *HeaderTree) RemoveByHash(hash common.Hash, deleteSelf bool)
func (*HeaderTree) ShrinkToBranch ¶
func (t *HeaderTree) ShrinkToBranch(node types.HeaderIntf) *HeaderTree
cut all branch's except root by node ,return a HeaderTree with node as root
type HeaderTreeManager ¶
type HeaderTreeManager struct {
// contains filtered or unexported fields
}
func NewHeaderTreeManager ¶
func NewHeaderTreeManager(shardId uint16, database ethdb.Database) *HeaderTreeManager
func (*HeaderTreeManager) AddNewHead ¶
func (t *HeaderTreeManager) AddNewHead(node types.HeaderIntf)
func (*HeaderTreeManager) AddNewHeads ¶
func (t *HeaderTreeManager) AddNewHeads(nodes []types.HeaderIntf) []types.HeaderIntf
add new BLock to tree, if more than 6 blocks has reached, a new block will popup to shard_pool if the node can not be add to any existing tree, a new tree will be established
func (*HeaderTreeManager) GetMaxTd ¶
func (t *HeaderTreeManager) GetMaxTd() (*types.ShardBlockInfo, error)
func (*HeaderTreeManager) GetPendingCount ¶
func (t *HeaderTreeManager) GetPendingCount() int
func (*HeaderTreeManager) GetTd ¶
func (t *HeaderTreeManager) GetTd(header types.HeaderIntf) uint64
func (*HeaderTreeManager) Pending ¶
func (t *HeaderTreeManager) Pending() []types.HeaderIntf
func (*HeaderTreeManager) ReduceTo ¶
func (t *HeaderTreeManager) ReduceTo(node types.HeaderIntf) error
cut all node, only tree from node survived
func (*HeaderTreeManager) RemoveHead ¶
func (t *HeaderTreeManager) RemoveHead(node types.HeaderIntf)
remove shard block with given hash, do nothing if the block does not exist
func (*HeaderTreeManager) RemoveHeadByHash ¶
func (t *HeaderTreeManager) RemoveHeadByHash(hash common.Hash)
func (*HeaderTreeManager) SetConfirmed ¶
func (t *HeaderTreeManager) SetConfirmed(head types.HeaderIntf) []types.HeaderIntf
func (*HeaderTreeManager) SetRootHash ¶
func (t *HeaderTreeManager) SetRootHash(hash common.Hash)
func (*HeaderTreeManager) TreeOf ¶
func (t *HeaderTreeManager) TreeOf(hash common.Hash) *HeaderTree
func (*HeaderTreeManager) Trees ¶
func (t *HeaderTreeManager) Trees() map[common.Hash]*HeaderTree
type PendingShard ¶
type PendingShard map[uint64]types.ShardBlockInfo
type QHeaderChain ¶
type QHeaderChain struct {
// contains filtered or unexported fields
}
QHeaderChain implements the basic block header chain logic that is shared by core.BlockChain and light.LightChain. It is not usable in itself, only as a part of either structure. It is not thread safe either, the encapsulating chain structures should do the necessary mutex locking/unlocking.
func NewQHeaderChain ¶
func NewQHeaderChain(chainDb ethdb.Database, config *params.ChainConfig, engine consensus.Engine, procInterrupt func() bool, shardId uint16) (*QHeaderChain, error)
NewQHeaderChain creates a new QHeaderChain structure.
getValidator should return the parent's validator procInterrupt points to the parent's interrupt semaphore wg points to the parent's shutdown wait group
func (*QHeaderChain) Config ¶
func (hc *QHeaderChain) Config() *params.ChainConfig
Config retrieves the header chain's chain configuration.
func (*QHeaderChain) CurrentHeader ¶
func (hc *QHeaderChain) CurrentHeader() types.HeaderIntf
CurrentHeader retrieves the current head header of the canonical chain. The header is retrieved from the QHeaderChain's internal cache.
func (*QHeaderChain) Engine ¶
func (hc *QHeaderChain) Engine() consensus.Engine
Engine retrieves the header chain's consensus engine.
func (*QHeaderChain) GetAncestor ¶
func (hc *QHeaderChain) GetAncestor(hash common.Hash, number, ancestor uint64, maxNonCanonical *uint64) (common.Hash, uint64)
GetAncestor retrieves the Nth ancestor of a given block. It assumes that either the given block or a close ancestor of it is canonical. maxNonCanonical points to a downwards counter limiting the number of blocks to be individually checked before we reach the canonical chain.
Note: ancestor == 0 returns the same block, 1 returns its parent and so on.
func (*QHeaderChain) GetBlock ¶
GetBlock implements consensus.ChainReader, and returns nil for every input as a header chain does not have blocks available for retrieval.
func (*QHeaderChain) GetBlockHashesFromHash ¶
GetBlockHashesFromHash retrieves a number of block hashes starting at a given hash, fetching towards the genesis block.
func (*QHeaderChain) GetBlockNumber ¶
func (hc *QHeaderChain) GetBlockNumber(hash common.Hash) *uint64
GetBlockNumber retrieves the block number belonging to the given hash from the cache or database
func (*QHeaderChain) GetHeader ¶
func (hc *QHeaderChain) GetHeader(hash common.Hash, number uint64) types.HeaderIntf
GetHeader retrieves a block header from the database by hash and number, caching it if found.
func (*QHeaderChain) GetHeaderByHash ¶
func (hc *QHeaderChain) GetHeaderByHash(hash common.Hash) types.HeaderIntf
GetHeaderByHash retrieves a block header from the database by hash, caching it if found.
func (*QHeaderChain) GetHeaderByNumber ¶
func (hc *QHeaderChain) GetHeaderByNumber(number uint64) types.HeaderIntf
GetHeaderByNumber retrieves a block header from the database by number, caching it (associated with its hash) if found.
func (*QHeaderChain) GetTd ¶
GetTd retrieves a block's total difficulty in the canonical chain from the database by hash and number, caching it if found.
func (*QHeaderChain) GetTdByHash ¶
func (hc *QHeaderChain) GetTdByHash(hash common.Hash) *big.Int
GetTdByHash retrieves a block's total difficulty in the canonical chain from the database by hash, caching it if found.
func (*QHeaderChain) HasHeader ¶
func (hc *QHeaderChain) HasHeader(hash common.Hash, number uint64) bool
HasHeader checks if a block header is present in the database or not.
func (*QHeaderChain) InsertHeaderChain ¶
func (hc *QHeaderChain) InsertHeaderChain(chain []types.HeaderIntf, start time.Time) ([]types.HeaderIntf, error)
func (*QHeaderChain) SetCacheHeader ¶
func (hc *QHeaderChain) SetCacheHeader(header types.HeaderIntf)
GetHeader retrieves a block header from the database by hash and number, caching it if found.
func (*QHeaderChain) SetCurrentHeader ¶
func (hc *QHeaderChain) SetCurrentHeader(head types.HeaderIntf)
SetCurrentHeader sets the current head header of the canonical chain.
func (*QHeaderChain) SetGenesis ¶
func (hc *QHeaderChain) SetGenesis(head types.HeaderIntf)
SetGenesis sets a new genesis block header for the chain
func (*QHeaderChain) SetHead ¶
func (hc *QHeaderChain) SetHead(head uint64, delFn DeleteCallback)
SetHead rewinds the local chain to a new head. Everything above the new head will be deleted and the new one set.
func (*QHeaderChain) ShardId ¶
func (hc *QHeaderChain) ShardId() uint16
func (*QHeaderChain) ValidateHeader ¶
func (hc *QHeaderChain) ValidateHeader(chain []types.HeaderIntf, checkFreq int) (int, error)
func (*QHeaderChain) WriteConfirmedHeader ¶
func (hc *QHeaderChain) WriteConfirmedHeader(header types.HeaderIntf) error
WriteHeader writes a header into the local chain, given that its parent is already known. If the total difficulty of the newly inserted header becomes greater than the current known TD, the canonical chain is re-routed.
Note: This method is not concurrent-safe with inserting blocks simultaneously into the chain, as side effects caused by reorganisations cannot be emulated without the real blocks. Hence, writing headers directly should only be done in two scenarios: pure-header mode of operation (light clients), or properly separated header/block phases (non-archive clients).
func (*QHeaderChain) WriteHeaderToDb ¶
func (hc *QHeaderChain) WriteHeaderToDb(header types.HeaderIntf) error
type ShardChainPool ¶
type ShardChainPool struct {
// contains filtered or unexported fields
}
func NewShardChainPool ¶
func NewShardChainPool(bc *core.BlockChain, database ethdb.Database) *ShardChainPool
func (*ShardChainPool) GetAncestor ¶
func (*ShardChainPool) GetBlockByHash ¶
func (*ShardChainPool) GetHeaderByHash ¶
func (scp *ShardChainPool) GetHeaderByHash(hash common.Hash, shardId uint16) types.HeaderIntf
func (*ShardChainPool) GetHeaderByNumber ¶
func (scp *ShardChainPool) GetHeaderByNumber(number uint64, shardId uint16) types.HeaderIntf
func (*ShardChainPool) GetMaxTds ¶
func (scp *ShardChainPool) GetMaxTds() map[uint16]types.ShardBlockInfo
* return all max Tds block info of shard
func (*ShardChainPool) InsertChain ¶
func (scp *ShardChainPool) InsertChain(blocks types.BlockIntfs) error
func (*ShardChainPool) Pending ¶
func (scp *ShardChainPool) Pending() (map[uint16]PendingShard, error)
miner's worker uses Pending to retrieve shardblockInfos which could be packed into master block
func (*ShardChainPool) Stop ¶
func (scp *ShardChainPool) Stop()
func (*ShardChainPool) SubscribeChainShardsEvent ¶
func (scp *ShardChainPool) SubscribeChainShardsEvent(newShardCh chan *core.ChainsShardEvent) event.Subscription
func (*ShardChainPool) SubscribeMasterHeadProcsEvent ¶
func (scp *ShardChainPool) SubscribeMasterHeadProcsEvent(newMasterProcCh chan core.ChainHeadEvent) event.Subscription
type SortHead ¶
type SortHead []types.HeaderIntf
type WhCallback ¶
type WhCallback func(types.HeaderIntf) error
WhCallback is a callback function for inserting individual headers. A callback is used for two reasons: first, in a LightChain, status should be processed and light chain events sent, while in a BlockChain this is not necessary since chain events are sent after inserting blocks. Second, the header writes should be protected by the parent chain mutex individually.