revoxhere / duino-coin

ᕲ Duino-Coin is a coin that can be mined with almost everything, including Arduino boards.
https://duinocoin.com
MIT License
1.06k stars 513 forks source link

Fix divide by zero on hashrate calculation (sends nonce with zero hashrate) #1767

Closed GerardoNevarez closed 3 months ago

GerardoNevarez commented 3 months ago

Had issues with hashrate calculation causing divide by zero exceptions, and restarting the client connection. Tried to use nanoseconds to capture elapsed time, but still some hash calculations were very fast, resulting in the same exception.

Changed to logic to just send invalid data back, when the elapsed time is zero. While this results in a rejected response, it keeps the client connection active.

-- Obviously that, while trying to determine a good miner response message was for this scenario, I changed the hashrate calculation to report THs/s , and got a warning in my account :-) Hope this doesn't get me banned!