comit-network / xmr-btc-swap

Bitcoin–Monero Cross-chain Atomic Swap
GNU General Public License v3.0
645 stars 81 forks source link

Electrum queries are inefficient, may produce server bans #865

Open icy-ux opened 2 years ago

icy-ux commented 2 years ago

Queries to the electrum server are done in an inefficient way. When using an electrs locally hosted back end, the following log messages are produced: your wallet uses less efficient method of querying electrs, consider contacting the developer of your wallet. Reason: blockchain.scripthash.get_history called for unsubscribed scripthash: c28a[......]

This may be related to #797 where the (public) electrum server rejects our requests, probably to avoid DoS attacks.

icy-ux commented 2 years ago

After several tries, I managed to do a successful swap between a local asb instance and my local client only when both asb and swap were using my local electrs server.

When either or both asb and swap were using the default public Electrum server, the swap errored out at one or the other point, with the CloseNotify issue discussed in #797

rishflab commented 2 years ago

Thanks for writing up the issue.

I have not looked into this deeply but It seems like there has been changes to electrum, this is the first time I have seen this message. When we implemented this we put a fair bit of work in making the queries efficient as we were triggering DDoS protection.

We are happy to accept a PR on this and happy to provide guidance. Alternatively running a local electrum server might be the best way to go for now.

icy-ux commented 2 years ago

On Sun, Dec 12, 2021 at 10:57:52PM -0800, rishflab wrote:

Thanks for writing up the issue.

I have not looked into this deeply but It seems like there has been changes to electrum, this is the first time I have seen this message. When we implemented this we put a fair bit of work in making the queries efficient as we were triggering DDoS protection.

We are happy to accept a PR on this. Alternatively running a local electrum server might be the best way to go for now.

I'm not an electrs or electrum developer, so I can't give any technical background. I am currently running an electrum server and that fixed the issue.

Unfortunately the issue also crops up when I run swap. I don't think it's reasonable to expect a client (who is only running swap) to run their own electrum server.

binarybaron commented 2 years ago

I analyzed the outgoing traffic of the Bob and the Cli is making tons of blockchain.scripthash.get_history calls to the electrum server. We may need to replace that with a subscription.

{"method":"blockchain.scripthash.get_history","params":["71fc8007a74346f8d3f8748936857173e2d3bd74fbbd8d52951c347863a5bad2"],"id":2693}

delta1 commented 2 years ago

Some info here too

https://github.com/bitcoindevkit/bdk/issues/618