You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
platform-wallet: wallet state guards panic when the wallet was removed #5738
WalletStateReadGuard and WalletStateWriteGuard in packages/rs-platform-wallet/src/wallet/platform_wallet.rs look the wallet up again on every Deref, DerefMut and wallet() call, and each lookup ends in .expect("wallet exists in guard"). The guard only holds the WalletManager lock. It does not pin the wallet. A PlatformWallet handle can outlive the wallet's removal from its manager, for example while a caller is resolving a mnemonic through the FFI resolver. Once that happens, every state(), state_mut() and state_blocking() caller panics instead of returning an error. Across the FFI that is an abort of the host app.
Evidence
origin/v5.1-dev: platform_wallet.rs, the five expect("wallet exists in guard") calls in the WalletStateReadGuard and WalletStateWriteGuard impls.
#5727 works around this for derive_core_address_private_key alone, by replacing state_blocking() with a direct get_wallet_and_info lookup that returns PlatformWalletError::WalletNotFound. Its test should_report_a_removed_wallet_as_missing removes a wallet while holding its PlatformWallet and shows the reveal would otherwise panic. Every other guard user still has the panic.
Fix
Make the guard fallible at construction. state(), state_mut() and state_blocking() (and the try_ variants) check that the wallet and its info exist while they hold the lock and return Result<_, PlatformWalletError::WalletNotFound>. The guard then stores the checked references, or keeps the invariant by construction, so Deref and wallet() cannot fail. Callers propagate the error with ?.
Activity