Building a Blockchain with Go - Part 10 - Finishing Up

in #utopian-io6 years ago

golang.jpg

Repository

https://github.com/golang/go

What Will I Learn?

  • You will learn how to implement the network library into the blockchain
  • You will learn how to properly close BadgerDB should your program crash
  • You will learn how to truncate the BadgerDB database and remove a Lock file
  • You will learn how to create multiple files and directories for multiple instances of a program
  • You will learn how to check the diff of a blockchain against another node
  • You will learn about block height and how it works to sync multiple blockchains

Requirements

System Requirements:

Operating System:

  • FreeBSD 10.3 or later
  • Linux 2.6.23 or later with glibc
  • macOS 10.10 or later
  • Windows 7, Server 2008R2 or later

Required Knowledge

  • A little understanding of the Go programming language
  • Go installed on your computer
  • A text editor or IDE like Gogland (VS Code used)

Resources for Go and this Project:

Credits/Sources:

Difficulty

  • Advanced

Description

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.

Building a Blockchain Network on a Single Machine

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.

terminals.png

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.

Network Simplification

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.

simplified-network.png

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

Video Tutorial

Curriculum

Proof of Work Done

https://github.com/tensor-programming

Sort:  

Hi @Tensor

I get to see the final video on this series of how the final programming goes. Good for you for having the stamina to work through the entire series until the end.

This series will be good for learning to learn how to build a blockchain with Go and now they have the step by step outline and flowcharts to follow.

Thank you again for taking the time to outline the fundamental and detail steps for learners.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thanks again @rosatravels. I do enjoy making these videos so its not hard to sit through the making of an entire series like this.

Thank you for your review, @rosatravels! Keep up the good work!

Hi, @tensor!

You just got a 6.71% upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in here to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.

Hi @tensor!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hey, @tensor!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!





This post has been voted on by the SteemSTEM curation team and voting trail in collaboration with @curie.

If you appreciate the work we are doing then consider voting both projects for witness by selecting stem.witness and curie!

For additional information please join us on the SteemSTEM discord and to get to know the rest of the community!

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 58130.32
ETH 2361.48
USDT 1.00
SBD 2.38