Bitcoin for Distributed Systems Enthusiasts – Discovery and Consensus in one of the most popular distributed logs



Bitcoin for Distributed Systems Enthusiasts – Discovery and Consensus in one of the most popular distributed logs

0 0


BitcoinForDistributedSystemsEnthusiasts


On Github JustinTArthur / BitcoinForDistributedSystemsEnthusiasts

Bitcoin for Distributed Systems Enthusiasts

Discovery and Consensus in one of the most popular distributed logs

Justin Turner Arthur / @JustinTArthur / https://github.com/JustinTArthur

I’m a programmer and a bitcoin user. I’m fascinated by the science behind it. In my open source activities, I've contributed to bitcoin trading and mining software solutions.

Bitcoin

Bitcoin is a payment system.

Bitcoin is a peer-to-peer distributed system.

It maintains the state and history of what amounts of payable asset (Bitcoin) belong to the payable entities known to the system (addresses).

Bitcoin as a Distributed System

It's not a distributed system for the sake of…

  • Scaling storage capacity
  • Scaling computation

It is a distributed system for the sake of…

  • Redundancy and fault tolerance
  • Anonymity
  • Decentralized ownership

Bitcoin as a Distributed System

What gets distributed?

The Blockchain

An append-only log of every transaction that has moved Bitcoin currency from one address to another in the Bitcoin system.

You're likely to hear ledger vs log.

A quick look at transactions:

Ken Shirriff | http://www.righto.com/
Transactions have two big requirements in order to be valid, one they spend bitcoin that from addresses that truly have access to that bitcoin thanks to previous transactions. Two, they are verifiably signed by the spending addresses' private keys. Show one on blockchain.info">

The P2P Network

From the network, a node gleans and keeps:

  • A list of IP addresses known by itself and peers.
  • New transactions that are valid per its current copy of the blockchain.

The P2P Network

A full node also maintains a copy of the blockchain.

P2P Node Discovery

  • First, check actively-maintained DNS records
  • Query IRC channels
  • Worst case scenario, use hardcoded list of nodes that were known active.
Similar to Gnutella and other p2p networks.

Consensus

The consensus algorithm attempts to solve two problems:

  • What transactions are committed to the blockchain?
  • How does new coin get injected into the system?

We want to inject new coins in a way that rewards actors contributing to the system.

Consensus gives us a perfect opportunity for this.

We can reward actors that validate and commit transactions to the blockchain.

What transactions are committed to the blockchain?

We could use the leader/follower pattern of Raft and let leaders confirm transactions.

The slides on Raft are included because the previous talk at the Austin Distributed Systems Enthusiast Meetup was on Raft.

But in Raft, we would invite race-to-leader abuse when being a leader is reward-able.

And, our nodes aren't tied to a entity we could reward (address, person, etc.)

So instead of using something like Raft, we have mining.

A miner:

Asks a node for a block of uncommitted valid txs. Adds a reward-me tx of its own to the block. Performs proof-of-work that signs block as confirmed. If able to successfully confirm block, has node broadcast it as part of blockchain.

Proof-of-Work

Bulk of the work is artificially difficult as a way to throttle the system:
while true:
    block_hash = SHA256(SHA256(EndianFlipEvery32Bits(data + nonce)))
    if block_hash < difficulty_target:
        tell everyone about our new block in the blockchain
        exit and try to generate/mine another block
    else:
        nonce = nonce + 1

Mining presents its own distributed system problem

Needing to scale computation as difficulty increases.

Miners have started participating in mining pools, working together to generate confirmed blocks.

Discussion