core

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2021 License: LGPL-3.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChainSyncStart = iota
	ChainSyncFinish
	ChainSyncFailed
)

Variables

View Source
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")
)
View Source
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")
)
View Source
var (
	BloomTrieTablePrefix = "blt-"
)
View Source
var (
	ChtTablePrefix = "cht-"
)
View Source
var DefaultTxPoolConfig = TxPoolConfig{
	Journal:   "transactions.rlp",
	Rejournal: time.Hour,

	PriceLimit: 1,
	PriceBump:  10,

	AccountSlots: 64,
	GlobalSlots:  4096,
	AccountQueue: 256,
	GlobalQueue:  1024,

	Lifetime: 3 * time.Hour,
}
View Source
var (
	ErrCancelled = errors.New("cancelled")
)
View Source
var ErrGenesisNoNetworkId = errors.New("genesis has no networkId")
View Source
var (
	ErrNoGenesis = errors.New("genesis not found in chain")
)

Functions

func BuildTemporaryCHT

func BuildTemporaryCHT(t *trie.Trie, headers []*types.Header) common.Hash

func CalcGasLimit

func CalcGasLimit(parent *types.Block) uint64

CalcGasLimit computes the gas limit of the next block after parent. This is miner strategy, not consensus protocol.

func CanTransfer

func CanTransfer(db vm.StateDB, addr common.Address, amount *big.Int) bool

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 CombineVMConfig

func CombineVMConfig(yp *params.YouParams, lcfg vm.LocalConfig) *vm.Config

func GenerateChain

func GenerateChain(parent *types.Block, engine consensus.Engine, db youdb.Database, n int, processor Processor, gen func(int, *BlockGen)) ([]*types.Block, []types.Receipts)

func GetHashFn

func GetHashFn(ref *types.Header, chain ChainContext) func(n uint64) common.Hash

GetHashFn returns a GetHashFunc which retrieves header hashes by number

func IntrinsicGas

func IntrinsicGas(basicGas uint64, data []byte) (uint64, error)

func NewEVMContext

func NewEVMContext(msg Message, header *types.Header, chain ChainContext, author common.Address, recorder local.DetailRecorder) vm.Context

NewEVMContext creates a new context for use in the EVM.

func PrepareVMConfig

func PrepareVMConfig(ctx ChainContext, round uint64, lcfg vm.LocalConfig) (*vm.Config, error)

func ProcessSenders

func ProcessSenders(txs []*types.Transaction, signer types.Signer)

func ProcessYouVersionState

func ProcessYouVersionState(prev, curr *types.Header) error

ProcessYouVersionState determines the current protocol state from the previous header, and applies it to the current header. If there is something wrong, it returns an error.

func ResetStakingTrieOnNewPeriod

func ResetStakingTrieOnNewPeriod(frequency, currentRound uint64, state *state.StateDB)

func SetupGenesisBlock

func SetupGenesisBlock(db youdb.Database, networkId uint64, genesis *Genesis) (gh common.Hash, err 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 | default-value by networkId 	|  genesis
db has genesis    | from DB           			|  from DB (will check whether the hashes are equal)

func StakingRootForNewBlock

func StakingRootForNewBlock(frequency uint64, parent *types.Header) common.Hash

func Transfer

func Transfer(db vm.StateDB, sender, recipient common.Address, amount *big.Int)

Transfer subtracts amount from sender and adds amount to recipient using the given Db

func VerifyYouVersionState

func VerifyYouVersionState(prev, curr *types.Header) (err error)

VerifyYouVersionState verifies whether the current protocol state was upgraded or derived under the rules.

Types

type BlockChain

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

func NewBlockChain

func NewBlockChain(db youdb.Database, engine consensus.Engine, eventMux *event.TypeMux, t params.NodeType, detailDb local.DetailDB) (*BlockChain, error)

func (*BlockChain) BadBlocks

func (bc *BlockChain) BadBlocks() []*types.Block

BadBlocks returns a list of the last 'bad blocks' that the client has seen on the network

func (*BlockChain) BloomStatus

func (bc *BlockChain) BloomStatus() (uint64, uint64)

BloomStatus returns the bloom size and current stored sections.

func (*BlockChain) BltTrieNode

func (bc *BlockChain) BltTrieNode(hash common.Hash) ([]byte, error)

func (*BlockChain) ChtTrieNode

func (bc *BlockChain) ChtTrieNode(hash common.Hash) ([]byte, error)

func (*BlockChain) CurrentBlock

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

CurrentBlock retrieves the current head block of the canonical chain. The block is retrieved from the blockchain's internal cache.

func (*BlockChain) CurrentHeader

func (bc *BlockChain) CurrentHeader() *types.Header

CurrentHeader retrieves the current head header of the canonical chain. The header is retrieved from the HeaderChain's internal cache.

func (*BlockChain) Engine

func (bc *BlockChain) Engine() consensus.Engine

func (*BlockChain) FullOriginBlockNumber

func (bc *BlockChain) FullOriginBlockNumber() *big.Int

FullOriginBlockNumber returns the full-sync origin block number

func (*BlockChain) Genesis

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

Genesis retrieves the chain's genesis block.

func (*BlockChain) GetAcReader

func (bc *BlockChain) GetAcReader() rawdb.AcReader

func (*BlockChain) GetAncestor

func (bc *BlockChain) GetAncestor(hash common.Hash, number, ancestor uint64, maxNonCanonical *uint64) (common.Hash, uint64)

func (*BlockChain) GetBlock

func (bc *BlockChain) GetBlock(hash common.Hash, number uint64) *types.Block

func (*BlockChain) GetBlockByHash

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

GetBlockByHash retrieves a block from the database by hash, caching it if found.

func (*BlockChain) GetBlockByNumber

func (bc *BlockChain) GetBlockByNumber(number uint64) *types.Block

GetBlockByNumber retrieves a block from the database by number, caching it (associated with its hash) if found.

func (*BlockChain) GetBlockNumber

func (bc *BlockChain) GetBlockNumber(hash common.Hash) *uint64

func (*BlockChain) GetBodyRLP

func (bc *BlockChain) GetBodyRLP(hash common.Hash) rlp.RawValue

GetBodyRLP retrieves a block body in RLP encoding from the database by hash, caching it if found.

func (*BlockChain) GetChtBuilder

func (bc *BlockChain) GetChtBuilder() ChtBuilder

GetChtBuilder returns the CHTIndexer backend, for use of validating ACoCHT.

func (*BlockChain) GetHashFromCht

func (bc *BlockChain) GetHashFromCht(headerNum uint64) (common.Hash, error)

func (*BlockChain) GetHeader

func (bc *BlockChain) GetHeader(hash common.Hash, number uint64) *types.Header

GetHeader retrieves a block header from the database by hash and number.

func (*BlockChain) GetHeaderByHash

func (bc *BlockChain) GetHeaderByHash(hash common.Hash) *types.Header

GetHeaderByHash retrieves a block header from the database by its hash.

func (*BlockChain) GetHeaderByNumber

func (bc *BlockChain) GetHeaderByNumber(number uint64) *types.Header

GetHeaderByNumber retrieves a block header from the database by number.

func (*BlockChain) GetLightStartHeader

func (bc *BlockChain) GetLightStartHeader() *types.Header

func (*BlockChain) GetReceiptsByHash

func (bc *BlockChain) GetReceiptsByHash(hash common.Hash) types.Receipts

GetReceiptsByHash retrieves the receipts for all transactions in a given block.

func (*BlockChain) GetVMConfig

func (bc *BlockChain) GetVMConfig() *vm.LocalConfig

GetVMConfig returns the block chain VM config.

func (*BlockChain) GetVldReader

func (bc *BlockChain) GetVldReader(valRoot common.Hash) (state.ValidatorReader, error)

func (*BlockChain) HasBlock

func (bc *BlockChain) HasBlock(hash common.Hash, number uint64) bool

HasBlock checks if a block is fully present in the database or not.

func (*BlockChain) HasBlockAndState

func (bc *BlockChain) HasBlockAndState(hash common.Hash, number uint64) bool

HasBlockAndState checks if a block and associated state trie is fully present in the database or not, caching it if present.

func (*BlockChain) HasHeader

func (bc *BlockChain) HasHeader(hash common.Hash, number uint64) bool

func (*BlockChain) HasState

func (bc *BlockChain) HasState(hash common.Hash) bool

HasState checks if state trie is fully present in the database or not.

func (*BlockChain) InsertChain

func (bc *BlockChain) InsertChain(chain types.Blocks) error

func (*BlockChain) InsertGuaranteedHeaderChain

func (bc *BlockChain) InsertGuaranteedHeaderChain(chain []*types.Header) (int, error)

InsertGuaranteedHeaderChain attempts to insert the given header chain into the local chain, the header chain here MUST be already guaranteed by cht or other verification. If an error is returned, it will return the index number of the failing header as well an error describing what went wrong.

func (*BlockChain) InsertHeaderChain

func (bc *BlockChain) InsertHeaderChain(chain []*types.Header) (int, error)

InsertHeaderChain attempts to insert the given header chain into the local chain. The header which number is multiple of seedLookBack will be verifying seal, but the others will not. If an error is returned, it will return the index number of the failing header as well an error describing what went wrong.

func (*BlockChain) InsertReceiptChain

func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain []types.Receipts, postEvent bool) (int, error)

InsertReceiptChain attempts to complete an already existing header chain with transaction and receipt data.

func (*BlockChain) IsLight

func (bc *BlockChain) IsLight() bool

func (*BlockChain) IsUcon

func (bc *BlockChain) IsUcon() bool

IsUcon returns whether the consensus is Ucon

func (*BlockChain) LookBackVldReaderForRound added in v1.0.0

func (bc *BlockChain) LookBackVldReaderForRound(r uint64, isCert bool) (state.ValidatorReader, error)

func (*BlockChain) PostChainEvents

func (bc *BlockChain) PostChainEvents(events []interface{}, logs []*types.Log)

func (*BlockChain) Processor

func (bc *BlockChain) Processor() Processor

Processor returns the current processor.

func (*BlockChain) Reset

func (bc *BlockChain) Reset() error

func (*BlockChain) ResetWithGenesisBlock

func (bc *BlockChain) ResetWithGenesisBlock(genesis *types.Block) error

ResetWithGenesisBlock purges the entire blockchain, restoring it to the specified genesis state.

func (*BlockChain) SetHead

func (bc *BlockChain) SetHead(head uint64) error

func (*BlockChain) SetProcessor

func (bc *BlockChain) SetProcessor(processor Processor)

SetProcessor sets the processor required for making state modifications.

func (*BlockChain) SetValidator

func (bc *BlockChain) SetValidator(validator Validator)

UpdateValidator sets the validator which is used to validate incoming blocks.

func (*BlockChain) SetVldFetcher

func (bc *BlockChain) SetVldFetcher(fetcher VldFetcher)

func (*BlockChain) Start

func (bc *BlockChain) Start()

func (*BlockChain) State

func (bc *BlockChain) State() (*state.StateDB, error)

State returns a new mutable state based on the current HEAD block.

func (*BlockChain) StateAt

func (bc *BlockChain) StateAt(root, valRoot, stakingRoot common.Hash) (*state.StateDB, error)

StateAt returns a new mutable state based on the specific state root hash.

