Repository navigation
ltc-electrum: pin MWEB's P2P sync to our own Litecoin nodes - #9
Merged
Merged
Conversation
Electrum-LTC's embedded mwebd syncs MWEB over Litecoin P2P (neutrino), from DNS seeds and whatever peers gossip, so `-1 -s` never covered it: on btcpay-stg it held connections to eight random :9333 peers. Electrum-LTC passes mwebd nothing but its proxy setting, and mwebd's own peer option only adds a peer beside the random ones. So the LTC Electrum containers now run pin-proxy.py, a loopback SOCKS5 proxy, and point Electrum at it with -p. It sends every P2P connection to one of MWEB_PEERS, whatever peer mwebd asked for, passes Electrum's connection to its pinned server, and refuses anything else. Rewriting rather than refusing matters: a fresh wallet's address book holds none of our nodes, so refusing would leave MWEB never syncing. On mainnet the containers refuse to start without MWEB_PEERS, as they already do without a server.
mwebd keeps 8 outbound peers. Sent all to our two nodes, that made btcpay-stg the largest netgroup on each, so a full litecoind's inbound eviction dropped our youngest connection every time mwebd opened another: ~600 connections a minute per container, median lifetime 0.05s. Now each container holds at most one connection per node. mwebd's other dials are held, unanswered, until one closes: its dialer has no timeout, so they just wait, where refusing them would have it retry in a loop.
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.
Why
-1 -spins Electrum-LTC's server, but not MWEB. Electrum-LTC runs an embedded mwebd that syncs over Litecoin P2P (neutrino), using peers from DNS seeds and gossip. On our staging host each LTC Electrum container held 8 random:9333peers.It can't be pinned by configuration:
contrib/mwebd/main.go) passes mwebd onlyChain,DataDirandProxyAddr.ServerArgs.PeerAddrmaps to neutrinoAddPeers. That adds a peer, but DNS seeding and 8 random outbound peers continue (ConnectPeers, the exclusive option, isn't exposed).What
docker/ltc-electrum/pin-proxy.pyis a SOCKS5 proxy on the container's loopback, using only the standard library and run by the entrypoint. Electrum gets-p socks5:127.0.0.1:1080, which mwebd also uses. The proxy:MWEB_PEERS, whichever peer mwebd asked for. It rewrites rather than refuses: a fresh wallet's address book holds none of our nodes, so refusing would mean MWEB never syncs and peg-outs stall.ELECTRUM_SERVER_ADDRESS. Electrum hands the hostname to the proxy, so DNS for it happens in the proxy.On mainnet the LTC containers refuse to start without
MWEB_PEERS, the same way they already do without a server. Peers must be IP literals. New env var:LITECOIN_MWEB_PEERS(README,.env.example, compose). CI now byte-compiles and pyflakes the proxy, andtests/test_pin_proxy.pycovers the routing.Tested on staging (dry run)
LTC wallet volumes were backed up first.
:9333peers.:9333and one to our Electrum server, and nothing else. mwebd itself talks only to the proxy.MWEB_PEERSon mainnet exits 1, and a hostname exits 2.The full evidence is in the deploy PR in our private infra repo, which must land with this one, since the new image refuses to start without
MWEB_PEERS. Not deployed to production.