iceland2k14 / solominer

Solo Mining in python for BTC Block Reward, Pure luck
MIT License
80 stars 31 forks source link

new block listen thread #7

Closed papacrouz closed 2 years ago

papacrouz commented 2 years ago

As we know a block header is hashed repeatedly by miners by altering the nonce value, the blockheader contains the previous block hash, so i've add poor new block listen thread that checks for new block in network, if a new block is detected, the miner stops to hash the current block header and starts working into a new block header, also i add a logging method that stores events into a file called miner.log instead of printing them in terminal. The pull request is just for reference.

papacrouz commented 2 years ago

The repo link https://github.com/papacrouz/solominer

iceland2k14 commented 2 years ago

Thank you @papacrouz for this pull request. It has beautifully extended this toy :) Before Merging the code, I think you need to also catch a SIGINT or CTRL-C, to exit the Thread in between, if user tries it.

Also There is another suggestion, (if you want to) Since we are connected to ckpool for the blockheader and payload submission, it is also possible to be in consistent communication about the Job Work change whenever it appears from the ckpool itself (Ckpool Stratum Protocol Then we will not need any Api request for deciding the block change.

papacrouz commented 2 years ago

Hello @iceland2k14 . Yes handler must be added, i will push fix it. Regrading the ckpool stratum i will take a look into it. Also i have this https://gist.github.com/papacrouz/104204500e73772ece5459dd8f885074, https://gist.github.com/papacrouz/7b970d16cda10ab15ca32c09f5afb7c5 has an acquired ExitedThread and some more info regarding the block, do you think i have to add something from it to this pull request ? or have to keep the code simple ?

iceland2k14 commented 2 years ago

Thankx @papacrouz. I looked at the gist, which seems ok, although i would prefer to keep it simple at the moment. (Maybe in future if more things are done, like multi cpu, we could adapt to it).

  1. The idea at present is, This simple miner should allow sufficient flexibility for quick experimentation. I would try to use extranonce2 and nonce both field with different ideas of randomization, it's all luck and chance. Blockheader could be just a function with varying nonce and extranonce2.
  2. The idea about fetching the updated jobs from ckpool was to avoid working on Stale Jobs, as we are moving from 10M check to continuous check now.
  3. If you are ready to work on few things, i might assign you the collaborator access.
  4. I think i have a bug, blockheader = version + prevhash + merkle_root + ntime + nbits + nonce this should be correct.
  5. Think about it and let me know.
papacrouz commented 2 years ago

Hi @iceland2k14 . I'm looking into stratum proptocol. I'm a bit busy but i will try to find time to work on this.

iceland2k14 commented 2 years ago

Thank you. I sent you collaborator request. You may merge the commit as you progress.

papacrouz commented 2 years ago

Take a look at this patch, https://github.com/papacrouz/solominer/tree/patch-1 i use ckpool to catch new Job Work as you sugggested, also i will commit soon the multi cpu support and some other basic info. I've use context instead of global variables.

iceland2k14 commented 2 years ago

I agree. Nice.

iceland2k14 commented 2 years ago

@hadi19851364 When you are fetching the Mining Jobs from a pool, you don't need to worry about the individual transactions inside the job. It is the work of the pool to make it and provide the relevant info to the miner so that calculation can begin. If you are working on your own pool then you might have to do it all by hand. Here it's not the case.

At this moment yes the nonce number changes randomly instead of sequentially. In initial versions before the edits from @papacrouz it was only checking 1 time for 10 million hash. Now it makes more sense to modify and include some more creative way of handling it. (Maybe in future)

You can use / change whichever api or code you want. Have fun. :)