the servers from the coins_config_tcp.json are passed to the electrum call by the apps
This approach has some drawbacks:
if one or more of the servers are lagging behind the chain and mm2 uses them, it will show a wrong balance and swaps will fail too
if the 3 servers selected by the script in coins repo are later failing, the coin will not work any more, even though the initial config has eg 6 servers and the others are still working
if the SSL certificates of the 3 selected servers expire, the coin can't be enabled any more, even though TCP would still work (assuming TCP ports are also configured in the initial config, like it is with all servers run by us, see eg KMD)
I propose to make mm2 do all the filtering to which servers it connects and to which it doesn't, so if i pass 6 electrum servers to the electrum call, it should choose eg 2 or 3 good working ones and connect to them. The filtering should include the following:
don't connect to servers that are lagging behind the chain... eg choose 2 with the highest height... if there are only 2 and they differ, then connect only to one... there should be a tolerance though (optimal would be if the tolerance is not a fixed number of blocks, but dependent on the block time of the chain, so for BTC 3 blocks is a lot while for DGB 3 blocks is still acceptable... coins file contains avg_blocktime in seconds, which can be used for this)
don't connect to the same server twice, even if it is passed twice to the electrum call.. this is done often, since config in coins repo contains both TCP and SSL ports for many servers, even though it is the same server... maybe we can also go down to the IP level, so if 2 hosts in DNS point to the same IP, mm2 connects only once to one of them... this will also reduce the number of file descriptors used and help Mobile since it only support 128 open files afaik
optionally we can also filter based on connection time, even though i guess that it is not that important since most time is spent with processing the request not with the sending/receiving the data itself... maybe define "connection time" as the time needed to process a certain call, since that also includes the speed of the actual server and not only the time needed to connect to it... i propose to use blockchain.headers.subscribe for this test... it also returns the latest height, so the data can be used for the filtering based on height
The situation atm is as follows:
electrum
call by the appsThis approach has some drawbacks:
I propose to make mm2 do all the filtering to which servers it connects and to which it doesn't, so if i pass 6 electrum servers to the
electrum
call, it should choose eg 2 or 3 good working ones and connect to them. The filtering should include the following:avg_blocktime
in seconds, which can be used for this)electrum
call.. this is done often, since config in coins repo contains both TCP and SSL ports for many servers, even though it is the same server... maybe we can also go down to the IP level, so if 2 hosts in DNS point to the same IP, mm2 connects only once to one of them... this will also reduce the number of file descriptors used and help Mobile since it only support 128 open files afaikblockchain.headers.subscribe
for this test... it also returns the latest height, so the data can be used for the filtering based on heightMaybe some of the things mentioned here are already implemented in https://github.com/KomodoPlatform/komodo-defi-framework/pull/1966