Block Chain
A protocol view
fanfeilong@outlook.com
Block Chain Protocol
A
C
B
A P2P network, the detail of P2P network will be ignored in this document,
since it is another topic.
D
Block Chain Protocol
A
C
B
A creates a block with 10 virtual currency (or anything you can imagine)
H1:10@A
D
Block Chain Protocol
A
C
B
A broadcasts this block to the P2P network
H1:10@A
D
Block Chain Protocol
A
C
B
A,B,C in the P2P network will all have the block chain
H1:10@A
H1:10@A
H1:10@A
D
H1:10@A
Block Chain Protocol
A
C
B
A try to transfer 5 to D, A broadcasts a transaction message to the P2P network
5@(A->D),5@A
H1:10@A
H1:10@A
H1:10@A
D
H1:10@A
Block Chain Protocol
A
C
B
B and C Receive the transaction message
5@(A->D),5@A
5@(A->D),5@A
5@(A->D),5@A
H1:10@A
H1:10@A
H1:10@A
D
H1:10@A
Block Chain Protocol
A
C
B
B and C validate the message by both block chain and the transaction message.
In fact, the verify process use the RSA algorithm and P2PKH scripts or P2SH scripts which is so
called smart-contract.
5@(A->D),5@A
5@(A->D),5@A
5@(A->D),5@A
H1:10@A
H1:10@A
H1:10@A
D
H1:10@A
Block Chain Protocol
A
C
B
B and C combine the block chain and transaction to create a new block
Both B and C are doing a Proof Of Work(POW) to calculate a new hash value
which SHOULD match some condition, it’s not easy and time consuming.
B and C are both try to reward himself by 1.
H1,H2:5@(A->D),1@C
5@(A->D),5@A
H1:10@A
H1:10@A
H1:10@A
H1,H3:5@(A->D),1@B
D
H1:10@A
A new block always
contains thousands
of new transactions,
here we just add a
new one for
demonstrate!
Block Chain Protocol
A
C
B
B and C are both broadcasts the new block to the P2P network,
the Proof Of Work will ensure that the P2P network can product
a new block every ten minutes on average . So, B may be faster than C.
5@(A->D),5@A
H1:10@A
H1:10@A
H1:10@A
D
H1:10@A
H1,H2:5@(A->D),1@C
H1,H3:5@(A->D),1@B
Block Chain Protocol
A
C
B
Assuming that B’s block is first accepted by more than half of nodes in the P2P network,
and the node D receive 5 from A.
NOTE: Proof Of Work(POW) is important, which ensures the eventual consistency of the block chain.
5@(A->D),5@A
H1:10@A
H1:10@A
H1:10@A
D
H1:10@A
H1,H2:5@(A->D),1@C
H1,H3:5@(A->D),1@B
Block Chain Protocol
A
C
B
And then C’s block will be discarded
5@(A->D),5@A
H1:10@A
H1:10@A
H1:10@A
D
H1:10@A
H1,H2:5@(A->D),1@C
H1,H3:5@(A->D),1@B
H1,H3:5@(A->D),1@B
H1,H3:5@(A->D),1@B
H1,H3:5@(A->D),1@B
Block Chain Protocol
A
C
B
H1:10@A
H1:10@A
H1:10@A
D
H1:10@A
H1,H3:5@(A->D),1@B
H1,H3:5@(A->D),1@B
H1,H3:5@(A->D),1@B
H1,H3:5@(A->D),1@B
B win the 1
Block Chain Protocol
A
C
B
H1:10@A
H1:10@A
H1:10@A
D
H1:10@A
H1,H3:5@(A->D),1@B
H1,H3:5@(A->D),1@B
H1,H3:5@(A->D),1@B
H1,H3:5@(A->D),1@B
If A try to spend the old 10 again, it will be rejected by most nodes
Since all nodes can use the block chain to verify A’s assets.
And the block chain contains all transaction records.
5@(A->B),5@A
Double spend
A
C
B
5@(A->D),5@A
H1:10@A
H1:10@A
H1:10@A
D
H1:10@A
5@(A->B),5@A
Coming later
Double spend
A
C
B
5@(A->D),5@A
H1:10@A
H1:10@A
H1:10@A
D
H1:10@A
5@(A->B),5@A
5@(A->B),5@A
5@(A->D),5@A
5@(A->D),5@A
Double spend
A
C
B
5@(A->D),5@A
H1:10@A
H1:10@A
H1:10@A
D
H1:10@A
5@(A->B),5@A
5@(A->B),5@A
5@(A->D),5@A
5@(A->D),5@A
Double spend
A
C
B
5@(A->D),5@A
H1:10@A
H1:10@A
H1:10@A
D
H1:10@A
5@(A->B),5@A
H1,H3:5@(A->D),1@B
H1,H2:5@(A->D),1@C
H1,H2:5@(A->B),1@D
E
H1:10@A
Double spend
A
C
B
5@(A->D),5@A
H1:10@A
H1:10@A
H1:10@A
D
H1:10@A
5@(A->B),5@A
H1,H3:5@(A->D),1@B
H1,H2:5@(A->D),1@C
H1,H2:5@(A->B),1@D
E
H1:10@A
Double spend
A
C
5@(A->D),5@A
H1:10@A
H1:10@A
D
H1:10@A
5@(A->B),5@A
H1,H2:5@(A->D),1@C
H1,H2:5@(A->B),1@D
E
H1:10@A
H1,H2:5@(A->B),1@D
B
H1:10@A
H1,H2:5@(A->D),1@C
H1,H2:5@(A->D),1@C
Double spend
A
C
H1:10@A
H1:10@A
D
H1:10@A
H1,H2:5@(A->D),1@C
H1,H2:5@(A->B),1@D
E
H1:10@A
H1,H2:5@(A->B),1@D
B
H1:10@A
H1,H2:5@(A->D),1@C
H1,H2:5@(A->D),1@C
Double spend
A
C
H1:10@A
H1:10@A
D
H1:10@A
H1,H2:5@(A->D),1@C
H1,H2:5@(A->B),1@D
E
H1:10@A
H1,H2:5@(A->B),1@D
B
H1:10@A
H1,H2:5@(A->D),1@C
H1,H2:5@(A->D),1@C
H2,H3:…,1@A
Double spend
A
C
H1:10@A
H1:10@A
D
H1:10@A
H1,H2:5@(A->D),1@C
H1,H2:5@(A->B),1@D
E
H1:10@A
H1,H2:5@(A->B),1@D
B
H1:10@A
H1,H2:5@(A->D),1@C
H1,H2:5@(A->D),1@C
H2,H3:…,1@A
H2,H3:…,1@A
H2,H3:…,1@A
H2,H3:…,1@A
H2,H3:…,1@A
Now, E and D have branches
Double spend
A
C
H1:10@A
H1:10@A
D
H1:10@A
H1,H2:5@(A->D),1@C
H1,H2:5@(A->B),1@D
E
H1:10@A
H1,H2:5@(A->B),1@D
B
H1:10@A
H1,H2:5@(A->D),1@C
H1,H2:5@(A->D),1@C
H2,H3:…,1@A
H2,H3:…,1@A
H2,H3:…,1@A
H2,H3:…,1@A
H2,H3:…,1@A
H3, H4:…,1@E
E will choose the longest branch to create new block
Double spend
A
C
H1:10@A
H1:10@A
D
H1:10@A
H1,H2:5@(A->D),1@C
E
H1:10@A
B
H1:10@A
H1,H2:5@(A->D),1@C
H1,H2:5@(A->D),1@C
H2,H3:…,1@A
H2,H3:…,1@A
H2,H3:…,1@A
H2,H3:…,1@A
H2,H3:…,1@A
H3, H4:…,1@E
coverage
H3, H4:…,1@E
H3, H4:…,1@E
H3, H4:…,1@E
H3, H4:…,1@E
H1,H2:5@(A->D),1@C
H1,H2:5@(A->D),1@C