bitcoinj-cash / bitcoinj

A library for working with Bitcoin
http://bitcoinj.cash
Apache License 2.0
64 stars 35 forks source link

DNS peer discovery not working properly #66

Open rafa-js opened 6 years ago

rafa-js commented 6 years ago

I have noticed sometimes the MultiplexingDiscovery is not able to find peers. This issue occurs randomly and is very confusing for the user: Can't see the balance increasing after send some funds. Some additional details:

Example of log file:

W/MultiplexingDiscovery: Seed seed.bitcoinabc.org: timed out
W/MultiplexingDiscovery: Seed seed-abc.bitcoinforks.org: timed out
W/MultiplexingDiscovery: Seed btccash-seeder.bitcoinunlimited.info: timed out
W/MultiplexingDiscovery: Seed seed.bitprim.org: timed out
W/MultiplexingDiscovery: Seed seed.deadalnix.me: timed out
W/MultiplexingDiscovery: Seed seeder.criptolayer.net: timed out
E/PeerGroup: Peer discovery failure org.bitcoinj.net.discovery.PeerDiscoveryException: No peer discovery returned any results in 5000ms. Check internet connection?
at org.bitcoinj.net.discovery.MultiplexingDiscovery.getPeers(MultiplexingDiscovery.java:116)
at org.bitcoinj.core.PeerGroup.discoverPeers(PeerGroup.java:1051)
at org.bitcoinj.core.PeerGroup$6.go(PeerGroup.java:546)
at org.bitcoinj.core.PeerGroup$6.run(PeerGroup.java:512)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at org.bitcoinj.utils.ContextPropagatingThreadFactory$1.run(ContextPropagatingThreadFactory.java:49)
at java.lang.Thread.run(Thread.java:761)
I/PeerGroup: Peer discovery didn't provide us any more peers, will try again in 6010ms.

Have you experienced anything similar? Any ideas or alternatives?

Regards,

Danconnolly commented 6 years ago

I've not seen this before but it's interesting. I'll try and have a look at it later.

Danconnolly commented 6 years ago

I had this today, not sure if its relevant but putting it here for later analysis:

2018-07-15 14:28:36.793 [PeerGroup Thread] INFO  org.bitcoinj.core.PeerGroup - Peer discovery took 3.751 s and returned 77 items
2018-07-15 14:28:36.794 [PeerGroup Thread] INFO  org.bitcoinj.core.PeerGroup - Waiting 1000 msec before next connect attempt to [2607:5300:120:9ac:0:0:0:0]:8333
2018-07-15 14:28:37.795 [PeerGroup Thread] INFO  org.bitcoinj.core.PeerGroup - Waiting 1000 msec before next connect attempt to [119.23.173.138]:8333

There was then 10 minutes of just trying these two addresses, no others.

Danconnolly commented 6 years ago

Interesting, travis had the same problem:

2018-07-15 12:07:05.376 [PeerGroup Thread] INFO  org.bitcoinj.core.PeerGroup - Peer discovery took 1.209 s and returned 63 items
2018-07-15 12:07:05.376 [PeerGroup Thread] INFO  org.bitcoinj.core.PeerGroup - Waiting 1000 msec before next connect attempt to [67.207.85.98]:8333
2018-07-15 12:07:06.377 [PeerGroup Thread] INFO  org.bitcoinj.core.PeerGroup - Waiting 1000 msec before next connect attempt to [186.136.138.196]:8333
rafa-js commented 6 years ago

I think this is the normal behaviour for the PeerGroup::discoverPeers()method in case the response is obtained in less time than the vPeerDiscoveryTimeoutMillis, which is 5 seconds by default.

The question is, why does it takes 5 seconds and don't get a response? Part of the implementation or part of the DNS servers?

Danconnolly commented 6 years ago

You're right, not related. I think its part of the underlying OS, network, or DNS servers. To be honest, I'd probably recommend just increasing the timeout.

HashEngineering commented 6 years ago

Various types of connectivity issues are common. What I see from users of my app are transactions that are not sent due to insufficient peers. This is from not finding enough peers from the DNS servers, in addition to the minimum number of peers required to broadcast setting.

One thing that is missing from this library is getting addresses from other peers and storing them to use later when there are not enough connections or when dns was failing.

rafa-js commented 6 years ago

@HashEngineering I also came up with your last insight of remembering connected peers, but not sure how this would speed up the process. Anyway this is an optimization more than fix.

Will try with increasing the timeout and report back. Since this is an intermittent issue is both hard to replicate and hard to verify.