Skip to content

refactor(bdk_electrum_streaming): Replace State::{reset,init} with State::start - #17

Open
evanlinjin wants to merge 1 commit into
mainfrom
refactor/state-start
Open

refactor(bdk_electrum_streaming): Replace State::{reset,init} with State::start#17
evanlinjin wants to merge 1 commit into
mainfrom
refactor/state-start

Conversation

@evanlinjin

Copy link
Copy Markdown
Owner

init had two callers: the run loops (right after reset) and the top of advance. The one in advance was dead weight — advance only runs on an incoming message, and the server only speaks once we have sent it a request, which only init does. A caller who skipped init got a silent connection and never reached advance, so the init_reqs_sent guard could not rescue them.

Since every real call site was reset(); init(); in sequence, this folds them into a single start(&mut ReqQueue) and drops the flag with it. Also drops the now-unused ReqCoord::clearstart deliberately keeps pending requests so they are resent.

Breaking: State::reset and State::init are replaced by State::start. run_async/run_blocking call it for you, so only code driving State by hand is affected.

The one hazard left is forgetting start entirely, which is exactly what the init-in-advance call 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

`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>

@evanlinjin evanlinjin left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK ceb8959

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