duino-coin icon indicating copy to clipboard operation
duino-coin copied to clipboard

Implement PING/PONG worker port response and getPoolList API

Open nigeljohnson73 opened this issue 5 years ago • 10 comments

Is your feature request related to a problem? Please describe. Devices are given a pool to attach to by the getPool API call. However, this can be a pool that is broken and does not take into account remote device geography. For example, a device in the US would be better connecting to a US-based pool.

Describe the solution you'd like Implement a getPoolList would return a list of name/IP/ports for all the managed pools. Each miner can then do a connection request to each endpoint, sending a PING data packet, and log the time it took. The fastest pool will be the closest (network geography wise) and least loaded, this can then be used by the device. This would provide basic load balancing and geographic dispersion.

Describe alternatives you've considered getPool only returns the one pool so nothing can be done with that. a PING/PONG response probably isn't needed, as any data could be sent, and an error would be returned which would be just as ok for the connecting device.

Additional context N/A

nigeljohnson73 avatar Aug 26 '21 11:08 nigeljohnson73

I agree with this approach. Sometimes we can't connect to some pools due to connection issues.

naphob avatar Aug 26 '21 11:08 naphob

Having the miner connect to all the pools available (even if it's just pinging it) would create lots of traffic with about 20k clients we're currently handling and slow all of them

revoxhere avatar Aug 26 '21 12:08 revoxhere

This is true, but if a single miner ends up submitting 100 jobs, that one connection was only 1% of traffic. An ESP32 has 2 cores, and seems to be stable as much as the servers are, so total additional load is tenths of a per cent in total.

nigeljohnson73 avatar Aug 26 '21 12:08 nigeljohnson73

Okay, you know better, go ahead

revoxhere avatar Aug 26 '21 12:08 revoxhere

location isnt there yet, but a start is here: https://server.duinocoin.com/all_pools

BastelPichi avatar Aug 26 '21 14:08 BastelPichi

Thanks @BastelPichi, is there a non-ssl, IP address version of that URL so I can use it in the ESP32 sketch?

nigeljohnson73 avatar Aug 26 '21 15:08 nigeljohnson73

I have written a function that works, and I've tried with some servers that are down and some ports that don't serve things, and things seem to hold together:

Connected to WiFi!
    IP address: 10.10.1.152
      Rig name: NJESP32-99

Pool JSON length: 1000 bytes
findPool(): Skipping 'skip-pool-1'
findPool(): Checking 'bad-pool-1' - connection failed
findPool(): Checking 'crap-pool-1' - connection failed
findPool(): Checking 'pulse-pool-1' - 1047 ms
findPool(): Checking 'pulse-pool-2' - 1055 ms
findPool(): Checking 'star-pool-1' - 1047 ms
findPool(): Checking 'beyond-pool-1' - 1659 ms
findPool(): Checking 'beyond-pool-2' - 1326 ms

findPool(): best connection: 'pulse-pool-1' at 1047ms

I have written it so it's protected by a #define so the new behaviour can be tested. The current behaviour is the default. Because of the JSON string processing, the new behaviour might be quite space-intensive. In testing, it needed at least a 2k static JsonDocument, but taking out the things that are not needed (cpu, connections and ram) would reduce this, but with them in, the logic can be honed. This works on my ESP32 with a 4k allocation and I still have loads left.

I have also blocked the threads from attempting connections until a pool has specifically been set.

It seems that the current getPool API is on a server/port combo that works without an SSL certificate, and the ESP32 seems to like URLs to be IP addresses so it doesn't have to tangle with DNS.

I'm guessing it's on a shared VPS so you can't get the IP Address to work for server.duinocoin.com in its raw form (https://35.186.238.101/all_pools) and you can't override the Host header in the expressif HttpClient.

If the new all_pools API could be moved to the same place the existing pool getting URL (http://51.15.127.80:4242/getPool) is, I can code that in.

http://51.15.127.80:4242/getPoolList http://51.15.127.80:4242/all_pools

Or whatever you want to call it.

@BastelPichi is this what you meant by location?

I'll have a bit more of a go and see if I can get my ESP to handle DNS or at least SSL a bit better in the meantime.

nigeljohnson73 avatar Aug 26 '21 16:08 nigeljohnson73

Without coding the SSL certificate into a variable, there is no way I can find to connect to an HTTPS endpoint.

DNS does seem to work fine though, but I'm not sure how reliable it is, or if it is supported natively on other boards.

nigeljohnson73 avatar Aug 28 '21 06:08 nigeljohnson73

SSL costs a heavy premium :)

Existing solution: Sketch uses 927881 bytes (70%) of program storage space. Maximum is 1310720 bytes.
   HTTPS no debug: Sketch uses 1086249 bytes (82%) of program storage space. Maximum is 1310720 bytes.
  HTTPS and debug: Sketch uses 1088413 bytes (83%) of program storage space. Maximum is 1310720 bytes.

nigeljohnson73 avatar Aug 28 '21 10:08 nigeljohnson73

Closing due to inactivity/solved in the latest versions

revoxhere avatar Sep 26 '21 19:09 revoxhere