core

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2019 License: LGPL-3.0 Imports: 31 Imported by: 60

Documentation

Index

Constants

View Source
const (

	// BlockTransactionNumberLimit block transaction number limit, 1000 simple transactions are about 152kb
	// If for block size as 100KB, it could contains about 5k transactions
	BlockTransactionNumberLimit = 5000

	// BlockByteLimit is the limit of size in bytes
	BlockByteLimit = 1024 * 1024
)
View Source
const MaxBlockHeightGap = 40

Variables

View Source
var (
	// ErrBlockAlreadyExists is returned when inserted block already exists
	ErrBlockAlreadyExists = errors.New("block already exists")

	// ErrBlockStateHashMismatch is returned when the calculated account state hash of block
	// does not match the state root hash in block header.
	ErrBlockStateHashMismatch = errors.New("block state hash mismatch")

	// ErrBlockReceiptHashMismatch is returned when the calculated receipts hash of block
	// does not match the receipts root hash in block header.
	ErrBlockReceiptHashMismatch = errors.New("block receipts hash mismatch")

	// ErrBlockEmptyTxs is returned when writing a block with empty transactions.
	ErrBlockEmptyTxs = errors.New("empty transactions in block")

	// ErrBlockCreateTimeNull is returned when block create time is nil
	ErrBlockCreateTimeNull = errors.New("block must have create time")

	// ErrBlockCreateTimeInFuture is returned when block create time is ahead of 10 seconds of now
	ErrBlockCreateTimeInFuture = errors.New("future block. block time is ahead 10 seconds of now")

	// ErrBlockTooManyTxs is returned when block have too many txs
	ErrBlockTooManyTxs = errors.New("block have too many transactions")

	// ErrBlockExtraDataNotEmpty is returned when the block extra data is not empty.
	ErrBlockExtraDataNotEmpty = errors.New("block extra data is not empty")

	// ErrNotSupported is returned when unsupported method invoked.
	ErrNotSupported = errors.New("not supported function")
)
View Source
var (
	// ErrGenesisHashMismatch is returned when the genesis block hash between the store and memory mismatch.
	ErrGenesisHashMismatch = errors.New("genesis block hash mismatch")

	// ErrGenesisNotFound is returned when genesis block not found in the store.
	ErrGenesisNotFound = errors.New("genesis block not found")
)
View Source
var DebtManagerPoolCapacity = 100000

DebtManagerPoolCapacity capacity for to-be-sent debt in real test. the memory usage for 100000 will be about 150MB

View Source
var DebtPoolCapacity = 100000

DebtPoolCapacity we need bigger capacity to hold more debt in real test. the memory usage for 100000 will be about 150MB

View Source
var ToConfirmedDebtCapacity = 100000

ToConfirmedDebtCapacity capacity for to confirmed debt map in real test. the memory usage for 100000 will be about 150MB

Functions

func DeleteLargerHeightBlocks

func DeleteLargerHeightBlocks(bcStore store.BlockchainStore, largerHeight uint64, rp *recoveryPoint) error

DeleteLargerHeightBlocks deletes the height-to-hash mappings with larger height in the canonical chain.

func OverwriteStaleBlocks

func OverwriteStaleBlocks(bcStore store.BlockchainStore, staleHash common.Hash, rp *recoveryPoint) error

OverwriteStaleBlocks overwrites the stale canonical height-to-hash mappings.

func ValidateBlockHeader

func ValidateBlockHeader(header *types.BlockHeader, engine consensus.Engine, bcStore store.BlockchainStore, chainReader consensus.ChainReader) error

ValidateBlockHeader validates the specified header.

Types

type BlockIndex

type BlockIndex struct {
	// contains filtered or unexported fields
}

BlockIndex is the index of the block chain

func NewBlockIndex

func NewBlockIndex(hash common.Hash, height uint64, td *big.Int) *BlockIndex

NewBlockIndex constructs and returns a BlockIndex instance

type BlockLeaves

type BlockLeaves struct {
	// contains filtered or unexported fields
}

BlockLeaves is the block leaves used for block forking Note that BlockLeaves is not thread safe

func NewBlockLeaves

func NewBlockLeaves() *BlockLeaves

NewBlockLeaves constructs and returns a NewBlockLeaves instance

func (*BlockLeaves) Add

func (bf *BlockLeaves) Add(index *BlockIndex)

Add adds the specified block index to the block leaves

func (*BlockLeaves) Count

func (bf *BlockLeaves) Count() int

Count returns the number of the block indices in the block leaves

func (*BlockLeaves) GetBestBlockIndex

func (bf *BlockLeaves) GetBestBlockIndex() *BlockIndex

GetBestBlockIndex gets the best block index in the block leaves

func (*BlockLeaves) GetBlockIndexByHash

func (bf *BlockLeaves) GetBlockIndexByHash(hash common.Hash) *BlockIndex

GetBlockIndexByHash gets the block index with the specified hash in the block leaves

func (*BlockLeaves) GetWorstBlockIndex

func (bf *BlockLeaves) GetWorstBlockIndex() *BlockIndex

GetWorstBlockIndex gets the worst block index in the block leaves.

func (*BlockLeaves) IsBestBlockIndex

func (bf *BlockLeaves) IsBestBlockIndex(index *BlockIndex) bool

IsBestBlockIndex indicates whether the given block index is the best compared with all indices in the block leaves

func (*BlockLeaves) PurgeAsync

func (bf *BlockLeaves) PurgeAsync(bcStore store.BlockchainStore, callback func(error))

PurgeAsync purges the worst chain in forking tree.

func (*BlockLeaves) Remove

func (bf *BlockLeaves) Remove(hash common.Hash)

Remove removes the block index of the specified hash from the block leaves

type Blockchain

type Blockchain struct {
	// contains filtered or unexported fields
}

Blockchain represents the blockchain with a genesis block. The Blockchain manages blocks insertion, deletion, reorganizations and persistence with a given database. This is a thread safe structure. we must keep all of its parameters are thread safe too.

func NewBlockchain

func NewBlockchain(bcStore store.BlockchainStore, accountStateDB database.Database, recoveryPointFile string, engine consensus.Engine,
	verifier types.DebtVerifier, startHeight int) (*Blockchain, error)

NewBlockchain returns an initialized blockchain with the given store and account state DB.

func NewTestBlockchain

func NewTestBlockchain() *Blockchain

func NewTestBlockchainWithVerifier

func NewTestBlockchainWithVerifier(verifier types.DebtVerifier) *Blockchain

func (*Blockchain) AccountDB

func (bc *Blockchain) AccountDB() database.Database

AccountDB returns the account state database in blockchain.

func (*Blockchain) AddBlockLeaves

func (bc *Blockchain) AddBlockLeaves(blockIndex *BlockIndex)

func (*Blockchain) ApplyDebtWithoutVerify

func (bc *Blockchain) ApplyDebtWithoutVerify(statedb *state.Statedb, d *types.Debt, coinbase common.Address) error

ApplyDebtWithoutVerify applies a debt and update statedb.

func (*Blockchain) ApplyTransaction

func (bc *Blockchain) ApplyTransaction(tx *types.Transaction, txIndex int, coinbase common.Address, statedb *state.Statedb,
	blockHeader *types.BlockHeader) (*types.Receipt, error)

ApplyTransaction applies a transaction, changes corresponding statedb and generates its receipt

func (*Blockchain) CurrentBlock

func (bc *Blockchain) CurrentBlock() *types.Block

CurrentBlock returns the HEAD block of the blockchain.

func (*Blockchain) CurrentHeader

func (bc *Blockchain) CurrentHeader() *types.BlockHeader

CurrentHeader returns the HEAD block header of the blockchain.

func (*Blockchain) Genesis

func (bc *Blockchain) Genesis() *types.Block

Genesis returns the genesis block of blockchain.

func (*Blockchain) GetBlockByHash

func (bc *Blockchain) GetBlockByHash(hash common.Hash) *types.Block

GetBlockByHash retrieves a block by hash.

func (*Blockchain) GetCurrentInfo

func (bc *Blockchain) GetCurrentInfo() (*types.Block, *state.Statedb, error)

GetCurrentInfo return the current block and current state info

func (*Blockchain) GetCurrentState

func (bc *Blockchain) GetCurrentState() (*state.Statedb, error)

GetCurrentState returns the state DB of the current block.

func (*Blockchain) GetHeadRollbackEventManager added in v1.0.2

func (bc *Blockchain) GetHeadRollbackEventManager() *event.EventManager

func (*Blockchain) GetHeaderByHash

func (bc *Blockchain) GetHeaderByHash(hash common.Hash) *types.BlockHeader

GetHeaderByHash retrieves a block header by hash.

func (*Blockchain) GetHeaderByHeight

func (bc *Blockchain) GetHeaderByHeight(height uint64) *types.BlockHeader

GetHeaderByHeight retrieves a block header by height.

func (*Blockchain) GetShardNumber

func (bc *Blockchain) GetShardNumber() (uint, error)

GetShardNumber returns the shard number of blockchain.

func (*Blockchain) GetState

func (bc *Blockchain) GetState(root common.Hash) (*state.Statedb, error)

GetState returns the state DB of the specified root hash.

func (*Blockchain) GetStateByRootAndBlockHash

