Documentation ¶
Overview ¶
* todo ODR: on-demand retrieva, 按需检索
Index ¶
- Constants
- Variables
- func GetBlock(ctx context.Context, odr OdrBackend, hash common.Hash, number uint64) (*types.Block, error)
- func GetBlockLogs(ctx context.Context, odr OdrBackend, hash common.Hash, number uint64) ([][]*types.Log, error)
- func GetBlockReceipts(ctx context.Context, odr OdrBackend, hash common.Hash, number uint64) (types.Receipts, error)
- func GetBloomBits(ctx context.Context, odr OdrBackend, bitIdx uint, sectionIdxList []uint64) ([][]byte, error)
- func GetBloomTrieRoot(db ethdb.Database, sectionIdx uint64, sectionHead common.Hash) common.Hash
- func GetBody(ctx context.Context, odr OdrBackend, hash common.Hash, number uint64) (*types.Body, error)
- func GetBodyRLP(ctx context.Context, odr OdrBackend, hash common.Hash, number uint64) (rlp.RawValue, error)
- func GetCanonicalHash(ctx context.Context, odr OdrBackend, number uint64) (common.Hash, error)
- func GetChtRoot(db ethdb.Database, sectionIdx uint64, sectionHead common.Hash) common.Hash
- func GetChtV2Root(db ethdb.Database, sectionIdx uint64, sectionHead common.Hash) common.Hash
- func GetHeaderByNumber(ctx context.Context, odr OdrBackend, number uint64) (*types.Header, error)
- func NewBloomTrieIndexer(db ethdb.Database, clientMode bool, odr OdrBackend) *core.ChainIndexer
- func NewChtIndexer(db ethdb.Database, clientMode bool, odr OdrBackend) *core.ChainIndexer
- func NewState(ctx context.Context, head *types.Header, odr OdrBackend) *state.StateDB
- func NewStateDatabase(ctx context.Context, head *types.Header, odr OdrBackend) state.Database
- func StoreBloomTrieRoot(db ethdb.Database, sectionIdx uint64, sectionHead, root common.Hash)
- func StoreChtRoot(db ethdb.Database, sectionIdx uint64, sectionHead, root common.Hash)
- type BlockRequest
- type BloomRequest
- type BloomTrieIndexerBackend
- type ChtIndexerBackend
- type ChtNode
- type ChtRequest
- type CodeRequest
- type LightChain
- func (self *LightChain) Config() *params.ChainConfig
- func (self *LightChain) CurrentHeader() *types.Header
- func (bc *LightChain) Engine() consensus.Engine
- func (self *LightChain) GasLimit() uint64
- func (bc *LightChain) Genesis() *types.Block
- func (bc *LightChain) GetAncestor(hash common.Hash, number, ancestor uint64, maxNonCanonical *uint64) (common.Hash, uint64)
- func (self *LightChain) GetBlock(ctx context.Context, hash common.Hash, number uint64) (*types.Block, error)
- func (self *LightChain) GetBlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
- func (self *LightChain) GetBlockByNumber(ctx context.Context, number uint64) (*types.Block, error)
- func (self *LightChain) GetBlockHashesFromHash(hash common.Hash, max uint64) []common.Hash
- func (self *LightChain) GetBody(ctx context.Context, hash common.Hash) (*types.Body, error)
- func (self *LightChain) GetBodyRLP(ctx context.Context, hash common.Hash) (rlp.RawValue, error)
- func (self *LightChain) GetHeader(hash common.Hash, number uint64) *types.Header
- func (self *LightChain) GetHeaderByHash(hash common.Hash) *types.Header
- func (self *LightChain) GetHeaderByNumber(number uint64) *types.Header
- func (self *LightChain) GetHeaderByNumberOdr(ctx context.Context, number uint64) (*types.Header, error)
- func (self *LightChain) GetTd(hash common.Hash, number uint64) *big.Int
- func (self *LightChain) GetTdByHash(hash common.Hash) *big.Int
- func (bc *LightChain) HasBlock(hash common.Hash, number uint64) bool
- func (bc *LightChain) HasHeader(hash common.Hash, number uint64) bool
- func (self *LightChain) InsertHeaderChain(chain []*types.Header, checkFreq int) (int, error)
- func (self *LightChain) LockChain()
- func (self *LightChain) Odr() OdrBackend
- func (bc *LightChain) Reset()
- func (bc *LightChain) ResetWithGenesisBlock(genesis *types.Block)
- func (self *LightChain) Rollback(chain []common.Hash)
- func (bc *LightChain) SetHead(head uint64)
- func (bc *LightChain) State() (*state.StateDB, error)
- func (bc *LightChain) Stop()
- func (self *LightChain) SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
- func (self *LightChain) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
- func (self *LightChain) SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription
- func (self *LightChain) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription
- func (self *LightChain) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription
- func (self *LightChain) SyncCht(ctx context.Context) bool
- func (self *LightChain) UnlockChain()
- type NodeList
- type NodeSet
- func (db *NodeSet) DataSize() int
- func (db *NodeSet) Get(key []byte) ([]byte, error)
- func (db *NodeSet) Has(key []byte) (bool, error)
- func (db *NodeSet) KeyCount() int
- func (db *NodeSet) NodeList() NodeList
- func (db *NodeSet) Put(key []byte, value []byte) error
- func (db *NodeSet) Store(target ethdb.Putter)
- type OdrBackend
- type OdrRequest
- type ReceiptsRequest
- type TrieID
- type TrieRequest
- type TrustedCheckpoint
- type TxPool
- func (self *TxPool) Add(ctx context.Context, tx *types.Transaction) error
- func (self *TxPool) AddBatch(ctx context.Context, txs []*types.Transaction)
- func (self *TxPool) Content() (map[common.Address]types.Transactions, map[common.Address]types.Transactions)
- func (pool *TxPool) GetNonce(ctx context.Context, addr common.Address) (uint64, error)
- func (tp *TxPool) GetTransaction(hash common.Hash) *types.Transaction
- func (self *TxPool) GetTransactions() (txs types.Transactions, err error)
- func (self *TxPool) RemoveTransactions(txs types.Transactions)
- func (pool *TxPool) RemoveTx(hash common.Hash)
- func (pool *TxPool) Stats() (pending int)
- func (pool *TxPool) Stop()
- func (pool *TxPool) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subscription
- type TxRelayBackend
Constants ¶
const ( // CHTFrequencyClient is the block frequency for creating CHTs on the client side. // // TODO CHTFrequencyClient: 是在(轻节点)客户端上创建CHT的block频率 CHTFrequencyClient = 32768 // todo 用于Client // CHTFrequencyServer is the block frequency for creating CHTs on the server side. // Eventually this can be merged back with the client version, but that requires a // full database upgrade, so that should be left for a suitable moment. // // todo CHTFrequencyServer: 是在(轻节点)服务器端创建CHT的block频率 // 最终,可以将其与客户端版本合并,但是这需要对数据库进行全面升级,因此应保留适当的时间. CHTFrequencyServer = 4096 // todo 用于 Server // number of confirmations before a server is expected to have the given HelperTrie available // // 预期服务器使给定的HelperTrie `可用` 之前的确认次数 // todo 因为: CHT仅在2048次确认后生成,以确保不会被链重组更改 /** CHT仅在2048次确认后生成,以确保不会被链重组更改 */ HelperTrieConfirmations = 2048 // todo 主要用于 Client 端 !? // number of confirmations before a HelperTrie is generated // // HelperTrie `生成` 之前的确认次数 HelperTrieProcessConfirmations = 256 // todo 重要用于 Server 端? )
const (
// 这个是 Client 每隔 32768 组一个 BloomTrie
BloomTrieFrequency = 32768
)
Variables ¶
var ( ErrNoTrustedCht = errors.New("No trusted canonical hash trie") ErrNoTrustedBloomTrie = errors.New("No trusted bloom trie") ErrNoHeader = errors.New("Header not found") ChtTablePrefix = "cht-" // todo 规范hash trie 的相关node 的key的prefix )
var (
BloomTrieTablePrefix = "blt-"
)
var ErrNoPeers = errors.New("no suitable peers available")
ErrNoPeers is returned if no peers capable of serving a queued request are available
var NoOdr = context.Background()
NoOdr is the default context passed to an ODR capable function when the ODR service is not required.
NoOdr是不需要ODR服务时传递给支持ODR的功能的默认上下文
Functions ¶
func GetBlock ¶
func GetBlock(ctx context.Context, odr OdrBackend, hash common.Hash, number uint64) (*types.Block, error)
GetBlock retrieves an entire block corresponding to the hash, assembling it back from the stored header and body.
func GetBlockLogs ¶
func GetBlockLogs(ctx context.Context, odr OdrBackend, hash common.Hash, number uint64) ([][]*types.Log, error)
GetBlockLogs retrieves the logs generated by the transactions included in a block given by its hash.
func GetBlockReceipts ¶
func GetBlockReceipts(ctx context.Context, odr OdrBackend, hash common.Hash, number uint64) (types.Receipts, error)
GetBlockReceipts retrieves the receipts generated by the transactions included in a block given by its hash.
func GetBloomBits ¶
func GetBloomBits(ctx context.Context, odr OdrBackend, bitIdx uint, sectionIdxList []uint64) ([][]byte, error)
GetBloomBits retrieves a batch of compressed bloomBits vectors belonging to the given bit index and section indexes
GetBloomBits: 检索一批属于给 定位索引 <given bit index> 和 section索引的 压缩bloomBits 集合
func GetBloomTrieRoot ¶
GetBloomTrieRoot reads the BloomTrie root assoctiated to the given section from the database
func GetBody ¶
func GetBody(ctx context.Context, odr OdrBackend, hash common.Hash, number uint64) (*types.Body, error)
GetBody retrieves the block body (transactons, uncles) corresponding to the hash.
func GetBodyRLP ¶
func GetBodyRLP(ctx context.Context, odr OdrBackend, hash common.Hash, number uint64) (rlp.RawValue, error)
GetBodyRLP retrieves the block body (transactions and uncles) in RLP encoding.
func GetCanonicalHash ¶
func GetChtRoot ¶
GetChtRoot reads the CHT root assoctiated to the given section from the database Note that sectionIdx is specified according to LES/1 CHT section size
* GetChtRoot: 从 db 中读取分配给给定 section 的CHT root。 请注意,sectionIdx 是遵循 LES/1 CHT section 大小指定的
入参 :
sectionIdx: 第几个 section !? (从 0 开始 !?) sectionHead: section的第一个 block header Hash !?
func GetChtV2Root ¶
GetChtV2Root reads the CHT root assoctiated to the given section from the database Note that sectionIdx is specified according to LES/2 CHT section size
* GetChtV2Root: 从数据库中读取分配给给定节的CHT根。请注意,sectionIdx是根据 LES/2 CHT section大小指定的
func GetHeaderByNumber ¶
func NewBloomTrieIndexer ¶
func NewBloomTrieIndexer(db ethdb.Database, clientMode bool, odr OdrBackend) *core.ChainIndexer
NewBloomTrieIndexer creates a BloomTrie chain indexer
NewBloomTrieIndexer: 创建一个BloomTrie链索引器
func NewChtIndexer ¶
func NewChtIndexer(db ethdb.Database, clientMode bool, odr OdrBackend) *core.ChainIndexer
func NewStateDatabase ¶
func StoreBloomTrieRoot ¶
StoreBloomTrieRoot writes the BloomTrie root assoctiated to the given section into the database
Types ¶
type BlockRequest ¶
type BlockRequest struct { OdrRequest Hash common.Hash Number uint64 Rlp []byte }
BlockRequest is the ODR request type for retrieving block bodies
func (*BlockRequest) StoreResult ¶
func (req *BlockRequest) StoreResult(db ethdb.Database)
StoreResult stores the retrieved data in local database
type BloomRequest ¶
type BloomRequest struct { // 这个只是为了继承 OdrRequest 的方法 // 但是并没有看到赋值的地方 OdrRequest BloomTrieNum uint64 // 表示第几个section所对应的 bloomtrie BitIdx uint // 表示 查询该 bloom 中的bit 的index SectionIdxList []uint64 // 表示Section的index BloomTrieRoot common.Hash // trie 的 root BloomBits [][]byte // 整个 bloom bit vector Proofs *NodeSet // 校验结果的 proof }
BloomRequest is the ODR request type for retrieving bloom filters from a CHT structure
BloomRequest: 是ODR请求类型,用于从CHT结构中检索的 Bloom过滤器
func (*BloomRequest) StoreResult ¶
func (req *BloomRequest) StoreResult(db ethdb.Database)
StoreResult stores the retrieved data in local database
StoreResult: 将检索到的 <BloomRequest> 数据存储在本地数据库中 todo 这里做旋转!?
type BloomTrieIndexerBackend ¶
type BloomTrieIndexerBackend struct {
// contains filtered or unexported fields
}
BloomTrieIndexerBackend implements core.ChainIndexerBackend
todo 块分为固定长度的部分(LES BloomBits Trie的部分大小为32768块),
BloomBits[bitIdx][sectionIdx]是一个32768位(4096字节)长的位向量, 其中包含来自块范围的每个Bloom过滤器的单个位 sectionIdx*SectionSize ... (sectionIdx+1)*SectionSize-1
func (*BloomTrieIndexerBackend) Commit ¶
func (b *BloomTrieIndexerBackend) Commit() error
Commit implements core.ChainIndexerBackend
type ChtIndexerBackend ¶
type ChtIndexerBackend struct {
// contains filtered or unexported fields
}
ChtIndexerBackend implements core.ChainIndexerBackend
func (*ChtIndexerBackend) Commit ¶
func (c *ChtIndexerBackend) Commit() error
Commit implements core.ChainIndexerBackend
type ChtRequest ¶
type ChtRequest struct { OdrRequest // ChtNum: 表示 section num <第几个章节, 从0开始> // BlockNum: 表示被包含在 这 section 中的某个 blockNum ChtNum, BlockNum uint64 // 本 章节的 Cht trie 的 root ChtRoot common.Hash // 这个就是去请求的header 引用,最终根据这个的 num 和 hash 进行存储 Header *types.Header // 下面这两个值基本是对应的resp回来时被回填的 Td *big.Int Proof *NodeSet }
ChtRequest is the ODR request type for state/storage trie entries
* ChtRequest: 是 state/storage Trie条目的ODR req类型
func (*ChtRequest) StoreResult ¶
func (req *ChtRequest) StoreResult(db ethdb.Database)
StoreResult stores the retrieved data in local database
StoreResult: 将检索到的 <ChtRequest> 数据存储在本地数据库中
type CodeRequest ¶
type CodeRequest struct { OdrRequest // 引用帐户的存储树 Id *TrieID // references storage trie of the account Hash common.Hash // 这个是对端节点发回来的code hash Data []byte // 这个是对端节点发回来的 Code 内容 }
CodeRequest is the ODR request type for retrieving contract code
func (*CodeRequest) StoreResult ¶
func (req *CodeRequest) StoreResult(db ethdb.Database)
StoreResult stores the retrieved data in local database
type LightChain ¶
type LightChain struct {
// contains filtered or unexported fields
}
LightChain represents a canonical chain that by default only handles block headers, downloading block bodies and receipts on demand through an ODR interface. It only does header validation during chain insertion.
func NewLightChain ¶
func NewLightChain(odr OdrBackend, config *params.ChainConfig, engine consensus.Engine) (*LightChain, error)
NewLightChain returns a fully initialised light chain using information available in the database. It initialises the default Ethereum header validator.
func (*LightChain) Config ¶
func (self *LightChain) Config() *params.ChainConfig
Config retrieves the header chain's chain configuration.
func (*LightChain) CurrentHeader ¶
func (self *LightChain) CurrentHeader() *types.Header
CurrentHeader retrieves the current head header of the canonical chain. The header is retrieved from the HeaderChain's internal cache.
func (*LightChain) Engine ¶
func (bc *LightChain) Engine() consensus.Engine
Engine retrieves the light chain's consensus engine.
func (*LightChain) GasLimit ¶
func (self *LightChain) GasLimit() uint64
GasLimit returns the gas limit of the current HEAD block.
func (*LightChain) Genesis ¶
func (bc *LightChain) Genesis() *types.Block
Genesis returns the genesis block
func (*LightChain) GetAncestor ¶
func (bc *LightChain) 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 (*LightChain) GetBlock ¶
func (self *LightChain) GetBlock(ctx context.Context, hash common.Hash, number uint64) (*types.Block, error)
GetBlock retrieves a block from the database or ODR service by hash and number, caching it if found.
func (*LightChain) GetBlockByHash ¶
GetBlockByHash retrieves a block from the database or ODR service by hash, caching it if found.
func (*LightChain) GetBlockByNumber ¶
GetBlockByNumber retrieves a block from the database or ODR service by number, caching it (associated with its hash) if found.
func (*LightChain) GetBlockHashesFromHash ¶
GetBlockHashesFromHash retrieves a number of block hashes starting at a given hash, fetching towards the genesis block.
func (*LightChain) GetBody ¶
GetBody retrieves a block body (transactions and uncles) from the database or ODR service by hash, caching it if found.
func (*LightChain) GetBodyRLP ¶
GetBodyRLP retrieves a block body in RLP encoding from the database or ODR service by hash, caching it if found.
func (*LightChain) GetHeader ¶
GetHeader retrieves a block header from the database by hash and number, caching it if found.
func (*LightChain) GetHeaderByHash ¶
func (self *LightChain) GetHeaderByHash(hash common.Hash) *types.Header
GetHeaderByHash retrieves a block header from the database by hash, caching it if found.
func (*LightChain) GetHeaderByNumber ¶
func (self *LightChain) GetHeaderByNumber(number uint64) *types.Header
GetHeaderByNumber retrieves a block header from the database by number, caching it (associated with its hash) if found.
func (*LightChain) GetHeaderByNumberOdr ¶
func (self *LightChain) GetHeaderByNumberOdr(ctx context.Context, number uint64) (*types.Header, error)
GetHeaderByNumberOdr retrieves a block header from the database or network by number, caching it (associated with its hash) if found.
func (*LightChain) GetTd ¶
GetTd retrieves a block's total difficulty in the canonical chain from the database by hash and number, caching it if found.
func (*LightChain) GetTdByHash ¶
func (self *LightChain) 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 (*LightChain) HasBlock ¶
func (bc *LightChain) HasBlock(hash common.Hash, number uint64) bool
HasBlock checks if a block is fully present in the database or not, caching it if present.
func (*LightChain) HasHeader ¶
func (bc *LightChain) 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 (*LightChain) 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 verfy nonces, as well as because nonces can be verified sparsely, not needing to check each.
In the case of a light chain, InsertHeaderChain also creates and posts light chain events when necessary.
func (*LightChain) LockChain ¶
func (self *LightChain) LockChain()
LockChain locks the chain mutex for reading so that multiple canonical hashes can be retrieved while it is guaranteed that they belong to the same version of the chain
func (*LightChain) Odr ¶
func (self *LightChain) Odr() OdrBackend
Odr returns the ODR backend of the chain
func (*LightChain) Reset ¶
func (bc *LightChain) Reset()
Reset purges the entire blockchain, restoring it to its genesis state.
func (*LightChain) ResetWithGenesisBlock ¶
func (bc *LightChain) ResetWithGenesisBlock(genesis *types.Block)
ResetWithGenesisBlock purges the entire blockchain, restoring it to the specified genesis state.
func (*LightChain) Rollback ¶
func (self *LightChain) 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 (*LightChain) SetHead ¶
func (bc *LightChain) SetHead(head uint64)
SetHead rewinds the local chain to a new head. Everything above the new head will be deleted and the new one set.
func (*LightChain) State ¶
func (bc *LightChain) State() (*state.StateDB, error)
State returns a new mutable state based on the current HEAD block.
func (*LightChain) Stop ¶
func (bc *LightChain) Stop()
Stop stops the blockchain service. If any imports are currently in progress it will abort them using the procInterrupt.
func (*LightChain) SubscribeChainEvent ¶
func (self *LightChain) SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
SubscribeChainEvent registers a subscription of ChainEvent.
func (*LightChain) SubscribeChainHeadEvent ¶
func (self *LightChain) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
SubscribeChainHeadEvent registers a subscription of ChainHeadEvent.
func (*LightChain) SubscribeChainSideEvent ¶
func (self *LightChain) SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription
SubscribeChainSideEvent registers a subscription of ChainSideEvent.
func (*LightChain) SubscribeLogsEvent ¶
func (self *LightChain) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription
SubscribeLogsEvent implements the interface of filters.Backend LightChain does not send logs events, so return an empty subscription.
func (*LightChain) SubscribeRemovedLogsEvent ¶
func (self *LightChain) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription
SubscribeRemovedLogsEvent implements the interface of filters.Backend LightChain does not send core.RemovedLogsEvent, so return an empty subscription.
func (*LightChain) UnlockChain ¶
func (self *LightChain) UnlockChain()
UnlockChain unlocks the chain mutex
type NodeList ¶
NodeList stores an ordered list of trie nodes. It implements ethdb.Putter.
type NodeSet ¶
type NodeSet struct {
// contains filtered or unexported fields
}
NodeSet stores a set of trie nodes. It implements trie.Database and can also act as a cache for another trie.Database.
type OdrBackend ¶
type OdrBackend interface { Database() ethdb.Database ChtIndexer() *core.ChainIndexer BloomTrieIndexer() *core.ChainIndexer BloomIndexer() *core.ChainIndexer Retrieve(ctx context.Context, req OdrRequest) error }
OdrBackend is an interface to a backend service that handles ODR retrievals type
OdrBackend是处理ODR检索类型的后端服务的接口
type OdrRequest ¶
OdrRequest is an interface for retrieval requests
type ReceiptsRequest ¶
ReceiptsRequest is the ODR request type for retrieving block bodies
func (*ReceiptsRequest) StoreResult ¶
func (req *ReceiptsRequest) StoreResult(db ethdb.Database)
StoreResult stores the retrieved data in local database
type TrieID ¶
TrieID identifies a state or account storage trie
func StateTrieID ¶
StateTrieID returns a TrieID for a state trie belonging to a certain block header.
type TrieRequest ¶
type TrieRequest struct { OdrRequest Id *TrieID Key []byte Proof *NodeSet }
TrieRequest is the ODR request type for state/storage trie entries
func (*TrieRequest) StoreResult ¶
func (req *TrieRequest) StoreResult(db ethdb.Database)
StoreResult stores the retrieved data in local database
type TrustedCheckpoint ¶
type TrustedCheckpoint struct { SectionIdx uint64 SectionHead, CHTRoot, BloomRoot common.Hash // contains filtered or unexported fields }
TrustedCheckpoint represents a set of post-processed trie roots (CHT and BloomTrie) associated with the appropriate section index and head hash. It is used to start light syncing from this checkpoint and avoid downloading the entire header chain while still being able to securely access old headers/logs.
* TrustedCheckpoint:
表示一组与适当的 section 索引和 header hash 关联的后处理的trie根(CHT和BloomTrie)。 它用于从此 checkpoint 开始进行 light 同步,并避免下载整个 header chain, 同时仍然能够安全地访问旧的headers/logs.
type TxPool ¶
type TxPool struct {
// contains filtered or unexported fields
}
TxPool implements the transaction pool for light clients, which keeps track of the status of locally created transactions, detecting if they are included in a block (mined) or rolled back. There are no queued transactions since we always receive all locally signed transactions in the same order as they are created.
func NewTxPool ¶
func NewTxPool(config *params.ChainConfig, chain *LightChain, relay TxRelayBackend) *TxPool
NewTxPool creates a new light transaction pool
func (*TxPool) Add ¶
Add adds a transaction to the pool if valid and passes it to the tx relay backend
func (*TxPool) AddBatch ¶
func (self *TxPool) AddBatch(ctx context.Context, txs []*types.Transaction)
AddTransactions adds all valid transactions to the pool and passes them to the tx relay backend
func (*TxPool) Content ¶
func (self *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 nonce.
func (*TxPool) GetNonce ¶
GetNonce returns the "pending" nonce of a given address. It always queries the nonce belonging to the latest header too in order to detect if another client using the same key sent a transaction.
func (*TxPool) GetTransaction ¶
func (tp *TxPool) GetTransaction(hash common.Hash) *types.Transaction
GetTransaction returns a transaction if it is contained in the pool and nil otherwise.
func (*TxPool) GetTransactions ¶
func (self *TxPool) GetTransactions() (txs types.Transactions, err error)
GetTransactions returns all currently processable transactions. The returned slice may be modified by the caller.
func (*TxPool) RemoveTransactions ¶
func (self *TxPool) RemoveTransactions(txs types.Transactions)
RemoveTransactions removes all given transactions from the pool.
func (*TxPool) SubscribeNewTxsEvent ¶
func (pool *TxPool) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subscription
SubscribeNewTxsEvent registers a subscription of core.NewTxsEvent and starts sending event to the given channel.
type TxRelayBackend ¶
type TxRelayBackend interface { Send(txs types.Transactions) NewHead(head common.Hash, mined []common.Hash, rollback []common.Hash) Discard(hashes []common.Hash) }
TxRelayBackend provides an interface to the mechanism that forwards transacions to the ETH network. The implementations of the functions should be non-blocking.
Send instructs backend to forward new transactions NewHead notifies backend about a new head after processed by the tx pool,
including mined and rolled back transactions since the last event
Discard notifies backend about transactions that should be discarded either
because they have been replaced by a re-send or because they have been mined long ago and no rollback is expected