Feat/mempool cleanup + single EventSource#441
Merged
ClemensLey merged 15 commits intostagingfrom Mar 4, 2026
Merged
Conversation
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.
This PR refactors the SSE subscription system and introduces a mempool cleanup triggering mechanism.
- Mempool expiry alignment
Adds stale unconfirmed transaction cleanup logic to align with each network’s mempool expiry policy and improves consistency between the Bitcoin node mempool state and Bitcoin Computer Node database records.
Cleanup runs at a configurable interval: default to 1 hour for BTC and LTC (mainnet/testnet), 15 minutes for PEPE and DOGE, configurable via
.envparameterBCN_MEMPOOL_CLEANUP_INTERVAL_MS.Mempool cleanups are also triggered immediate in reaction to Bitcoin mempool eviction.
A Server-Sent Events (SSE) notifications is triggered on cleanup completion, allowing clients to react and refresh state when stale mempool transactions are removed.
A dedicated cleanup endpoint is also exposed, enabling applications to trigger it manually, it can be enabled or disabled via environment configuration
BCN_MEMPOOL_CLEANUP_ENDPOINT_ENABLED.- Refactors the Server-Sent Events (SSE) subscription system
Use a single EventSource connection for all event types, including mempool cleanups, tx ids, and multiple streamTXO filters. Previously, separate EventSources were created for each subscription, but now a unified manager handles dynamic additions/removals with brief reconnects, server-side filtering, and client-side dispatching.
- New field in db
Output.staleSincewas added to record when the output became stale.- Integration with apps
Mempool cleanup subscriptions and singe EventSource has been added to the Chat app.
- Add filter by
publicKeyfor StreamTXOSNow it is possible to subscribe for notifications by
publicKey. Will this new filter notifications will be triggered if the output script contains that exact publicKey.The
publicKeyoption can also be used to filter for an specific script chunk. A chunk can be an opcode ("OP_1", "OP_RETURN", "OP_CHECKSIG", etc.) or a hexadecimal data push (e.g. a public key "02f7f0..." or OP_RETURN data). To match multiple chunks (e.g. both "OP_1" and a specific public key), subscribe twice with the same callback. Examples were added.