Repository navigation
fix(electrum): reject a custom server that is on another chain - #232
Open
coolstack-coder wants to merge 1 commit into
Open
coolstack-coder wants to merge 1 commit into
coolstack-coder wants to merge 1 commit into
Conversation
The server test only checked that a server answered server.version and server.ping, so a mainnet server could be saved as the Signet one (by hand or from a setelectrumserver link) and the reverse. Once saved it took over: scripthash queries came back empty, so balances and history vanished, and broadcasts failed. A wrong port is enough on hosts that serve several chains, such as testnet3 on 51002 next to testnet4 on 52002. testConnection now compares the genesis hash from server.features with the chain's own and, on a mismatch, throws an error naming the network, which the settings screen shows instead of saving. Each network config carries its genesis hash, checked against the shipped peers.
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.
Problem
testConnectiononly checksserver.versionandserver.ping, so any reachable server passes. Saving a server for another chain is accepted, whether by hand or from asetelectrumserverlink:testnet.aranguren.org:51002is testnet3, next to testnet4 on52002.The per-chain preference keys stop a saved server leaking across networks, but they can't stop the wrong chain's server from being saved under the active one.
Fix
NetworkConfiggetsgenesisHash.testConnectioncomparesserver.features().genesis_hashwith the chain's own. On a mismatch, or when the server doesn't report one, it throws an error naming the network.ElectrumServerSettingsalready shows a thrown error's message, so the server isn't saved and the user sees why. An unreachable server still resolvesfalse, as before.testConnectiontakes an optionalnetworkId, which defaults to the active network.I checked the three hashes against the shipped peers. bluewallet and foundationdevices return the mainnet hash, aranguren
52002the testnet4 hash, and the Shroud signet Fulcrum the signet hash. aranguren51002returns the testnet3 hash, so it's rejected.Tests
tests/unit/electrum-test-connection.test.ts, with a mocked client, covers: the right chain, the hash in either case, the wrong chain, an explicitnetworkId, a missing hash, and an unreachable server.tests/integration/Electrum.test.jspasses each fallback peer's chain and asserts the wrong-chain cases reject. It passes against the live servers.tscandeslintare clean.sendDetails.test.tsx› "fills in a payment request opened from home" fails onmastertoo, so it's unrelated to this change.