func (*BlockChain) StateTrieNode

func (bc *BlockChain) StateTrieNode(hash common.Hash) ([]byte, error)

StateTrieNode retrieves a blob of data associated with a trie node (or code hash) either from ephemeral in-memory cache, or from persistent storage.

func (*BlockChain) Stop

func (bc *BlockChain) Stop()

func (*BlockChain) SubscribeChainEvent

func (bc *BlockChain) SubscribeChainEvent(ch chan<- ChainEvent) event.Subscription

SubscribeChainEvent registers a subscription of ChainEvent.

func (*BlockChain) SubscribeChainHeadEvent

func (bc *BlockChain) SubscribeChainHeadEvent(ch chan<- ChainHeadEvent) event.Subscription

func (*BlockChain) SubscribeLogsEvent

func (bc *BlockChain) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription

SubscribeLogsEvent registers a subscription of []*types.Log.

func (*BlockChain) SubscribeNewMinedBlockEvent

func (bc *BlockChain) SubscribeNewMinedBlockEvent(ch chan NewMinedBlockEvent) event.Subscription

func (*BlockChain) SubscribeRemovedLogsEvent

func (bc *BlockChain) SubscribeRemovedLogsEvent(ch chan<- RemovedLogsEvent) event.Subscription

SubscribeRemovedLogsEvent registers a subscription of RemovedLogsEvent.

func (*BlockChain) TrieBackingDb

func (bc *BlockChain) TrieBackingDb(kind types.TrieKind) youdb.Database

TrieBackingDb returns the backing database of the specific kind of trie

func (*BlockChain) UconLookBackParams

func (bc *BlockChain) UconLookBackParams() (seedLookBack, stakeLookBack uint64)

func (*BlockChain) UpdateExistedHeader

func (bc *BlockChain) UpdateExistedHeader(header *types.Header)

just update the votes' info of the existed header, do not change the header number and hash

func (*BlockChain) UpdateTrustedBlt

func (bc *BlockChain) UpdateTrustedBlt(acHeader *types.Header) error

func (*BlockChain) UpdateTrustedCht

func (bc *BlockChain) UpdateTrustedCht(acHeader *types.Header) error

func (*BlockChain) Validator

func (bc *BlockChain) Validator() Validator

Validator returns the current validator.

func (*BlockChain) VerifyAcHeader

func (bc *BlockChain) VerifyAcHeader(header *types.Header, verifiedAcParents []*types.Header) error

func (*BlockChain) VerifyYouVersionState

func (bc *BlockChain) VerifyYouVersionState(chain types.Blocks) (int, error)

func (*BlockChain) VerifyYouVersionState2

func (bc *BlockChain) VerifyYouVersionState2(chain []*types.Header) (int, error)

func (*BlockChain) VersionForRound

func (bc *BlockChain) VersionForRound(r uint64) (*params.YouParams, error)

func (*BlockChain) VersionForRoundWithParents

func (bc *BlockChain) VersionForRoundWithParents(r uint64, parents []*types.Header) (*params.YouParams, error)

func (*BlockChain) VldTrieNode

func (bc *BlockChain) VldTrieNode(hash common.Hash) ([]byte, error)

validator trie shares the same trie database with the state

func (*BlockChain) WriteBlockWithState

func (bc *BlockChain) WriteBlockWithState(block *types.Block, state *state.StateDB, receipts []*types.Receipt) error

WriteBlockWithState writes the block and all associated state to the database.

func (*BlockChain) WriteBlockWithoutState

func (bc *BlockChain) WriteBlockWithoutState(block *types.Block) error

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 BlockChainState

type BlockChainState interface {
	HasBlockAndState(hash common.Hash, number uint64) bool
	HasBlock(hash common.Hash, number uint64) bool
	GetHeaderByNumber(number uint64) *types.Header
	// GetAcReader returns an AcReader for reading ac node from database
	GetAcReader() rawdb.AcReader
	//
	GetChtBuilder() ChtBuilder
}

type BlockGen

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

func (*BlockGen) AddTx

