mempool

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2018 License: BSD-2-Clause Imports: 19 Imported by: 34

Documentation

Index

Constants

View Source
const (
	OrphanTxExpireTime          = 20 * 60
	OrphanTxExpireInterval      = 5 * 60
	DefaultMaxOrphanTransaction = 100
)
View Source
const (
	RollingFeeHalfLife = 12 * 60 * 60
)

Variables

This section is empty.

Functions

func Close added in v0.0.3

func Close()

Close FIXME this is only for test. We must do it in a graceful way

func InitMempool

func InitMempool()

func SetInstance added in v0.0.3

func SetInstance(p *TxMempool)

Types

type EntryAncestorFeeRateSort

type EntryAncestorFeeRateSort TxEntry

func (*EntryAncestorFeeRateSort) Less

type EntryFeeSort

type EntryFeeSort TxEntry

func (EntryFeeSort) Less

func (e EntryFeeSort) Less(than mapcontainer.Lesser) bool

type LockPoints

type LockPoints struct {
	// Height and Time will be set to the blockChain height and median time past values that
	// would be necessary to satisfy all relative lockTime constraints (BIP68)
	// of this tx given our view of block chain history
	Height int32
	Time   int64
	// MaxInputBlock as long as the current chain descends from the highest height block
	// containing one of the inputs used in the calculation, then the cached
	// values are still valid even after a reOrg.
	MaxInputBlock *blockindex.BlockIndex
}

func NewLockPoints

func NewLockPoints() *LockPoints

type OrphanTx

type OrphanTx struct {
	Tx         *tx.Tx
	NodeID     int64
	Expiration int
}

type PoolRemovalReason

type PoolRemovalReason int
const (
	// UNKNOWN Manually removed or unknown reason
	UNKNOWN PoolRemovalReason = iota
	// EXPIRY Expired from memPool
	EXPIRY
	// SIZELIMIT Removed in size limiting
	SIZELIMIT
	// REORG Removed for reorganization
	REORG
	// BLOCK Removed for block
	BLOCK
	// CONFLICT Removed for conflict with in-block transaction
	CONFLICT
	// REPLACED Removed for replacement
	REPLACED
)

Reason why a transaction was removed from the memPool, this is passed to the notification signal.

type StatisInformation

type StatisInformation struct {
	// sumTxCountWithDescendants is this tx and all Descendants transaction's number. init number is 1.
	SumTxCountWithDescendants int64
	// sumFeeWithDescendants is calculated by this tx and all Descendants transaction;
	SumTxFeeWithDescendants int64
	// sumSizeWithDescendants size calculated by this tx and all Descendants transaction;
	SumTxSizeWithDescendants int64

	SumTxCountWithAncestors      int64
	SumTxSizeWitAncestors        int64
	SumTxSigOpCountWithAncestors int64
	SumTxFeeWithAncestors        int64
}

type TxEntry

type TxEntry struct {
	Tx     *tx.Tx
	TxSize int
	// txFee tis transaction fee
	TxFee    int64
	TxHeight int32
	// sigOpCount sigop plus P2SH sigops count
	SigOpCount int

	// childTx the tx's all Descendants transaction
	ChildTx map[*TxEntry]struct{}
	// parentTx the tx's all Ancestors transaction
	ParentTx map[*TxEntry]struct{}

	//Statistics Information for every txentry with its ancestors And descend.
	StatisInformation
	// contains filtered or unexported fields
}

func NewTxentry

func NewTxentry(tx *tx.Tx, txFee int64, acceptTime int64, height int32, lp LockPoints, sigOpsCount int,
	spendCoinbase bool) *TxEntry

func (*TxEntry) CheckLockPointValidity

func (t *TxEntry) CheckLockPointValidity(chain *chain.Chain) bool

func (*TxEntry) GetFeeRate

func (t *TxEntry) GetFeeRate() *util.FeeRate

func (*TxEntry) GetInfo

func (t *TxEntry) GetInfo() *TxMempoolInfo

func (*TxEntry) GetLockPointFromTxEntry

func (t *TxEntry) GetLockPointFromTxEntry() LockPoints

