refactor(cbf): drop latest_tip mirror, source chain tip from kyoto directly#12
Open
randomlogin wants to merge 3 commits intofebyeji:add-cbf-chain-sourcefrom
Open
refactor(cbf): drop latest_tip mirror, source chain tip from kyoto directly#12randomlogin wants to merge 3 commits intofebyeji:add-cbf-chain-sourcefrom
randomlogin wants to merge 3 commits intofebyeji:add-cbf-chain-sourcefrom
Conversation
`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>
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.
Summary
Removes the
latest_tip: Arc<Mutex<Option<BlockHash>>>field fromCbfChainSourceandCbfEventState. The only functional consumer wasfee_rate_cache_from_cbf, which now callsRequester::chain_tip()per invocation instead of reading from a mirrored cache.Motivation
latest_tipwas cross-task shared mutable state maintained in three places:Event::FiltersSynced.BlockHeaderChanges::Reorganized.get_blockfailures insidefee_rate_cache_from_cbf(theidx == 0branches).All three exist to keep the mirror consistent with kyoto's actual view of the chain. Asking kyoto directly removes the need for any of them.
Why this is safer than the mirror
chain_tip()returns the post-reorg value without us manually invalidating anything.auto-restart with exponential backoff): the newRequesteris swapped intocbf_runtime_status, sochain_tip()calls throughself.requester()pick up the fresh handle automatically. The old mirror could hold a stale hash from before the crash, which would then get handed toget_blockand trigger the defensive "clear-cached-tip-and-return-None" fallback. That fallback is now gone.Ok(None)whenlatest_tipisNone, we skip whentip.height < FEE_RATE_LOOKBACK_BLOCKS— more precise (the real requirement is "enough history to sample"), and no separate "have we synced yet?" signal needed.Changes
latest_tipfromCbfChainSource(field, init,Arcclone instart()'s restart loop).latest_tipfromCbfEventState(field + event-state construction inside the restart loop).Event::FiltersSyncedwriter and theBlockHeaderChanges::Reorganizedclearer.fee_rate_cache_from_cbf:tokio::time::timeout(timeout, requester.chain_tip()).idx == 0stale-tip defensive branches; anyget_blockfailure is now a hard error.Stacked on #11. Retargets to
add-cbf-chain-sourceonce that merges.Disclosure: drafted with assistance from Claude Code.