func (b *BlockGen) AddTx(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 (*BlockGen) AddTxWithChain

func (b *BlockGen) AddTxWithChain(bc ChainContext, tx *types.Transaction)

func (*BlockGen) Header

func (b *BlockGen) Header() *types.Header

func (*BlockGen) Number

func (b *BlockGen) Number() *big.Int

Number returns the block number of the block being generated.

func (*BlockGen) OffsetTime

func (b *BlockGen) OffsetTime(seconds int64)

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 (*BlockGen) PrevBlock

func (b *BlockGen) PrevBlock(index int) *types.Block

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 (*BlockGen) Receipts

func (b *BlockGen) Receipts() []*types.Receipt

func (*BlockGen) SetCoinbase

func (b *BlockGen) SetCoinbase(addr common.Address)

SetCoinbase sets the coinbase of the generated block. It can be called at most once.

func (*BlockGen) SetExtra

func (b *BlockGen) SetExtra(data []byte)

SetExtra sets the extra data field of the generated block.

func (*BlockGen) Statedb

func (b *BlockGen) Statedb() *state.StateDB

func (*BlockGen) TxNonce

func (b *BlockGen) TxNonce(addr common.Address) uint64

TxNonce returns the next valid transaction nonce for the account at addr. It panics if the account does not exist.

type BlockHookFn

type BlockHookFn func(chain vm.ChainReader, header *types.Header, txs []*types.Transaction, state *state.StateDB, seal bool, recorder local.DetailRecorder) (*types.Receipt, []byte, error)

type BlockValidator

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

func NewBlockValidator

func NewBlockValidator(blockChain BlockChainState) *BlockValidator

func (*BlockValidator) ValidateACoCHT

func (v *BlockValidator) ValidateACoCHT(headers []*types.Header, block *types.Block, index int, isNeedBuildTemp bool) error

func (*BlockValidator) ValidateBody

func (v *BlockValidator) ValidateBody(block *types.Block) error

func (*BlockValidator) ValidateState

func (v *BlockValidator) ValidateState(block, parent *types.Block, statedb *state.StateDB, receipts types.Receipts, usedGas uint64) error

type BloomWithTrieIndexer

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

BloomWithTrieIndexer implements core.ChainIndexer, building up a rotated bloom bits index for the YOUChain header bloom filters, permitting blazing fast filtering. And meanwhile building up the bloom trie for the Additional Chain of CHT.

func (*BloomWithTrieIndexer) Commit

func (b *BloomWithTrieIndexer) Commit() error

Commit implements core.ChainIndexerBackend, finalizing the bloom section and writing it out into the database.

func (*BloomWithTrieIndexer) Process

func (b *BloomWithTrieIndexer) Process(ctx context.Context, header *types.Header) error

Process implements core.ChainIndexerBackend, adding a new header's bloom into the index.

func (*BloomWithTrieIndexer) Reset

func (b *BloomWithTrieIndexer) Reset(ctx context.Context, section uint64, lastSectionHead common.Hash) error

Reset implements core.ChainIndexerBackend, starting a new bloombits index section.

func (*BloomWithTrieIndexer) TrieDB

func (b *BloomWithTrieIndexer) TrieDB() *trie.Database

type ChainContext

type ChainContext interface {
	// VersionForRound retrieves the YOUChain protocol parameters for the specific round
	VersionForRound(round uint64) (*params.YouParams, error)

	// GetHeader returns the hash corresponding to their hash.
	GetHeader(common.Hash, uint64) *types.Header
}

ChainContext supports retrieving headers and consensus parameters from the current blockchain to be used during transaction processing.

type ChainEvent

type ChainEvent struct {
	Block *types.Block
	Hash  common.Hash
	Logs  []*types.Log
}

type ChainHeadEvent

type ChainHeadEvent struct{ Block *types.Block }

ChainHeadEvent is posted when a block has been insert

type ChainIndexer

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

ChainIndexer does a post-processing job for equally sized sections of the canonical chain (like BlooomBits and CHT structures). A ChainIndexer is connected to the blockchain through the event system by starting a ChainHeadEventLoop in a goroutine.

Further child ChainIndexers can be added which use the output of the parent section indexer. These child indexers receive new head notifications only after an entire section has been finished or in case of rollbacks that might affect already finished sections.

func NewBloomWithTrieIndexer

func NewBloomWithTrieIndexer(db youdb.Database, fetcher MissingNodesFetcher, size, confirms uint64) *ChainIndexer

NewBloomIndexer returns a chain indexer that generates bloom bits data for the canonical chain for fast logs filtering.

func NewChainIndexer

func NewChainIndexer(chainDb, indexDb youdb.Database, backend ChainIndexerBackend, section, confirm uint64, throttling time.Duration, kind string) *ChainIndexer

NewChainIndexer creates a new chain indexer to do background processing on chain segments of a given size after certain number of confirmations passed. The throttling parameter might be used to prevent database thrashing.

func NewChtIndexer

func NewChtIndexer(db youdb.Database, fetcher MissingNodesFetcher, size, confirms uint64) *ChainIndexer

NewChtIndexer creates a Cht chain indexer

func (*ChainIndexer) AddChildIndexer

func (c *ChainIndexer) AddChildIndexer(indexer *ChainIndexer)

AddChildIndexer adds a child ChainIndexer that can use the output of this one

func (*ChainIndexer) Close

func (c *ChainIndexer) Close() error

Close tears down all goroutines belonging to the indexer and returns any error that might have occurred internally.

func (*ChainIndexer) SectionHead

func (c *ChainIndexer) SectionHead(section uint64) common.Hash

SectionHead retrieves the last block hash of a processed section from the index database.

func (*ChainIndexer) Sections

func (c *ChainIndexer) Sections() (uint64, uint64, common.Hash)

Sections returns the number of processed sections maintained by the indexer and also the information about the last header indexed for potential canonical verifications.

func (*ChainIndexer) Start

func (c *ChainIndexer) Start(chain ChainIndexerChain)

Start creates a goroutine to feed chain head events into the indexer for cascading background processing. Children do not need to be started, they are notified about new events by their parents.

func (*ChainIndexer) UpdateSection

func (c *ChainIndexer) UpdateSection(section uint64, shead common.Hash) error

type ChainIndexerBackend

type ChainIndexerBackend interface {
	// Reset initiates the processing of a new chain segment, potentially terminating
	// any partially completed operations (in case of a reorg).
	Reset(ctx context.Context, section uint64, prevHead common.Hash) error

	// Process crunches through the next header in the chain segment. The caller
	// will ensure a sequential order of headers.
	Process(ctx context.Context, header *types.Header) error

	// Commit finalizes the section metadata and stores it into the database.
	Commit() error
}

ChainIndexerBackend defines the methods needed to process chain segments in the background and write the segment results into the database. These can be used to create filter blooms or CHTs.

type ChainIndexerChain

type ChainIndexerChain interface {
	IsLight() bool
	// CurrentHeader retrieves the latest locally known header.
	CurrentHeader() *types.Header

	// SubscribeChainHeadEvent subscribes to new head header notifications.
	SubscribeChainHeadEvent(ch chan<- ChainHeadEvent) event.Subscription
}

ChainIndexerChain interface is used for connecting the indexer to a blockchain

type ChainSyncEvent

type ChainSyncEvent struct {
	Type ChainSyncType
}

type ChainSyncType

type ChainSyncType int

type ChtBuilder

type ChtBuilder interface {
	GetCopiedCHT() (t *trie.Trie, headNum uint64)
}

ChtBuilder can build a temporary cht based on an existing trie and new headers

type ChtIndexerBackend

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

ChtIndexerBackend implements core.ChainIndexerBackend.For building canonical hash trie.

func NewChtBackend

func NewChtBackend(db youdb.Database, fetcher MissingNodesFetcher, size, confirms uint64) *ChtIndexerBackend

func (*ChtIndexerBackend) Commit

func (c *ChtIndexerBackend) Commit() error

Commit implements core.ChainIndexerBackend

func (*ChtIndexerBackend) GetCopiedCHT

func (c *ChtIndexerBackend) GetCopiedCHT() (t *trie.Trie, headNum uint64)

func (*ChtIndexerBackend) GetValue

func (c *ChtIndexerBackend) GetValue(headerNum uint64) ([]byte, error)

func (*ChtIndexerBackend) Process

func (c *ChtIndexerBackend) Process(ctx context.Context, header *types.Header) error

Process implements core.ChainIndexerBackend

func (*ChtIndexerBackend) Reset

func (c *ChtIndexerBackend) Reset(ctx context.Context, section uint64, lastSectionHead common.Hash) error

Reset implements core.ChainIndexerBackend

func (*ChtIndexerBackend) TrieDB

func (c *ChtIndexerBackend) TrieDB() *trie.Database

type DefaultConverter

type DefaultConverter struct {
}

func (*DefaultConverter) ApplyMessage

func (d *DefaultConverter) ApplyMessage(msgCtx *MessageContext) (ret []byte, usedGas uint64, failed bool, err error)

func (*DefaultConverter) IntrinsicGas

func (d *DefaultConverter) IntrinsicGas(data []byte, to *common.Address) (uint64, error)

type DeleteBlockContentCallback

type DeleteBlockContentCallback func(youdb.Deleter, common.Hash, uint64)

DeleteBlockContentCallback is a callback function that is called by SetHead before each header is deleted.

type DumpAllTx

type DumpAllTx struct {
	Pending DumpTransaction
	Queue   DumpTransaction
}

type DumpList

type DumpList struct {
	Transaction map[uint64]DumpTxdata `json:"txlist"`
}

type DumpTransaction

type DumpTransaction struct {
	TxList map[string]DumpList `json:"address"`
}

type DumpTxdata

type DumpTxdata struct {
	AccountNonce uint64          `json:"nonce"`
	Price        *big.Int        `json:"gasPrice"`
	GasLimit     uint64          `json:"gas"`
	Recipient    *common.Address `json:"to"` // nil means contract creation
	Amount       *big.Int        `json:"value"`
	Payload      []byte          `json:"input"`

	// Signature values
	V string `json:"v"`
	R string `json:"r"`
	S string `json:"s"`

	// This is only used when marshaling to JSON.
	Hash common.Hash `json:"hash"`
}

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.

func (*GasPool) AddGas

func (gp *GasPool) AddGas(amount uint64) *GasPool

AddGas makes gas available for execution.

func (*GasPool) Gas

func (gp *GasPool) Gas() uint64

Gas returns the amount of gas remaining in the pool.

func (*GasPool) String

func (gp *GasPool) String() string

func (*GasPool) SubGas

func (gp *GasPool) SubGas(amount uint64) error

SubGas deducts the given amount from the pool if enough gas is available and returns an error otherwise.

type Genesis

type Genesis struct {
	NetworkId   uint64            `json:"networkId"`
	Timestamp   uint64            `json:"timestamp"`
	GasLimit    uint64            `json:"gasLimit"   gencodec:"required"`
	ExtraData   []byte            `json:"extraData"`
	Consensus   []byte            `json:"consensus"`
	Mixhash     common.Hash       `json:"mixHash"`
	Coinbase    common.Address    `json:"coinbase"`
	Alloc       GenesisAlloc      `json:"alloc"      gencodec:"required"`
	Validators  GenesisValidators `json:"validators"`
	CurrVersion params.YouVersion `json:"version"    gencodec:"required"`

	// These fields are used for consensus tests. Please don't use them
	// in actual genesis blocks.
	Number     uint64      `json:"number"`
	GasUsed    uint64      `json:"gasUsed"`
	ParentHash common.Hash `json:"parentHash"`
}

Genesis specifies the header fields, state of a genesis block. It also defines hard fork switch-over blocks through the chain configuration.

func DefaultGenesisBlock

func DefaultGenesisBlock() *Genesis

DefaultGenesisBlock returns the YOUChain main net genesis block.

func DefaultTestNetGenesisBlock

func DefaultTestNetGenesisBlock() *Genesis

DefaultTestNetGenesisBlock returns the YOUChain public test-net genesis block.

func (*Genesis) Commit

func (g *Genesis) Commit(db youdb.Database) (*types.Block, error)

Commit writes the block and state of a genesis specification to the database. The block is committed as the canonical head block.

func (Genesis) MarshalJSON

func (g Genesis) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*Genesis) MustCommit

