refactor(cli): consolidate relay logic in RelayManager#1635
Merged
Conversation
Preparatory commit before moving the relay-selection functions into RelayManager methods. The `Arc<Mutex<>>` wrapper around `RelayManager` only exists to synchronize `failed_relays` and gets in the way of that refactor, so move the `Arc<Mutex<>>` inside `RelayManager` onto the `failed_relays` field. As a bonus, `RelayManager` becomes simpler to use - callers no longer lock on every method call.
Move the free `fetch_ohttp_keys` from ohttp.rs into an `&self` method on `RelayManager`, so relay selection lives in the type that owns the relay state. The method reads `config` from `self` instead of taking it as an argument. The relay functions are relocated bottom-up through the call graph (`fetch_ohttp_keys` <- `unwrap_ohttp_keys_or_else_fetch` <- `App::unwrap_relay_or_else_fetch`); this is the first. Its only caller now invokes the method on its `relay_manager` argument, which becomes `self` once that caller is moved too.
Move the free `unwrap_ohttp_keys_or_else_fetch` from ohttp.rs into an `&self` method on `RelayManager`, reading `config` from `self`. Second step of relocating relay selection into the type that owns the relay state. Its caller in `receive_payjoin` now invokes the method directly on `self.relay_manager`, dropping the per-call `relay_manager.clone()` and the `config` argument.
Collaborator
Coverage Report for CI Build 27272110652Coverage increased (+0.05%) to 85.244%Details
Uncovered Changes
Coverage Regressions1 previously-covered line in 1 file lost coverage.
Coverage Stats
💛 - Coveralls |
benalleng
requested changes
Jun 10, 2026
benalleng
approved these changes
Jun 10, 2026
benalleng
left a comment
Collaborator
There was a problem hiding this comment.
TACK f130191
ran the cli with 5 active sessions and was able to see that once one relay hit the example.com relay it dropped it from the list and was not tried again during the lifetime of the resume process for any of the sessions
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.
Relates to #1582
Done per the plan from #1582 (comment):
Arc<Mutex<>>wrapper aroundRelayManagerArc<Mutex<>>on thefailed_relaysfield instead&selfmethods onRelayManagerThe original plan mentioned three functions, but
App::unwrap_relay_or_else_fetchwas turned intoApp::post_via_relayin #1628, so only two methods were moved here. It could be worth movingpost_via_relayintoRelayManageras well, but I'd suggest leaving that out of the scope of this PR.Commands to verify the function moves (bash/zsh; strips the method's extra
implindent so only the signature/self-receiver changes show up).b28a1d8eis the master tip this branch is based on, pinned so the line ranges stay valid:fetch_ohttp_keys:unwrap_ohttp_keys_or_else_fetch:Disclosure: code written by hand, Claude was used for review and discussion.
Pull Request Checklist
Please confirm the following before requesting review: