Writing Proof Of Work Blockchain full-node from scratch

What the point in all of this?

What need to understand before proceeding

  1. No off chain data. As we can’t trust anyone, that implies that we cant trust any data outside our blockchain database. That means that we can’t use things like time, API calls to any services, etc. Which makes things much harder.
    Some systems that used on-chain services called Oracles to access off-chain data, but that’s another story.
  2. Blockchain trilemma. Which come from the CAP theorem. You can pick only two. So there can’t be Blazing Fast, Decentralized, and Secure solution.

PoW Blockchain

Transactions

Blocks

Proof Of Work algorithm

Mining

Merkel Tree

System together

Problems

  • Running mining concurrently and increasing difficulty use too much resources, that could be used more useful.
  • As difficulty too big for one person to mine, people gathered in a mining pools, which uses their resources to mine block and spread reward among all participants.

Codding part

  • Blockchain based on Proof Of Work algorithm
  • Transaction spent control. Each Tx Input pointed to the previous Tx Output
  • Signed Inputs by wallet private key
  • Using Merkel Tree for faster Block hash computation during mining
  • Mining process
  • Sync process between nodes
  • Transaction and Block verifiers
  • Same configuration on reward and difficulty for all blocks. Thus no supply limits.
  • Nodes blocks, txs, nodes address gossip broadcast
  • Covering Blockchain split brain situation but only for one level.
  • Openapi schema + UI (generated by FastAPI)
  • Some tests for blockchain. Cause it very simple to mess things up with all these hashes
  • Multi-level split brain
  • Automatic node discovery in subnets through service discovery protocol and ping
  • Integration testing
  • Byzantine testing
  • Many things that real blockchain solution has. If you interesting in such, you can open Bitcoin or Ethereum after reading this.
  • Multiprocessing for mining
  • Light client
  • No limitation on block sizes or number of Txs. Block mining starts after previous mining ends.

Wallet

Blocks

Verifiers

Blockchain

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store