Operating System:
Big library: https://golang.org/pkg/math/big/Bytes library: https://golang.org/pkg/bytes/In this final tutorial video, we finish up the blockchain and produce a program that is near production level. By combining the network module with the code for our Command line interface, wallet module and blockchain module, this application now is able to simulate a blockchain network in real time on a single local machine. This also includes the creation of multiple databases and wallet files for each instance of the application along with the ability to quickly scan a blockchain for changes. We also look at how we can protect our BadgerDB against corruption should the program terminate prematurely.
In our network module, we've already specified the main way that we want our programs to talk with one another. The RPC or remote procedure calls are passed around via TCP with each instance of the client being represented by localhost machines listening on different ports. Using this structure, we can modify the existing Blockchain, Wallet and Command line interface code to account for multiple different local programs each with their own Node ID. This also means that we are able to run a miner, SPV and a full node all on the same computer.
In the image above are three terminals each running an instance of this blockchain. The top left terminal is connected to the main central node of the application. This node acts as a full node on the blockchain network; it preforms routing and tries to maintain the most consistent copy of the blockchain. The terminal on the bottom left is our wallet or SPV node. This node is responsible for sending transactions to the network. The terminal on the far right is the miner node of the network. When enough transactions are passed from the wallet node to the full node and then to the miner node, the miner node verifies the transactions and then runs the proof of work algorithm to create a new block. This new block is then sent to the main node which then proliferates the changes out to the other two nodes.
This network system is a simplified version of a production blockchain. The central node acts somewhat like a server which goes against the idea of a decentralized architecture. Also, the SPV node and the miner node contain full copies of the blockchain. This was mainly done because the nodes do not have a message to discover each other on the network.
In a real blockchain, there can be multiple instances of the same chain which have different lengths or heights. In our example, we just take the new blocks and add them to our blockchain unconditionally. To save computing power, our network does not validate the block before adding it to the chain. The image above highlights the main differences between our version and a production level version. Each node routes through the Full Node where as in a real example, each node will communicate with one another independently.
The Source Code for this video may be found here: https://github.com/tensor-programming/golang-blockchain/tree/part_10