The Golang Diaries - A bitcoin fork genesis block generator with parallel miner

in #bitcoin7 years ago (edited)

I have just completed and am in the process of testing the benefits of parallelising my port of this genesis block generator written in C. You can see it in its current state indefinitely at github here

Note: The code previously linked to was incorrect, and was aiming at much too low a target. It now fully works and uses all cores of your processor and on my i5-7600 pops out an answer in under 5 seconds.

It's the very first time I have written any program in Golang that uses goroutines. In this case it is completely simple, no channels, no locks, no nothing. It doesn't need anything, because it simply starts with a nonce of zero, grabs the unix timestamp, each thread copies the block header so it can alter the nonce and timestamp without clobbering the data of the other threads.

Whichever of the threads finds the solution first prints out its result and kills the process.

For anyone who wants to, for fun or maybe profit, write a bitcoin (or possibly other bitcoin fork, fork) fork (spork!) this is an essential tool for the process of building a fork, and maybe there is ways to make the very basic miner built into it significantly faster on a CPU, you only need to run this a few times to generate the several different networks you will need for your fork (mainnet, testnet, regression net).

Happy gophering!

Follow me to learn more useful things for budding Gophers especially relating to cryptocurrency programming!