func (*TxEntry) GetSigOpCountWithAncestors

func (t *TxEntry) GetSigOpCountWithAncestors() int64

func (*TxEntry) GetSpendsCoinbase

func (t *TxEntry) GetSpendsCoinbase() bool

func (*TxEntry) GetTime

func (t *TxEntry) GetTime() int64

func (*TxEntry) GetUsageSize

func (t *TxEntry) GetUsageSize() int64

func (*TxEntry) Less

func (t *TxEntry) Less(than mapcontainer.Lesser) bool

func (*TxEntry) SetLockPointFromTxEntry

func (t *TxEntry) SetLockPointFromTxEntry(lp LockPoints)

func (*TxEntry) UpdateAncestorState

func (t *TxEntry) UpdateAncestorState(updateCount, updateSize, updateSigOps int, updateFee int64)

func (*TxEntry) UpdateChild

func (t *TxEntry) UpdateChild(child *TxEntry, add bool)

func (*TxEntry) UpdateChildOfParents

func (t *TxEntry) UpdateChildOfParents(add bool)

func (*TxEntry) UpdateDescendantState

func (t *TxEntry) UpdateDescendantState(updateCount, updateSize int, updateFee int64)

func (*TxEntry) UpdateParent

func (t *TxEntry) UpdateParent(parent *TxEntry, add bool)

UpdateParent update the tx's parent transaction.

type TxMempool

type TxMempool struct {

	//transactionsUpdated mempool update transaction total number when create mempool late.
	TransactionsUpdated      uint64
	OrphanTransactionsByPrev map[outpoint.OutPoint]map[util.Hash]OrphanTx
	OrphanTransactions       map[util.Hash]OrphanTx
	// contains filtered or unexported fields
}

TxMempool is safe for concurrent write And read access.

func GetInstance

func GetInstance() *TxMempool

func NewTxMempool

func NewTxMempool() *TxMempool

func (*TxMempool) AddOrphanTx

func (m *TxMempool) AddOrphanTx(orphantx *tx.Tx, nodeID int64)

func (*TxMempool) AddTx

func (m *TxMempool) AddTx(txEntry *TxEntry, ancestors map[*TxEntry]struct{}) error

AddTx operator is safe for concurrent write And read access. this function is used to add tx to the memPool, and now the tx should be passed all appropriate checks.

func (*TxMempool) CalculateDescendants

func (m *TxMempool) CalculateDescendants(entry *TxEntry, descendants map[*TxEntry]struct{})

CalculateDescendants Calculates descendants of entry that are not already in setDescendants, and adds to setDescendants. Assumes entry it is already a tx in the mempool and setMemPoolChildren is correct for tx and all descendants. Also assumes that if an entry is in setDescendants already, then all in-mempool descendants of it are already in setDescendants as well, so that we can save time by not iterating over those entries.

func (*TxMempool) CalculateDescendantsWithLock

func (m *TxMempool) CalculateDescendantsWithLock(txHash *util.Hash) map[*TxEntry]struct{}

func (*TxMempool) CalculateMemPoolAncestors

func (m *TxMempool) CalculateMemPoolAncestors(tx *tx.Tx, limitAncestorCount uint64,
	limitAncestorSize uint64, limitDescendantCount uint64, limitDescendantSize uint64,
	searchForParent bool) (ancestors map[*TxEntry]struct{}, err error)

CalculateMemPoolAncestors get tx all ancestors transaction in mempool. when the find is false: the tx must in mempool, so directly get his parent.

func (*TxMempool) CalculateMemPoolAncestorsWithLock

func (m *TxMempool) CalculateMemPoolAncestorsWithLock(txhash *util.Hash) map[*TxEntry]struct{}

func (*TxMempool) CleanOrphan added in v0.0.3

func (m *TxMempool) CleanOrphan()

func (*TxMempool) EraseOrphanTx

func (m *TxMempool) EraseOrphanTx(txHash util.Hash, removeRedeemers bool)

func (*TxMempool) FindTx

func (m *TxMempool) FindTx(hash util.Hash) *TxEntry

func (*TxMempool) GetAllSpentOutWithoutLock

