Skip to content

Mining hash / operation queues proposal - #12

Open
johndpope wants to merge 13 commits into
vkoskiv:masterfrom
johndpope:master
Open

Mining hash / operation queues proposal#12
johndpope wants to merge 13 commits into
vkoskiv:masterfrom
johndpope:master

Conversation

@johndpope

Copy link
Copy Markdown
Contributor

needs some proper unit tests.
with the added queues x3 - we can reliably interject / cancel when other signals (block found remote / propagation) occur from block chain.

so the mining queue is basically the recursion to find next block.
the hashing queue is parallel threaded to determine hash
the block found queue I added as a sanity check to prevent two blocks being found at same time.
There's also a block found state variable to help orchestrate things.

you will notice that / they hang off the blockchain queue
the SynchronizedArray should prevent the underlying mutation of the blockchain data while all the threads are in action.

I've been testing and it seems stable.

eg.

var blockFound:Bool{
     get {
         return blockChain.queue.sync {
             _blockFound
         }
     }
     set {
         blockChain.queue.sync {
             _blockFound = newValue
         }
     }
 }

There's some delays that are added as bandaids which basically give the process some cycles on other threads to catch up.

eg
before we call mine - we sleep for a few milliseconds.
This delay variable value is more of an art that a science.

                usleep(Miner.bandAidDelay)
                 Miner.mine()

John Pope added 13 commits January 15, 2018 11:52
Avoid thread explosion. Use operations queues instead of dispatch queues to organise work.
Maintain thread count.
use a static thread count on miner so we can reference outside of instance.
introduce block found boolean on blockchain queue.
reworking miner to allow cancelling of operations. extra sanity checks across threads.
introduce additional operation queues to avoid dead locks.
@johndpope johndpope changed the title Mining hash / queues proposal Mining hash / operation queues proposal Jan 15, 2018
@vkoskiv

vkoskiv commented Jan 16, 2018

Copy link
Copy Markdown
Owner

Looks great so far. I'll do some testing and merge it ASAP if all looks good.

Just as a side note: I really appreciate you helping out with this project! This is the first time anyone has taken an interest in any of my projects at this level, and submitting pull requests for me. It really means a lot.

@vkoskiv

vkoskiv commented Jan 16, 2018

Copy link
Copy Markdown
Owner

A note on unit tests:
Feel free to make them. My philosophy with that stuff is basically: This code isn't mission-critical. Let's get it to a working state, and then worry more about proper testing and project structuring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants