refactor(bdk_electrum_streaming): Replace State::{reset,init} with State::start - #17
Open
evanlinjin wants to merge 1 commit into
Open
refactor(bdk_electrum_streaming): Replace State::{reset,init} with State::start#17evanlinjin wants to merge 1 commit into
State::{reset,init} with State::start#17evanlinjin wants to merge 1 commit into
Conversation
`init` was called both by the run loops (after `reset`) and at the top of `advance`. The latter was dead: `advance` only runs on an incoming message, and the server only speaks once we have sent a request, which only `init` does. So the `init_reqs_sent` guard could never actually rescue a caller who skipped `init`. Since every call site was `reset(); init();` in sequence, fold them into a single `start(&mut ReqQueue)` and drop the flag along with it. Also drop the now-unused `ReqCoord::clear` - `start` deliberately keeps the pending requests so they get resent. Co-Authored-By: Claude Opus 5 <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.
inithad two callers: the run loops (right afterreset) and the top ofadvance. The one inadvancewas dead weight —advanceonly runs on an incoming message, and the server only speaks once we have sent it a request, which onlyinitdoes. A caller who skippedinitgot a silent connection and never reachedadvance, so theinit_reqs_sentguard could not rescue them.Since every real call site was
reset(); init();in sequence, this folds them into a singlestart(&mut ReqQueue)and drops the flag with it. Also drops the now-unusedReqCoord::clear—startdeliberately keeps pending requests so they are resent.Breaking:
State::resetandState::initare replaced byState::start.run_async/run_blockingcall it for you, so only code drivingStateby hand is affected.The one hazard left is forgetting
startentirely, which is exactly what theinit-in-advancecall pretended to cover but could not. It is documented on the method. A typestate that makes it a compile error seemed like more machinery than the problem deserves.🤖 Generated with Claude Code