func (m *TxMempool) GetAllSpentOutWithoutLock() map[outpoint.OutPoint]*TxEntry

func (*TxMempool) GetAllTxEntry

func (m *TxMempool) GetAllTxEntry() map[util.Hash]*TxEntry

func (*TxMempool) GetAllTxEntryWithoutLock

func (m *TxMempool) GetAllTxEntryWithoutLock() map[util.Hash]*TxEntry

func (*TxMempool) GetCheckFrequency

func (m *TxMempool) GetCheckFrequency() uint64

func (*TxMempool) GetCoin

func (m *TxMempool) GetCoin(outpoint *outpoint.OutPoint) *utxo.Coin

func (*TxMempool) GetMinFee

func (m *TxMempool) GetMinFee(sizeLimit int64) util.FeeRate

func (*TxMempool) GetMinFeeRate

func (m *TxMempool) GetMinFeeRate() util.FeeRate

func (*TxMempool) GetPoolAllTxSize

func (m *TxMempool) GetPoolAllTxSize(lock bool) uint64

func (*TxMempool) GetPoolUsage

func (m *TxMempool) GetPoolUsage() int64

func (*TxMempool) GetRootTx

func (m *TxMempool) GetRootTx() map[util.Hash]TxEntry

func (*TxMempool) HasSPentOutWithoutLock

func (m *TxMempool) HasSPentOutWithoutLock(out *outpoint.OutPoint) *TxEntry

func (*TxMempool) HasSpentOut

func (m *TxMempool) HasSpentOut(out *outpoint.OutPoint) bool

func (*TxMempool) HaveTransaction added in v0.0.3

func (m *TxMempool) HaveTransaction(tx *tx.Tx) bool

func (*TxMempool) IsOrphanInPool added in v0.0.3

func (m *TxMempool) IsOrphanInPool(tx *tx.Tx) bool

func (*TxMempool) IsTransactionInPool added in v0.0.3

func (m *TxMempool) IsTransactionInPool(tx *tx.Tx) bool

func (*TxMempool) LimitMempoolSize

func (m *TxMempool) LimitMempoolSize(sizeLimit, age int64)

LimitMempoolSize limit mempool size with time And limit size. when the noSpendsRemaining set, the function will return these have removed transaction's txin from mempool which use TrimToSize rule. Later, caller will remove these txin from uxto cache.

func (*TxMempool) Lock added in v0.0.3

func (m *TxMempool) Lock()

func (*TxMempool) RLock added in v0.0.3

func (m *TxMempool) RLock()

func (*TxMempool) RUnlock added in v0.0.3

func (m *TxMempool) RUnlock()

func (*TxMempool) RemoveOrphansByTag

func (m *TxMempool) RemoveOrphansByTag(nodeID int64) int

func (*TxMempool) RemoveStaged

func (m *TxMempool) RemoveStaged(entriesToRemove map[*TxEntry]struct{}, updateDescendants bool, reason PoolRemovalReason)

func (*TxMempool) RemoveTxRecursive

func (m *TxMempool) RemoveTxRecursive(origTx *tx.Tx, reason PoolRemovalReason)

func (*TxMempool) RemoveTxSelf

func (m *TxMempool) RemoveTxSelf(txs []*tx.Tx)

RemoveTxSelf will only remove these transaction self.

func (*TxMempool) Size

func (m *TxMempool) Size() int

func (*TxMempool) TxInfoAll

func (m *TxMempool) TxInfoAll() []*TxMempoolInfo

func (*TxMempool) Unlock added in v0.0.3

func (m *TxMempool) Unlock()

type TxMempoolInfo

type TxMempoolInfo struct {
	Tx      *tx.Tx       // The transaction itself
	Time    int64        // Time the transaction entered the memPool
	FeeRate util.FeeRate // FeeRate of the transaction
}

func (*TxMempoolInfo) Serialize

func (info *TxMempoolInfo) Serialize(w io.Writer) error

func (*TxMempoolInfo) Unserialize

func (info *TxMempoolInfo) Unserialize(r io.Reader) error

Jump to

Keyboard shortcuts

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