txpool

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2020 License: LGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const BucketDuration = uint32(60)

TimeBuckets中每一个slot覆盖的时间范围,单位为秒

Variables

View Source
var (
	ErrNotFoundBlockCache = errors.New("not found block in TxGuard'Cache")
	ErrTimeBucketTime     = errors.New("block timestamp should be greater than bucket base time")
	ErrDifferentGenesis   = errors.New("found different genesis block")
	ErrInvalidTx          = errors.New("the transaction is broken")
	ErrTxIsExist          = errors.New("the transaction is exist in txPool")
	ErrTxPoolExtendFail   = errors.New("txPool extend fail")
	ErrInvalidBaseTime    = errors.New("invalid stable block time")
)

Functions

This section is empty.

Types

type BlockCache added in v1.4.0

type BlockCache map[common.Hash]*BlockNode

根据区块Hash索引区块

func (BlockCache) Add added in v1.4.0

func (cache BlockCache) Add(block *types.Block)

func (BlockCache) CollectBlocks added in v1.4.0

func (cache BlockCache) CollectBlocks(blockHashSet HashSet) (BlockNodes, error)

SliceOnFork collect blocks' hashes from specific fork and specific height range [minHeight, maxHeight]

func (BlockCache) Del added in v1.4.0

func (cache BlockCache) Del(hash common.Hash)

func (BlockCache) Get added in v1.4.0

func (cache BlockCache) Get(hash common.Hash) *BlockNode

func (BlockCache) IsAppearedOnFork added in v1.4.0

func (cache BlockCache) IsAppearedOnFork(blockHashes HashSet, startBlockHash common.Hash) bool

IsAppearedOnFork tests if the blocks are appeared on the fork from startBlock

func (BlockCache) SliceOnFork added in v1.4.0

func (cache BlockCache) SliceOnFork(startBlockHash common.Hash, minHeight uint32, maxHeight uint32) (blockHashes []common.Hash, err error)

SliceOnFork collect blocks' hashes from specific fork and specific height range [minHeight, maxHeight]. The result array is from leaf block hash to root block hash

type BlockNode added in v1.4.0

type BlockNode struct {
	Header *types.Header

	/* 该块打包的交易列表 */
	Txs types.Transactions
}

简化的区块数据

type BlockNodes added in v1.4.0

type BlockNodes []*BlockNode

type HashList added in v1.4.0

type HashList []common.Hash

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

func (HashSet) Merge added in v1.4.0

func (set HashSet) Merge(set2 HashSet)

type TimeBuckets added in v1.4.0

type TimeBuckets struct {
	// 第一个bucket的起始时间,是BucketDuration的整数倍。此时间戳是随着链上的stable变化而变化的
	TimeBase uint32
	// contains filtered or unexported fields
}

func (*TimeBuckets) Add added in v1.4.0

func (timeBucket *TimeBuckets) Add(time uint32, hash common.Hash) error

Add save hash into time bucket

func (*TimeBuckets) Expire added in v1.4.0

func (timeBucket *TimeBuckets) Expire(newTimeBase uint32) []common.Hash

Expire delete all expired data by move time base pointer

type TxGuard added in v1.4.0

type TxGuard struct {
	RW sync.RWMutex
	// contains filtered or unexported fields
}

TxGuard is used test if a transaction or block is contained in some fork It contains the blocks half hour before stable block, and contains unstable blocks

func NewTxGuard added in v1.4.0

func NewTxGuard(stableBlockTime uint32) *TxGuard

func (*TxGuard) DelOldBlocks added in v1.4.0

func (guard *TxGuard) DelOldBlocks(newStableBlockTime uint32)

DelOldBlocks 根据时间删去过期了的区块和交易

func (*TxGuard) ExistTx added in v1.4.0

func (guard *TxGuard) ExistTx(startBlockHash common.Hash, tx *types.Transaction) bool

ExistTx 判断tx是否已经在当前分支存在,startBlockHash为指定分支的子节点的区块hash

func (*TxGuard) ExistTxs added in v1.4.0

func (guard *TxGuard) ExistTxs(startBlockHash common.Hash, txs types.Transactions) bool

ExistTxs 判断txs中是否有交易已经在当前分支存在,startBlockHash为指定分支的子节点的区块hash

func (*TxGuard) GetTxsByBranch added in v1.4.0

func (guard *TxGuard) GetTxsByBranch(block1, block2 *types.Block) (txs1, txs2 types.Transactions, err error)

GetTxsByBranch 根据两个区块的叶子节点,获取它们到共同父节点之间的两个分支上的交易列表

func (*TxGuard) SaveBlock added in v1.4.0

func (guard *TxGuard) SaveBlock(block *types.Block)

SaveBlock save the block and record its transactions' appearance

type TxPool

type TxPool struct {
	RW sync.RWMutex
	// contains filtered or unexported fields
}

TxPool saves the transactions which could be packaged in current fork

func NewTxPool

func NewTxPool() *TxPool

func (*TxPool) AddTx added in v1.4.0

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

func (*TxPool) AddTxs added in v1.4.0

func (pool *TxPool) AddTxs(txs types.Transactions) int

AddTxs push txs into pool and return the number of new txs

func (*TxPool) DelTxs added in v1.4.0

func (pool *TxPool) DelTxs(txs types.Transactions)

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

func (*TxPool) GetTxs added in v1.4.0

func (pool *TxPool) GetTxs(time uint32, size int) types.Transactions

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

func (*TxPool) IsEmpty added in v1.4.0

func (pool *TxPool) IsEmpty() bool

type TxTracer added in v1.4.0

type TxTracer map[common.Hash]HashSet

TxTracer use transaction hash to be the key, and the value is block hashes which the transaction appeared

func (TxTracer) AddTrace added in v1.4.0

func (t TxTracer) AddTrace(tx *types.Transaction, blockHash common.Hash)

func (TxTracer) DelTrace added in v1.4.0

func (t TxTracer) DelTrace(tx *types.Transaction)

func (TxTracer) LoadTraces added in v1.4.0

func (t TxTracer) LoadTraces(txs types.Transactions) HashSet

loadTraces load the block hash list which txs appeared

Jump to

Keyboard shortcuts

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