Repository navigation
Stop caching every mempool tx for bitcoind - #1216
Open
benthecarman wants to merge 1 commit into
Open
benthecarman wants to merge 1 commit into
benthecarman wants to merge 1 commit into
Conversation
With a bitcoind chain source, every mempool transaction was fetched into `mempool_txs_cache` and kept there until it left the mempool, so the node held a decoded copy of every transaction in bitcoind's mempool, which can reach hundreds of MB when the mempool is full. Only the onchain wallet consumes these transactions, and it keeps just the relevant ones. The cache only needs the transactions we have to emit again, i.e., those that entered the mempool above our best processed height. Restrict it to those. As a result, if a poll fails partway through, the retry fetches the transactions it already fetched again, rather than taking them from the cache. This only lowers steady-state memory use. `mempool_entries_cache` still holds one small entry per mempool transaction, and the first poll after startup still collects the whole mempool before handing it to the wallet. Also stop pre-sizing the transaction cache and the emit buffer to the whole mempool on every poll. This change was made with the help of Claude Code.
|
👋 Thanks for assigning @tnull as a reviewer! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ldk-server was taking a lot of memory on my server. Doing this reduced memory by 100MB for me
With a bitcoind chain source, every mempool transaction was fetched into
mempool_txs_cacheand kept there until it left the mempool, so the node held a full decoded copy of bitcoind's mempool (roughly 0.9 KB per transaction, i.e. hundreds of MB when the mempool is full). Only the onchain wallet consumes these transactions, and it keeps just the relevant ones.The cache only serves transactions we may have to emit again, i.e. those that entered the mempool above our best processed height. Restrict it to those. Also stop shrinking the entries map and pre-sizing the emit buffer to the full mempool on every two-second poll, which churned multi-megabyte allocations and fragmented the heap.