Skip to content

fix(cbf): clean scan state and allow zero-fee blocks#24

Closed
febyeji wants to merge 23 commits into
add-cbf-chain-sourcefrom
cbf-timeout-zero-fee-cleanup
Closed

fix(cbf): clean scan state and allow zero-fee blocks#24
febyeji wants to merge 23 commits into
add-cbf-chain-sourcefrom
cbf-timeout-zero-fee-cleanup

Conversation

@febyeji

@febyeji febyeji commented May 29, 2026

Copy link
Copy Markdown
Owner
  • Clean CBF filter scan state when sync futures are dropped on timeout.
  • Treat zero-fee sampled blocks with the minimum fee-rate floor.
  • Add unit coverage for zero-fee, zero-weight, and normal block fee-rate calculations.

febyeji and others added 23 commits May 22, 2026 12:06
Fixes the problem when the funding tx is not registered for CBF node, for
example during splicing.

Added macros to skip incompatible with CBF backend tests (which require
mempool).
Decrease timeouts to not falsely conclude some tests as passing
Previously we tracked synced height and also had dirty flag for rescan
which was made from the genesis block. This was removed in favor of
block heights from channel manager and onchain wallet.

Safety reorg interval of 7 blocks (look-back) is added.

Force tests use CBF config with 1 required peers, as otherwise it would
die if one of two required peers went offline (which made impossible
testing of scenarios with 2 nodes on which goes offline).
  add auto-restart with exponential backoff (#10)

* refactor(cbf): extract build_cbf_node helper and add wallet reference
* feat(cbf): auto-restart bip157 node with exponential backoff
* feat(cbf): add liveness check before returning requester
* fix(cbf): clean up scan state on filter scan failure
* fix(cbf): add per-block-fetch timeout to wallet sync
The old wait_for_cbf_sync only checked that the onchain sync timestamp
advanced, which could false-pass when the timestamp updated but wallet
state was still stale. The new version verifies both onchain and
lightning wallet syncs completed, and accepts a check closure so callers
can assert concrete wallet state (e.g. balance, payment existence).

Also simplifies CbfSyncConfig in test setup to use Default (which
already sets required_peers: 1 and reasonable timeouts).
`push` only appends above the tip, so when `recent_history` contained
blocks at or below the wallet's current checkpoint height after a reorg,
the stale hashes on the wallet checkpoint were never replaced. Switch to
`CheckPoint::insert`, which detects conflicting hashes and purges stale
blocks, matching bdk-kyoto's `UpdateBuilder::apply_chain_event`.

Also clear `latest_tip` on `BlockHeaderChanges::Reorganized` so cached
tip state does not point at an abandoned chain.

Update the `checkpoint_building_handles_reorg` unit test (added in
c1844b3) to exercise the fixed behaviour: a reorg where the new tip
is at the same height as the wallet's checkpoint must still result
in the reorged hashes winning.

Disclosure: drafted with assistance from Claude Code.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…_cbf

After a checkpoint-based resume, `requester.chain_tip()` can return the
checkpoint hash which has no `BlockNode` in kyoto's tree yet, causing
`get_block` to fail with `FetchBlockError::UnknownHash` and surfacing as
`FeerateEstimationUpdateFailed` from `node.start()`. Skip the cycle and
retry later instead of erroring.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…istered

`sync_lightning_wallet` returned early without updating
`latest_lightning_wallet_sync_timestamp` when no scripts were registered,
causing `wait_for_cbf_sync` to hang on start/stop/reinit cycles. Fold the
empty-scripts branch into the main path so both share a single
`update_node_metrics_timestamp` site at the end of the closure.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
main now imports BestBlock as BlockLocator. Update new_cbf return type to match.
Codebase convention is .expect("lock") rather than .unwrap() for Mutex/RwLock guards. Brings 28 sites in src/chain/cbf.rs and src/wallet/mod.rs in line with the rest of the crate and unblocks the clippy::unwrap_used lint in CI.
Previously if we try to stop kyoto during the backoff wait it would
restart despite the user's command to stop.
* Add lookahead to cbf chain source

Previously we could miss our address e.g. when we restore the wallet
from the same seed.

* Cbf: change registered scripts vec to hashmap
* Use kyoto's rescan_from(h) instead of rescan()

Previously rescan would go from kyoto's build-time checkpoint, which
might be a very old block. We can explicitely use rescan_from(height) to
process only new blocks.

* Bump kyoto version to 0.6.0
- Stop runtime-dependent chain sources before waiting for non-cancellable background tasks.

- Allow the CBF requester shutdown to unblock the node run loop during Node::stop.
Previously we had to refetch the blocks from peers on each fee rate
update, which is a huge bandwith overhead. Now we store cache of 12
previously caculated fee rates and download blocks only one by one.
- Store the CBF wallet reference as Weak<Wallet> instead of Arc<Wallet>
- Clean CBF filter scan state when sync futures are dropped on timeout.
- Treat zero-fee sampled blocks with the minimum fee-rate floor.
- Add unit coverage for zero-fee, zero-weight, and normal block fee-rate calculations.
@febyeji febyeji force-pushed the add-cbf-chain-source branch from 75cd5ae to 31e867c Compare June 3, 2026 09:34
@febyeji febyeji closed this Jun 5, 2026
@febyeji febyeji deleted the cbf-timeout-zero-fee-cleanup branch June 5, 2026 16:11
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