Skip to content

electrum: notify scripthash-only subscribers of new blocks (for #237) - #272

Open
shanurwan wants to merge 1 commit into
Blockstream:delta-driven-subscription-updatesfrom
shanurwan:fix/237-scripthash-only-block-ticks
Open

shanurwan wants to merge 1 commit into
Blockstream:delta-driven-subscription-updatesfrom
shanurwan:fix/237-scripthash-only-block-ticks

Conversation

@shanurwan

Copy link
Copy Markdown

Follow-up to my comment on #237, as offered: the three tests and the fix, against this branch.

Bug: tip_changed is only set through last_header_entry, which is None unless the client called blockchain.headers.subscribe. A client that subscribes only to scripthashes never sees tip_changed, so on a block-only tick (the spend was never in our mempool) the touched-scripthash fast path skips its subscription and the notification is lost.

Fix: each connection remembers the chain tip from its last periodic tick (last_tick_tip), whether or not it subscribed to headers. A new tip forces the full scan, as before.

Tests (raw TCP in tests/electrum.rs):

  • test_electrum_subscription_notified_on_mempool_tx: passes before and after.
  • test_electrum_subscription_notified_on_block_without_mempool_tx: passes on new-index, fails on this branch, passes with the fix.
  • test_electrum_subscription_notified_on_block_with_headers_subscription: passes before and after.

Happy to change the approach if you'd rather fold this into tip_changed differently.

tip_changed was only set through last_header_entry, which stays None unless
the client subscribed to headers. A scripthash-only client never saw a new
tip, so on a block-only tick the touched-scripthash fast path skipped its
subscription and the notification was lost.

Track the tip from each connection's last periodic tick and force the full
scan when it changes. Add raw-TCP tests for a mempool tx, a block without a
mempool tx, and a block with a headers subscription.
@shanurwan

Copy link
Copy Markdown
Author

@DeviaVir, this still applies cleanly on delta-driven-subscription-updates. If it's easier, I can fold the last_tick_tip fix into #237 directly, or split out just the three tests so you can take them separately. Happy to adjust either way.

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.

1 participant