Documentation
¶
Index ¶
- Constants
- Variables
- func InitMempool()
- type BtcPerKilobyte
- type EntryAncestorFeeRateSort
- type EntryFeeSort
- type FeeEstimator
- func (ef *FeeEstimator) EstimateFee(numBlocks uint32) (BtcPerKilobyte, error)
- func (ef *FeeEstimator) LastKnownHeight() int32
- func (ef *FeeEstimator) ObserveTransaction(t *tx.Tx)
- func (ef *FeeEstimator) RegisterBlock(block *block.Block) error
- func (ef *FeeEstimator) Rollback(hash *util.Hash) error
- func (ef *FeeEstimator) Save() FeeEstimatorState
- type FeeEstimatorState
- type LockPoints
- type OrphanTx
- type PoolRemovalReason
- type SatoshiPerByte
- type StatisInformation
- type TxEntry
- func (t *TxEntry) CheckLockPointValidity(chain *chain.Chain) bool
- func (t *TxEntry) GetFeeRate() *util.FeeRate
- func (t *TxEntry) GetInfo() *TxMempoolInfo
- func (t *TxEntry) GetLockPointFromTxEntry() LockPoints
- func (t *TxEntry) GetSigOpCountWithAncestors() int64
- func (t *TxEntry) GetSpendsCoinbase() bool
- func (t *TxEntry) GetTime() int64
- func (t *TxEntry) GetUsageSize() int64
- func (t *TxEntry) Less(than btree.Item) bool
- func (t *TxEntry) SetLockPointFromTxEntry(lp LockPoints)
- func (t *TxEntry) UpdateAncestorState(updateCount, updateSize, updateSigOps int, updateFee int64)
- func (t *TxEntry) UpdateChild(child *TxEntry, add bool)
- func (t *TxEntry) UpdateChildOfParents(add bool)
- func (t *TxEntry) UpdateDescendantState(updateCount, updateSize int, updateFee int64)
- func (t *TxEntry) UpdateParent(parent *TxEntry, add bool)
- type TxMempool
- func (m *TxMempool) AddOrphanTx(orphantx *tx.Tx, nodeID int64)
- func (m *TxMempool) AddTx(txEntry *TxEntry, ancestors map[*TxEntry]struct{}) error
- func (m *TxMempool) CalculateDescendants(entry *TxEntry, descendants map[*TxEntry]struct{})
- func (m *TxMempool) CalculateDescendantsWithLock(txHash *util.Hash) map[*TxEntry]struct{}
- func (m *TxMempool) CalculateMemPoolAncestors(tx *tx.Tx, limitAncestorCount uint64, limitAncestorSize uint64, ...) (ancestors map[*TxEntry]struct{}, err error)
- func (m *TxMempool) CalculateMemPoolAncestorsWithLock(txhash *util.Hash) map[*TxEntry]struct{}
- func (m *TxMempool) EraseOrphanTx(txHash util.Hash, removeRedeemers bool)
- func (m *TxMempool) FindTx(hash util.Hash) *TxEntry
- func (m *TxMempool) GetAllSpentOutWithoutLock() map[outpoint.OutPoint]*TxEntry
- func (m *TxMempool) GetAllTxEntry() map[util.Hash]*TxEntry
- func (m *TxMempool) GetAllTxEntryWithoutLock() map[util.Hash]*TxEntry
- func (m *TxMempool) GetCheckFrequency() float64
- func (m *TxMempool) GetCoin(outpoint *outpoint.OutPoint) *utxo.Coin
- func (m *TxMempool) GetMinFee(sizeLimit int64) util.FeeRate
- func (m *TxMempool) GetMinFeeRate() util.FeeRate
- func (m *TxMempool) GetPoolAllTxSize() uint64
- func (m *TxMempool) GetPoolUsage() int64
- func (m *TxMempool) GetRootTx() map[util.Hash]TxEntry
- func (m *TxMempool) HasSPentOutWithoutLock(out *outpoint.OutPoint) *TxEntry
- func (m *TxMempool) HasSpentOut(out *outpoint.OutPoint) bool
- func (m *TxMempool) LimitMempoolSize() []*outpoint.OutPoint
- func (m *TxMempool) LimitOrphanTx() (removeNum int)
- func (m *TxMempool) RemoveOrphansByTag(nodeID int64) int
- func (m *TxMempool) RemoveStaged(entriesToRemove map[*TxEntry]struct{}, updateDescendants bool, ...)
- func (m *TxMempool) RemoveTxRecursive(origTx *tx.Tx, reason PoolRemovalReason)
- func (m *TxMempool) RemoveTxSelf(txs []*tx.Tx)
- func (m *TxMempool) Size() int
- func (m *TxMempool) TxInfoAll() []*TxMempoolInfo
- type TxMempoolInfo
Constants ¶
const ( // DefaultEstimateFeeMaxRollback is the default number of rollbacks // allowed by the fee estimator for orphaned blocks. DefaultEstimateFeeMaxRollback = 2 // DefaultEstimateFeeMinRegisteredBlocks is the default minimum // number of blocks which must be observed by the fee estimator before // it will provide fee estimations. DefaultEstimateFeeMinRegisteredBlocks = 3 )
const ( OrphanTxExpireTime = 20 * 60 OrphanTxExpireInterval = 5 * 60 DefaultMaxOrphanTransaction = 100 )
const (
RollingFeeHalfLife = 12 * 60 * 60
)
const ( // UnminedHeight is the height used for the "block" height field of the // contextual transaction information provided in a transaction store // when it has not yet been mined into a block. UnminedHeight = 0x7fffffff )
Variables ¶
var ( // EstimateFeeDatabaseKey is the key that we use to // store the fee estimator in the database. EstimateFeeDatabaseKey = []byte("estimatefee") )
Functions ¶
func InitMempool ¶
func InitMempool()
Types ¶
type BtcPerKilobyte ¶
type BtcPerKilobyte float64
BtcPerKilobyte is number with units of bitcoins per kilobyte.
type EntryAncestorFeeRateSort ¶
type EntryAncestorFeeRateSort TxEntry
type EntryFeeSort ¶
type EntryFeeSort TxEntry
type FeeEstimator ¶
type FeeEstimator struct {
// contains filtered or unexported fields
}
FeeEstimator manages the data necessary to create fee estimations. It is safe for concurrent access.
func NewFeeEstimator ¶
func NewFeeEstimator(maxRollback, minRegisteredBlocks uint32) *FeeEstimator
NewFeeEstimator creates a FeeEstimator for which at most maxRollback blocks can be unregistered and which returns an error unless minRegisteredBlocks have been registered with it.
func RestoreFeeEstimator ¶
func RestoreFeeEstimator(data FeeEstimatorState) (*FeeEstimator, error)
RestoreFeeEstimator takes a FeeEstimatorState that was previously returned by Save and restores it to a FeeEstimator
func (*FeeEstimator) EstimateFee ¶
func (ef *FeeEstimator) EstimateFee(numBlocks uint32) (BtcPerKilobyte, error)
EstimateFee estimates the fee per byte to have a tx confirmed a given number of blocks from now.
func (*FeeEstimator) LastKnownHeight ¶
func (ef *FeeEstimator) LastKnownHeight() int32
LastKnownHeight returns the height of the last block which was registered.
func (*FeeEstimator) ObserveTransaction ¶
func (ef *FeeEstimator) ObserveTransaction(t *tx.Tx)
ObserveTransaction is called when a new transaction is observed in the mempool.
func (*FeeEstimator) RegisterBlock ¶
func (ef *FeeEstimator) RegisterBlock(block *block.Block) error
RegisterBlock informs the fee estimator of a new block to take into account.
func (*FeeEstimator) Rollback ¶
func (ef *FeeEstimator) Rollback(hash *util.Hash) error
Rollback unregisters a recently registered block from the FeeEstimator. This can be used to reverse the effect of an orphaned block on the fee estimator. The maximum number of rollbacks allowed is given by maxRollbacks.
Note: not everything can be rolled back because some transactions are deleted if they have been observed too long ago. That means the result of Rollback won't always be exactly the same as if the last block had not happened, but it should be close enough.
func (*FeeEstimator) Save ¶
func (ef *FeeEstimator) Save() FeeEstimatorState
Save records the current state of the FeeEstimator to a []byte that can be restored later.
type FeeEstimatorState ¶
type FeeEstimatorState []byte
FeeEstimatorState represents a saved FeeEstimator that can be restored with data from an earlier session of the program.
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 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 SatoshiPerByte ¶
type SatoshiPerByte float64
SatoshiPerByte is number with units of satoshis per byte.
func NewSatoshiPerByte ¶
func NewSatoshiPerByte(fee amount.Amount, size uint32) SatoshiPerByte
NewSatoshiPerByte creates a SatoshiPerByte from an Amount and a size in bytes.
func (SatoshiPerByte) Fee ¶
func (rate SatoshiPerByte) Fee(size uint32) amount.Amount
Fee returns the fee for a transaction of a given size for the given fee rate.
func (SatoshiPerByte) ToBtcPerKb ¶
func (rate SatoshiPerByte) ToBtcPerKb() BtcPerKilobyte
ToBtcPerKb returns a float value that represents the given SatoshiPerByte converted to satoshis per kb.
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 (*TxEntry) CheckLockPointValidity ¶
func (*TxEntry) GetFeeRate ¶
func (*TxEntry) GetInfo ¶
func (t *TxEntry) GetInfo() *TxMempoolInfo
func (*TxEntry) GetLockPointFromTxEntry ¶
func (t *TxEntry) GetLockPointFromTxEntry() LockPoints
func (*TxEntry) GetSigOpCountWithAncestors ¶
func (*TxEntry) GetSpendsCoinbase ¶
func (*TxEntry) GetUsageSize ¶
func (*TxEntry) SetLockPointFromTxEntry ¶
func (t *TxEntry) SetLockPointFromTxEntry(lp LockPoints)
func (*TxEntry) UpdateAncestorState ¶
func (*TxEntry) UpdateChild ¶
func (*TxEntry) UpdateChildOfParents ¶
func (*TxEntry) UpdateDescendantState ¶
func (*TxEntry) UpdateParent ¶
UpdateParent update the tx's parent transaction.
type TxMempool ¶
type TxMempool struct { sync.RWMutex //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 RecentRejects map[util.Hash]struct{} // 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) AddTx ¶
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 ¶
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 (*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 (*TxMempool) EraseOrphanTx ¶
func (*TxMempool) GetAllSpentOutWithoutLock ¶
func (*TxMempool) GetAllTxEntryWithoutLock ¶
func (*TxMempool) GetCheckFrequency ¶
func (*TxMempool) GetMinFeeRate ¶
func (*TxMempool) GetPoolAllTxSize ¶
func (*TxMempool) GetPoolUsage ¶
func (*TxMempool) HasSPentOutWithoutLock ¶
func (*TxMempool) LimitMempoolSize ¶
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) LimitOrphanTx ¶
func (*TxMempool) RemoveOrphansByTag ¶
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 ¶
RemoveTxSelf will only remove these transaction self.
func (*TxMempool) TxInfoAll ¶
func (m *TxMempool) TxInfoAll() []*TxMempoolInfo
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) Unserialize ¶
func (info *TxMempoolInfo) Unserialize(r io.Reader) error