Skip to content

accounts/usbwallet: fix De Morgan error dropping stale wallets on refresh#35150

Open
cuiweixie wants to merge 1 commit into
ethereum:masterfrom
cuiweixie:fix-usbwallet-hub-demorgan
Open

accounts/usbwallet: fix De Morgan error dropping stale wallets on refresh#35150
cuiweixie wants to merge 1 commit into
ethereum:masterfrom
cuiweixie:fix-usbwallet-hub-demorgan

Conversation

@cuiweixie

@cuiweixie cuiweixie commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

The inner loop in refreshWallets drops cached wallets that sort before the next enumerated device or that have failed. When this drop-while logic was refactored into an early break, the condition was negated but the boolean operator was left as ||, so the negation is incomplete.

The drop condition is:

(URL.Cmp(url) < 0) || (failure != nil)

so the break (abort dropping) condition must be its De Morgan negation:

(URL.Cmp(url) >= 0) && (failure == nil)

With ||, the loop breaks as soon as the front wallet is operational, even when it sorts before the current device. The stale wallet is not dropped in place, and neither the "wrap new wallet" nor the "keep matching wallet" branch matches, so the still-present device is silently skipped for that refresh cycle (no WalletArrived) and is only re-added on a later refresh.

Switch the operator to && so the break condition correctly mirrors the intended drop semantics.

…resh

The inner loop in refreshWallets drops cached wallets that sort before
the next enumerated device or that have failed. When this drop-while
logic was refactored into an early break, the condition was negated but
the boolean operator was left as ||, so the negation is incomplete.

The drop condition is:

    (URL.Cmp(url) < 0) || (failure != nil)

so the break (abort dropping) condition must be its De Morgan negation:

    (URL.Cmp(url) >= 0) && (failure == nil)

With ||, the loop breaks as soon as the front wallet is operational,
even when it sorts before the current device. The stale wallet is not
dropped in place, and neither the "wrap new wallet" nor the "keep
matching wallet" branch matches, so the still-present device is silently
skipped for that refresh cycle (no WalletArrived) and is only re-added
on a later refresh.

Switch the operator to && so the break condition correctly mirrors the
intended drop semantics.
@cuiweixie cuiweixie requested a review from gballet as a code owner June 11, 2026 12:59
@cuiweixie cuiweixie changed the title accounts/usbwallet: fix De Morgan error dropping stale wallets on ref… accounts/usbwallet: fix De Morgan error dropping stale wallets on refresh Jun 11, 2026
@gballet gballet self-assigned this Jun 12, 2026
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