func (bc *Blockchain) GetStateByRootAndBlockHash(root, blockHash common.Hash) (*state.Statedb, error)

GetStateByRootAndBlockHash will panic, since not supported

func (*Blockchain) GetStore

func (bc *Blockchain) GetStore() store.BlockchainStore

GetStore returns the blockchain store instance.

func (*Blockchain) PutCurrentHeader added in v1.0.2

func (bc *Blockchain) PutCurrentHeader(header *types.BlockHeader)

The following functions are only supported in lightclient

func (*Blockchain) PutTd added in v1.0.2

func (bc *Blockchain) PutTd(td *big.Int)

func (*Blockchain) RemoveBlockLeaves

func (bc *Blockchain) RemoveBlockLeaves(hash common.Hash)

func (*Blockchain) UpdateCurrentBlock

func (bc *Blockchain) UpdateCurrentBlock(block *types.Block)

UpdateCurrentBlock updates the HEAD block of the blockchain.

func (*Blockchain) WriteBlock

func (bc *Blockchain) WriteBlock(block *types.Block) error

WriteBlock writes the specified block to the blockchain store.

func (*Blockchain) WriteHeader

func (bc *Blockchain) WriteHeader(*types.BlockHeader) error

WriteHeader writes the specified head to the blockchain store, only used in lightchain.

type ConcurrentDebtMap

type ConcurrentDebtMap struct {
	// contains filtered or unexported fields
}

func NewConcurrentDebtMap

func NewConcurrentDebtMap(capacity int) *ConcurrentDebtMap

type DebtPool

type DebtPool struct {
	*Pool
	// contains filtered or unexported fields
}

DebtPool debt pool

func NewDebtPool

func NewDebtPool(chain blockchain, verifier types.DebtVerifier) *DebtPool

func (*DebtPool) AddDebt

func (dp *DebtPool) AddDebt(debt *types.Debt) error

func (*DebtPool) AddDebtArray

func (dp *DebtPool) AddDebtArray(debts []*types.Debt)

func (*DebtPool) DoCheckingDebt

func (dp *DebtPool) DoCheckingDebt()

func (*DebtPool) DoMulCheckingDebt

func (dp *DebtPool) DoMulCheckingDebt() error

DoMulCheckingDebt use multiple threads to validate debts

func (*DebtPool) DoMulCheckingDebtHandler

func (dp *DebtPool) DoMulCheckingDebtHandler(d *types.Debt) error

DoMulCheckingDebtHandler DoMulCheckingDebt handler

func (*DebtPool) GetDebtByHash

func (dp *DebtPool) GetDebtByHash(hash common.Hash) *types.Debt

func (*DebtPool) GetDebtCount

func (dp *DebtPool) GetDebtCount(processing, pending bool) int

func (*DebtPool) GetDebts

func (dp *DebtPool) GetDebts(processing, pending bool) []*types.Debt

func (*DebtPool) GetProcessableDebts

func (dp *DebtPool) GetProcessableDebts(size int) ([]*types.Debt, int)

func (*DebtPool) RemoveDebtByHash

func (dp *DebtPool) RemoveDebtByHash(hash common.Hash)

type EventPool

type EventPool struct {
	// contains filtered or unexported fields
}

EventPool event pool

func NewEventPool

func NewEventPool(capacity uint, mainChainStore store.BlockchainStore, chain blockchain, abi *listener.ContractEventABI) (*EventPool, error)

NewEventPool creates and returns an event pool.

type Genesis

type Genesis struct {
	// contains filtered or unexported fields
}

Genesis represents the genesis block in the blockchain.

func GetGenesis

func GetGenesis(info *GenesisInfo) *Genesis

GetGenesis gets the genesis block according to accounts' balance

func (*Genesis) GetShardNumber

func (genesis *Genesis) GetShardNumber() uint

GetShardNumber gets the shard number of genesis

func (*Genesis) InitializeAndValidate

func (genesis *Genesis) InitializeAndValidate(bcStore store.BlockchainStore, accountStateDB database.Database) error

InitializeAndValidate writes the genesis block in the blockchain store if unavailable. Otherwise, check if the existing genesis block is valid in the blockchain store.

type GenesisInfo

type GenesisInfo struct {
	// Accounts accounts info for genesis block used for test
	// map key is account address -> value is account balance
	Accounts map[common.Address]*big.Int `json:"accounts,omitempty"`

	// Difficult initial difficult for mining. Use bigger difficult as you can. Because block is chosen by total difficult
	Difficult int64 `json:"difficult"`

	// ShardNumber is the shard number of genesis block.
	ShardNumber uint `json:"shard"`

	// CreateTimestamp is the initial time of genesis
	CreateTimestamp *big.Int `json:"timestamp"`

	// Consensus consensus type
	Consensus types.ConsensusType `json:"consensus"`

	// Validators istanbul consensus validators
	Validators []common.Address `json:"validators"`

	// master account
	Masteraccount common.Address `json:"master"`

	// balance of the master account
	Balance *big.Int `json:"balance"`
}