func (g *Genesis) MustCommit(db youdb.Database) *types.Block

MustCommit writes the genesis block and state to db, panicking on error. The block is committed as the canonical head block.

func (*Genesis) PreCheck

func (g *Genesis) PreCheck() error

func (*Genesis) ToBlock

func (g *Genesis) ToBlock(db youdb.Database) *types.Block

ToBlock creates the genesis block and writes state of a genesis specification to the given database (or discards it if nil).

func (*Genesis) UnmarshalJSON

func (g *Genesis) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

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"`
}

GenesisAccount is an account in the state of the genesis block.

func (GenesisAccount) MarshalJSON

func (g GenesisAccount) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*GenesisAccount) UnmarshalJSON

func (g *GenesisAccount) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type GenesisAlloc

type GenesisAlloc map[common.Address]GenesisAccount

GenesisAlloc specifies the initial state that is part of the genesis block.

func (*GenesisAlloc) UnmarshalJSON

func (ga *GenesisAlloc) UnmarshalJSON(data []byte) error

type GenesisMismatchError

type GenesisMismatchError struct {
	Stored, New common.Hash
}

GenesisMismatchError is raised when trying to overwrite an existing genesis block with an incompatible one.

func (*GenesisMismatchError) Error

func (e *GenesisMismatchError) Error() string

