Post
Topic
Board Development & Technical Discussion
Re: Python based Solo miner for CPU | Learn Basic Bitcoin Mining | Just for fun
by
vshoes
on 29/02/2024, 11:37:02 UTC
I made some small improvements:
1) I called the noncework function 2**32 times, not just 10 million million times
2) every time i called the noncework function, i passed the loop value k, using that number as the nounce and not a random number

I could also have used the time parameter, another 5000 or 6000 times cycle, so that the root merkle only resets once every 5000*2**32. In that case, if we had a 100 TH/S asic instead of a CPU, it would have to recalculate the nounce every 4 or 5 seconds, if I'm not mistaken.

Code:
# omitted for brevity
   
    #  use this loop if you want to do a speed test with only 1 million rounds
    start = time.time()
    for k in range(1000000):
        noncework(k)
    end = time.time()
    print(end - start)
    # about 42.5
    '''
    # use this loop if you want to try all the nounce with 2**32 rounds
    for k in range(2**32):
    noncework(k)
    '''
    print("Finished nounce. Regaining Information.")
    sock.close()
    main()

main()


I'm interested to understand why you chose (2**32) as the target for noncework. Given the end-start times when I tried your script, the noncework function takes around 2.5 hours. In that time, it's almost certain that a block would be found and you'd be looking at coinbase etc information from a non-current block. Am I wrong here, or should you be regaining information much sooner?

Also, can you explain the advantage of noncework(k) instead of noncework() ? Thanks!

I'm trying to optimize the script as a bit of fun, given I'll never mine a block, my goal is to improve my Mh/s figure as much as possible and learn more about the technical background underpinning mining.