Documentation ¶
Overview ¶
Modified from go-ethereum under GNU Lesser General Public License
Package core implements the Ethereum consensus protocol.
Index ¶
- Variables
- func ApplyMessage(evm *vm.EVM, msg Message, gp *GasPool, feeRate *big.Rat) ([]byte, uint64, bool, error)
- func ApplyTransaction(config *params.ChainConfig, bc ChainContext, gp *GasPool, ...) ([]byte, *types.Receipt, uint64, error)
- func CalculateRootBlockCoinbase(config *config.QuarkChainConfig, block *types.RootBlock) *big.Int
- func CanTransfer(db vm.StateDB, addr common.Address, amount *big.Int) bool
- func GenerateMinorBlockChain(config *params.ChainConfig, quarkChainConfig *config.QuarkChainConfig, ...) ([]*types.MinorBlock, []types.Receipts)
- func GenerateRootBlockChain(parent *types.RootBlock, engine consensus.Engine, n int, ...) []*types.RootBlock
- func GetHashFn(ref types.IHeader, chain ChainContext) func(n uint64) common.Hash
- func IntrinsicGas(data []byte, contractCreation, isCrossShard bool) (uint64, error)
- func NewEVMContext(msg types.Message, mheader types.IHeader, chain ChainContext) vm.Context
- func SetReceiptsData(config *config.QuarkChainConfig, mBlock types.IBlock, receipts types.Receipts) error
- func SetupGenesisMinorBlock(db ethdb.Database, genesis *Genesis, rootBlock *types.RootBlock, ...) (*config.QuarkChainConfig, common.Hash, error)
- func SetupGenesisRootBlock(db ethdb.Database, genesis *Genesis) (*config.QuarkChainConfig, common.Hash, error)
- func Transfer(db vm.StateDB, sender, recipient common.Address, amount *big.Int)
- func ValidateTransaction(state vm.StateDB, tx *types.Transaction, fromAddress *account.Address) error
- type Backend
- type CacheConfig
- type ChainContext
- type DeleteCallback
- type Filter
- type GasPool
- type Genesis
- func (g *Genesis) CommitMinorBlock(db ethdb.Database, rootBlock *types.RootBlock, fullShardId uint32) (*types.MinorBlock, error)
- func (g *Genesis) CommitRootBlock(db ethdb.Database) (*types.RootBlock, error)
- func (g *Genesis) CreateMinorBlock(rootBlock *types.RootBlock, fullShardId uint32, db ethdb.Database) (*types.MinorBlock, error)
- func (g *Genesis) CreateRootBlock() *types.RootBlock
- func (g *Genesis) MustCommitMinorBlock(db ethdb.Database, rootBlock *types.RootBlock, fullShardId uint32) *types.MinorBlock
- func (g *Genesis) MustCommitRootBlock(db ethdb.Database) *types.RootBlock
- type GenesisAccount
- type GenesisMismatchError
- type HeaderChain
- func (hc *HeaderChain) Config() *config.QuarkChainConfig
- func (hc *HeaderChain) CurrentHeader() types.IHeader
- func (hc *HeaderChain) Engine() consensus.Engine
- func (hc *HeaderChain) GetAncestor(hash common.Hash, number, ancestor uint64, maxNonCanonical *uint64) (common.Hash, uint64)
- func (hc *HeaderChain) GetBlock(hash common.Hash) types.IBlock
- func (hc *HeaderChain) GetBlockHashesFromHash(hash common.Hash, max uint64) []common.Hash
- func (hc *HeaderChain) GetBlockNumber(hash common.Hash) *uint64
- func (hc *HeaderChain) GetHeader(hash common.Hash) types.IHeader
- func (hc *HeaderChain) GetHeaderByHash(hash common.Hash) types.IHeader
- func (hc *HeaderChain) GetHeaderByNumber(number uint64) types.IHeader
- func (hc *HeaderChain) GetTd(hash common.Hash, number uint64) *big.Int
- func (hc *HeaderChain) GetTdByHash(hash common.Hash) *big.Int
- func (hc *HeaderChain) HasHeader(hash common.Hash, number uint64) bool
- func (hc *HeaderChain) InsertHeaderChain(chain []*types.MinorBlockHeader, writeHeader MinorWhCallback, start time.Time) (int, error)
- func (hc *HeaderChain) SetCurrentHeader(head *types.MinorBlockHeader)
- func (hc *HeaderChain) SetGenesis(head *types.MinorBlockHeader)
- func (hc *HeaderChain) SetHead(head uint64, delFn DeleteCallback)
- func (hc *HeaderChain) ValidateHeaderChain(chain []*types.MinorBlockHeader, checkFreq int) (int, error)
- func (hc *HeaderChain) WriteHeader(header *types.MinorBlockHeader) (status WriteStatus, err error)
- func (hc *HeaderChain) WriteTd(hash common.Hash, number uint64, td *big.Int) error
- type Message
- type MinorBlockChain
- func (m *MinorBlockChain) AddBlock(block types.IBlock) error
- func (m *MinorBlockChain) AddCrossShardTxListByMinorBlockHash(h common.Hash, txList types.CrossShardTransactionDepositList)
- func (m *MinorBlockChain) AddRootBlock(rBlock *types.RootBlock) (bool, error)
- func (m *MinorBlockChain) AddTx(tx *types.Transaction) error
- func (m *MinorBlockChain) Config() *config.QuarkChainConfig
- func (m *MinorBlockChain) CreateBlockToMine(createTime *uint64, address *account.Address, gasLimit *big.Int) (*types.MinorBlock, error)
- func (m *MinorBlockChain) CurrentBlock() *types.MinorBlock
- func (m *MinorBlockChain) CurrentHeader() types.IHeader
- func (m *MinorBlockChain) Engine() consensus.Engine
- func (m *MinorBlockChain) EstimateGas(tx *types.Transaction, fromAddress account.Address) (uint32, error)
- func (m *MinorBlockChain) ExecuteTx(tx *types.Transaction, fromAddress *account.Address, height *uint64) ([]byte, error)
- func (m *MinorBlockChain) Export(w io.Writer) error
- func (m *MinorBlockChain) ExportN(w io.Writer, first uint64, last uint64) error
- func (m *MinorBlockChain) FinalizeAndAddBlock(block *types.MinorBlock) (*types.MinorBlock, types.Receipts, error)
- func (m *MinorBlockChain) GasLimit() uint64
- func (m *MinorBlockChain) GasPrice() (uint64, error)
- func (m *MinorBlockChain) Genesis() *types.MinorBlock
- func (m *MinorBlockChain) GetAncestor(hash common.Hash, number, ancestor uint64, maxNonCanonical *uint64) (common.Hash, uint64)
- func (m *MinorBlockChain) GetBalance(recipient account.Recipient, height *uint64) (*big.Int, error)
- func (m *MinorBlockChain) GetBlock(hash common.Hash) types.IBlock
- func (m *MinorBlockChain) GetBlockByNumber(number uint64) types.IBlock
- func (m *MinorBlockChain) GetBlockHashesFromHash(hash common.Hash, max uint64) []common.Hash
- func (m *MinorBlockChain) GetBlocksFromHash(hash common.Hash, n int) (blocks []types.IBlock)
- func (m *MinorBlockChain) GetBranch() account.Branch
- func (m *MinorBlockChain) GetCode(recipient account.Recipient, height *uint64) ([]byte, error)
- func (m *MinorBlockChain) GetHeader(hash common.Hash) types.IHeader
- func (m *MinorBlockChain) GetHeaderByHash(hash common.Hash) types.IHeader
- func (m *MinorBlockChain) GetHeaderByNumber(number uint64) types.IHeader
- func (m *MinorBlockChain) GetLogs(hash common.Hash) [][]*types.Log
- func (m *MinorBlockChain) GetLogsByAddressAndTopic(start uint64, end uint64, addresses []account.Address, topics [][]common.Hash) ([]*types.Log, error)
- func (m *MinorBlockChain) GetMinorBlock(hash common.Hash) *types.MinorBlock
- func (m *MinorBlockChain) GetPOSWCoinbaseBlockCnt(headerHash common.Hash, length *uint32) (map[account.Recipient]uint32, error)
- func (m *MinorBlockChain) GetReceiptsByHash(hash common.Hash) types.Receipts
- func (m *MinorBlockChain) GetRootBlockByHash(hash common.Hash) *types.RootBlock
- func (m *MinorBlockChain) GetRootTip() *types.RootBlockHeader
- func (m *MinorBlockChain) GetShardStatus() (*rpc.ShardStatus, error)
- func (m *MinorBlockChain) GetStorageAt(recipient account.Recipient, key common.Hash, height *uint64) (common.Hash, error)
- func (m *MinorBlockChain) GetTd(hash common.Hash, number uint64) *big.Int
- func (m *MinorBlockChain) GetTdByHash(hash common.Hash) *big.Int
- func (m *MinorBlockChain) GetTransactionByAddress(address account.Address, start []byte, limit uint32) ([]*rpc.TransactionDetail, []byte, error)
- func (m *MinorBlockChain) GetTransactionByHash(hash common.Hash) (*types.MinorBlock, uint32)
- func (m *MinorBlockChain) GetTransactionCount(recipient account.Recipient, height *uint64) (uint64, error)
- func (m *MinorBlockChain) GetTransactionReceipt(hash common.Hash) (*types.MinorBlock, uint32, *types.Receipt)
- func (m *MinorBlockChain) GetUnconfirmedHeaderList() []*types.MinorBlockHeader
- func (m *MinorBlockChain) GetUnconfirmedHeadersCoinbaseAmount() uint64
- func (m *MinorBlockChain) GetVMConfig() *vm.Config
- func (m *MinorBlockChain) HasBlock(hash common.Hash) bool
- func (m *MinorBlockChain) HasBlockAndState(hash common.Hash) bool
- func (m *MinorBlockChain) HasHeader(hash common.Hash, number uint64) bool
- func (m *MinorBlockChain) HasState(hash common.Hash) bool
- func (m *MinorBlockChain) InitFromRootBlock(rBlock *types.RootBlock) error
- func (m *MinorBlockChain) InitGenesisState(rBlock *types.RootBlock) (*types.MinorBlock, error)
- func (m *MinorBlockChain) InsertChain(chain []types.IBlock) (int, error)
- func (m *MinorBlockChain) InsertChainForDeposits(chain []types.IBlock) (int, [][]*types.CrossShardTransactionDeposit, error)
- func (m *MinorBlockChain) InsertHeaderChain(chain []types.IHeader, checkFreq int) (int, error)
- func (m *MinorBlockChain) InsertReceiptChain(blockChain []types.IBlock, receiptChain []types.Receipts) (int, error)
- func (m *MinorBlockChain) POSWDiffAdjust(block types.IBlock) (uint64, error)
- func (m *MinorBlockChain) PostChainEvents(events []interface{}, logs []*types.Log)
- func (m *MinorBlockChain) Processor() Processor
- func (m *MinorBlockChain) ReadCrossShardTxList(hash common.Hash) *types.CrossShardTransactionDepositList
- func (m *MinorBlockChain) ReadLastConfirmedMinorBlockHeaderAtRootBlock(hash common.Hash) common.Hash
- func (m *MinorBlockChain) Reset() error
- func (m *MinorBlockChain) ResetWithGenesisBlock(genesis *types.MinorBlock) error
- func (m *MinorBlockChain) Rollback(chain []common.Hash)
- func (m *MinorBlockChain) SetBroadcastMinorBlockFunc(f func(block *types.MinorBlock) error)
- func (m *MinorBlockChain) SetHead(head uint64) error
- func (m *MinorBlockChain) SetProcessor(processor Processor)
- func (m *MinorBlockChain) SetValidator(validator Validator)
- func (m *MinorBlockChain) State() (*state.StateDB, error)
- func (m *MinorBlockChain) StateAt(root common.Hash) (*state.StateDB, error)
- func (m *MinorBlockChain) StateCache() state.Database
- func (m *MinorBlockChain) Stop()
- func (m *MinorBlockChain) SubscribeChainEvent(ch chan<- MinorChainEvent) event.Subscription
- func (m *MinorBlockChain) SubscribeChainHeadEvent(ch chan<- MinorChainHeadEvent) event.Subscription
- func (m *MinorBlockChain) SubscribeChainSideEvent(ch chan<- MinorChainSideEvent) event.Subscription
- func (m *MinorBlockChain) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription
- func (m *MinorBlockChain) SubscribeRemovedLogsEvent(ch chan<- RemovedLogsEvent) event.Subscription
- func (m *MinorBlockChain) TrieNode(hash common.Hash) ([]byte, error)
- func (m *MinorBlockChain) Validator() Validator
- func (m *MinorBlockChain) WriteBlockWithState(block *types.MinorBlock, receipts []*types.Receipt, state *state.StateDB, ...) (status WriteStatus, err error)
- func (m *MinorBlockChain) WriteBlockWithoutState(block types.IBlock, td *big.Int) (err error)
- type MinorBlockGen
- func (b *MinorBlockGen) AddTx(quarkChainConfig *config.QuarkChainConfig, tx *types.Transaction)
- func (b *MinorBlockGen) AddTxWithChain(quarkChainConfig *config.QuarkChainConfig, bc *MinorBlockChain, ...)
- func (b *MinorBlockGen) Number() *big.Int
- func (b *MinorBlockGen) PrevBlock(index int) *types.MinorBlock
- func (b *MinorBlockGen) SetCoinbase(addr account.Address)
- func (b *MinorBlockGen) SetDifficulty(value uint64)
- func (b *MinorBlockGen) SetExtra(data []byte)
- func (b *MinorBlockGen) SetNonce(nonce uint64)
- func (b *MinorBlockGen) TxNonce(addr common.Address) uint64
- type MinorBlockValidator
- func (v *MinorBlockValidator) ValidateBlock(mBlock types.IBlock) error
- func (v *MinorBlockValidator) ValidateHeader(header types.IHeader) error
- func (v *MinorBlockValidator) ValidateState(mBlock, parent types.IBlock, statedb *state.StateDB, receipts types.Receipts, ...) error
- func (v *MinorBlockValidator) ValidatorSeal(mHeader types.IHeader) error
- type MinorChainEvent
- type MinorChainHeadEvent
- type MinorChainSideEvent
- type MinorWhCallback
- type NewMinedBlockEvent
- type NewTxsEvent
- type PendingLogsEvent
- type Processor
- type RemovedLogsEvent
- type RootBlockChain
- func (bc *RootBlockChain) AddBlock(block types.IBlock) error
- func (bc *RootBlockChain) AddValidatedMinorBlockHeader(hash common.Hash)
- func (bc *RootBlockChain) CalculateRootBlockCoinBase(rootBlock *types.RootBlock) *big.Int
- func (bc *RootBlockChain) ClearCommittingHash()
- func (bc *RootBlockChain) Config() *config.QuarkChainConfig
- func (bc *RootBlockChain) CreateBlockToMine(mHeaderList []*types.MinorBlockHeader, address *account.Address, ...) (*types.RootBlock, error)
- func (bc *RootBlockChain) CurrentBlock() *types.RootBlock
- func (bc *RootBlockChain) CurrentHeader() types.IHeader
- func (bc *RootBlockChain) Engine() consensus.Engine
- func (bc *RootBlockChain) Export(w io.Writer) error
- func (bc *RootBlockChain) ExportN(w io.Writer, first uint64, last uint64) error
- func (bc *RootBlockChain) Genesis() *types.RootBlock
- func (bc *RootBlockChain) GetAncestor(hash common.Hash, number, ancestor uint64, maxNonCanonical *uint64) (common.Hash, uint64)
- func (bc *RootBlockChain) GetBlock(hash common.Hash) types.IBlock
- func (bc *RootBlockChain) GetBlockByNumber(number uint64) types.IBlock
- func (bc *RootBlockChain) GetBlockCount(rootHeight uint32) (map[uint32]map[account.Recipient]uint32, error)
- func (bc *RootBlockChain) GetBlockHashesFromHash(hash common.Hash, max uint64) []common.Hash
- func (bc *RootBlockChain) GetCommittingBlockHash() common.Hash
- func (bc *RootBlockChain) GetHeader(hash common.Hash) types.IHeader
- func (bc *RootBlockChain) GetHeaderByNumber(number uint64) types.IHeader
- func (bc *RootBlockChain) GetLatestMinorBlockHeaders(hash common.Hash) map[uint32]*types.MinorBlockHeader
- func (bc *RootBlockChain) GetNextDifficulty(create *uint64) (*big.Int, error)
- func (bc *RootBlockChain) GetTd(hash common.Hash) *big.Int
- func (bc *RootBlockChain) HasBlock(hash common.Hash) bool
- func (bc *RootBlockChain) HasHeader(hash common.Hash) bool
- func (bc *RootBlockChain) InsertChain(chain []types.IBlock) (int, error)
- func (bc *RootBlockChain) InsertHeaderChain(chain []*types.RootBlockHeader, checkFreq int) (int, error)
- func (bc *RootBlockChain) IsMinorBlockValidated(hash common.Hash) bool
- func (bc *RootBlockChain) PostChainEvents(events []interface{})
- func (bc *RootBlockChain) PutRootBlockIndex(block *types.RootBlock) error
- func (bc *RootBlockChain) Reset() error
- func (bc *RootBlockChain) ResetWithGenesisBlock(genesis *types.RootBlock) error
- func (bc *RootBlockChain) Rollback(chain []common.Hash)
- func (bc *RootBlockChain) SetBroadcastRootBlockFunc(f func(block *types.RootBlock) error)
- func (bc *RootBlockChain) SetEnableCountMinorBlocks(flag bool)
- func (bc *RootBlockChain) SetHead(head uint64) error
- func (bc *RootBlockChain) SetLatestMinorBlockHeaders(hash common.Hash, headerMap map[uint32]*types.MinorBlockHeader)
- func (bc *RootBlockChain) SetValidator(validator Validator)
- func (bc *RootBlockChain) Stop()
- func (bc *RootBlockChain) SubscribeChainEvent(ch chan<- RootChainEvent) event.Subscription
- func (bc *RootBlockChain) SubscribeChainHeadEvent(ch chan<- RootChainHeadEvent) event.Subscription
- func (bc *RootBlockChain) SubscribeChainSideEvent(ch chan<- RootChainSideEvent) event.Subscription
- func (bc *RootBlockChain) SubscribeRemovedLogsEvent(ch chan<- RemovedLogsEvent) event.Subscription
- func (bc *RootBlockChain) Validator() Validator
- func (bc *RootBlockChain) WriteBlockWithState(block *types.RootBlock) (status WriteStatus, err error)
- func (bc *RootBlockChain) WriteBlockWithoutState(block types.IBlock, td *big.Int) (err error)
- func (bc *RootBlockChain) WriteCommittingHash(hash common.Hash)
- type RootBlockGen
- func (b *RootBlockGen) Number() uint64
- func (b *RootBlockGen) PrevBlock(index int) *types.RootBlock
- func (b *RootBlockGen) SetCoinbase(addr account.Address)
- func (b *RootBlockGen) SetDifficulty(value uint64)
- func (b *RootBlockGen) SetExtra(data []byte)
- func (b *RootBlockGen) SetNonce(nonce uint64)
- func (b *RootBlockGen) SetTotalDifficulty(value *big.Int)
- type RootBlockValidator
- func (v *RootBlockValidator) ValidateBlock(block types.IBlock) error
- func (v *RootBlockValidator) ValidateHeader(header types.IHeader) error
- func (v *RootBlockValidator) ValidateState(block, parent types.IBlock, statedb *state.StateDB, receipts types.Receipts, ...) error
- func (v *RootBlockValidator) ValidatorSeal(rHeader types.IHeader) error
- type RootChainEvent
- type RootChainHeadEvent
- type RootChainSideEvent
- type RootHeaderChain
- func (hc *RootHeaderChain) Config() *config.QuarkChainConfig
- func (hc *RootHeaderChain) CurrentHeader() types.IHeader
- func (hc *RootHeaderChain) Engine() consensus.Engine
- func (hc *RootHeaderChain) GetAncestor(hash common.Hash, number, ancestor uint64, maxNonCanonical *uint64) (common.Hash, uint64)
- func (hc *RootHeaderChain) GetBlock(hash common.Hash) types.IBlock
- func (hc *RootHeaderChain) GetBlockHashesFromHash(hash common.Hash, max uint64) []common.Hash
- func (hc *RootHeaderChain) GetBlockNumber(hash common.Hash) *uint64
- func (hc *RootHeaderChain) GetHeader(hash common.Hash) types.IHeader
- func (hc *RootHeaderChain) GetHeaderByNumber(number uint64) types.IHeader
- func (hc *RootHeaderChain) GetTd(hash common.Hash) *big.Int
- func (hc *RootHeaderChain) HasHeader(hash common.Hash) bool
- func (hc *RootHeaderChain) InsertHeaderChain(chain []*types.RootBlockHeader, writeHeader WhCallback, start time.Time) (int, error)
- func (hc *RootHeaderChain) SetCurrentHeader(head *types.RootBlockHeader)
- func (hc *RootHeaderChain) SetGenesis(head *types.RootBlockHeader)
- func (hc *RootHeaderChain) SetHead(head uint64, delFn DeleteCallback)
- func (hc *RootHeaderChain) ValidateHeaderChain(chain []*types.RootBlockHeader, checkFreq int) (int, error)
- func (hc *RootHeaderChain) WriteHeader(header *types.RootBlockHeader) (status WriteStatus, err error)
- func (hc *RootHeaderChain) WriteTd(hash common.Hash, td *big.Int) error
- type StateProcessor
- type StateTransition
- type TxPool
- func (pool *TxPool) AddLocal(tx *types.Transaction) error
- func (pool *TxPool) AddLocals(txs []*types.Transaction) []error
- func (pool *TxPool) AddRemote(tx *types.Transaction) error
- func (pool *TxPool) AddRemotes(txs []*types.Transaction) []error
- func (m *TxPool) CheckTxBeforeAdd(tx *types.Transaction) error
- func (pool *TxPool) Content() (map[common.Address]types.Transactions, map[common.Address]types.Transactions)
- func (pool *TxPool) GasPrice() *big.Int
- func (pool *TxPool) Get(hash common.Hash) *types.Transaction
- func (pool *TxPool) GetPendingTxsFromAddress(addr account.Recipient) types.Transactions
- func (pool *TxPool) GetQueueTxsFromAddress(addr account.Recipient) types.Transactions
- func (pool *TxPool) Locals() []common.Address
- func (pool *TxPool) Pending() (map[common.Address]types.Transactions, error)
- func (pool *TxPool) PendingCount() int
- func (pool *TxPool) SetGasPrice(price *big.Int)
- func (pool *TxPool) State() *state.ManagedState
- func (pool *TxPool) Stats() (int, int)
- func (pool *TxPool) Status(hashes []common.Hash) []TxStatus
- func (pool *TxPool) Stop()
- func (pool *TxPool) SubscribeNewTxsEvent(ch chan<- NewTxsEvent) event.Subscription
- type TxPoolConfig
- type TxStatus
- type Validator
- type WhCallback
- type WriteStatus
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrKnownBlock is returned when a block to import is already known locally. ErrKnownBlock = errors.New("block already known") // ErrGasLimitReached is returned by the gas pool if the amount of gas required // by a transaction is higher than what's left in the block. ErrGasLimitReached = errors.New("gas limit reached") // ErrBlacklistedHash is returned if a block to import is on the blacklist. ErrBlacklistedHash = errors.New("blacklisted hash") // ErrNonceTooHigh is returned if the nonce of a transaction is higher than the // next one expected based on the local chain. ErrNonceTooHigh = errors.New("nonce too high") //ErrPrevBlockMissing is returned if a block's previous block is not exist in DB ErrPrevBlockMissing = errors.New("previous hash block mismatch") // ErrUnknownAncestor is returned when validating a block requires an ancestor // that is unknown. ErrUnknownAncestor = errors.New("unknown ancestor") // ErrPrunedAncestor is returned when validating a block requires an ancestor // that is known, but the state of which is not available. ErrPrunedAncestor = errors.New("pruned ancestor") // ErrFutureBlock is returned when a block's timestamp is in the future according // to the current node. ErrFutureBlock = errors.New("block in the future") // ErrInvalidNumber is returned if a block's number doesn't equal it's parent's // plus one. ErrInvalidNumber = errors.New("invalid block number") ErrMinorBlockIsNil = errors.New("minor block is nil") ErrRootBlockIsNil = errors.New("root block is nil") ErrInvalidMinorBlock = errors.New("minor block is invalid") ErrHeightMismatch = errors.New("block height not match") ErrPreBlockNotFound = errors.New("parent block not found") ErrBranch = errors.New("branch not match") ErrTime = errors.New("time not match") ErrMetaHash = errors.New("meta hash not match") ErrExtraLimit = errors.New("extra data exceeds limit") ErrTrackLimit = errors.New("track data exceeds limit") ErrTxHash = errors.New("tx hash not match") ErrMinerFullShardKey = errors.New("coinbase full shard key not match") ErrDifficulty = errors.New("diff not match") ErrGasUsed = errors.New("gas used not match") ErrCoinbaseAmount = errors.New("wrong coinbase amount") ErrXShardList = errors.New("xShardReceivedGasUsed not match") ErrNetWorkID = errors.New("network id not match") ErrNotNeighbor = errors.New("is not a neighbor") ErrNotSameRootChain = errors.New("is not same root chain") )
var ( ErrorTxContinue = errors.New("apply tx continue") ErrorTxBreak = errors.New("apply tx break") )
var ( // ErrInvalidSender is returned if the transaction contains an invalid signature. ErrInvalidSender = errors.New("invalid sender") // ErrNonceTooLow is returned if the nonce of a transaction is lower than the // one present in the local chain. ErrNonceTooLow = errors.New("nonce too low") // ErrUnderpriced is returned if a transaction's gas price is below the minimum // configured for the transaction pool. ErrUnderpriced = errors.New("transaction underpriced") // ErrReplaceUnderpriced is returned if a transaction is attempted to be replaced // with a different one without the required price bump. ErrReplaceUnderpriced = errors.New("replacement transaction underpriced") // ErrInsufficientFunds is returned if the total cost of executing a transaction // is higher than the balance of the user's account. ErrInsufficientFunds = errors.New("insufficient funds for gas * price + value") // ErrIntrinsicGas is returned if the transaction is specified to use less gas // than required to start the invocation. ErrIntrinsicGas = errors.New("intrinsic gas too low") // ErrGasLimit is returned if a transaction's requested gas limit exceeds the // maximum allowance of the current block. ErrGasLimit = errors.New("exceeds block gas limit") // ErrNegativeValue is a sanity error to ensure noone is able to specify a // transaction with a negative value. ErrNegativeValue = errors.New("negative value") // ErrOversizedData is returned if the input data of a transaction is greater // than some meaningful limit a user might use. This is not a consensus error // making the transaction invalid, rather a DOS protection. ErrOversizedData = errors.New("oversized data") )
var DefaultTxPoolConfig = TxPoolConfig{ PriceLimit: 1, PriceBump: 10, AccountSlots: 16, GlobalSlots: 8092, AccountQueue: 64, GlobalQueue: 1024, Lifetime: 3 * time.Hour, NetWorkID: 3, }
DefaultTxPoolConfig contains the default configurations for the transaction pool.
var (
ErrNoGenesis = errors.New("Genesis not found in chain")
)
Functions ¶
func ApplyMessage ¶
func ApplyMessage(evm *vm.EVM, msg Message, gp *GasPool, feeRate *big.Rat) ([]byte, uint64, bool, error)
ApplyMessage computes the new state by applying the given message against the old state within the environment.
ApplyMessage returns the bytes returned by any EVM execution (if it took place), the gas used (which includes gas refunds) and an error if it failed. An error always indicates a core error meaning that the message would always fail for that particular state and would never be accepted within a block.
func ApplyTransaction ¶
func ApplyTransaction(config *params.ChainConfig, bc ChainContext, gp *GasPool, statedb *state.StateDB, header types.IHeader, tx *types.Transaction, usedGas *uint64, cfg vm.Config) ([]byte, *types.Receipt, uint64, error)
ApplyTransaction apply tx
func CanTransfer ¶
CanTransfer checks whether there are enough funds in the address' account to make a transfer. This does not take the necessary gas in to account to make the transfer valid.
func GenerateMinorBlockChain ¶
func GenerateMinorBlockChain(config *params.ChainConfig, quarkChainConfig *config.QuarkChainConfig, parent *types.MinorBlock, engine consensus.Engine, db ethdb.Database, n int, gen func(*config.QuarkChainConfig, int, *MinorBlockGen)) ([]*types.MinorBlock, []types.Receipts)
GenerateMinorChain creates a chain of n blocks. The first block's parent will be the provided parent. db is used to store intermediate states and should contain the parent's state trie.
The generator function is called with a new block generator for every block. Any transactions and uncles added to the generator become part of the block. If gen is nil, the blocks will be empty and their coinbase will be the zero address.
Blocks created by GenerateChain do not contain valid proof of work values. Inserting them into MinorBlockChain requires use of FakePow or a similar non-validating proof of work implementation.
Example ¶
var ( id1, _ = account.CreatRandomIdentity() id2, _ = account.CreatRandomIdentity() id3, _ = account.CreatRandomIdentity() addr1 = account.CreatAddressFromIdentity(id1, 0) addr2 = account.CreatAddressFromIdentity(id2, 0) addr3 = account.CreatAddressFromIdentity(id3, 0) db = ethdb.NewMemDatabase() fakeClusterConfig = config.NewClusterConfig() ) prvKey1, err := crypto.HexToECDSA(hex.EncodeToString(id1.GetKey().Bytes())) if err != nil { panic(err) } prvKey2, err := crypto.HexToECDSA(hex.EncodeToString(id2.GetKey().Bytes())) if err != nil { panic(err) } ids := fakeClusterConfig.Quarkchain.GetGenesisShardIds() for _, v := range ids { addr := addr1.AddressInShard(v) shardConfig := fakeClusterConfig.Quarkchain.GetShardConfigByFullShardID(v) shardConfig.Genesis.Alloc[addr] = big.NewInt(1000000) } fakeClusterConfig.Quarkchain.SkipMinorDifficultyCheck = true // Ensure that key1 has some funds in the genesis block. gspec := &Genesis{ qkcConfig: fakeClusterConfig.Quarkchain, } rootBlock := gspec.CreateRootBlock() genesis := gspec.MustCommitMinorBlock(db, rootBlock, gspec.qkcConfig.Chains[0].ShardSize|0) chain, _ := GenerateMinorBlockChain(params.TestChainConfig, fakeClusterConfig.Quarkchain, genesis, new(consensus.FakeEngine), db, 5, func(config *config.QuarkChainConfig, i int, gen *MinorBlockGen) { switch i { case 0: // In block 1, addr1 sends addr2 some ether. tx, _ := types.SignTx(types.NewEvmTransaction(gen.TxNonce(addr1.Recipient), account.BytesToIdentityRecipient(addr2.Recipient.Bytes()), big.NewInt(100000), params.TxGas, nil, 0, 0, 3, 0, nil), types.MakeSigner(0), prvKey1) gen.AddTx(config, transEvmTxToTx(tx)) case 1: // In block 2, addr1 sends some more ether to addr2. // addr2 passes it on to addr3. tx1, _ := types.SignTx(types.NewEvmTransaction(gen.TxNonce(addr1.Recipient), account.BytesToIdentityRecipient(addr2.Recipient.Bytes()), big.NewInt(1000), params.TxGas, nil, 0, 0, 3, 0, nil), types.MakeSigner(0), prvKey1) tx2, _ := types.SignTx(types.NewEvmTransaction(gen.TxNonce(addr2.Recipient), account.BytesToIdentityRecipient(addr3.Recipient.Bytes()), big.NewInt(1000), params.TxGas, nil, 0, 0, 3, 0, nil), types.MakeSigner(0), prvKey2) gen.AddTx(config, transEvmTxToTx(tx1)) gen.AddTx(config, transEvmTxToTx(tx2)) case 2: // Block 3 is empty but was mined by addr3. gen.SetCoinbase(account.NewAddress(account.BytesToIdentityRecipient(addr3.Recipient.Bytes()), 0)) gen.SetExtra([]byte("yeehaw")) } }) fakeFullShardID := fakeClusterConfig.Quarkchain.Chains[0].ShardSize | 0 // Import the chain. This runs all block validation rules. chainConfig := params.TestChainConfig blockchain, _ := NewMinorBlockChain(db, nil, chainConfig, fakeClusterConfig, new(consensus.FakeEngine), vm.Config{}, nil, fakeFullShardID) genesis, err = blockchain.InitGenesisState(rootBlock) if err != nil { panic(err) } defer blockchain.Stop() if i, err := blockchain.InsertChain(toMinorBlocks(chain)); err != nil { fmt.Printf("insert error (block %d): %v\n", chain[i].NumberU64(), err) return } state, _ := blockchain.State() fmt.Printf("last block: #%d\n", blockchain.CurrentBlock().Number()) fmt.Println("balance of addr1:", state.GetBalance(addr1.Recipient)) fmt.Println("balance of addr2:", state.GetBalance(addr2.Recipient)) fmt.Println("balance of addr3:", state.GetBalance(addr3.Recipient))
Output: last block: #5 balance of addr1: 899000 balance of addr2: 100000 balance of addr3: 2500000000000001000
func GenerateRootBlockChain ¶
func GenerateRootBlockChain(parent *types.RootBlock, engine consensus.Engine, n int, gen func(int, *RootBlockGen)) []*types.RootBlock
GenerateRootBlockChain creates a chain of n blocks. The first block's parent will be the provided parent. db is used to store intermediate states and should contain the parent's state trie.
The generator function is called with a new block generator for every block. Any transactions and uncles added to the generator become part of the block. If gen is nil, the blocks will be empty and their coinbase will be the zero address.
Blocks created by GenerateRootBlockChain do not contain valid proof of work values. Inserting them into BlockChain requires use of FakePow or a similar non-validating proof of work implementation.
Example ¶
var ( addr1 = account.Address{Recipient: account.Recipient{1}, FullShardKey: 0} addr2 = account.Address{Recipient: account.Recipient{2}, FullShardKey: 0} addr3 = account.Address{Recipient: account.Recipient{3}, FullShardKey: 0} db = ethdb.NewMemDatabase() qkcconfig = config.NewQuarkChainConfig() genesis = Genesis{qkcConfig: qkcconfig} genesisBlock = genesis.MustCommitRootBlock(db) engine = new(consensus.FakeEngine) ) chain := GenerateRootBlockChain(genesisBlock, engine, 5, func(i int, gen *RootBlockGen) { switch i { case 0: // In block 1, addr1 sends addr2 some ether. header := types.MinorBlockHeader{Number: 1, Coinbase: addr1, ParentHash: genesisBlock.Hash(), Time: genesisBlock.Time()} gen.Headers = append(gen.Headers, &header) case 1: // In block 2, addr1 sends some more ether to addr2. // addr2 passes it on to addr3. header1 := types.MinorBlockHeader{Number: 1, Coinbase: addr1, ParentHash: genesisBlock.Hash(), Time: genesisBlock.Time()} header2 := types.MinorBlockHeader{Number: 2, Coinbase: addr2, ParentHash: header1.Hash(), Time: genesisBlock.Time()} gen.Headers = append(gen.Headers, &header1) gen.Headers = append(gen.Headers, &header2) case 2: // Block 3 is empty but was mined by addr3. gen.SetCoinbase(addr3) gen.SetExtra([]byte("yeehaw")) } }) // Import the chain. This runs all block validation rules. blockchain, err := NewRootBlockChain(db, qkcconfig, engine, nil) if err != nil { fmt.Printf("new root block chain error %v\n", err) return } defer blockchain.Stop() blockchain.SetValidator(&fakeRootBlockValidator{nil}) if i, err := blockchain.InsertChain(ToBlocks(chain)); err != nil { fmt.Printf("insert error (block %d): %v\n", chain[i].NumberU64(), err) return } fmt.Printf("last block: #%d\n", blockchain.CurrentBlock().Number())
Output: last block: #5
func IntrinsicGas ¶
IntrinsicGas computes the 'intrinsic gas' for a message with the given data.
func NewEVMContext ¶
func SetReceiptsData ¶
func SetReceiptsData(config *config.QuarkChainConfig, mBlock types.IBlock, receipts types.Receipts) error
SetReceiptsData computes all the non-consensus fields of the receipts
func SetupGenesisMinorBlock ¶
func SetupGenesisRootBlock ¶
func SetupGenesisRootBlock(db ethdb.Database, genesis *Genesis) (*config.QuarkChainConfig, common.Hash, error)
SetupGenesisBlock writes or updates the genesis block in db. The block that will be used is:
genesis == nil genesis != nil +------------------------------------------ db has no genesis | main-net default | genesis db has genesis | from DB | genesis (if compatible)
The stored chain configuration will be updated if it is compatible (i.e. does not specify a fork block below the local head block). In case of a conflict, the error is a *params.ConfigCompatError and the new, unwritten config is returned.
The returned chain configuration is never nil.
func Transfer ¶
Transfer subtracts amount from sender and adds amount to recipient using the given Db
func ValidateTransaction ¶
func ValidateTransaction(state vm.StateDB, tx *types.Transaction, fromAddress *account.Address) error
ValidateTransaction validateTx before applyTx
Types ¶
type CacheConfig ¶
type CacheConfig struct { Disabled bool // Whether to disable trie write caching (archive node) TrieCleanLimit int // Memory allowance (MB) to use for caching trie nodes in memory TrieDirtyLimit int // Memory limit (MB) at which to start flushing dirty trie nodes to disk TrieTimeLimit time.Duration // Time limit after which to flush the current in-memory trie to disk }
CacheConfig contains the configuration values for the trie caching/pruning that's resident in a blockchain.
type ChainContext ¶
type ChainContext interface { // Engine retrieves the chain's consensus engine. Engine() consensus.Engine Config() *config.QuarkChainConfig // GetHeader returns the hash corresponding to their hash. GetHeader(common.Hash) types.IHeader }
ChainContext supports retrieving Headers and consensus parameters from the current blockchain to be used during transaction processing.
type DeleteCallback ¶
type DeleteCallback func(rawdb.DatabaseDeleter, common.Hash)
DeleteCallback is a callback function that is called by SetHead before each header is deleted.
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter can be used to retrieve and filter logs.
type GasPool ¶
type GasPool uint64
GasPool tracks the amount of gas available during execution of the transactions in a block. The zero value is a pool with zero gas available.
type Genesis ¶
type Genesis struct {
// contains filtered or unexported fields
}
func NewGenesis ¶
func NewGenesis(config *config.QuarkChainConfig) *Genesis
func (*Genesis) CommitMinorBlock ¶
func (g *Genesis) CommitMinorBlock(db ethdb.Database, rootBlock *types.RootBlock, fullShardId uint32) (*types.MinorBlock, error)
CommitMinorBlock writes the block and state of a genesis specification to the database. The block is committed as the canonical head block.
func (*Genesis) CommitRootBlock ¶
CommitRootBlock writes the block and state of a genesis specification to the database. The block is committed as the canonical head block.
func (*Genesis) CreateMinorBlock ¶
func (*Genesis) CreateRootBlock ¶
func (*Genesis) MustCommitMinorBlock ¶
func (g *Genesis) MustCommitMinorBlock(db ethdb.Database, rootBlock *types.RootBlock, fullShardId uint32) *types.MinorBlock
MustCommit writes the genesis block and state to db, panicking on error. The block is committed as the canonical head block.
type GenesisAccount ¶
type GenesisAccount struct { Code []byte `json:"code,omitempty"` Storage map[common.Hash]common.Hash `json:"storage,omitempty"` Balance *big.Int `json:"balance" gencodec:"required"` Nonce uint64 `json:"nonce,omitempty"` PrivateKey []byte `json:"secretKey,omitempty"` // for tests }
GenesisAccount is an account in the state of the genesis block.
type GenesisMismatchError ¶
func (*GenesisMismatchError) Error ¶
func (e *GenesisMismatchError) Error() string
type HeaderChain ¶
type HeaderChain struct {
// contains filtered or unexported fields
}
HeaderChain implements the basic block header chain logic that is shared by core.MinorBlockChain 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 NewMinorHeaderChain ¶
func NewMinorHeaderChain(chainDb ethdb.Database, config *config.QuarkChainConfig, engine consensus.Engine, procInterrupt func() bool) (*HeaderChain, error)
NewMinorHeaderChain creates a new HeaderChain 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 (*HeaderChain) Config ¶
func (hc *HeaderChain) Config() *config.QuarkChainConfig
Config retrieves the header chain's chain configuration.
func (*HeaderChain) CurrentHeader ¶
func (hc *HeaderChain) CurrentHeader() types.IHeader
CurrentHeader retrieves the current head header of the canonical chain. The header is retrieved from the HeaderChain's internal cache.
func (*HeaderChain) Engine ¶
func (hc *HeaderChain) Engine() consensus.Engine
Engine retrieves the header chain's consensus engine.
func (*HeaderChain) GetAncestor ¶
func (hc *HeaderChain) 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 (*HeaderChain) GetBlock ¶
func (hc *HeaderChain) GetBlock(hash common.Hash) types.IBlock
GetBlock implements consensus.ChainReader, and returns nil for every input as a header chain does not have blocks available for retrieval.
func (*HeaderChain) GetBlockHashesFromHash ¶
GetBlockHashesFromHash retrieves a number of block hashes starting at a given hash, fetching towards the genesis block.
func (*HeaderChain) GetBlockNumber ¶
func (hc *HeaderChain) GetBlockNumber(hash common.Hash) *uint64
GetBlockNumber retrieves the block number belonging to the given hash from the cache or database
func (*HeaderChain) GetHeader ¶
func (hc *HeaderChain) GetHeader(hash common.Hash) types.IHeader
GetHeader retrieves a block header from the database by hash and number, caching it if found.
func (*HeaderChain) GetHeaderByHash ¶
func (hc *HeaderChain) GetHeaderByHash(hash common.Hash) types.IHeader
GetHeaderByHash retrieves a block header from the database by hash, caching it if found.
func (*HeaderChain) GetHeaderByNumber ¶
func (hc *HeaderChain) GetHeaderByNumber(number uint64) types.IHeader
GetHeaderByNumber retrieves a block header from the database by number, caching it (associated with its hash) if found.
func (*HeaderChain) GetTd ¶
GetTd retrieves a block's total difficulty in the canonical chain from the database by hash and number, caching it if found.
func (*HeaderChain) GetTdByHash ¶
func (hc *HeaderChain) 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 (*HeaderChain) HasHeader ¶
func (hc *HeaderChain) HasHeader(hash common.Hash, number uint64) bool
HasHeader checks if a block header is present in the database or not.
func (*HeaderChain) InsertHeaderChain ¶
func (hc *HeaderChain) InsertHeaderChain(chain []*types.MinorBlockHeader, writeHeader MinorWhCallback, start time.Time) (int, error)
InsertHeaderChain attempts to insert the given header chain in to the local chain, possibly creating a reorg. If an error is returned, it will return the index number of the failing header as well an error describing what went wrong.
The verify parameter can be used to fine tune whether nonce verification should be done or not. The reason behind the optional check is because some of the header retrieval mechanisms already need to verfy nonces, as well as because nonces can be verified sparsely, not needing to check each.
func (*HeaderChain) SetCurrentHeader ¶
func (hc *HeaderChain) SetCurrentHeader(head *types.MinorBlockHeader)
SetCurrentHeader sets the current head header of the canonical chain.
func (*HeaderChain) SetGenesis ¶
func (hc *HeaderChain) SetGenesis(head *types.MinorBlockHeader)
SetGenesis sets a new genesis block header for the chain
func (*HeaderChain) SetHead ¶
func (hc *HeaderChain) 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 (*HeaderChain) ValidateHeaderChain ¶
func (hc *HeaderChain) ValidateHeaderChain(chain []*types.MinorBlockHeader, checkFreq int) (int, error)
func (*HeaderChain) WriteHeader ¶
func (hc *HeaderChain) WriteHeader(header *types.MinorBlockHeader) (status WriteStatus, err 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).
type Message ¶
type Message interface { From() common.Address //FromFrontier() (common.Address, error) To() *common.Address GasPrice() *big.Int Gas() uint64 Value() *big.Int Nonce() uint64 CheckNonce() bool Data() []byte IsCrossShard() bool FromFullShardKey() uint32 ToFullShardKey() uint32 TxHash() common.Hash }
Message represents a message sent to a contract.
type MinorBlockChain ¶
type MinorBlockChain struct {
// contains filtered or unexported fields
}
MinorBlockChain represents the canonical chain given a database with a genesis block. The Blockchain manages chain imports, reverts, chain reorganisations.
Importing blocks in to the block chain happens according to the set of rules defined by the two stage Validator. Processing of blocks is done using the Processor which processes the included transaction. The validation of the state is done in the second part of the Validator. Failing results in aborting of the import.
The MinorBlockChain also helps in returning blocks from **any** chain included in the database as well as blocks that represents the canonical chain. It's important to note that GetBlock can return any block and does not need to be included in the canonical one where as GetBlockByNumber always represents the canonical chain.
func NewMinorBlockChain ¶
func NewMinorBlockChain( db ethdb.Database, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, clusterConfig *config.ClusterConfig, engine consensus.Engine, vmConfig vm.Config, shouldPreserve func(block *types.MinorBlock) bool, fullShardID uint32, ) (*MinorBlockChain, error)
NewMinorBlockChain returns a fully initialised block chain using information available in the database. It initialises the default Ethereum Validator and Processor.
func (*MinorBlockChain) AddCrossShardTxListByMinorBlockHash ¶
func (m *MinorBlockChain) AddCrossShardTxListByMinorBlockHash(h common.Hash, txList types.CrossShardTransactionDepositList)
AddCrossShardTxListByMinorBlockHash add crossShardTxList by slave
func (*MinorBlockChain) AddRootBlock ¶
func (m *MinorBlockChain) AddRootBlock(rBlock *types.RootBlock) (bool, error)
AddRootBlock add root block for minorBlockChain
func (*MinorBlockChain) AddTx ¶
func (m *MinorBlockChain) AddTx(tx *types.Transaction) error
AddTx add tx to txPool
func (*MinorBlockChain) Config ¶
func (m *MinorBlockChain) Config() *config.QuarkChainConfig
Config retrieves the blockchain's chain configuration.
func (*MinorBlockChain) CreateBlockToMine ¶
func (m *MinorBlockChain) CreateBlockToMine(createTime *uint64, address *account.Address, gasLimit *big.Int) (*types.MinorBlock, error)
CreateBlockToMine create block to mine
func (*MinorBlockChain) CurrentBlock ¶
func (m *MinorBlockChain) CurrentBlock() *types.MinorBlock
CurrentBlock retrieves the current head block of the canonical chain. The block is retrieved from the blockchain's internal cache.
func (*MinorBlockChain) CurrentHeader ¶
func (m *MinorBlockChain) CurrentHeader() types.IHeader
CurrentHeader retrieves the current head header of the canonical chain. The header is retrieved from the HeaderChain's internal cache.
func (*MinorBlockChain) Engine ¶
func (m *MinorBlockChain) Engine() consensus.Engine
Engine retrieves the blockchain's consensus engine.
func (*MinorBlockChain) EstimateGas ¶
func (m *MinorBlockChain) EstimateGas(tx *types.Transaction, fromAddress account.Address) (uint32, error)
EstimateGas estimate gas for this tx
func (*MinorBlockChain) ExecuteTx ¶
func (m *MinorBlockChain) ExecuteTx(tx *types.Transaction, fromAddress *account.Address, height *uint64) ([]byte, error)
ExecuteTx execute tx
func (*MinorBlockChain) Export ¶
func (m *MinorBlockChain) Export(w io.Writer) error
Export writes the active chain to the given writer.
func (*MinorBlockChain) FinalizeAndAddBlock ¶
func (m *MinorBlockChain) FinalizeAndAddBlock(block *types.MinorBlock) (*types.MinorBlock, types.Receipts, error)
FinalizeAndAddBlock finalize minor block and add it to chain only used in test now
func (*MinorBlockChain) GasLimit ¶
func (m *MinorBlockChain) GasLimit() uint64
GasLimit returns the gas limit of the current HEAD block.
func (*MinorBlockChain) GasPrice ¶
func (m *MinorBlockChain) GasPrice() (uint64, error)
GasPrice gas price
func (*MinorBlockChain) Genesis ¶
func (m *MinorBlockChain) Genesis() *types.MinorBlock
Genesis retrieves the chain's genesis block.
func (*MinorBlockChain) GetAncestor ¶
func (m *MinorBlockChain) 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 (*MinorBlockChain) GetBalance ¶
GetBalance get balance for address
func (*MinorBlockChain) GetBlock ¶
func (m *MinorBlockChain) GetBlock(hash common.Hash) types.IBlock
GetBlock retrieves a block from the database by hash and number, caching it if found.
func (*MinorBlockChain) GetBlockByNumber ¶
func (m *MinorBlockChain) GetBlockByNumber(number uint64) types.IBlock
GetBlockByNumber retrieves a block from the database by number, caching it (associated with its hash) if found.
func (*MinorBlockChain) GetBlockHashesFromHash ¶
GetBlockHashesFromHash retrieves a number of block hashes starting at a given hash, fetching towards the genesis block.
func (*MinorBlockChain) GetBlocksFromHash ¶
GetBlocksFromHash returns the block corresponding to hash and up to n-1 ancestors. [deprecated by eth/62]
func (*MinorBlockChain) GetBranch ¶
func (m *MinorBlockChain) GetBranch() account.Branch
func (*MinorBlockChain) GetHeader ¶
func (m *MinorBlockChain) GetHeader(hash common.Hash) types.IHeader
GetHeader retrieves a block header from the database by hash and number, caching it if found.
func (*MinorBlockChain) GetHeaderByHash ¶
func (m *MinorBlockChain) GetHeaderByHash(hash common.Hash) types.IHeader
GetHeaderByHash retrieves a block header from the database by hash, caching it if found.
func (*MinorBlockChain) GetHeaderByNumber ¶
func (m *MinorBlockChain) GetHeaderByNumber(number uint64) types.IHeader
GetHeaderByNumber retrieves a block header from the database by number, caching it (associated with its hash) if found.
func (*MinorBlockChain) GetLogs ¶
func (m *MinorBlockChain) GetLogs(hash common.Hash) [][]*types.Log
func (*MinorBlockChain) GetLogsByAddressAndTopic ¶
func (*MinorBlockChain) GetMinorBlock ¶
func (m *MinorBlockChain) GetMinorBlock(hash common.Hash) *types.MinorBlock
GetMinorBlock retrieves a block from the database by hash, caching it if found.
func (*MinorBlockChain) GetPOSWCoinbaseBlockCnt ¶
func (*MinorBlockChain) GetReceiptsByHash ¶
func (m *MinorBlockChain) GetReceiptsByHash(hash common.Hash) types.Receipts
GetReceiptsByHash retrieves the receipts for all transactions in a given block.
func (*MinorBlockChain) GetRootBlockByHash ¶
func (m *MinorBlockChain) GetRootBlockByHash(hash common.Hash) *types.RootBlock
GetRootBlockByHash get rootBlock by hash in minorBlockChain
func (*MinorBlockChain) GetRootTip ¶
func (m *MinorBlockChain) GetRootTip() *types.RootBlockHeader
func (*MinorBlockChain) GetShardStatus ¶
func (m *MinorBlockChain) GetShardStatus() (*rpc.ShardStatus, error)
GetShardStatus show shardStatus
func (*MinorBlockChain) GetStorageAt ¶
func (m *MinorBlockChain) GetStorageAt(recipient account.Recipient, key common.Hash, height *uint64) (common.Hash, error)
GetStorageAt get storage for addr
func (*MinorBlockChain) GetTd ¶
GetTd retrieves a block's total difficulty in the canonical chain from the database by hash and number, caching it if found.
func (*MinorBlockChain) GetTdByHash ¶
func (m *MinorBlockChain) 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 (*MinorBlockChain) GetTransactionByAddress ¶
func (m *MinorBlockChain) GetTransactionByAddress(address account.Address, start []byte, limit uint32) ([]*rpc.TransactionDetail, []byte, error)
func (*MinorBlockChain) GetTransactionByHash ¶
func (m *MinorBlockChain) GetTransactionByHash(hash common.Hash) (*types.MinorBlock, uint32)
GetTransactionByHash get tx by hash
func (*MinorBlockChain) GetTransactionCount ¶
func (m *MinorBlockChain) GetTransactionCount(recipient account.Recipient, height *uint64) (uint64, error)
GetTransactionCount get txCount for addr
func (*MinorBlockChain) GetTransactionReceipt ¶
func (m *MinorBlockChain) GetTransactionReceipt(hash common.Hash) (*types.MinorBlock, uint32, *types.Receipt)
GetTransactionReceipt get tx receipt by hash for slave
func (*MinorBlockChain) GetUnconfirmedHeaderList ¶
func (m *MinorBlockChain) GetUnconfirmedHeaderList() []*types.MinorBlockHeader
GetUnconfirmedHeaderList get unconfirmed headerList
func (*MinorBlockChain) GetUnconfirmedHeadersCoinbaseAmount ¶
func (m *MinorBlockChain) GetUnconfirmedHeadersCoinbaseAmount() uint64
GetUnconfirmedHeadersCoinbaseAmount get unconfirmed Headers coinbase amount
func (*MinorBlockChain) GetVMConfig ¶
func (m *MinorBlockChain) GetVMConfig() *vm.Config
GetVMConfig returns the block chain VM config.
func (*MinorBlockChain) HasBlock ¶
func (m *MinorBlockChain) HasBlock(hash common.Hash) bool
HasBlock checks if a block is fully present in the database or not.
func (*MinorBlockChain) HasBlockAndState ¶
func (m *MinorBlockChain) HasBlockAndState(hash common.Hash) bool
HasBlockAndState checks if a block and associated state trie is fully present in the database or not, caching it if present.
func (*MinorBlockChain) HasHeader ¶
func (m *MinorBlockChain) HasHeader(hash common.Hash, number uint64) bool
HasHeader checks if a block header is present in the database or not, caching it if present.
func (*MinorBlockChain) HasState ¶
func (m *MinorBlockChain) HasState(hash common.Hash) bool
HasState checks if state trie is fully present in the database or not.
func (*MinorBlockChain) InitFromRootBlock ¶
func (m *MinorBlockChain) InitFromRootBlock(rBlock *types.RootBlock) error
InitFromRootBlock init minorBlockChain from rootBlock
func (*MinorBlockChain) InitGenesisState ¶
func (m *MinorBlockChain) InitGenesisState(rBlock *types.RootBlock) (*types.MinorBlock, error)
func (*MinorBlockChain) InsertChain ¶
func (m *MinorBlockChain) InsertChain(chain []types.IBlock) (int, error)
InsertChain attempts to insert the given batch of blocks in to the canonical chain or, otherwise, create a fork. If an error is returned it will return the index number of the failing block as well an error describing what went wrong.
After insertion is done, all accumulated events will be fired.
func (*MinorBlockChain) InsertChainForDeposits ¶
func (m *MinorBlockChain) InsertChainForDeposits(chain []types.IBlock) (int, [][]*types.CrossShardTransactionDeposit, error)
InsertChainForDeposits also return cross-shard transaction deposits in addition to content returned from `InsertChain`.
func (*MinorBlockChain) InsertHeaderChain ¶
InsertHeaderChain attempts to insert the given header chain in to the local chain, possibly creating a reorg. If an error is returned, it will return the index number of the failing header as well an error describing what went wrong.
The verify parameter can be used to fine tune whether nonce verification should be done or not. The reason behind the optional check is because some of the header retrieval mechanisms already need to verify nonces, as well as because nonces can be verified sparsely, not needing to check each.
func (*MinorBlockChain) InsertReceiptChain ¶
func (m *MinorBlockChain) InsertReceiptChain(blockChain []types.IBlock, receiptChain []types.Receipts) (int, error)
InsertReceiptChain attempts to complete an already existing header chain with transaction and receipt data.
func (*MinorBlockChain) POSWDiffAdjust ¶
func (m *MinorBlockChain) POSWDiffAdjust(block types.IBlock) (uint64, error)
POSWDiffAdjust POSW diff calc,already locked by insertChain TODO to finish it later
func (*MinorBlockChain) PostChainEvents ¶
func (m *MinorBlockChain) PostChainEvents(events []interface{}, logs []*types.Log)
PostChainEvents iterates over the events generated by a chain insertion and posts them into the event feed. TODO: Should not expose PostChainEvents. The chain events should be posted in WriteBlock.
func (*MinorBlockChain) Processor ¶
func (m *MinorBlockChain) Processor() Processor
Processor returns the current processor.
func (*MinorBlockChain) ReadCrossShardTxList ¶
func (m *MinorBlockChain) ReadCrossShardTxList(hash common.Hash) *types.CrossShardTransactionDepositList
func (*MinorBlockChain) ReadLastConfirmedMinorBlockHeaderAtRootBlock ¶
func (m *MinorBlockChain) ReadLastConfirmedMinorBlockHeaderAtRootBlock(hash common.Hash) common.Hash
func (*MinorBlockChain) Reset ¶
func (m *MinorBlockChain) Reset() error
reset purges the entire blockchain, restoring it to its genesis state.
func (*MinorBlockChain) ResetWithGenesisBlock ¶
func (m *MinorBlockChain) ResetWithGenesisBlock(genesis *types.MinorBlock) error
ResetWithGenesisBlock purges the entire blockchain, restoring it to the specified genesis state.
func (*MinorBlockChain) Rollback ¶
func (m *MinorBlockChain) Rollback(chain []common.Hash)
Rollback is designed to remove a chain of links from the database that aren't certain enough to be valid.
func (*MinorBlockChain) SetBroadcastMinorBlockFunc ¶
func (m *MinorBlockChain) SetBroadcastMinorBlockFunc(f func(block *types.MinorBlock) error)
func (*MinorBlockChain) SetHead ¶
func (m *MinorBlockChain) SetHead(head uint64) error
SetHead rewinds the local chain to a new head. In the case of Headers, everything above the new head will be deleted and the new one set. In the case of blocks though, the head may be further rewound if block bodies are missing (non-archive nodes after a fast sync). already have locked
func (*MinorBlockChain) SetProcessor ¶
func (m *MinorBlockChain) SetProcessor(processor Processor)
SetProcessor sets the processor required for making state modifications.
func (*MinorBlockChain) SetValidator ¶
func (m *MinorBlockChain) SetValidator(validator Validator)
SetValidator sets the validator which is used to validate incoming blocks.
func (*MinorBlockChain) State ¶
func (m *MinorBlockChain) State() (*state.StateDB, error)
State returns a new mutable state based on the current HEAD block.
func (*MinorBlockChain) StateAt ¶
StateAt returns a new mutable state based on a particular point in time.
func (*MinorBlockChain) StateCache ¶
func (m *MinorBlockChain) StateCache() state.Database
StateCache returns the caching database underpinning the blockchain instance.
func (*MinorBlockChain) Stop ¶
func (m *MinorBlockChain) Stop()
Stop stops the blockchain service. If any imports are currently in progress it will abort them using the procInterrupt.
func (*MinorBlockChain) SubscribeChainEvent ¶
func (m *MinorBlockChain) SubscribeChainEvent(ch chan<- MinorChainEvent) event.Subscription
SubscribeChainEvent registers a subscription of ChainEvent.
func (*MinorBlockChain) SubscribeChainHeadEvent ¶
func (m *MinorBlockChain) SubscribeChainHeadEvent(ch chan<- MinorChainHeadEvent) event.Subscription
SubscribeChainHeadEvent registers a subscription of ChainHeadEvent.
func (*MinorBlockChain) SubscribeChainSideEvent ¶
func (m *MinorBlockChain) SubscribeChainSideEvent(ch chan<- MinorChainSideEvent) event.Subscription
SubscribeChainSideEvent registers a subscription of ChainSideEvent.
func (*MinorBlockChain) SubscribeLogsEvent ¶
func (m *MinorBlockChain) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription
SubscribeLogsEvent registers a subscription of []*types.Log.
func (*MinorBlockChain) SubscribeRemovedLogsEvent ¶
func (m *MinorBlockChain) SubscribeRemovedLogsEvent(ch chan<- RemovedLogsEvent) event.Subscription
SubscribeRemovedLogsEvent registers a subscription of RemovedLogsEvent.
func (*MinorBlockChain) TrieNode ¶
func (m *MinorBlockChain) 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 (*MinorBlockChain) Validator ¶
func (m *MinorBlockChain) Validator() Validator
Validator returns the current validator.
func (*MinorBlockChain) WriteBlockWithState ¶
func (m *MinorBlockChain) WriteBlockWithState(block *types.MinorBlock, receipts []*types.Receipt, state *state.StateDB, xShardList []*types.CrossShardTransactionDeposit, updateTip bool) (status WriteStatus, err error)
WriteBlockWithState writes the block and all associated state to the database.
func (*MinorBlockChain) WriteBlockWithoutState ¶
WriteBlockWithoutState writes only the block and its metadata to the database, but does not write any state. This is used to construct competing side forks up to the point where they exceed the canonical total difficulty.
type MinorBlockGen ¶
type MinorBlockGen struct {
// contains filtered or unexported fields
}
MinorBlockGen creates blocks for testing. See GenerateChain for a detailed explanation.
func (*MinorBlockGen) AddTx ¶
func (b *MinorBlockGen) AddTx(quarkChainConfig *config.QuarkChainConfig, tx *types.Transaction)
AddTx adds a transaction to the generated block. If no coinbase has been set, the block's coinbase is set to the zero address.
AddTx panics if the transaction cannot be executed. In addition to the protocol-imposed limitations (gas limit, etc.), there are some further limitations on the content of transactions that can be added. Notably, contract code relying on the BLOCKHASH instruction will panic during execution.
func (*MinorBlockGen) AddTxWithChain ¶
func (b *MinorBlockGen) AddTxWithChain(quarkChainConfig *config.QuarkChainConfig, bc *MinorBlockChain, tx *types.Transaction)
AddTxWithChain adds a transaction to the generated block. If no coinbase has been set, the block's coinbase is set to the zero address.
AddTxWithChain panics if the transaction cannot be executed. In addition to the protocol-imposed limitations (gas limit, etc.), there are some further limitations on the content of transactions that can be added. If contract code relies on the BLOCKHASH instruction, the block in chain will be returned.
func (*MinorBlockGen) Number ¶
func (b *MinorBlockGen) Number() *big.Int
Number returns the block number of the block being generated.
func (*MinorBlockGen) PrevBlock ¶
func (b *MinorBlockGen) PrevBlock(index int) *types.MinorBlock
PrevBlock returns a previously generated block by number. It panics if num is greater or equal to the number of the block being generated. For index -1, PrevBlock returns the parent block given to GenerateChain.
func (*MinorBlockGen) SetCoinbase ¶
func (b *MinorBlockGen) SetCoinbase(addr account.Address)
SetCoinbase sets the coinbase of the generated block. It can be called at most once.
func (*MinorBlockGen) SetDifficulty ¶
func (b *MinorBlockGen) SetDifficulty(value uint64)
OffsetTime modifies the time instance of a block, implicitly changing its associated difficulty. It's useful to test scenarios where forking is not tied to chain length directly.
func (*MinorBlockGen) SetExtra ¶
func (b *MinorBlockGen) SetExtra(data []byte)
SetExtra sets the extra data field of the generated block.
func (*MinorBlockGen) SetNonce ¶
func (b *MinorBlockGen) SetNonce(nonce uint64)
SetNonce sets the nonce field of the generated block.
type MinorBlockValidator ¶
type MinorBlockValidator struct {
// contains filtered or unexported fields
}
MinorBlockValidator is responsible for validating block Headers, uncles and processed state.
MinorBlockValidator implements Validator.
func NewBlockValidator ¶
func NewBlockValidator(quarkChainConfig *config.QuarkChainConfig, blockchain *MinorBlockChain, engine consensus.Engine, branch account.Branch) *MinorBlockValidator
NewBlockValidator returns a new block validator which is safe for re-use
func (*MinorBlockValidator) ValidateBlock ¶
func (v *MinorBlockValidator) ValidateBlock(mBlock types.IBlock) error
ValidateBlock validates the given block's uncles and verifies the block header's transaction and uncle roots. The Headers are assumed to be already validated at this point.
func (*MinorBlockValidator) ValidateHeader ¶
func (v *MinorBlockValidator) ValidateHeader(header types.IHeader) error
ValidateHeader calls underlying engine's header verification method plus some sanity check.
func (*MinorBlockValidator) ValidateState ¶
func (v *MinorBlockValidator) ValidateState(mBlock, parent types.IBlock, statedb *state.StateDB, receipts types.Receipts, usedGas uint64) error
ValidateState validates the various changes that happen after a state transition, such as amount of used gas, the receipt roots and the state root itself. ValidateState returns a database batch if the validation was a success otherwise nil and an error is returned.
func (*MinorBlockValidator) ValidatorSeal ¶
func (v *MinorBlockValidator) ValidatorSeal(mHeader types.IHeader) error
ValidatorBlockSeal validate minor block seal when validate block
type MinorChainEvent ¶
type MinorChainHeadEvent ¶
type MinorChainHeadEvent struct{ Block *types.MinorBlock }
type MinorChainSideEvent ¶
type MinorWhCallback ¶
type MinorWhCallback func(header *types.MinorBlockHeader) error
MinorWhCallback 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 MinorBlockChain 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.
type NewMinedBlockEvent ¶
NewMinedBlockEvent is posted when a block has been imported.
type NewTxsEvent ¶
type NewTxsEvent struct{ Txs []*types.Transaction }
NewTxsEvent is posted when a batch of transactions enter the transaction pool.
type PendingLogsEvent ¶
PendingLogsEvent is posted pre mining and notifies of pending logs.
type Processor ¶
type Processor interface {
Process(block *types.MinorBlock, statedb *state.StateDB, cfg vm.Config, txIncluded []*types.Transaction, xShardReceivedTxList []*types.CrossShardTransactionDeposit) (types.Receipts, []*types.Log, uint64, error)
}
Processor is an interface for processing blocks using a given initial state.
Process takes the block to be processed and the statedb upon which the initial state is based. It should return the receipts generated, amount of gas used in the process and return an error if any of the internal rules failed.
type RemovedLogsEvent ¶
RemovedLogsEvent is posted when a reorg happens
type RootBlockChain ¶
type RootBlockChain struct {
// contains filtered or unexported fields
}
RootBlockChain represents the canonical chain given a database with a genesis block. The Blockchain manages chain imports, reverts, chain reorganisations.
Importing blocks in to the block chain happens according to the set of rules defined by the two stage Validator. Processing of blocks is done using the Processor which processes the included transaction. The validation of the state is done in the second part of the Validator. Failing results in aborting of the import.
The RootBlockChain also helps in returning blocks from **any** chain included in the database as well as blocks that represents the canonical chain. It's important to note that GetBlock can return any block and does not need to be included in the canonical one where as GetBlockByNumber always represents the canonical chain.
func NewRootBlockChain ¶
func NewRootBlockChain(db ethdb.Database, chainConfig *config.QuarkChainConfig, engine consensus.Engine, shouldPreserve func(block *types.RootBlock) bool) (*RootBlockChain, error)
NewBlockChain returns a fully initialized block chain using information available in the database. It initializes the default Ethereum Validator and Processor.
func (*RootBlockChain) AddValidatedMinorBlockHeader ¶
func (bc *RootBlockChain) AddValidatedMinorBlockHeader(hash common.Hash)
func (*RootBlockChain) CalculateRootBlockCoinBase ¶
func (bc *RootBlockChain) CalculateRootBlockCoinBase(rootBlock *types.RootBlock) *big.Int
func (*RootBlockChain) ClearCommittingHash ¶
func (bc *RootBlockChain) ClearCommittingHash()
func (*RootBlockChain) Config ¶
func (bc *RootBlockChain) Config() *config.QuarkChainConfig
Config retrieves the blockchain's chain configuration.
func (*RootBlockChain) CreateBlockToMine ¶
func (bc *RootBlockChain) CreateBlockToMine(mHeaderList []*types.MinorBlockHeader, address *account.Address, createTime *uint64) (*types.RootBlock, error)
func (*RootBlockChain) CurrentBlock ¶
func (bc *RootBlockChain) CurrentBlock() *types.RootBlock
CurrentBlock retrieves the current head block of the canonical chain. The block is retrieved from the blockchain's internal cache.
func (*RootBlockChain) CurrentHeader ¶
func (bc *RootBlockChain) CurrentHeader() types.IHeader
CurrentHeader retrieves the current head header of the canonical chain. The header is retrieved from the RootHeaderChain's internal cache.
func (*RootBlockChain) Engine ¶
func (bc *RootBlockChain) Engine() consensus.Engine
Engine retrieves the blockchain's consensus engine.
func (*RootBlockChain) Export ¶
func (bc *RootBlockChain) Export(w io.Writer) error
Export writes the active chain to the given writer.
func (*RootBlockChain) Genesis ¶
func (bc *RootBlockChain) Genesis() *types.RootBlock
Genesis retrieves the chain's genesis block.
func (*RootBlockChain) GetAncestor ¶
func (bc *RootBlockChain) 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 (*RootBlockChain) GetBlock ¶
func (bc *RootBlockChain) GetBlock(hash common.Hash) types.IBlock
GetBlock retrieves a block from the database by hash and number, caching it if found.
func (*RootBlockChain) GetBlockByNumber ¶
func (bc *RootBlockChain) GetBlockByNumber(number uint64) types.IBlock
GetBlockByNumber retrieves a block from the database by number, caching it (associated with its hash) if found.
func (*RootBlockChain) GetBlockCount ¶
func (*RootBlockChain) GetBlockHashesFromHash ¶
GetBlockHashesFromHash retrieves a number of block hashes starting at a given hash, fetching towards the genesis block.
func (*RootBlockChain) GetCommittingBlockHash ¶
func (bc *RootBlockChain) GetCommittingBlockHash() common.Hash
func (*RootBlockChain) GetHeader ¶
func (bc *RootBlockChain) GetHeader(hash common.Hash) types.IHeader
GetHeader retrieves a block header from the database by hash and number, caching it if found.
func (*RootBlockChain) GetHeaderByNumber ¶
func (bc *RootBlockChain) GetHeaderByNumber(number uint64) types.IHeader
GetHeaderByNumber retrieves a block header from the database by number, caching it (associated with its hash) if found.
func (*RootBlockChain) GetLatestMinorBlockHeaders ¶
func (bc *RootBlockChain) GetLatestMinorBlockHeaders(hash common.Hash) map[uint32]*types.MinorBlockHeader
func (*RootBlockChain) GetNextDifficulty ¶
func (bc *RootBlockChain) GetNextDifficulty(create *uint64) (*big.Int, error)
func (*RootBlockChain) GetTd ¶
func (bc *RootBlockChain) GetTd(hash common.Hash) *big.Int
GetTd retrieves a block's total difficulty in the canonical chain from the database by hash and number, caching it if found.
func (*RootBlockChain) HasBlock ¶
func (bc *RootBlockChain) HasBlock(hash common.Hash) bool
HasBlock checks if a block is fully present in the database or not.
func (*RootBlockChain) HasHeader ¶
func (bc *RootBlockChain) HasHeader(hash common.Hash) bool
HasHeader checks if a block header is present in the database or not, caching it if present.
func (*RootBlockChain) InsertChain ¶
func (bc *RootBlockChain) InsertChain(chain []types.IBlock) (int, error)
InsertChain attempts to insert the given batch of blocks in to the canonical chain or, otherwise, create a fork. If an error is returned it will return the index number of the failing block as well an error describing what went wrong.
After insertion is done, all accumulated events will be fired.
func (*RootBlockChain) InsertHeaderChain ¶
func (bc *RootBlockChain) InsertHeaderChain(chain []*types.RootBlockHeader, checkFreq int) (int, error)
InsertHeaderChain attempts to insert the given header chain in to the local chain, possibly creating a reorg. If an error is returned, it will return the index number of the failing header as well an error describing what went wrong.
The verify parameter can be used to fine tune whether nonce verification should be done or not. The reason behind the optional check is because some of the header retrieval mechanisms already need to verify nonces, as well as because nonces can be verified sparsely, not needing to check each.
func (*RootBlockChain) IsMinorBlockValidated ¶
func (bc *RootBlockChain) IsMinorBlockValidated(hash common.Hash) bool
func (*RootBlockChain) PostChainEvents ¶
func (bc *RootBlockChain) PostChainEvents(events []interface{})
PostChainEvents iterates over the events generated by a chain insertion and posts them into the event feed. TODO: Should not expose PostChainEvents. The chain events should be posted in WriteBlock.
func (*RootBlockChain) PutRootBlockIndex ¶
func (bc *RootBlockChain) PutRootBlockIndex(block *types.RootBlock) error
func (*RootBlockChain) Reset ¶
func (bc *RootBlockChain) Reset() error
Reset purges the entire blockchain, restoring it to its genesis state.
func (*RootBlockChain) ResetWithGenesisBlock ¶
func (bc *RootBlockChain) ResetWithGenesisBlock(genesis *types.RootBlock) error
ResetWithGenesisBlock purges the entire blockchain, restoring it to the specified genesis state.
func (*RootBlockChain) Rollback ¶
func (bc *RootBlockChain) Rollback(chain []common.Hash)
Rollback is designed to remove a chain of links from the database that aren't certain enough to be valid.
func (*RootBlockChain) SetBroadcastRootBlockFunc ¶
func (bc *RootBlockChain) SetBroadcastRootBlockFunc(f func(block *types.RootBlock) error)
func (*RootBlockChain) SetEnableCountMinorBlocks ¶
func (bc *RootBlockChain) SetEnableCountMinorBlocks(flag bool)
func (*RootBlockChain) SetHead ¶
func (bc *RootBlockChain) SetHead(head uint64) error
SetHead rewinds the local chain to a new head. In the case of Headers, everything above the new head will be deleted and the new one set. In the case of blocks though, the head may be further rewound if block bodies are missing (non-archive nodes after a fast sync).
func (*RootBlockChain) SetLatestMinorBlockHeaders ¶
func (bc *RootBlockChain) SetLatestMinorBlockHeaders(hash common.Hash, headerMap map[uint32]*types.MinorBlockHeader)
func (*RootBlockChain) SetValidator ¶
func (bc *RootBlockChain) SetValidator(validator Validator)
SetValidator sets the validator which is used to validate incoming blocks.
func (*RootBlockChain) Stop ¶
func (bc *RootBlockChain) Stop()
Stop stops the blockchain service. If any imports are currently in progress it will abort them using the procInterrupt.
func (*RootBlockChain) SubscribeChainEvent ¶
func (bc *RootBlockChain) SubscribeChainEvent(ch chan<- RootChainEvent) event.Subscription
SubscribeChainEvent registers a subscription of ChainEvent.
func (*RootBlockChain) SubscribeChainHeadEvent ¶
func (bc *RootBlockChain) SubscribeChainHeadEvent(ch chan<- RootChainHeadEvent) event.Subscription
SubscribeChainHeadEvent registers a subscription of ChainHeadEvent.
func (*RootBlockChain) SubscribeChainSideEvent ¶
func (bc *RootBlockChain) SubscribeChainSideEvent(ch chan<- RootChainSideEvent) event.Subscription
SubscribeChainSideEvent registers a subscription of ChainSideEvent.
func (*RootBlockChain) SubscribeRemovedLogsEvent ¶
func (bc *RootBlockChain) SubscribeRemovedLogsEvent(ch chan<- RemovedLogsEvent) event.Subscription
SubscribeRemovedLogsEvent registers a subscription of RemovedLogsEvent.
func (*RootBlockChain) Validator ¶
func (bc *RootBlockChain) Validator() Validator
Validator returns the current validator.
func (*RootBlockChain) WriteBlockWithState ¶
func (bc *RootBlockChain) WriteBlockWithState(block *types.RootBlock) (status WriteStatus, err error)
todo WriteBlockWithState writes the block and all associated state to the database.
func (*RootBlockChain) WriteBlockWithoutState ¶
WriteBlockWithoutState writes only the block and its metadata to the database, but does not write any state. This is used to construct competing side forks up to the point where they exceed the canonical total difficulty.
func (*RootBlockChain) WriteCommittingHash ¶
func (bc *RootBlockChain) WriteCommittingHash(hash common.Hash)
type RootBlockGen ¶
type RootBlockGen struct { Headers types.MinorBlockHeaders // contains filtered or unexported fields }
RootBlockGen creates blocks for testing. See GenerateRootBlockChain for a detailed explanation.
func (*RootBlockGen) Number ¶
func (b *RootBlockGen) Number() uint64
Number returns the block number of the block being generated.
func (*RootBlockGen) PrevBlock ¶
func (b *RootBlockGen) PrevBlock(index int) *types.RootBlock
PrevBlock returns a previously generated block by number. It panics if num is greater or equal to the number of the block being generated. For index -1, PrevBlock returns the parent block given to GenerateRootBlockChain.
func (*RootBlockGen) SetCoinbase ¶
func (b *RootBlockGen) SetCoinbase(addr account.Address)
SetCoinbase sets the coinbase of the generated block. It can be called at most once.
func (*RootBlockGen) SetDifficulty ¶
func (b *RootBlockGen) SetDifficulty(value uint64)
OffsetTime modifies the time instance of a block, implicitly changing its associated difficulty. It's useful to test scenarios where forking is not tied to chain length directly.
func (*RootBlockGen) SetExtra ¶
func (b *RootBlockGen) SetExtra(data []byte)
SetExtra sets the extra data field of the generated block.
func (*RootBlockGen) SetNonce ¶
func (b *RootBlockGen) SetNonce(nonce uint64)
SetNonce sets the nonce field of the generated block.
func (*RootBlockGen) SetTotalDifficulty ¶
func (b *RootBlockGen) SetTotalDifficulty(value *big.Int)
type RootBlockValidator ¶
type RootBlockValidator struct {
// contains filtered or unexported fields
}
RootBlockValidator implements Validator.
func NewRootBlockValidator ¶
func NewRootBlockValidator(config *config.QuarkChainConfig, blockchain *RootBlockChain, engine consensus.Engine) *RootBlockValidator
NewRootBlockValidator returns a new root block validator which is safe for re-use
func (*RootBlockValidator) ValidateBlock ¶
func (v *RootBlockValidator) ValidateBlock(block types.IBlock) error
ValidateBlock validates the given block and verifies the block header's roots.
func (*RootBlockValidator) ValidateHeader ¶
func (v *RootBlockValidator) ValidateHeader(header types.IHeader) error
RootBlockValidator calls underlying engine's header verification method.
func (*RootBlockValidator) ValidateState ¶
func (*RootBlockValidator) ValidatorSeal ¶
func (v *RootBlockValidator) ValidatorSeal(rHeader types.IHeader) error
type RootChainHeadEvent ¶
type RootChainSideEvent ¶
type RootHeaderChain ¶
type RootHeaderChain struct {
// contains filtered or unexported fields
}
RootHeaderChain implements the basic block header chain logic that is shared by core.RootBlockChain 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 NewHeaderChain ¶
func NewHeaderChain(chainDb ethdb.Database, config *config.QuarkChainConfig, engine consensus.Engine, procInterrupt func() bool) (*RootHeaderChain, error)
NewHeaderChain creates a new RootHeaderChain 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 (*RootHeaderChain) Config ¶
func (hc *RootHeaderChain) Config() *config.QuarkChainConfig
Config retrieves the header chain's chain configuration.
func (*RootHeaderChain) CurrentHeader ¶
func (hc *RootHeaderChain) CurrentHeader() types.IHeader
CurrentHeader retrieves the current head header of the canonical chain. The header is retrieved from the RootHeaderChain's internal cache.
func (*RootHeaderChain) Engine ¶
func (hc *RootHeaderChain) Engine() consensus.Engine
Engine retrieves the header chain's consensus engine.
func (*RootHeaderChain) GetAncestor ¶
func (hc *RootHeaderChain) 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 (*RootHeaderChain) GetBlock ¶
func (hc *RootHeaderChain) GetBlock(hash common.Hash) types.IBlock
GetBlock implements consensus.ChainReader, and returns nil for every input as a header chain does not have blocks available for retrieval.
func (*RootHeaderChain) GetBlockHashesFromHash ¶
GetBlockHashesFromHash retrieves a number of block hashes starting at a given hash, fetching towards the genesis block.
func (*RootHeaderChain) GetBlockNumber ¶
func (hc *RootHeaderChain) GetBlockNumber(hash common.Hash) *uint64
GetBlockNumber retrieves the block number belonging to the given hash from the cache or database
func (*RootHeaderChain) GetHeader ¶
func (hc *RootHeaderChain) GetHeader(hash common.Hash) types.IHeader
GetHeader retrieves a block header from the database by hash and number, caching it if found.
func (*RootHeaderChain) GetHeaderByNumber ¶
func (hc *RootHeaderChain) GetHeaderByNumber(number uint64) types.IHeader
GetHeaderByNumber retrieves a block header from the database by number, caching it (associated with its hash) if found.
func (*RootHeaderChain) GetTd ¶
func (hc *RootHeaderChain) GetTd(hash common.Hash) *big.Int
GetTd retrieves a block's total difficulty in the canonical chain from the database by hash and number, caching it if found.
func (*RootHeaderChain) HasHeader ¶
func (hc *RootHeaderChain) HasHeader(hash common.Hash) bool
HasHeader checks if a block header is present in the database or not.
func (*RootHeaderChain) InsertHeaderChain ¶
func (hc *RootHeaderChain) InsertHeaderChain(chain []*types.RootBlockHeader, writeHeader WhCallback, start time.Time) (int, error)
InsertHeaderChain attempts to insert the given header chain in to the local chain, possibly creating a reorg. If an error is returned, it will return the index number of the failing header as well an error describing what went wrong.
The verify parameter can be used to fine tune whether nonce verification should be done or not. The reason behind the optional check is because some of the header retrieval mechanisms already need to verfy nonces, as well as because nonces can be verified sparsely, not needing to check each.
func (*RootHeaderChain) SetCurrentHeader ¶
func (hc *RootHeaderChain) SetCurrentHeader(head *types.RootBlockHeader)
SetCurrentHeader sets the current head header of the canonical chain.
func (*RootHeaderChain) SetGenesis ¶
func (hc *RootHeaderChain) SetGenesis(head *types.RootBlockHeader)
SetGenesis sets a new genesis block header for the chain
func (*RootHeaderChain) SetHead ¶
func (hc *RootHeaderChain) 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 (*RootHeaderChain) ValidateHeaderChain ¶
func (hc *RootHeaderChain) ValidateHeaderChain(chain []*types.RootBlockHeader, checkFreq int) (int, error)
func (*RootHeaderChain) WriteHeader ¶
func (hc *RootHeaderChain) WriteHeader(header *types.RootBlockHeader) (status WriteStatus, err 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).
type StateProcessor ¶
type StateProcessor struct {
// contains filtered or unexported fields
}
StateProcessor is a basic Processor, which takes care of transitioning state from one point to another.
StateProcessor implements Processor.
func NewStateProcessor ¶
func NewStateProcessor(config *params.ChainConfig, bc *MinorBlockChain, engine consensus.Engine) *StateProcessor
NewStateProcessor initialises a new StateProcessor.
func (*StateProcessor) Process ¶
func (p *StateProcessor) Process(block *types.MinorBlock, statedb *state.StateDB, cfg vm.Config, evmTxIncluded []*types.Transaction, xShardReceiveTxList []*types.CrossShardTransactionDeposit) (types.Receipts, []*types.Log, uint64, error)
Process processes the state changes according to the Ethereum rules by running the transaction messages using the statedb and applying any rewards to both the processor (coinbase) and any included uncles.
Process returns the receipts and logs accumulated during the process and returns the amount of gas that was used in the process. If any of the transactions failed to execute due to insufficient gas it will return an error.
type StateTransition ¶
type StateTransition struct {
// contains filtered or unexported fields
}
The State Transitioning Model
A state transition is a change made when a transaction is applied to the current world state The state transitioning model does all the necessary work to work out a valid new state root.
1) Nonce handling 2) Pre pay gas 3) Create a new state object if the recipient is \0*32 4) Value transfer == If contract creation ==
4a) Attempt to run transaction data 4b) If valid, use result as code for the new state object
== end == 5) Run Script section 6) Derive new state root
func NewStateTransition ¶
func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) *StateTransition
NewStateTransition initialises and returns a new state transition object.
func (*StateTransition) TransitionDb ¶
func (st *StateTransition) TransitionDb(feeRate *big.Rat) (ret []byte, usedGas uint64, failed bool, err error)
TransitionDb will transition the state by applying the current message and returning the result including the used gas. It returns an error if failed. An error indicates a consensus issue.
type TxPool ¶
type TxPool struct {
// contains filtered or unexported fields
}
TxPool contains all currently known transactions. Transactions enter the pool when they are received from the network or submitted locally. They exit the pool when they are included in the blockchain.
The pool separates processable transactions (which can be applied to the current state) and future transactions. Transactions move between those two states over time as they are received and processed.
func NewTxPool ¶
func NewTxPool(config TxPoolConfig, chain minorBlockChain) *TxPool
NewTxPool creates a new transaction pool to gather, sort and filter inbound transactions from the network.
func (*TxPool) AddLocal ¶
func (pool *TxPool) AddLocal(tx *types.Transaction) error
AddLocal enqueues a single transaction into the pool if it is valid, marking the sender as a local one in the mean time, ensuring it goes around the local pricing constraints.
func (*TxPool) AddLocals ¶
func (pool *TxPool) AddLocals(txs []*types.Transaction) []error
AddLocals enqueues a batch of transactions into the pool if they are valid, marking the senders as a local ones in the mean time, ensuring they go around the local pricing constraints.
func (*TxPool) AddRemote ¶
func (pool *TxPool) AddRemote(tx *types.Transaction) error
AddRemote enqueues a single transaction into the pool if it is valid. If the sender is not among the locally tracked ones, full pricing constraints will apply.
func (*TxPool) AddRemotes ¶
func (pool *TxPool) AddRemotes(txs []*types.Transaction) []error
AddRemotes enqueues a batch of transactions into the pool if they are valid. If the senders are not among the locally tracked ones, full pricing constraints will apply.
func (*TxPool) CheckTxBeforeAdd ¶
func (m *TxPool) CheckTxBeforeAdd(tx *types.Transaction) error
func (*TxPool) Content ¶
func (pool *TxPool) Content() (map[common.Address]types.Transactions, map[common.Address]types.Transactions)
Content retrieves the data content of the transaction pool, returning all the pending as well as queued transactions, grouped by account and sorted by nonce.
func (*TxPool) Get ¶
func (pool *TxPool) Get(hash common.Hash) *types.Transaction
Get returns a transaction if it is contained in the pool and nil otherwise.
func (*TxPool) GetPendingTxsFromAddress ¶
func (pool *TxPool) GetPendingTxsFromAddress(addr account.Recipient) types.Transactions
func (*TxPool) GetQueueTxsFromAddress ¶
func (pool *TxPool) GetQueueTxsFromAddress(addr account.Recipient) types.Transactions
func (*TxPool) Pending ¶
Pending retrieves all currently processable transactions, grouped by origin account and sorted by nonce. The returned transaction set is a copy and can be freely modified by calling code.
func (*TxPool) PendingCount ¶
func (*TxPool) SetGasPrice ¶
SetGasPrice updates the minimum price required by the transaction pool for a new transaction, and drops all transactions below this threshold.
func (*TxPool) State ¶
func (pool *TxPool) State() *state.ManagedState
State returns the virtual managed state of the transaction pool.
func (*TxPool) Stats ¶
Stats retrieves the current pool stats, namely the number of pending and the number of queued (non-executable) transactions.
func (*TxPool) Status ¶
Status returns the status (unknown/pending/queued) of a batch of transactions identified by their hashes.
func (*TxPool) SubscribeNewTxsEvent ¶
func (pool *TxPool) SubscribeNewTxsEvent(ch chan<- NewTxsEvent) event.Subscription
SubscribeNewTxsEvent registers a subscription of NewTxsEvent and starts sending event to the given channel.
type TxPoolConfig ¶
type TxPoolConfig struct { Locals []common.Address // Addresses that should be treated by default as local NoLocals bool // Whether local transaction handling should be disabled PriceLimit uint64 // Minimum gas price to enforce for acceptance into the pool PriceBump uint64 // Minimum price bump percentage to replace an already existing transaction (nonce) AccountSlots uint64 // Number of executable transaction slots guaranteed per account GlobalSlots uint64 // Maximum number of executable transaction slots for all accounts AccountQueue uint64 // Maximum number of non-executable transaction slots permitted per account GlobalQueue uint64 // Maximum number of non-executable transaction slots for all accounts Lifetime time.Duration // Maximum amount of time non-executable transaction are queued NetWorkID uint32 }
TxPoolConfig are the configuration parameters of the transaction pool.
type TxStatus ¶
type TxStatus uint
TxStatus is the current status of a transaction as seen by the pool.
type Validator ¶
type Validator interface { // ValidateBlock validates the given block's content. ValidateBlock(block types.IBlock) error ValidateHeader(header types.IHeader) error // ValidateState validate state ValidateState(block, parent types.IBlock, state *state.StateDB, receipts types.Receipts, usedGas uint64) error ValidatorSeal(rHeader types.IHeader) error }
Validator is an interface which defines the standard for block validation. It is only responsible for validating block contents, as the header validation is done by the specific consensus engines.
type WhCallback ¶
type WhCallback func(*types.RootBlockHeader) 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 RootBlockChain 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.
type WriteStatus ¶
type WriteStatus byte
WriteStatus status of write
const ( NonStatTy WriteStatus = iota CanonStatTy SideStatTy )
Source Files ¶
- blockchain_insert.go
- chain_makers.go
- common.go
- error.go
- events.go
- evm.go
- filter.go
- gaspool.go
- genesis.go
- interface.go
- minorblock_validator.go
- minorblockchain.go
- minorblockchain_addon.go
- minorheaderchain.go
- rootblock_validator.go
- rootblockchain.go
- rootheaderchain.go
- state_processor.go
- state_transition.go
- test_utils.go
- tx_cacher.go
- tx_list.go
- tx_pool.go
Directories ¶
Path | Synopsis |
---|---|
Modified from go-ethereum under GNU Lesser General Public License Modified from go-ethereum under GNU Lesser General Public License
|
Modified from go-ethereum under GNU Lesser General Public License Modified from go-ethereum under GNU Lesser General Public License |
Package state provides a caching layer atop the Ethereum state trie.
|
Package state provides a caching layer atop the Ethereum state trie. |
Modified from go-ethereum under GNU Lesser General Public License
|
Modified from go-ethereum under GNU Lesser General Public License |
Package vm implements the Ethereum Virtual Machine.
|
Package vm implements the Ethereum Virtual Machine. |
runtime
Package runtime provides a basic execution model for executing EVM code.
|
Package runtime provides a basic execution model for executing EVM code. |