type GenesisValidator

type GenesisValidator struct {
	Name            string               `json:"name"`
	OperatorAddress common.Address       `json:"operatorAddress"`
	Coinbase        common.Address       `json:"coinbase"`
	MainPubKey      hexutil.Bytes        `json:"mainPubKey"`
	BlsPubKey       hexutil.Bytes        `json:"blsPubKey"`
	Token           *big.Int             `json:"token"`
	Role            params.ValidatorRole `json:"role"`
	Status          uint8                `json:"status"`
}

func (GenesisValidator) MarshalJSON

func (g GenesisValidator) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*GenesisValidator) UnmarshalJSON

func (g *GenesisValidator) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type GenesisValidators

type GenesisValidators map[common.Address]GenesisValidator // mainAddress => Validator

func (*GenesisValidators) UnmarshalJSON

func (gv *GenesisValidators) UnmarshalJSON(data []byte) error

type HeaderChain

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

HeaderChain implements the basic block header chain logic that is shared by core.BlockChain and light.LightChain. It is not usable in itself, only as a part of either structure. It is not thread safe either, the encapsulating chain structures should do the necessary mutex locking/unlocking.

func NewHeaderChain

func NewHeaderChain(chainDb youdb.Database, parent *BlockChain, engine consensus.Engine, procInterrupt func() bool) (*HeaderChain, error)

NewHeaderChain 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) CurrentHeader

func (hc *HeaderChain) CurrentHeader() *types.Header

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

func (hc *HeaderChain) GetAcReader() rawdb.AcReader

GetAcReader returns an AcReader for reading ac node from database

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, number uint64) *types.Block

GetBlock implements consensus.ChainReader, and returns nil for every input as a header chain does not have blocks available for retrieval.

func (*HeaderChain) GetBlockByNumber

func (hc *HeaderChain) GetBlockByNumber(number uint64) *types.Block

func (*HeaderChain) GetBlockHashesFromHash

func (hc *HeaderChain) GetBlockHashesFromHash(hash common.Hash, max uint64) []common.Hash

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

func (hc *HeaderChain) GetCanonicalHash(number uint64) common.Hash

func (*HeaderChain) GetHeader

func (hc *HeaderChain) GetHeader(hash common.Hash, number uint64) *types.Header

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.Header

GetHeaderByHash retrieves a block header from the database by hash, caching it if found.

func (*HeaderChain) GetHeaderByNumber

func (hc *HeaderChain) GetHeaderByNumber(number uint64) *types.Header

GetHeaderByNumber retrieves a block header from the database by number, caching it (associated with its hash) if found.

func (*HeaderChain) GetLightStartHeader

func (hc *HeaderChain) GetLightStartHeader() *types.Header

func (*HeaderChain) GetVldReader

func (hc *HeaderChain) GetVldReader(valRoot common.Hash) (state.ValidatorReader, error)

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.Header, writeHeader WhCallback, start time.Time) (int, error)

InsertHeaderChain attempts to insert the given header chain into the local chain. If an error is returned, it will return the index number of the failing header as well an error describing what went wrong.

func (*HeaderChain) SetCurrentHeader

func (hc *HeaderChain) SetCurrentHeader(head *types.Header)

SetCurrentHeader sets the current head header of the canonical chain.

func (*HeaderChain) SetGenesis

func (hc *HeaderChain) SetGenesis(head *types.Header)

SetGenesis sets a new genesis block header for the chain

func (*HeaderChain) SetHead

func (hc *HeaderChain) SetHead(head uint64, updateFn UpdateHeadBlocksCallback, delFn DeleteBlockContentCallback)

SetHead rewinds the local chain to a new head. Everything above the new head will be deleted and the new one set.

func (*HeaderChain) SetLightStartHeader

func (hc *HeaderChain) SetLightStartHeader(head *types.Header)

func (*HeaderChain) UpdateExistedHeader

func (hc *HeaderChain) UpdateExistedHeader(header *types.Header)

func (*HeaderChain) ValidateHeaderChain

func (hc *HeaderChain) ValidateHeaderChain(chain []*types.Header, seals []bool) (int, error)

func (*HeaderChain) VersionForRound

func (hc *HeaderChain) VersionForRound(r uint64) (*params.YouParams, error)

func (*HeaderChain) VersionForRoundWithParents

func (hc *HeaderChain) VersionForRoundWithParents(r uint64, parents []*types.Header) (*params.YouParams, error)

func (*HeaderChain) WriteHeader

func (hc *HeaderChain) WriteHeader(header *types.Header) error

WriteHeader writes a header into the local chain, given that its parent is already known.

Note: This method is not concurrent-safe with inserting blocks simultaneously into the chain. 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 IRouter

type IRouter interface {
	AddEndBlockHook(name string, fn BlockHookFn)
	AddTxConverter(modelAddr common.Address, converter TxConverter)
	GetConverter(msgToAddr *common.Address) TxConverter
}

IRouter is an interface for routing a transaction to a state converter. It also provides extended EndBlock logic.

type InsertBlockEvent

type InsertBlockEvent struct {
	Block *types.Block
}

type Message

type Message interface {
	From() common.Address
	To() *common.Address

	GasPrice() *big.Int
	Gas() uint64
	Value() *big.Int

	Nonce() uint64
	TxHash() common.Hash
	CheckNonce() bool
	Data() []byte
}

Message represents a message to be applied to a state

type MessageContext

type MessageContext struct {
	Msg          Message
	State        *state.StateDB
	InitialGas   uint64
	AvailableGas uint64
	Header       *types.Header
	Coinbase     common.Address
	Chain        ChainContext
	GP           *GasPool
	Cfg          *vm.Config
	Recorder     local.DetailRecorder
}

MessageContext is the current context for applying a message

func NewMsgContext

func NewMsgContext(msg Message, statedb *state.StateDB, bc ChainContext, header *types.Header, coinBase common.Address, gp *GasPool, cfg *vm.Config, recorder local.DetailRecorder) *MessageContext

func (*MessageContext) GasUsed

func (mc *MessageContext) GasUsed() uint64

gasUsed returns the amount of gas used up by the state transition.

func (*MessageContext) UseGas

func (mc *MessageContext) UseGas(amount uint64) error

type MissingNodesFetcher

type MissingNodesFetcher interface {
	FetchMissingNodes(ctx context.Context, trie *trie.Trie, trieTable youdb.Database, section uint64, root common.Hash) error
}

MissingNodesFetcher is for a trie to fetch it's missing nodes

type NewMinedBlockEvent

type NewMinedBlockEvent struct{ Block *types.Block }

NewMinedBlockEvent is posted when a block has been mined.

type NewTxsEvent

type NewTxsEvent struct{ Txs []*types.Transaction }

NewTxsEvent is posted when a batch of transactions enter the transaction pool.

type PendingLogsEvent

type PendingLogsEvent struct {
	Logs []*types.Log
}

PendingLogsEvent is posted pre mining and notifies of pending logs.

type Processor

