In Part 1 we coded and went over the top level math and requirements for a single node to mine its own blockchain; we create new blocks that have the valid information, save them to a folder, and then start mining a new block.
Part 2 covered having multiple nodes and them having the ability to sync. If node 1 was doing the mining on its own and node 2 wanted to grab node 1’s blockchain, it can now do so.
For Part 3...
Nodes will compete to see who gets credit for mining a block. It’s a race! To do this, we’re adjusting mine.py to check if we have a valid block by only checking a section of nonce values rather than all the nonces until a match. Then APScheduler will handle running the mining jobs with the different nonce ranges. We shift the mining to the background if we want node.py to mine as well as being a Fl...
In Part 2 we write some code to introduce the ability for different nodes to communicate.
Initially we wanted to write about nodes syncing up and talking with each other, along with mining and broadcasting their winning blocks to other nodes. However, the amount of code and explanation to accomplish all of that was way too big for one post. Because of this, Part 2 is only about nodes beginning the process of talking for the future.
If you’re looking for the total implementation you should look at the entire code on the part-2 branch on Github.
In Part 1, we'll cover how to store the blockchain data and generate an initial block, how a node can sync up with the local blockchain data, how to display the blockchain (which will be used in the future to sync with other nodes), and then how to go through and mine and create valid new blocks. For this first post, there are no other nodes. There are no wallets, no peers, no important data. Information on those will come later.
A big thing to mention here is that there are differences in a basic blockchain like the one described here and a ‘professional’ blockchain. This chain will not create a crypto currency. Blockchains do not require producing coins that can be traded and exchanged for physical money. Blockchains are used to store and verify information. Coins help incentive nodes to participate in validation but don’t need to exist.
Here's a quick summary about how a blockchains work....