Documentation ¶
Index ¶
- Constants
- func ErrToRejectErr(err error) (protos.RejectCode, string)
- type Config
- type Policy
- type RuleError
- type SigPool
- func (mp *SigPool) ConnectSigns(sigs []*asiutil.BlockSign, height int32)
- func (mp *SigPool) DisConnectSigns(sigs []*asiutil.BlockSign, height int32)
- func (mp *SigPool) FetchSignature(sigHash *common.Hash) (*asiutil.BlockSign, int32, error)
- func (mp *SigPool) HaveSignature(hash *common.Hash) bool
- func (mp *SigPool) MiningDescs(height int32) []*asiutil.BlockSign
- func (mp *SigPool) ProcessSig(sig *asiutil.BlockSign) error
- type SignatureDesc
- type Tag
- type TxPool
- func (mp *TxPool) Count() int
- func (mp *TxPool) FetchAnyTransaction(txHash *common.Hash) (*asiutil.Tx, error)
- func (mp *TxPool) FetchTransaction(txHash *common.Hash) (*asiutil.Tx, bool, error)
- func (mp *TxPool) Halt()
- func (mp *TxPool) HasSpentInTxPool(PreviousOutPoints *[]protos.OutPoint) []protos.OutPoint
- func (mp *TxPool) HaveTransaction(hash *common.Hash) bool
- func (mp *TxPool) IsOrphanInPool(hash *common.Hash) bool
- func (mp *TxPool) IsTransactionInPool(hash *common.Hash) bool
- func (mp *TxPool) MaybeAcceptTransaction(tx *asiutil.Tx, isNew bool) ([]*common.Hash, *mining.TxDesc, error)
- func (mp *TxPool) ProcessOrphans(acceptedTx *asiutil.Tx) []*mining.TxDesc
- func (mp *TxPool) ProcessTransaction(tx *asiutil.Tx, allowOrphan, rateLimit bool, tag Tag) ([]*mining.TxDesc, error)
- func (mp *TxPool) RawMempoolVerbose() map[string]*rpcjson.GetRawMempoolVerboseResult
- func (mp *TxPool) RemoveDoubleSpends(tx *asiutil.Tx)
- func (mp *TxPool) RemoveOrphan(tx *asiutil.Tx)
- func (mp *TxPool) RemoveOrphansByTag(tag Tag) uint64
- func (mp *TxPool) RemoveTransaction(tx *asiutil.Tx, removeRedeemers bool)
- func (mp *TxPool) Start()
- func (mp *TxPool) TxDescs() mining.TxDescList
- func (mp *TxPool) TxHashes() []*common.Hash
- func (mp *TxPool) UpdateForbiddenTxs(txHashes []*common.Hash, height int64)
- type TxRuleError
Constants ¶
const ( // MaxReplacementEvictions is the maximum number of transactions that // can be evicted from the mempool when accepting a transaction // replacement. MaxReplacementEvictions = 100 )
Variables ¶
This section is empty.
Functions ¶
func ErrToRejectErr ¶
func ErrToRejectErr(err error) (protos.RejectCode, string)
ErrToRejectErr examines the underlying type of the error and returns a reject code and string appropriate to be sent in a protos.MsgReject message.
Types ¶
type Config ¶
type Config struct { // Policy defines the various mempool configuration options related // to policy. Policy Policy // FetchUtxoView defines the function to use to fetch unspent // transaction output information. FetchUtxoView func(*asiutil.Tx, bool) (*txo.UtxoViewpoint, error) // BestHeight defines the function to use to access the block height of // the current best chain. BestHeight func() int32 // MedianTimePast defines the function to use in order to access the // median time past calculated from the point-of-view of the current // chain tip within the best chain. MedianTimePast func() int64 // CalcSequenceLock defines the function to use in order to generate // the current sequence lock for the given transaction using the passed // utxo view. CalcSequenceLock func(*asiutil.Tx, *txo.UtxoViewpoint) (*blockchain.SequenceLock, error) // AddrIndex defines the optional address index instance to use for // indexing the unconfirmed transactions in the memory pool. // This can be nil if the address index is not enabled. AddrIndex *indexers.AddrIndex Chain *blockchain.BlockChain FeesChan chan interface{} CheckTransactionInputs func(tx *asiutil.Tx, txHeight int32, utxoView *txo.UtxoViewpoint, b *blockchain.BlockChain) (int64, *map[protos.Asset]int64, error) }
Config is a descriptor containing the memory pool configuration.
type Policy ¶
type Policy struct { // MaxTxVersion is the transaction version that the mempool should // accept. All transactions above this version are rejected as // non-standard. MaxTxVersion uint32 // MaxOrphanTxs is the maximum number of orphan transactions // that can be queued. MaxOrphanTxs int // MaxOrphanTxSize is the maximum size allowed for orphan transactions. // This helps prevent memory exhaustion attacks from sending a lot of // of big orphans. MaxOrphanTxSize int // MinTxPrice defines the minimum transaction price to be // considered a non-zero fee. MinRelayTxPrice float64 // RejectReplacement, if true, rejects accepting replacement // transactions using the Replace-By-Price (RBP) signaling policy into // the mempool. RejectReplacement bool }
Policy houses the policy (configuration parameters) which is used to control the mempool.
type RuleError ¶
type RuleError struct {
Err error
}
RuleError identifies a rule violation. It is used to indicate that processing of a transaction failed due to one of the many validation rules. The caller can use type assertions to determine if a failure was specifically due to a rule violation and use the Err field to access the underlying error, which will be either a TxRuleError or a blockchain.RuleError.
type SigPool ¶
type SigPool struct {
// contains filtered or unexported fields
}
func NewSigPool ¶
func NewSigPool() *SigPool
func (*SigPool) ConnectSigns ¶
ConnectSigns mark the passed block signature with packageHeight in the mempool.
This function is safe for concurrent access.
func (*SigPool) DisConnectSigns ¶
DisConnectSigns clear signatures' packageHeight which equals passed height from the mempool.
This function is safe for concurrent access.
func (*SigPool) FetchSignature ¶
FetchSignature return the block signature via signature hash from the mempool.
This function is safe for concurrent access.
func (*SigPool) HaveSignature ¶
HaveSignature return whether the blocksign in the mempool.
This function is safe for concurrent access.
func (*SigPool) MiningDescs ¶
MiningDescs return a block signature list used for mining.
This function is safe for concurrent access.
type SignatureDesc ¶
type SignatureDesc struct {
// contains filtered or unexported fields
}
//////////////////////////////////////// //////////// block signature pool ////////////////////////////////////////
type Tag ¶
type Tag uint64
Tag represents an identifier to use for tagging orphan transactions. The caller may choose any scheme it desires, however it is common to use peer IDs so that orphans can be identified by which peer first relayed them.
type TxPool ¶
type TxPool struct {
// contains filtered or unexported fields
}
TxPool is used as a source of transactions that need to be mined into blocks and relayed to other peers. It is safe for concurrent access from multiple peers.
func New ¶
New returns a new memory pool for validating and storing standalone transactions until they are mined into a block.
func (*TxPool) Count ¶
Count returns the number of transactions in the main pool. It does not include the orphan pool.
This function is safe for concurrent access.
func (*TxPool) FetchAnyTransaction ¶
FetchAnyTransaction returns the requested transaction from the transaction pool. This fetches from the main transaction pool and orphans.
This function is safe for concurrent access.
func (*TxPool) FetchTransaction ¶
FetchTransaction returns the requested transaction from the transaction pool. This only fetches from the main transaction pool and does not include orphans.
This function is safe for concurrent access.
func (*TxPool) HasSpentInTxPool ¶
func (*TxPool) HaveTransaction ¶
HaveTransaction returns whether or not the passed transaction already exists in the main pool or in the orphan pool.
This function is safe for concurrent access.
func (*TxPool) IsOrphanInPool ¶
IsOrphanInPool returns whether or not the passed transaction already exists in the orphan pool.
This function is safe for concurrent access.
func (*TxPool) IsTransactionInPool ¶
IsTransactionInPool returns whether or not the passed transaction already exists in the main pool.
This function is safe for concurrent access.
func (*TxPool) MaybeAcceptTransaction ¶
func (mp *TxPool) MaybeAcceptTransaction(tx *asiutil.Tx, isNew bool) ([]*common.Hash, *mining.TxDesc, error)
MaybeAcceptTransaction is the main workhorse for handling insertion of new free-standing transactions into a memory pool. It includes functionality such as rejecting duplicate transactions, ensuring transactions follow all rules, detecting orphan transactions, and insertion into the memory pool.
If the transaction is an orphan (missing parent transactions), the transaction is NOT added to the orphan pool, but each unknown referenced parent is returned. Use ProcessTransaction instead if new orphans should be added to the orphan pool.
This function is safe for concurrent access.
func (*TxPool) ProcessOrphans ¶
ProcessOrphans determines if there are any orphans which depend on the passed transaction hash (it is possible that they are no longer orphans) and potentially accepts them to the memory pool. It repeats the process for the newly accepted transactions (to detect further orphans which may no longer be orphans) until there are no more.
It returns a slice of transactions added to the mempool. A nil slice means no transactions were moved from the orphan pool to the mempool.
This function is safe for concurrent access.
func (*TxPool) ProcessTransaction ¶
func (mp *TxPool) ProcessTransaction(tx *asiutil.Tx, allowOrphan, rateLimit bool, tag Tag) ([]*mining.TxDesc, error)
ProcessTransaction is the main workhorse for handling insertion of new free-standing transactions into the memory pool. It includes functionality such as rejecting duplicate transactions, ensuring transactions follow all rules, orphan transaction handling, and insertion into the memory pool.
It returns a slice of transactions added to the mempool. When the error is nil, the list will include the passed transaction itself along with any additional orphan transaactions that were added as a result of the passed one being accepted.
This function is safe for concurrent access.
func (*TxPool) RawMempoolVerbose ¶
func (mp *TxPool) RawMempoolVerbose() map[string]*rpcjson.GetRawMempoolVerboseResult
RawMempoolVerbose returns all of the entries in the mempool as a fully populated rpcjson result.
This function is safe for concurrent access.
func (*TxPool) RemoveDoubleSpends ¶
RemoveDoubleSpends removes all transactions which spend outputs spent by the passed transaction from the memory pool. Removing those transactions then leads to removing all transactions which rely on them, recursively. This is necessary when a block is connected to the main chain because the block may contain transactions which were previously unknown to the memory pool.
This function is safe for concurrent access.
func (*TxPool) RemoveOrphan ¶
RemoveOrphan removes the passed orphan transaction from the orphan pool and previous orphan index.
This function is safe for concurrent access.
func (*TxPool) RemoveOrphansByTag ¶
RemoveOrphansByTag removes all orphan transactions tagged with the provided identifier.
This function is safe for concurrent access.
func (*TxPool) RemoveTransaction ¶
RemoveTransaction removes the passed transaction from the mempool. When the removeRedeemers flag is set, any transactions that redeem outputs from the removed transaction will also be removed recursively from the mempool, as they would otherwise become orphans.
This function is safe for concurrent access.
func (*TxPool) TxDescs ¶
func (mp *TxPool) TxDescs() mining.TxDescList
TxDescs returns a slice of descriptors for all the transactions in the pool. The descriptors are to be treated as read only.
This function is safe for concurrent access.
type TxRuleError ¶
type TxRuleError struct { RejectCode protos.RejectCode // The code to send with reject messages Description string // Human readable description of the issue }
TxRuleError identifies a rule violation. It is used to indicate that processing of a transaction failed due to one of the many validation rules. The caller can use type assertions to determine if a failure was specifically due to a rule violation and access the ErrorCode field to ascertain the specific reason for the rule violation.
func (TxRuleError) Error ¶
func (e TxRuleError) Error() string
Error satisfies the error interface and prints human-readable errors.