Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mining hash / operation queues proposal #12

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

johndpope
Copy link
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
Copy link
Owner

vkoskiv commented Jan 16, 2018

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
Copy link
Owner

vkoskiv commented Jan 16, 2018

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