GenesisInfo genesis info for generating genesis block, it could be used for initializing account balance

func NewGenesisInfo

func NewGenesisInfo(accounts map[common.Address]*big.Int, difficult int64, shard uint, timestamp *big.Int,
	consensus types.ConsensusType, validator []common.Address) *GenesisInfo

func (*GenesisInfo) Hash

func (info *GenesisInfo) Hash() common.Hash

Hash returns GenesisInfo hash

type HeaderChain

type HeaderChain struct {
	// contains filtered or unexported fields
}

HeaderChain represents the block header chain that is shared by the archive node and light node. This is a non-thread safe structure.

func NewHeaderChain

func NewHeaderChain(bcStore store.BlockchainStore) (*HeaderChain, error)

NewHeaderChain returns a new instance of the HeaderChain structure.

func (*HeaderChain) WriteHeader

func (hc *HeaderChain) WriteHeader(newHeader *types.BlockHeader) error

WriteHeader writes a new block header into the header chain. It requires the new header's parent header is the HEAD header in the chain.

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool is a thread-safe container for block object received from the network or submitted locally. An object will be removed from the pool once included in a blockchain or pending time too long (> timeoutDuration).

func NewPool

func NewPool(capacity int, chain blockchain, getObjectFromBlock getObjectFromBlockFunc,
	canRemove canRemoveFunc, log *log.SeeleLog, objectValidation objectValidationFunc, afterAdd afterAddFunc) *Pool

NewPool creates and returns a transaction pool.

func (*Pool) GetObject

func (pool *Pool) GetObject(objHash common.Hash) poolObject

GetObject returns a transaction if it is contained in the pool and nil otherwise.

func (*Pool) HandleChainHeaderChanged

func (pool *Pool) HandleChainHeaderChanged(newHeader, lastHeader common.Hash)

HandleChainHeaderChanged reinjects txs into pool in case of blockchain forked.

func (*Pool) HandleChainReversed

func (pool *Pool) HandleChainReversed(block *types.Block)

func (*Pool) Has

func (pool *Pool) Has(hash common.Hash) bool

func (*Pool) SetLogLevel

func (pool *Pool) SetLogLevel(level logrus.Level)

type TransactionPool

type TransactionPool struct {
	*Pool
}

TransactionPool is a thread-safe container for transactions received from the network or submitted locally. A transaction will be removed from the pool once included in a blockchain or pending time too long (> transactionTimeoutDuration).

func NewTransactionPool

func NewTransactionPool(config TransactionPoolConfig, chain blockchain) *TransactionPool

NewTransactionPool creates and returns a transaction pool.

func (*TransactionPool) AddTransaction

func (pool *TransactionPool) AddTransaction(tx *types.Transaction) error

AddTransaction adds a single transaction into the pool if it is valid and returns nil. Otherwise, return the error.

func (*TransactionPool) GetPendingTxCount

func (pool *TransactionPool) GetPendingTxCount() int

GetPendingTxCount returns the total number of pending transactions in the transaction pool.

func (*TransactionPool) GetProcessableTransactions

func (pool *TransactionPool) GetProcessableTransactions(size int) ([]*types.Transaction, int)

GetProcessableTransactions retrieves processable transactions from pool.

func (*TransactionPool) GetTransaction

func (pool *TransactionPool) GetTransaction(txHash common.Hash) *types.Transaction

GetTransaction returns a transaction if it is contained in the pool and nil otherwise.

func (*TransactionPool) GetTransactions

func (pool *TransactionPool) GetTransactions(processing, pending bool) []*types.Transaction

GetTransactions returns the transactions in the transaction pool.

func (*TransactionPool) GetTxCount

func (pool *TransactionPool) GetTxCount() int

GetTxCount returns the total number of transactions in the transaction pool.

func (*TransactionPool) RemoveTransaction

func (pool *TransactionPool) RemoveTransaction(txHash common.Hash)

RemoveTransaction removes transaction of specified transaction hash from pool

type TransactionPoolConfig

type TransactionPoolConfig struct {
	Capacity int // Maximum number of transactions in the pool.
}

TransactionPoolConfig is the configuration of the transaction pool.

func DefaultTxPoolConfig

func DefaultTxPoolConfig() *TransactionPoolConfig

DefaultTxPoolConfig returns the default configuration of the transaction pool.

Directories

Path Synopsis
svm
evm

Jump to

Keyboard shortcuts

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