Documentation
¶
Overview ¶
Package chain contains implementations for basic chain operations.
Package chain contains implementations for basic chain operations.
Index ¶
- Constants
- Variables
- func IsReOrg(new *types.Block, oldHead *types.Block) bool
- func MaxBlockHeightAllowedToCarryThePkg(txPkgHeight uint64) uint64
- func MaxPkgHeightAllowedToPutIntoTheBlock(blockHeight uint64) uint64
- func MinBlockHeightAllowedToCarryThePkg(txPkgHeight uint64) uint64
- func MinPkgHeightAllowedToPutIntoTheBlock(blockHeight uint64) uint64
- type BlockChain
- func (bc *BlockChain) CalcAndCheckState(block *types.Block) bool
- func (bc *BlockChain) CheckBlocksReverse() ([]common.Hash, map[common.Hash]common.Hash, bool)
- func (bc *BlockChain) CheckGreedy(block *types.Block, mainBlock *types.Block, greedy uint64) (bool, error)
- func (bc *BlockChain) CheckStateFrom(block *types.Block) (common.Hash, error)
- func (bc *BlockChain) CheckStateTrieFrom(block *types.Block) common.Hash
- func (bc *BlockChain) CurrentBlock() *types.Block
- func (bc *BlockChain) Database() dbwrapper.Database
- func (bc *BlockChain) FutureBlockTxPackages(blockHash common.Hash) types.TxPackages
- func (bc *BlockChain) FutureBlocks(relatedHash common.Hash) types.Blocks
- func (bc *BlockChain) FutureTxPackageBlocks(relatedTxPackageHash common.Hash) types.Blocks
- func (bc *BlockChain) Genesis() *types.Block
- func (bc *BlockChain) GetAncestorBlocksFromBlock(hash common.Hash, depth uint64) (blocks types.Blocks)
- func (bc *BlockChain) GetBackwardBlocks(b *types.Block, num uint64) types.Blocks
- func (bc *BlockChain) GetBlock(hash common.Hash) *types.Block
- func (bc *BlockChain) GetBlockBeforeCacheHeight(block *types.Block, cacheHeight uint8) (*types.Block, bool)
- func (bc *BlockChain) GetBlockChilds(hash common.Hash) []common.Hash
- func (bc *BlockChain) GetBlockStateChecked(block *types.Block) types.BlockStateCheckedEnum
- func (bc *BlockChain) GetBlocksFromBlock(hash common.Hash, depth uint64, reverse bool) types.Blocks
- func (bc *BlockChain) GetBlocksFromBlockRange(b1 *types.Block, b2 *types.Block) types.Blocks
- func (bc *BlockChain) GetBlocksFromRoundRange(r1 uint64, r2 uint64) types.Blocks
- func (bc *BlockChain) GetBreakPoint(checkpoint *types.Block, headBlock *types.Block) (*types.Block, *types.Block, error)
- func (bc *BlockChain) GetChainConfig() *config.ChainConfig
- func (bc *BlockChain) GetChainID() uint64
- func (bc *BlockChain) GetCheckPoints() *config.CheckPoints
- func (bc *BlockChain) GetDescendantBlocksFromBlock(hash common.Hash, depth uint64) (blocks types.Blocks)
- func (bc *BlockChain) GetGreedy() uint8
- func (bc *BlockChain) GetGreedyBlocks(greedy uint8) (blocks types.Blocks)
- func (bc *BlockChain) GetHopCount(block1 *types.Block, block2 *types.Block) (uint64, error)
- func (bc *BlockChain) GetMainBranchBlock(height uint64) (*types.BlockHeader, error)
- func (bc *BlockChain) GetNearbyBlocksFromBlock(hash common.Hash, width uint64) (blocks types.Blocks)
- func (bc *BlockChain) GetPackerInfoByPubKey(blockWhenPacking *types.Block, pubKey types.PackerECPubKey) (uint32, uint32, *types.PackerInfo, error)
- func (bc *BlockChain) GetPreBalanceAndPubkey(block *types.Block, address common.Address) (uint64, []byte, error)
- func (bc *BlockChain) GetPrePackerInfoByIndex(headBlockWhenPacking *types.Block, index uint32) (*types.PackerInfo, *types.Block, error)
- func (bc *BlockChain) GetPrePackerNumber(headBlockWhenPacking *types.Block) (uint32, error)
- func (bc *BlockChain) GetRelatedBlockForFutureTxPackage(hash common.Hash) common.Hash
- func (bc *BlockChain) GetStateBeforeCacheHeight(block *types.Block, cacheHeight uint8) (*state.StateDB, *types.Block, bool)
- func (bc *BlockChain) GetTxPackage(pkgHash common.Hash) *types.TxPackage
- func (bc *BlockChain) GetTxPackageList(hashes []common.Hash) types.TxPackages
- func (bc *BlockChain) HasBlock(hash common.Hash) bool
- func (bc *BlockChain) HasTxPackage(pkgHash common.Hash) bool
- func (bc *BlockChain) InsertBlock(block *types.Block)
- func (bc *BlockChain) InsertBlockNoCheck(block *types.Block)
- func (bc *BlockChain) InsertBlockWithState(block *types.Block, state *state.StateDB, receipts types.Receipts, ...)
- func (bc *BlockChain) InsertPastBlock(block *types.Block) error
- func (bc *BlockChain) IsInMainBranch(block *types.Block) bool
- func (bc *BlockChain) IsTxPackageInFuture(hash common.Hash) bool
- func (bc *BlockChain) MinAvailablePackageHeight() (uint64, error)
- func (bc *BlockChain) PutTxPackage(txPkg *types.TxPackage)
- func (bc *BlockChain) RemoveFutureBlockTxPackage(pkgHash common.Hash)
- func (bc *BlockChain) RemoveFutureBlocks(relatedHash common.Hash)
- func (bc *BlockChain) RemoveFutureTxPackageBlocks(relatedTxPackageHash common.Hash)
- func (bc *BlockChain) SearchTransactionInCache(txHash common.Hash) (*types.Transaction, common.Hash)
- func (bc *BlockChain) SendBlockExecutedFeed(block *types.Block)
- func (bc *BlockChain) SetCurrentBlock(currentBlock *types.Block)
- func (bc *BlockChain) SetMainBranchRecordBackend(m *MainBranchRecord)
- func (bc *BlockChain) StateAt(stateHash common.Hash) (*state.StateDB, error)
- func (bc *BlockChain) SubscribeBlockExecutedEvent(ch chan<- types.BlockExecutedEvent) event.Subscription
- func (bc *BlockChain) SubscribeChainUpdateEvent(ch chan<- types.ChainUpdateEvent) event.Subscription
- func (bc *BlockChain) TrieNode(hash common.Hash) ([]byte, error)
- func (bc *BlockChain) ValidatePackage(pkg *types.TxPackage, height uint64) error
- func (bc *BlockChain) VerifyBlock(block *types.Block, checkGreedy bool) (types.Blocks, common.Hash, common.Hash, error)
- func (bc *BlockChain) VerifyBlockDepend(block *types.Block) (common.Hash, error)
- func (bc *BlockChain) VerifyTxPackage(pkg *types.TxPackage) error
- type ChainBackend
- type MainBranchRecord
- type TxInChainProcessor
Constants ¶
const ( // Minimum height delay of the transaction package entering the block MinPackageHeightDelay = 2 // Maximum height delay of the transaction package entering the block MaxPackageHeightDelay = 4 )
const (
TxVerifyParallel = 16
)
Variables ¶
var ( ErrNoGenesis = errors.New("Genesis not found in chain") ErrPackTxNotMeetSharding = errors.New("Packed transaction doesn't meet sharding rules") ErrPackTxSignError = errors.New("Packed transaction sign error") ErrMoreThanOneGenesis = errors.New("There are two different blocks with a height of 0") ErrConfirmUnknownBlock = errors.New("Confirm an unknown block") ErrBlockNotMeetGreedy = errors.New("Block doesn't meet greedy rules") ErrConfirmBlockNotMeetGreedy = errors.New("Confirmed block doesn't meet greedy rules") ErrConfirmBlockNotMeetRound = errors.New("Confirmed block doesn't meet round range") ErrNotConfirmParentBlock = errors.New("Not confirm parent block") ErrBlockHeightTooLow = errors.New("block height is too low, we skip it") ErrBlockNotFound = errors.New("Block not found") ErrCannotFindParentBlock = errors.New("Can't find parent block") ErrCannotFindGrandparentBlock = errors.New("Can't find grandparent block") ErrBlockStateError = errors.New("Block state error") ErrBlockStateNotFound = errors.New("Block state not Found") ErrBlockHeightError = errors.New("Block height error") ErrBlockRoundTooLow = errors.New("The block round is too low") ErrBlockConsensusError = errors.New("Block consensus error") ErrBlockTxHashError = errors.New("Block txHash error") ErrBlockBloomError = errors.New("Block bloom error") ErrBlockReceiptError = errors.New("Block receipt error") ErrBlockNonceInfoMissing = errors.New("Block nonce info missing") ErrBlockTxPackageMissing = errors.New("Block txPackage missing") ErrBlockSigError = errors.New("Block sig error") ErrBlockFullSigError = errors.New("Block full sig error") ErrPackageHeightTooLow = errors.New("Package height too low") ErrPackageHeightTooHigh = errors.New("Package height too high") ErrTransactionNotMatchPacker = errors.New("the transaction and the packer don't match") ErrPackerNotAllowed = errors.New("the packer not allowed") ErrIsBroadcastTx = errors.New("the transaction should be broadcast") ErrPackerInfoNotFound = errors.New("cannot find the packer info") ErrPackerNumberIsZero = errors.New("packer number is zero") ErrInvalidGasLimit = errors.New("invalid gas limit") ErrInvalidGasUsed = errors.New("invalid gas used") ErrTxPackageRelatedBlockNotFound = errors.New("tx package related block not found") ErrConfirmedBlockHasSameSimpleHash = errors.New("confirmed block hash same simple hash") )
Functions ¶
func MinBlockHeightAllowedToCarryThePkg ¶
The minimum height of the block that the package is allowed to be placed in
func MinPkgHeightAllowedToPutIntoTheBlock ¶
The minimum height of the package that allowed to put into the block
Types ¶
type BlockChain ¶
type BlockChain struct {
// contains filtered or unexported fields
}
func NewBlockChain ¶
func NewBlockChain(cfg *config.Config, db dbwrapper.Database, executor txexec.TxExecutor, checkPoints *config.CheckPoints, packerInfoCacheSize uint8) (*BlockChain, error)
NewBlockChain returns a fully initialised block chain using information available in the database.
func (*BlockChain) CalcAndCheckState ¶
func (bc *BlockChain) CalcAndCheckState(block *types.Block) bool
func (*BlockChain) CheckBlocksReverse ¶
func (*BlockChain) CheckGreedy ¶
func (bc *BlockChain) CheckGreedy(block *types.Block, mainBlock *types.Block, greedy uint64) (bool, error)
CheckGreedy checks greedy rules
func (*BlockChain) CheckStateFrom ¶
func (*BlockChain) CheckStateTrieFrom ¶
func (bc *BlockChain) CheckStateTrieFrom(block *types.Block) common.Hash
func (*BlockChain) CurrentBlock ¶
func (bc *BlockChain) CurrentBlock() *types.Block
CurrentBlock retrieves the current head block of the canonical chain
func (*BlockChain) Database ¶
func (bc *BlockChain) Database() dbwrapper.Database
func (*BlockChain) FutureBlockTxPackages ¶
func (bc *BlockChain) FutureBlockTxPackages(blockHash common.Hash) types.TxPackages
func (*BlockChain) FutureBlocks ¶
func (bc *BlockChain) FutureBlocks(relatedHash common.Hash) types.Blocks
get future blocks for [relatedHash]
func (*BlockChain) FutureTxPackageBlocks ¶
func (bc *BlockChain) FutureTxPackageBlocks(relatedTxPackageHash common.Hash) types.Blocks
get future txpkg blocks for [relatedTxPackageHash]
func (*BlockChain) Genesis ¶
func (bc *BlockChain) Genesis() *types.Block
Genesis retrieves the chain's genesis block.
func (*BlockChain) GetAncestorBlocksFromBlock ¶
func (bc *BlockChain) GetAncestorBlocksFromBlock(hash common.Hash, depth uint64) (blocks types.Blocks)
GetAncestorBlocksFromBlock returns the block corresponding to hash and up to n-1 ancestors.
func (*BlockChain) GetBackwardBlocks ¶
GetBackwardBlocks retrieves num blocks older than the block b
func (*BlockChain) GetBlock ¶
func (bc *BlockChain) GetBlock(hash common.Hash) *types.Block
GetBlock retrieves a block from the database by hash, caching it if found.
func (*BlockChain) GetBlockBeforeCacheHeight ¶
func (*BlockChain) GetBlockChilds ¶
func (bc *BlockChain) GetBlockChilds(hash common.Hash) []common.Hash
func (*BlockChain) GetBlockStateChecked ¶
func (bc *BlockChain) GetBlockStateChecked(block *types.Block) types.BlockStateCheckedEnum
GetBlockStateChecked return the state checked flag
func (*BlockChain) GetBlocksFromBlock ¶
func (*BlockChain) GetBlocksFromBlockRange ¶
GetBlocksFromBlockRange retrieves the hash assigned to a block range (b1, b2]
func (*BlockChain) GetBlocksFromRoundRange ¶
func (bc *BlockChain) GetBlocksFromRoundRange(r1 uint64, r2 uint64) types.Blocks
GetBlocksFromRoundRange retrieves the hash assigned to a round range (r1, r2]
func (*BlockChain) GetBreakPoint ¶
func (*BlockChain) GetChainConfig ¶
func (bc *BlockChain) GetChainConfig() *config.ChainConfig
func (*BlockChain) GetChainID ¶
func (bc *BlockChain) GetChainID() uint64
func (*BlockChain) GetCheckPoints ¶
func (bc *BlockChain) GetCheckPoints() *config.CheckPoints
func (*BlockChain) GetDescendantBlocksFromBlock ¶
func (bc *BlockChain) GetDescendantBlocksFromBlock(hash common.Hash, depth uint64) (blocks types.Blocks)
GetDescendantBlocksFromBlock returns the block corresponding to hash and forward to n-1 descendants.
func (*BlockChain) GetGreedy ¶
func (bc *BlockChain) GetGreedy() uint8
func (*BlockChain) GetGreedyBlocks ¶
func (bc *BlockChain) GetGreedyBlocks(greedy uint8) (blocks types.Blocks)
GetGreedyBlocks returns the block for mining with greedy-param.
func (*BlockChain) GetHopCount ¶
func (*BlockChain) GetMainBranchBlock ¶
func (bc *BlockChain) GetMainBranchBlock(height uint64) (*types.BlockHeader, error)
func (*BlockChain) GetNearbyBlocksFromBlock ¶
func (bc *BlockChain) GetNearbyBlocksFromBlock(hash common.Hash, width uint64) (blocks types.Blocks)
GetNearbyBlocksFromBlock return the block corresponding to hash and up to width-1 ancestors and forward to width-1 descendants.
func (*BlockChain) GetPackerInfoByPubKey ¶
func (bc *BlockChain) GetPackerInfoByPubKey(blockWhenPacking *types.Block, pubKey types.PackerECPubKey) (uint32, uint32, *types.PackerInfo, error)
func (*BlockChain) GetPreBalanceAndPubkey ¶
func (*BlockChain) GetPrePackerInfoByIndex ¶
func (bc *BlockChain) GetPrePackerInfoByIndex(headBlockWhenPacking *types.Block, index uint32) (*types.PackerInfo, *types.Block, error)
func (*BlockChain) GetPrePackerNumber ¶
func (bc *BlockChain) GetPrePackerNumber(headBlockWhenPacking *types.Block) (uint32, error)
func (*BlockChain) GetRelatedBlockForFutureTxPackage ¶
func (bc *BlockChain) GetRelatedBlockForFutureTxPackage(hash common.Hash) common.Hash
func (*BlockChain) GetStateBeforeCacheHeight ¶
func (*BlockChain) GetTxPackage ¶
func (bc *BlockChain) GetTxPackage(pkgHash common.Hash) *types.TxPackage
func (*BlockChain) GetTxPackageList ¶
func (bc *BlockChain) GetTxPackageList(hashes []common.Hash) types.TxPackages
func (*BlockChain) HasBlock ¶
func (bc *BlockChain) HasBlock(hash common.Hash) bool
HasBlock checks if a block is fully present in the database or not.
func (*BlockChain) HasTxPackage ¶
func (bc *BlockChain) HasTxPackage(pkgHash common.Hash) bool
func (*BlockChain) InsertBlockNoCheck ¶
func (bc *BlockChain) InsertBlockNoCheck(block *types.Block)
insert block
func (*BlockChain) InsertBlockWithState ¶
func (*BlockChain) InsertPastBlock ¶
func (bc *BlockChain) InsertPastBlock(block *types.Block) error
insert block before current block
func (*BlockChain) IsInMainBranch ¶
func (bc *BlockChain) IsInMainBranch(block *types.Block) bool
func (*BlockChain) IsTxPackageInFuture ¶
func (bc *BlockChain) IsTxPackageInFuture(hash common.Hash) bool
func (*BlockChain) MinAvailablePackageHeight ¶
func (bc *BlockChain) MinAvailablePackageHeight() (uint64, error)
Return the min height: Packages with a lower height will not be packaged by the next mined block
func (*BlockChain) PutTxPackage ¶
func (bc *BlockChain) PutTxPackage(txPkg *types.TxPackage)
func (*BlockChain) RemoveFutureBlockTxPackage ¶
func (bc *BlockChain) RemoveFutureBlockTxPackage(pkgHash common.Hash)
remove the txpkg from map item value(type.Blocks), when the txpkg is handled already
func (*BlockChain) RemoveFutureBlocks ¶
func (bc *BlockChain) RemoveFutureBlocks(relatedHash common.Hash)
remove future blocks for [relatedHash]
func (*BlockChain) RemoveFutureTxPackageBlocks ¶
func (bc *BlockChain) RemoveFutureTxPackageBlocks(relatedTxPackageHash common.Hash)
remove future txpkg blocks for [relatedTxPackageHash]
func (*BlockChain) SearchTransactionInCache ¶
func (bc *BlockChain) SearchTransactionInCache(txHash common.Hash) (*types.Transaction, common.Hash)
func (*BlockChain) SendBlockExecutedFeed ¶
func (bc *BlockChain) SendBlockExecutedFeed(block *types.Block)
func (*BlockChain) SetCurrentBlock ¶
func (bc *BlockChain) SetCurrentBlock(currentBlock *types.Block)
only used by sync
func (*BlockChain) SetMainBranchRecordBackend ¶
func (bc *BlockChain) SetMainBranchRecordBackend(m *MainBranchRecord)
func (*BlockChain) StateAt ¶
StateAt returns a new mutable state based on a particular point in time.
func (*BlockChain) SubscribeBlockExecutedEvent ¶
func (bc *BlockChain) SubscribeBlockExecutedEvent(ch chan<- types.BlockExecutedEvent) event.Subscription
func (*BlockChain) SubscribeChainUpdateEvent ¶
func (bc *BlockChain) SubscribeChainUpdateEvent(ch chan<- types.ChainUpdateEvent) event.Subscription
SubscribeChainUpdateEvent registers a subscription of ChainUpdateEvent.
func (*BlockChain) TrieNode ¶
func (bc *BlockChain) TrieNode(hash common.Hash) ([]byte, error)
TrieNode retrieves a blob of data associated with a trie node (or code hash) either from ephemeral in-memory cache, or from persistent storage.
func (*BlockChain) ValidatePackage ¶
func (bc *BlockChain) ValidatePackage(pkg *types.TxPackage, height uint64) error
func (*BlockChain) VerifyBlock ¶
func (*BlockChain) VerifyBlockDepend ¶
func (*BlockChain) VerifyTxPackage ¶
func (bc *BlockChain) VerifyTxPackage(pkg *types.TxPackage) error
type ChainBackend ¶
type ChainBackend interface { GetBlock(hash common.Hash) *types.Block Database() dbwrapper.Database CurrentBlock() *types.Block SubscribeChainUpdateEvent(ch chan<- types.ChainUpdateEvent) event.Subscription SubscribeBlockExecutedEvent(ch chan<- types.BlockExecutedEvent) event.Subscription }
type MainBranchRecord ¶
type MainBranchRecord struct {
// contains filtered or unexported fields
}
func NewMainBranchRecord ¶
func NewMainBranchRecord(bc ChainBackend) *MainBranchRecord
func (*MainBranchRecord) GetMainBranchBlock ¶
func (m *MainBranchRecord) GetMainBranchBlock(height uint64) (*types.BlockHeader, error)
func (*MainBranchRecord) Start ¶
func (m *MainBranchRecord) Start()
type TxInChainProcessor ¶
type TxInChainProcessor struct {
// contains filtered or unexported fields
}
func NewTxInChainProcessor ¶
func NewTxInChainProcessor(chain *BlockChain, processPeriod int) *TxInChainProcessor
func (*TxInChainProcessor) AddBlock ¶
func (p *TxInChainProcessor) AddBlock(b *blockWithExecutedTx)
func (*TxInChainProcessor) SearchTransactionInHeap ¶
func (p *TxInChainProcessor) SearchTransactionInHeap(txHash common.Hash) (*types.Transaction, common.Hash)