chain

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2020 License: LGPL-3.0 Imports: 28 Imported by: 7

Documentation

Overview

Package chain contains implementations for basic chain operations.

Package chain contains implementations for basic chain operations.

Index

Constants

View Source
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
)
View Source
const (
	TxVerifyParallel = 16
)

Variables

View Source
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 IsReOrg

func IsReOrg(new *types.Block, oldHead *types.Block) bool

func MaxBlockHeightAllowedToCarryThePkg

func MaxBlockHeightAllowedToCarryThePkg(txPkgHeight uint64) uint64

func MaxPkgHeightAllowedToPutIntoTheBlock

func MaxPkgHeightAllowedToPutIntoTheBlock(blockHeight uint64) uint64

func MinBlockHeightAllowedToCarryThePkg

func MinBlockHeightAllowedToCarryThePkg(txPkgHeight uint64) uint64

The minimum height of the block that the package is allowed to be placed in

func MinPkgHeightAllowedToPutIntoTheBlock

func MinPkgHeightAllowedToPutIntoTheBlock(blockHeight uint64) uint64

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 (bc *BlockChain) CheckBlocksReverse() ([]common.Hash, map[common.Hash]common.Hash, bool)

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 (bc *BlockChain) CheckStateFrom(block *types.Block) (common.Hash, error)

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

func (bc *BlockChain) GetBackwardBlocks(b *types.Block, num uint64) types.Blocks

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 (bc *BlockChain) GetBlockBeforeCacheHeight(block *types.Block, cacheHeight uint8) (*types.Block, bool)

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 (bc *BlockChain) GetBlocksFromBlock(hash common.Hash, depth uint64, reverse bool) types.Blocks

func (*BlockChain) GetBlocksFromBlockRange

func (bc *BlockChain) GetBlocksFromBlockRange(b1 *types.Block, b2 *types.Block) types.Blocks

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 (bc *BlockChain) GetBreakPoint(checkpoint *types.Block, headBlock *types.Block) (*types.Block, *types.Block, error)

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 (bc *BlockChain) GetHopCount(block1 *types.Block, block2 *types.Block) (uint64, error)

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 (bc *BlockChain) GetPreBalanceAndPubkey(block *types.Block, address common.Address) (uint64, []byte, error)

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 (bc *BlockChain) GetStateBeforeCacheHeight(block *types.Block, cacheHeight uint8) (*state.StateDB, *types.Block, bool)

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) InsertBlock

func (bc *BlockChain) InsertBlock(block *types.Block)

insert block

func (*BlockChain) InsertBlockNoCheck

func (bc *BlockChain) InsertBlockNoCheck(block *types.Block)

insert block

func (*BlockChain) InsertBlockWithState

func (bc *BlockChain) InsertBlockWithState(block *types.Block, state *state.StateDB, receipts types.Receipts, executedTxs []*types.TxWithIndex, bloom *types.Bloom)

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) SetBlockState

func (bc *BlockChain) SetBlockState(block *types.Block, state types.BlockStateCheckedEnum)

SetBlockState set state checked flag for 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

func (bc *BlockChain) StateAt(stateHash common.Hash) (*state.StateDB, error)

StateAt returns a new mutable state based on a particular point in time.

func (*BlockChain) StopRecord

func (bc *BlockChain) StopRecord()

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 (bc *BlockChain) VerifyBlock(block *types.Block, checkGreedy bool) (types.Blocks, common.Hash, common.Hash, error)

func (*BlockChain) VerifyBlockDepend

func (bc *BlockChain) VerifyBlockDepend(block *types.Block) (common.Hash, error)

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()

func (*MainBranchRecord) Stop

func (m *MainBranchRecord) Stop()

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)

func (*TxInChainProcessor) Stop

func (p *TxInChainProcessor) Stop()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL