vkoskiv / VaporCoin

A peer-to-peer blockchain ledger, built with Swift, using Vapor
MIT License
69 stars 3 forks source link

Fix race condition in multithreaded miner #4

Open vkoskiv opened 6 years ago

vkoskiv commented 6 years ago

If two threads find a block at the exact time (At a low difficulty), the client crashes. Should be a fairly simple fix.

johndpope commented 6 years ago

my attempt to fix. https://github.com/VKoskiv/VaporCoin/pull/7

for some unknown reason - if this is set to 00 while (!candidate.blockHash.binaryString.hasPrefix("00")) { and usleep(20) is set here - it silently bails out . not sure why.

sleep(1) or usleep(20000) - seems to work fine.

screen shot 2018-01-10 at 3 17 12 pm