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

chain: optimize mempool memory usage for RPC clients #896

Merged
merged 2 commits into from
Nov 29, 2023

Conversation

yyforyongyu
Copy link
Collaborator

This PR makes the RPC client to use gettxspendingprevout to look up mempool spend for a given output, such that the internal inputs can be removed, which can save us quite some memory usage.

If we can use `gettxspendingprevout` to check the mempool spend of an
input, there's no need to maintain the large `inputs` map anymore.
This commit creates a new method `getTxSpendingPrevOut` that's used by
both ZMQ and RPC clients to lookup mempool spend for a given input.
@saubyk
Copy link

saubyk commented Nov 28, 2023

cc: @guggero @bhandras

@guggero guggero self-requested a review November 28, 2023 17:57
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 🐠

@@ -236,6 +247,11 @@ func (m *mempool) containsTx(hash chainhash.Hash) bool {
//
// NOTE: must be used inside a lock.
func (m *mempool) containsInput(op wire.OutPoint) (chainhash.Hash, bool) {
// TODO(yy): port `getprevout` to bitcoind and use it here?
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this occur on a higher level rn? Or you mean pulling down that check into the mempool logic itself?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

so mempool already has an rpc client in m.cfg.client, which can be used to call the rpc method. If we use it here, then both zmq and rpc clients can use this containsInput to do the lookup without checking hasPrevRPC flag.

@Roasbeef Roasbeef merged commit 5df09dd into btcsuite:master Nov 29, 2023
3 checks passed
@yyforyongyu yyforyongyu deleted the optimize-mempool branch November 30, 2023 09:09
buck54321 pushed a commit to buck54321/btcwallet that referenced this pull request Apr 21, 2024
chain: optimize mempool memory usage for RPC clients
buck54321 pushed a commit to buck54321/btcwallet that referenced this pull request Apr 21, 2024
chain: optimize mempool memory usage for RPC clients
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants