Skip to content

Feat/mempool cleanup + single EventSource#441

Merged
ClemensLey merged 15 commits intostagingfrom
feat/mempoolCleanup
Mar 4, 2026
Merged

Feat/mempool cleanup + single EventSource#441
ClemensLey merged 15 commits intostagingfrom
feat/mempoolCleanup

Conversation

@ltardivo
Copy link
Collaborator

@ltardivo ltardivo commented Jan 19, 2026

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 .env parameter BCN_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.staleSince was 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 publicKey for StreamTXOS

Now 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 publicKey option 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.

@ltardivo ltardivo changed the base branch from staging to main January 20, 2026 21:00
@ltardivo ltardivo changed the base branch from main to staging January 20, 2026 21:01
@ltardivo ltardivo changed the title Feat/mempool cleanup Feat/mempool cleanup + single EventSource Feb 2, 2026
Copy link
Contributor

@ClemensLey ClemensLey left a comment

Choose a reason for hiding this comment

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

Looks good to me

Copy link
Contributor

@ClemensLey ClemensLey left a comment

Choose a reason for hiding this comment

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

Looks good to me

@ClemensLey ClemensLey merged commit 0efd660 into staging Mar 4, 2026
@ClemensLey ClemensLey deleted the feat/mempoolCleanup branch March 4, 2026 23:20
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.

2 participants