type Processor interface {
	IRouter
	// 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.
	Process(yp *params.YouParams, block *types.Block, statedb *state.StateDB, cfg vm.LocalConfig, recorder local.DetailRecorder) (*types.ProcessResult, error)
	// ApplyTransaction attempts to apply a transaction to the given state database
	// and uses the input parameters for its environment. It returns the receipt
	// for the transaction, gas used and an error if the transaction failed,
	// indicating the block was invalid.
	ApplyTransaction(tx *types.Transaction, signer types.Signer, statedb *state.StateDB, bc ChainContext, header *types.Header, author *common.Address, usedGas *uint64, gasRewards *big.Int, gp *GasPool, cfg *vm.Config, recorder local.DetailRecorder) (*types.Receipt, uint64, 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 TxConverter execution (if it took place),
	// the gas used (which includes gas refunds) ,
	// a flag indicates whether the message is failed
	// but (with err == nil) would be accepted within a block,
	// 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.
	ApplyMessageEntry(msg Message, statedb *state.StateDB, bc ChainContext, header *types.Header, author *common.Address, gp *GasPool, cfg *vm.Config, recorder local.DetailRecorder) ([]byte, uint64, bool, error)

	// EndBlock executes some extended logic registered by other modules
	EndBlock(chain vm.ChainReader, header *types.Header, txs []*types.Transaction, state *state.StateDB, isSeal bool, recorder local.DetailRecorder) ([]*types.Receipt, [][]byte, []error)
}

Processor is an interface for processing blocks using a given initial state.

Processor provides several methods on different level, from common to detail is as follow: `Process` is the entry for replaying a whole block; `ApplyTransaction` is the entry for replaying a specific transaction; `ApplyMessageEntry` is the entry for applying a message (derives from a tx), this may be called independently ON LOCAL for test-case or contract call or estimating gas.

type RemovedLogsEvent

type RemovedLogsEvent struct{ Logs []*types.Log }

RemovedLogsEvent is posted when a reorg happens

type StateProcessor

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

func NewStateProcessor

func NewStateProcessor(bc *BlockChain, engine consensus.Engine) *StateProcessor

NewStateProcessor initialises a new StateProcessor.

func (*StateProcessor) AddEndBlockHook

func (p *StateProcessor) AddEndBlockHook(name string, fn BlockHookFn)

func (*StateProcessor) AddTxConverter

func (p *StateProcessor) AddTxConverter(modelAddr common.Address, converter TxConverter)

AddTxConverter adds a transaction converter for a given model address. This method should be called on the initialization stage and is NOT thread safe.

func (*StateProcessor) ApplyMessageEntry

func (p *StateProcessor) ApplyMessageEntry(msg Message, statedb *state.StateDB,
	bc ChainContext, header *types.Header, author *common.Address, gp *GasPool, cfg *vm.Config, recorder local.DetailRecorder) ([]byte, uint64, bool, error)

ApplyMessageEntry is the common entry for applying a message There are some common steps to do here.

func (*StateProcessor) ApplyTransaction

func (p *StateProcessor) ApplyTransaction(tx *types.Transaction, signer types.Signer, statedb *state.StateDB,
	bc ChainContext, header *types.Header, author *common.Address, usedGas *uint64, gasRewards *big.Int, gp *GasPool, cfg *vm.Config, recorder local.DetailRecorder) (*types.Receipt, uint64, error)

ApplyTransaction attempts to apply a transaction to the given state database and uses the input parameters for its environment. It returns the receipt for the transaction, gas used and an error if the transaction failed, indicating the block was invalid.

func (*StateProcessor) EndBlock

func (p *StateProcessor) EndBlock(chain vm.ChainReader, header *types.Header, txs []*types.Transaction, state *state.StateDB, isSeal bool, recorder local.DetailRecorder) ([]*types.Receipt, [][]byte, []error)

func (*StateProcessor) GetConverter

func (p *StateProcessor) GetConverter(msgToAddr *common.Address) TxConverter

func (*StateProcessor) Process

func (p *StateProcessor) Process(yp *params.YouParams, block *types.Block, statedb *state.StateDB, lcfg vm.LocalConfig, recorder local.DetailRecorder) (*types.ProcessResult, error)

type StateTransition

type StateTransition struct {
	*MessageContext
	// contains filtered or unexported fields
}

func (*StateTransition) TransitionDb

func (st *StateTransition) TransitionDb() (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. note: add ignoreNonce for preCheck

type TxConverter

type TxConverter interface {
	// IntrinsicGas computes the 'intrinsic gas' for a message with the given data.
	IntrinsicGas(data []byte, to *common.Address) (uint64, error)
	// ApplyMessage computes the new state by applying the given message
	// against the state database.
	// ApplyMessage returns the bytes returned by any 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.
	//
	// NOTE: If the message will be accepted, the converter MUST increase the sender nonce!
	ApplyMessage(msgCtx *MessageContext) ([]byte, uint64, bool, error)
}

TxConverter is an interface for converting the state with given transactions.

type TxPool

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

func NewTxPool

func NewTxPool(config TxPoolConfig, chain blockChain) *TxPool

func (*TxPool) AddLocal

func (pool *TxPool) AddLocal(tx *types.Transaction) error

func (*TxPool) AddLocals

func (pool *TxPool) AddLocals(txs []*types.Transaction) []error

AddRemotes should add the given transactions to the pool.

func (*TxPool) AddRemote

func (pool *TxPool) AddRemote(tx *types.Transaction) error

func (*TxPool) AddRemotes

func (pool *TxPool) AddRemotes(txs types.Transactions) []error

AddRemotes should add the given transactions to the pool.

func (*TxPool) AddRemotesSync

func (pool *TxPool) AddRemotesSync(txs []*types.Transaction) []error

This is like AddRemotes, but waits for pool reorganization. Tests use this method.

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

func (pool *TxPool) GasPrice() *big.Int

GasPrice returns the current gas price enforced by the transaction pool.

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

func (pool *TxPool) Locals() []common.Address

Locals retrieves the accounts currently considered local by the pool.

func (*TxPool) Nonce

func (pool *TxPool) Nonce(addr common.Address) uint64

Nonce returns the next nonce of an account, with all transactions executable by the pool already applied on top.

func (*TxPool) Pending

func (pool *TxPool) Pending() (map[common.Address]types.Transactions, error)

Pending retrieves all currently processable transactions, groupped by origin account and sorted by nonce. The returned transaction set is a copy and can be freely modified by calling code.

func (*TxPool) RawDump

func (pool *TxPool) RawDump(queue map[common.Address]*txList) DumpTransaction

func (*TxPool) SetGasPrice

func (pool *TxPool) SetGasPrice(price *big.Int)

SetGasPrice updates the minimum price required by the transaction pool for a new transaction, and drops all transactions below this threshold.

func (*TxPool) Stats

func (pool *TxPool) Stats() (int, int)

Stats retrieves the current pool stats, namely the number of pending and the number of queued (non-executable) transactions.

func (*TxPool) Status

func (pool *TxPool) Status(hashes []common.Hash) []TxStatus

Status returns the status (unknown/pending/queued) of a batch of transactions identified by their hashes.

func (*TxPool) Stop

func (pool *TxPool) Stop()

Stop terminates the transaction pool.

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.

func (*TxPool) TransactionsNumber

func (pool *TxPool) TransactionsNumber() (int, int)

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
	Journal   string           // Journal of local transactions to survive node restarts
	Rejournal time.Duration    // Time interval to regenerate the local transaction journal

	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
}

type TxStatus

type TxStatus uint

TxStatus is the current status of a transaction as seen by the pool.

const (
	TxStatusUnknown TxStatus = iota
	TxStatusQueued
	TxStatusPending
	TxStatusIncluded
)

type UpdateHeadBlocksCallback

type UpdateHeadBlocksCallback func(youdb.Putter, *types.Header)

UpdateHeadBlocksCallback is a callback function that is called by SetHead before head header is updated.

type Validator

type Validator interface {
	// ValidateBody validates the given block's content.
	ValidateBody(block *types.Block) error

	// ValidateState validates the given statedb and optionally the receipts and
	// gas used.
	ValidateState(block, parent *types.Block, statedb *state.StateDB, receipts types.Receipts, usedGas uint64) error

	// ValidateACoCHT validates the given block's ac node.
	// Before calling this function, the caller must check if is needed to do this validate.
	ValidateACoCHT(headers []*types.Header, block *types.Block, index int, isNeedBuildTemp bool) 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 VldFetcher

type VldFetcher interface {
	FetchVldTrie(root common.Hash) error
}

type WhCallback

type WhCallback func(*types.Header) error

WhCallback is a callback function for inserting individual headers. A callback is used for two reasons: first, in a LightChain, status should be processed and light chain events sent, while in a BlockChain this is not necessary since chain events are sent after inserting blocks. Second, the header writes should be protected by the parent chain mutex individually.

Directories

Path Synopsis
Package bloombits implements bloom filtering on batches of data.
Package bloombits implements bloom filtering on batches of data.
Package rawdb contains a collection of low level database accessors.
Package rawdb contains a collection of low level database accessors.
Package state provides a caching layer atop the Ethereum state trie.
Package state provides a caching layer atop the Ethereum state trie.
Package types contains data types related to Ethereum consensus.
Package types contains data types related to Ethereum consensus.
vm
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.

Jump to

Keyboard shortcuts

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