mempool

package
v8.0.0-...-ae3472c Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: ISC Imports: 16 Imported by: 2

Documentation

Index

Constants

View Source
const NumLatestMempoolTxns = 5

NumLatestMempoolTxns is the maximum number of mempool transactions that will be stored in the LatestTransactions field of the MempoolInfo generated by ParseTxns.

Variables

This section is empty.

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func ParseTxns

func ParseTxns(txs []exptypes.MempoolTx, params *chaincfg.Params, lastBlock *BlockID) *exptypes.MempoolInfo

ParseTxns analyzes the mempool transactions in the txs slice, and generates a MempoolInfo summary with categorized transactions.

func UseLogger

func UseLogger(logger slog.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type BlockID

type BlockID struct {
	Hash   chainhash.Hash
	Height int64
	Time   int64
}

BlockID provides basic identifying information about a block.

type ByAbsoluteFee

type ByAbsoluteFee struct {
	TicketsDetails
}

ByAbsoluteFee models TicketDetails sorted by fee

func (ByAbsoluteFee) Less

func (tix ByAbsoluteFee) Less(i, j int) bool

Less compares fee rates by fee_i < fee_j

type ByFeeRate

type ByFeeRate struct {
	TicketsDetails
}

ByFeeRate models TicketsDetails sorted by fee rates

func (ByFeeRate) Less

func (tix ByFeeRate) Less(i, j int) bool

Less compares fee rates by rate_i < rate_j

type DataCache

type DataCache struct {
	// contains filtered or unexported fields
}

DataCache models the basic data for the mempool cache.

func (*DataCache) GetFeeInfo

func (c *DataCache) GetFeeInfo() (uint32, chainjson.FeeInfoMempool)

GetFeeInfo returns the mempool height and basic fee info

func (*DataCache) GetFeeInfoExtra

func (c *DataCache) GetFeeInfoExtra() (uint32, *apitypes.MempoolTicketFeeInfo)

GetFeeInfoExtra returns the mempool height and detailed fee info

func (*DataCache) GetFeeRates

func (c *DataCache) GetFeeRates(N int) (uint32, int64, int, []float64)

GetFeeRates returns the mempool height, time, number of fees and an array of fee rates

func (*DataCache) GetFees

func (c *DataCache) GetFees(N int) (uint32, int, []float64)

GetFees returns the mempool height number of fees and an array of the fields

func (*DataCache) GetHeight

func (c *DataCache) GetHeight() uint32

GetHeight returns the mempool height

func (*DataCache) GetNumTickets

func (c *DataCache) GetNumTickets() (uint32, uint32)

GetNumTickets returns the mempool height and number of tickets

func (*DataCache) GetTicketPriceCountTime

func (c *DataCache) GetTicketPriceCountTime(feeAvgLength int) *apitypes.PriceCountTime

GetTicketPriceCountTime gathers the nominal info for mempool tickets.

func (*DataCache) GetTicketsDetails

func (c *DataCache) GetTicketsDetails(N int) (uint32, int64, int, TicketsDetails)

GetTicketsDetails returns the mempool height, time, number of tickets and the ticket details

func (*DataCache) SBits

func (c *DataCache) SBits() (int64, uint32)

SBits returns the current stake difficulty, and the current best block height.

func (*DataCache) StoreMPData

func (c *DataCache) StoreMPData(stakeData *StakeData, txsCopy []exptypes.MempoolTx, _ *exptypes.MempoolInfo)

StoreMPData stores info from data in the mempool cache. It is advisable to pass a copy of the []types.MempoolTx so that it may be modified (e.g. sorted) without affecting other MempoolDataSavers.

type DataCollector

type DataCollector struct {
	// contains filtered or unexported fields
}

DataCollector is used for retrieving and processing data from a chain server's mempool.

func NewDataCollector

func NewDataCollector(dcrdChainSvr NodeClient, params *chaincfg.Params) *DataCollector

NewDataCollector creates a new DataCollector. Use a rpcutils.AsyncTxClient to create a NodeClient from an rpcclient.Client or implement a wrapper that provides txhelpers.VerboseTransactionPromiseGetter.

func (*DataCollector) Collect

Collect is the main handler for collecting mempool data. Data collection is focused on stake-related information, including vote and ticket transactions, and fee info. Transactions of all types in mempool are returned as a []exptypes.MempoolTx, corresponding to the same data provided by the unexported mempoolTxns method.

type MempoolAddressStore

type MempoolAddressStore struct {
	// contains filtered or unexported fields
}

MempoolAddressStore wraps txhelpers.MempoolAddressStore with a Mutex.

type MempoolDataSaver

type MempoolDataSaver interface {
	StoreMPData(*StakeData, []exptypes.MempoolTx, *exptypes.MempoolInfo)
}

MempoolDataSaver is an interface for storing mempool data.

type MempoolInfo

type MempoolInfo struct {
	CurrentHeight               uint32
	NumTicketPurchasesInMempool uint32
	NumTicketsSinceStatsReport  int32
	LastCollectTime             time.Time
}

MempoolInfo models basic data about the node's mempool

type MempoolMonitor

type MempoolMonitor struct {
	// contains filtered or unexported fields
}

MempoolMonitor processes new transactions as they are added to mempool, and forwards the processed data on channels assigned during construction. An inventory of transactions in the current mempool is maintained to prevent repetitive data processing and signaling. Periodically, such as after a new block is mined, the mempool info and the transaction inventory are rebuilt fresh via the CollectAndStore method. A DataCollector is required to perform the collection and parsing, and an optional []MempoolDataSaver is used to to forward the data to arbitrary destinations. The last block's height, hash, and time are kept in memory in order to properly process votes in mempool.

func NewMempoolMonitor

func NewMempoolMonitor(ctx context.Context, collector *DataCollector,
	savers []MempoolDataSaver, params *chaincfg.Params,
	signalOuts []chan<- pstypes.HubMessage, initialStore bool) (*MempoolMonitor, error)

NewMempoolMonitor creates a new MempoolMonitor. The MempoolMonitor receives notifications of new transactions on newTxInChan, and of new blocks on the same channel using a nil transaction message. Once TxHandler is started, the MempoolMonitor will process incoming transactions, and forward new ones on via the newTxOutChan following an appropriate signal on hubRelay.

func (*MempoolMonitor) BlockHandler

func (p *MempoolMonitor) BlockHandler(height uint32, _ string) error

BlockHandler satisfies notification.BlockHandler. Triggers a websocket update.

func (*MempoolMonitor) CollectAndStore

func (p *MempoolMonitor) CollectAndStore() error

CollectAndStore collects mempool data, resets counters ticket counters and the timer, and dispatches the storers.

func (*MempoolMonitor) LastBlockHash

func (p *MempoolMonitor) LastBlockHash() chainhash.Hash

LastBlockHash returns the hash of the most recently stored block.

func (*MempoolMonitor) LastBlockHeight

func (p *MempoolMonitor) LastBlockHeight() int64

LastBlockHeight returns the height of the most recently stored block.

func (*MempoolMonitor) LastBlockTime

func (p *MempoolMonitor) LastBlockTime() int64

LastBlockTime returns the time of the most recently stored block.

func (*MempoolMonitor) Refresh

Refresh collects mempool data, resets counters ticket counters and the timer, but does not dispatch the MempoolDataSavers.

func (*MempoolMonitor) TxHandler

func (p *MempoolMonitor) TxHandler(rawTx *chainjson.TxRawResult) error

TxHandler receives signals from OnTxAccepted via the newTxIn, indicating that a new transaction has entered mempool. This function should be launched as a goroutine, and stopped by closing the quit channel, the broadcasting mechanism used by main. The newTxIn contains a chain hash for the transaction from the notification, or a zero value hash indicating it was from a Ticker or manually triggered.

func (*MempoolMonitor) UnconfirmedTxnsForAddress

func (p *MempoolMonitor) UnconfirmedTxnsForAddress(address string) (*txhelpers.AddressOutpoints, int64, error)

UnconfirmedTxnsForAddress indexes (1) outpoints in mempool that pay to the given address, (2) previous outpoint being consumed that paid to the address, and (3) all relevant transactions. See txhelpers.AddressOutpoints for more information. The number of unconfirmed transactions is also returned. This satisfies the rpcutils.MempoolAddressChecker interface for MempoolMonitor.

type MinableFeeInfo

type MinableFeeInfo struct {
	// contains filtered or unexported fields
}

MinableFeeInfo describes the ticket fees

type NewTx

type NewTx struct {
	Hash *chainhash.Hash
	T    time.Time
}

NewTx models data for a new transaction.

type NodeClient

NodeClient is similar to a rpcclient.Client, except for the addition of GetRawTransactionVerbosePromise. Use rpcutils.NewAsyncTxClient to create one from an rpcclient.Client or just implement a wrapper that provides txhelpers.VerboseTransactionPromiseGetter.

type ScriptPubKeyResult

type ScriptPubKeyResult struct {
	Asm       string   `json:"asm"`
	Hex       string   `json:"hex,omitempty"`
	ReqSigs   int32    `json:"reqSigs,omitempty"`
	Type      string   `json:"type"`
	Addresses []string `json:"addresses,omitempty"`
	CommitAmt *float64 `json:"commitamt,omitempty"`
}

type ScriptSig

type ScriptSig struct {
	Asm string `json:"asm"`
	Hex string `json:"hex"`
}

type StakeData

type StakeData struct {
	LatestBlock       BlockID
	Time              time.Time
	NumTickets        uint32
	NumVotes          uint32
	NewTickets        uint32
	Ticketfees        *chainjson.TicketFeeInfoResult
	MinableFees       *MinableFeeInfo
	AllTicketsDetails TicketsDetails
	StakeDiff         float64
}

StakeData models info about ticket purchases in mempool

func (*StakeData) Hash

func (m *StakeData) Hash() string

Hash returns the best block hash at the time the mempool data was gathered.

func (*StakeData) Height

func (m *StakeData) Height() uint32

Height returns the best block height at the time the mempool data was gathered.

type TicketsDetails

type TicketsDetails apitypes.TicketsDetails

TicketsDetails localizes apitypes.TicketsDetails

func (TicketsDetails) Len

func (tix TicketsDetails) Len() int

Len returns the length of TicketsDetails

func (TicketsDetails) Swap

func (tix TicketsDetails) Swap(i, j int)

Swap swaps TicketsDetails elements at i and j

type Tx

type Tx struct {
	Hex      string `json:"hex"`
	Txid     string `json:"txid"`
	Version  int32  `json:"version"`
	LockTime uint32 `json:"locktime"`
	Expiry   uint32 `json:"expiry"`
	Vin      []Vin  `json:"vin"`
	Vout     []Vout `json:"vout"`
}

type Vin

type Vin struct {
	Coinbase    string     `json:"coinbase"`
	Stakebase   string     `json:"stakebase"`
	Txid        string     `json:"txid"`
	Vout        uint32     `json:"vout"`
	Tree        int8       `json:"tree"`
	Sequence    uint32     `json:"sequence"`
	AmountIn    float64    `json:"amountin"`
	BlockHeight uint32     `json:"blockheight"`
	BlockIndex  uint32     `json:"blockindex"`
	ScriptSig   *ScriptSig `json:"scriptSig"`
}

type Vout

type Vout struct {
	Value        float64            `json:"value"`
	N            uint32             `json:"n"`
	Version      uint16             `json:"version"`
	ScriptPubKey ScriptPubKeyResult `json:"scriptPubKey"`
}

Vout models parts of the tx data. It is defined separately since both getrawtransaction and decoderawtransaction use the same structure.

Jump to

Keyboard shortcuts

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