txpool

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2019 License: LGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTxPoolBlockExpired = errors.New("the block has expired")

Functions

This section is empty.

Types

type BlockTimeBucket

type BlockTimeBucket struct {
	/* 块时间 */
	Time uint32

	/* 块列表,以高度索引块列表 */
	BlocksByHeight map[uint32]HashSet
}

type BlocksTrie

type BlocksTrie struct {

	/* 根据高度对块进行索引 */
	HeightBuckets map[uint32]NodeByHash

	/* 根据时间刻度对块Hash进行索引,用来回收块 */
	TimeBuckets []*BlockTimeBucket
}

最近一个小时的所有块

func NewBlocksTrie

func NewBlocksTrie() *BlocksTrie

func (*BlocksTrie) DelBlock

func (trie *BlocksTrie) DelBlock(block *types.Block)

func (*BlocksTrie) Path

func (trie *BlocksTrie) Path(hash common.Hash, height uint32, minHeight uint32, maxHeight uint32) []*TrieNode

从指定块开始,收集该块所在链指定高度区间的块[minHeight, maxHeight]

func (*BlocksTrie) PushBlock

func (trie *BlocksTrie) PushBlock(block *types.Block) error

收到一个新块,并返回过期的块的交易列表,块过期了,块中的交易肯定也过期了

type HashSet

type HashSet map[common.Hash]struct{}

HashSet 是hash的集合,用map实现高效查询

func (HashSet) Add

func (set HashSet) Add(hash common.Hash)

func (HashSet) Collect

func (set HashSet) Collect() []common.Hash

func (HashSet) Del

func (set HashSet) Del(hash common.Hash)

func (HashSet) Has

func (set HashSet) Has(hash common.Hash) bool

type NodeByHash

type NodeByHash map[common.Hash]*TrieNode

type RecentTx

type RecentTx struct {
	// key是交易hash,value是交易所在块的记录
	TraceMap map[common.Hash]TxTrace

	TxsByTime []*TxTimeBucket
}

近一个小时收到的所有交易的集合,用于防止交易重放

func NewTxRecently

func NewTxRecently() *RecentTx

func (*RecentTx) GetTrace

func (recent *RecentTx) GetTrace(txs []*types.Transaction) map[common.Hash]TxTrace

GetTrace 获取交易在区块中出现过的记录

func (*RecentTx) IsExist

func (recent *RecentTx) IsExist(tx *types.Transaction) bool

func (*RecentTx) PruneBlock

func (recent *RecentTx) PruneBlock(hash common.Hash, height int64, txs []*types.Transaction)

func (*RecentTx) RecvBlock

func (recent *RecentTx) RecvBlock(hash common.Hash, height int64, txs []*types.Transaction)

收到一个新块,把该块种的交易放入最近交易列表

func (*RecentTx) RecvTx

func (recent *RecentTx) RecvTx(tx *types.Transaction)

收到一条新的交易,放入最近交易列表

type TrieNode

type TrieNode struct {
	Header *types.Header

	/* 该块打包的交易列表的索引 */
	TxHashSet HashSet
}

type TxPool

type TxPool struct {
	/* 还未被打包进块的交易 */
	PendingTxs *TxQueue

	/* 最近1个小时的所有交易 */
	RecentTxs *RecentTx

	/* 从当前高度向后的3600个块 */
	BlockCache *BlocksTrie

	RW sync.RWMutex
}

func NewTxPool

func NewTxPool() *TxPool

func (*TxPool) DelInvalidTxs

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

本节点出块时,执行交易后,发现错误的交易通过该接口进行删除

func (*TxPool) Get

func (pool *TxPool) Get(time uint32, size int) []*types.Transaction

本节点出块时,从交易池中取出交易进行打包,但并不从交易池中删除

func (*TxPool) PruneBlock

func (pool *TxPool) PruneBlock(block *types.Block)

对链进行剪枝,剪下的块中的交易需要回归交易池

func (*TxPool) RecvBlock

func (pool *TxPool) RecvBlock(block *types.Block)

新收到一个通过验证的新块(包括本节点出的块),需要从交易池中删除该块中已打包的交易

func (*TxPool) RecvTx

func (pool *TxPool) RecvTx(tx *types.Transaction) bool

收到一笔新的交易

func (*TxPool) RecvTxs

func (pool *TxPool) RecvTxs(txs []*types.Transaction) bool

func (*TxPool) VerifyTxInBlock

func (pool *TxPool) VerifyTxInBlock(block *types.Block) bool

新收一个块时,验证块中的交易是否被同一条分叉上的其他块打包了

type TxQueue

type TxQueue struct {
	/* 交易状态标记,true:正常;false:已删除 */
	TxsStatus map[common.Hash]bool

	TxsQueue []*types.Transaction
}

func NewTxQueue

func NewTxQueue() *TxQueue

func (*TxQueue) Del

func (queue *TxQueue) Del(hash common.Hash)

func (*TxQueue) DelBatch

func (queue *TxQueue) DelBatch(hashes []common.Hash)

func (*TxQueue) Pop

func (queue *TxQueue) Pop(time uint32, size int) []*types.Transaction

func (*TxQueue) Push

func (queue *TxQueue) Push(tx *types.Transaction)

func (*TxQueue) PushBatch

func (queue *TxQueue) PushBatch(txs []*types.Transaction)

type TxTimeBucket

type TxTimeBucket struct {
	/* 交易超时时间,UTC */
	Expiration uint64

	/* 该超时时间下的所有交易列表 */
	TxIndexes HashSet
}

type TxTrace

type TxTrace map[common.Hash]int64

交易在区块中出现过的记录。key是区块hash,value是区块高度

func NewEmptyTxTrace

func NewEmptyTxTrace() TxTrace

func NewTxTrace

func NewTxTrace(hash common.Hash, height int64) TxTrace

Jump to

Keyboard shortcuts

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