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

Fix GetMempoolTx bug returning no entries #404

Merged
merged 1 commit into from
Jul 21, 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
4 changes: 0 additions & 4 deletions common/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func GetMempool(sendToClient func(*walletrpc.RawTransaction) error) error {
if g_lastBlockChainInfo.BestBlockHash != blockChainInfo.BestBlockHash {
// A new block has arrived
g_lastBlockChainInfo = blockChainInfo
Log.Infoln("Latest Block changed, clearing everything")
// We're the first thread to notice, clear cached state.
g_txidSeen = map[txid]struct{}{}
g_txList = []*walletrpc.RawTransaction{}
Expand Down Expand Up @@ -89,8 +88,6 @@ func GetMempool(sendToClient func(*walletrpc.RawTransaction) error) error {

// RefreshMempoolTxns gets all new mempool txns and sends any new ones to waiting clients
func refreshMempoolTxns() error {
Log.Infoln("Refreshing mempool")

params := []json.RawMessage{}
result, rpcErr := RawRequest("getrawmempool", params)
if rpcErr != nil {
Expand Down Expand Up @@ -132,7 +129,6 @@ func refreshMempoolTxns() error {
if err != nil {
return err
}
Log.Infoln("appending", txidstr)
newRtx := &walletrpc.RawTransaction{
Data: txBytes,
Height: uint64(g_lastBlockChainInfo.Blocks),
Expand Down
5 changes: 5 additions & 0 deletions frontend/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@ func (s *lwdStreamer) GetMempoolTx(exclude *walletrpc.Exclude, resp walletrpc.Co
}
newmempoolMap[txidstr] = &walletrpc.CompactTx{}
if tx.HasShieldedElements() {
txidBytes, err := hex.DecodeString(txidstr)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a future PR, we could make newmempoolMap more space-efficient by changing its key type to slice of bytes, rather than string. Then we wouldn't have to decode back to bytes here (but we would have to encode to string elsewhere). It's not too bad as it currently is, however, because the mempool typically doesn't have many entries.

if err != nil {
return err
}
tx.SetTxID(txidBytes)
newmempoolMap[txidstr] = tx.ToCompact( /* height */ 0)
}
}
Expand Down