Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: update getrawmempool #29

Merged
merged 1 commit into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions btcjson/chainsvrresults.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ type GetMempoolEntryResult struct {
WTxId string `json:"wtxid"`
Fees MempoolFees `json:"fees"`
Depends []string `json:"depends"`
SpentBy []string `json:"spentby"`
}

// GetChainTipsResult models the data returns from the getchaintips command.
Expand Down
44 changes: 25 additions & 19 deletions mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1507,36 +1507,42 @@ func (mp *TxPool) MiningDescs() []*mining.TxDesc {
// populated btcjson result.
//
// This function is safe for concurrent access.
func (mp *TxPool) RawMempoolVerbose() map[string]*btcjson.GetRawMempoolVerboseResult {
func (mp *TxPool) RawMempoolVerbose() map[string]*btcjson.GetMempoolEntryResult {
mp.mtx.RLock()
defer mp.mtx.RUnlock()

result := make(map[string]*btcjson.GetRawMempoolVerboseResult,
result := make(map[string]*btcjson.GetMempoolEntryResult,
len(mp.pool))
bestHeight := mp.cfg.BestHeight()

for _, desc := range mp.pool {
// Calculate the current priority based on the inputs to
// the transaction. Use zero if one or more of the
// input transactions can't be found for some reason.
tx := desc.Tx
var currentPriority float64
utxos, err := mp.fetchInputUtxos(tx)
if err == nil {
currentPriority = mining.CalcPriority(tx.MsgTx(), utxos,
bestHeight+1)
}

mpd := &btcjson.GetRawMempoolVerboseResult{
Size: int32(tx.MsgTx().SerializeSize()),
Vsize: int32(GetTxVirtualSize(tx)),
Weight: int32(blockchain.GetTransactionWeight(tx)),
Fee: btcutil.Amount(desc.Fee).ToBTC(),
Time: desc.Added.Unix(),
Height: int64(desc.Height),
StartingPriority: desc.StartingPriority,
CurrentPriority: currentPriority,
Depends: make([]string, 0),
mpd := &btcjson.GetMempoolEntryResult{
VSize: int32(GetTxVirtualSize(tx)),
Size: int32(tx.MsgTx().SerializeSize()),
Weight: blockchain.GetTransactionWeight(tx),
Fee: btcutil.Amount(desc.Fee).ToBTC(),
ModifiedFee: btcutil.Amount(desc.Fee).ToBTC(), // TODO, Deprecated
Time: desc.Added.Unix(),
Height: int64(desc.Height),
DescendantCount: 1, // TODO
DescendantSize: GetTxVirtualSize(tx), // TODO
DescendantFees: btcutil.Amount(desc.Fee).ToBTC(), // TODO, Deprecated
AncestorCount: 1, // TODO
AncestorSize: GetTxVirtualSize(tx), // TODO
AncestorFees: btcutil.Amount(desc.Fee).ToBTC(), // TODO, Deprecated
WTxId: desc.Tx.WitnessHash().String(),
Fees: btcjson.MempoolFees{
Base: btcutil.Amount(desc.Fee).ToBTC(),
Modified: btcutil.Amount(desc.Fee).ToBTC(), // TODO
Ancestor: btcutil.Amount(desc.Fee).ToBTC(), // TODO
Descendant: btcutil.Amount(desc.Fee).ToBTC(), // TODO
},
Depends: make([]string, 0), // TODO
SpentBy: make([]string, 0), // TODO
}
for _, txIn := range tx.MsgTx().TxIn {
hash := &txIn.PreviousOutPoint.Hash
Expand Down
53 changes: 51 additions & 2 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ var rpcHandlersBeforeInit = map[string]commandHandler{
"getheaders": handleGetHeaders,
"getinfo": handleGetInfo,
"getmempoolinfo": handleGetMempoolInfo,
"getmempoolentry": handleGetMempoolEntry,
"getmininginfo": handleGetMiningInfo,
"getnettotals": handleGetNetTotals,
"getnetworkhashps": handleGetNetworkHashPS,
Expand Down Expand Up @@ -239,8 +240,6 @@ var rpcAskWallet = map[string]struct{}{
// Commands that are currently unimplemented, but should ultimately be.
var rpcUnimplemented = map[string]struct{}{
"estimatepriority": {},
"getchaintips": {},
"getmempoolentry": {},
"getwork": {},
"preciousblock": {},
}
Expand Down Expand Up @@ -2483,6 +2482,56 @@ func handleGetMempoolInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct
return ret, nil
}

// handleGetMempoolEntry implements the getmempoolentry command.
func handleGetMempoolEntry(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {

c := cmd.(*btcjson.GetMempoolEntryCmd)
txHash, err := chainhash.NewHashFromStr(c.TxID)
if err != nil {
if err != nil {
return nil, rpcDecodeHexError(c.TxID)
}
}

mp := s.cfg.TxMemPool
for _, desc := range mp.TxDescs() {
tx := desc.Tx
if tx.Hash().IsEqual(txHash) {
continue
}
desc.Tx.WitnessHash()

ret := &btcjson.GetMempoolEntryResult{
VSize: int32(mempool.GetTxVirtualSize(tx)),
Size: int32(tx.MsgTx().SerializeSize()),
Weight: blockchain.GetTransactionWeight(tx),
Fee: btcutil.Amount(desc.Fee).ToBTC(),
ModifiedFee: btcutil.Amount(desc.Fee).ToBTC(), // TODO, Deprecated
Time: desc.Added.Unix(),
Height: int64(desc.Height),
DescendantCount: 1, // TODO
DescendantSize: mempool.GetTxVirtualSize(tx), // TODO
DescendantFees: btcutil.Amount(desc.Fee).ToBTC(), // TODO, Deprecated
AncestorCount: 1, // TODO
AncestorSize: mempool.GetTxVirtualSize(tx), // TODO
AncestorFees: btcutil.Amount(desc.Fee).ToBTC(), // TODO, Deprecated
WTxId: desc.Tx.WitnessHash().String(),
Fees: btcjson.MempoolFees{
Base: btcutil.Amount(desc.Fee).ToBTC(),
Modified: btcutil.Amount(desc.Fee).ToBTC(), // TODO
Ancestor: btcutil.Amount(desc.Fee).ToBTC(), // TODO
Descendant: btcutil.Amount(desc.Fee).ToBTC(), // TODO
},
Depends: make([]string, 0), // TODO
SpentBy: make([]string, 0), // TODO
}

return ret, nil
}

return nil, rpcNoTxInfoError(txHash)
}

// handleGetMiningInfo implements the getmininginfo command. We only return the
// fields that are not related to wallet functionality.
func handleGetMiningInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
Expand Down
29 changes: 29 additions & 0 deletions rpcserverhelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,34 @@ var helpDescsEnUS = map[string]string{
"getmininginforesult-pooledtx": "Number of transactions in the memory pool",
"getmininginforesult-testnet": "Whether or not server is using testnet",

"mempoolfees-base": "Transaction fee in LBC",
"mempoolfees-modified": "Transaction fee with fee deltas used for mining priority in LBC",
"mempoolfees-ancestor": "Modified fees (see above) of in-mempool ancestors (including this one) in LBC",
"mempoolfees-descendant": "modified fees (see above) of in-mempool descendants (including this one) in LBC",

// GetMempoolEntryCmd help.
"getmempoolentry--synopsis": "Returns mempool data for given transaction.",
"getmempoolentry-txid": "The hash of the transaction",

// GetMempoolEntryResult help.
"getmempoolentryresult-vsize": "Virtual transaction size as defined in BIP 141. This is different from actual serialized size for witness transactions as witness data is discounted.",
"getmempoolentryresult-size": "(DEPRECATED) same as vsize. ",
"getmempoolentryresult-weight": "Transaction weight as defined in BIP 141.",
"getmempoolentryresult-fee": "(DEPRECATED)Transaction fee in LBC",
"getmempoolentryresult-modifiedfee": "(DEPRECATED)Transaction fee with fee deltas used for mining priority",
"getmempoolentryresult-time": "Local time transaction entered pool in seconds since 1 Jan 1970 GMT",
"getmempoolentryresult-height": "Block height when transaction entered pool",
"getmempoolentryresult-descendantcount": "Number of in-mempool descendant transactions (including this one)",
"getmempoolentryresult-descendantsize": "Virtual transaction size of in-mempool descendants (including this one)",
"getmempoolentryresult-descendantfees": "(DEPRECATED)Modified fees (see above) of in-mempool descendants (including this one)",
"getmempoolentryresult-ancestorcount": "Number of in-mempool ancestor transactions (including this one)",
"getmempoolentryresult-ancestorsize": "Virtual transaction size of in-mempool ancestors (including this one)",
"getmempoolentryresult-ancestorfees": "(DEPRECATED)Modified fees (see above) of in-mempool ancestors (including this one)",
"getmempoolentryresult-wtxid": "hash of serialized transaction, including witness data",
"getmempoolentryresult-fees": "(json object)",
"getmempoolentryresult-depends": "Unconfirmed transactions used as inputs for this transaction",
"getmempoolentryresult-spentby": "Unconfirmed transactions spending outputs from this transaction",

// GetMiningInfoCmd help.
"getmininginfo--synopsis": "Returns a JSON object containing mining-related information.",

Expand Down Expand Up @@ -872,6 +900,7 @@ var rpcResultTypes = map[string][]interface{}{
"gethashespersec": {(*float64)(nil)},
"getheaders": {(*[]string)(nil)},
"getinfo": {(*btcjson.InfoChainResult)(nil)},
"getmempoolentry": {(*btcjson.GetMempoolEntryResult)(nil)},
"getmempoolinfo": {(*btcjson.GetMempoolInfoResult)(nil)},
"getmininginfo": {(*btcjson.GetMiningInfoResult)(nil)},
"getnettotals": {(*btcjson.GetNetTotalsResult)(nil)},
Expand Down