Skip to content

fix: report each catch-up block's own height to onBlock - #7

Open
gophersg wants to merge 1 commit into
BitVM:mainfrom
gophersg:main
Open

gophersg wants to merge 1 commit into
BitVM:mainfrom
gophersg:main

Conversation

@gophersg

@gophersg gophersg commented Oct 2, 2026

Copy link
Copy Markdown

Summary

startListening() replays every block between the last processed height and the
current chain tip. It called onBlock({ txids, height: latestHeight }), passing the
current chain tip as block.height for every replayed block. When catching up
multiple blocks (e.g. tip = 103, starting at 100), blocks 101, 102 and 103 were all
reported with height: 103.

Impact

BitVMClient.listen() derives utxoAge = block.height - utxo.blockHeight and stores
block.height as the UTXO's blockHeight. With the wrong height, UTXO ages and the
spendability/timelock window of graph transactions were computed against the tip instead
of the block the transaction actually confirmed in, producing incorrect utxoAge.

Fix

Capture currentHeight = prevHeight + 1 for the block being fetched and pass that to
onBlock. Extracted the catch-up loop into bitvm/listen.js (Node-safe, since
client.js pulls in browser globals via tapscript) so it can be unit-tested without
a browser.

Test

Added test/client-catchup-test.js: a Node regression test that mocks Esplora and
asserts a 3-block catch-up (100 -> 103) reports heights [101, 102, 103].

Run with: node test/client-catchup-test.js

Signed-off-by: gophersg <gopher@2980.com>
@gophersg

gophersg commented Oct 8, 2026

Copy link
Copy Markdown
Author

@RobinLinus Would you mind taking a quick look at this fix?

startListening() currently reports latestHeight for every block replayed during catch-up. For example, catching up 101–103 reports all three as height 103, which then makes BitVMClient.listen() compute incorrect utxoAge values.

This PR passes each replayed block's actual height instead and adds a small regression test covering a 3-block catch-up.

Thanks!

This branch has not been deployed

No deployments
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