Presentation is loading. Please wait.

Presentation is loading. Please wait.

刘振 上海交通大学 计算机科学与工程系 电信群楼3-509

Similar presentations


Presentation on theme: "刘振 上海交通大学 计算机科学与工程系 电信群楼3-509"— Presentation transcript:

1 刘振 上海交通大学 计算机科学与工程系 电信群楼3-509 liuzhen@sjtu.edu.cn
区块链技术 刘振 上海交通大学 计算机科学与工程系 电信群楼3-509

2 Bitcoin Consensus What data does each node store at its local storage? What does they do? fully validating nodes Complete blockchain The chain of the blockheads The transactions o the blockchain The list of UTXO (Unspent Transaction Output) To proceeds the transactions quickly Transaction Pool The node will select transactions from transaction pool and mine. lightweight nodes(Thin Clients or Simplified Payment Verification (SPV) Clients): The complete chain of the block heads They only store the pieces that they need to verify specific transactions that they care about Does not mine 完整的(共识)区块链 整条区块(头)链 区块链上的交易 还未被消费的“交易输出”列表 这个列表最好事放在内存里而非硬盘上,要用来快速判断待处理交易的有效性 交易池 收到的、待打包成块处理的交易 会从交易池收集数据、挖矿 轻量节点(轻客户端,简单付款验证,Simplified Payment Verification,SPV): 完整的区块(头)链 只存储所关心的、需要进行核验的部分交易 不挖矿

3 Bitcoin Consensus How does each node make sure that his local block chain is consistent with that of the major nodes in the system? Distributed Consensus Distributed Consensus Protocol There are n nodes that each have an input value. Some of these nodes are faulty or malicious. A distributed consensus protocol has the following two properties: It must terminate with all honest nodes in agreement on the value The value must have been generated by an honest node 协议能够终止,且此时所有诚实节点对数据达成一致 最终达成一致的数据必须是由诚实节点生成的

4 Bitcoin Consensus The target of Bitcoin consensus: Question:
At any moment, all nodes in the Bitcoin Network agrees on a series of blocks, and the transactions in these blocks. Question: A new block candidate is found and broadcast, some nodes receive and accept this new block, while others did not. What is the state? If there are multiple such blocks, what is the state? It must happens, since it is a p2p network 如果不只一个处于这样状态的区块,它们处于什么状态? 一定会有这样的(多个)区块的,因为是在一个分布式网络里、网络是异步的

5 Bitcoin Consensus 1 …… 100 101 102 1 …… 100 101 102 1 …… 100 101 102
Tx21,Tx22,Tx23 1 …… 100 101 Tx1 Tx2 102 Tx3 Tx4 Tx31,Tx32,Tx33 1 …… 100 101 Tx1 Tx2 102 Tx3 Tx4 Tx51,Tx52,Tx53 1 …… 100 101 Tx5 Tx6 102 Tx7 Tx8

6 Bitcoin Consensus Bitcoin Consensus
Who proposes the new block (the content of the blockchain)? The miners compete by computing hash, and broadcast the valid candidate to the Bitcoin Network Who decides whether the new block is accepted by whole bitcoin network? No discussion and negotiation, since the nodes does not trust each other Implicit consensus:each node makes its own decision on whether accept a new block Check the validity of the new block If accept, then uptae local blockchain by appending the new block to the current blockchain, and mine based on the updated blockchain If do not accept, still mine based on current blockchain Consensus result: If the majority nodes are `honest’, then all the nodes have the same local consensus blockchain. 谁决定被提出的块是否被整个网络接受?(对区块链的内容达成共识) 没有协商过程:各节点是互不信任的,不会互相协商 采用的是隐性共识:每个节点自己决定是否接受收到的块 检验块的有效性 如果接受,就把收到的该块作为最新块加到自己本地的区块链尾部来更新本地区块链,并在更新后的链的基础上再挖矿 如果不接受,则仍然以本地当前的区块链为基础继续挖矿 共识的结果: 系统中诚实节点占“大多数”的话,则所有节点本地的共识区块链是一致的。 诚实节点:遵循比特币协议的节点 大多数:并不是节点大多数、身份大多数等,而是“算力”大多数 所有节点达成共识:数据不与系统共识区块链一致的节点,其后继处理的交易、块等并不会被其他节点接受、纳入共识区块链。

7 Bitcoin Consensus Bitcoin Consensus
Honest Nodes:honestly executes the Bitcoin protocols Majority: not the number majority, but the computation power majority All nodes achieve consensus: If a node’s data is inconsistent with the system consensus blockchain, the transactions and blocks it proposes will be rejected by other nodes, thus cannot be added into the system blockchain. 谁决定被提出的块是否被整个网络接受?(对区块链的内容达成共识) 没有协商过程:各节点是互不信任的,不会互相协商 采用的是隐性共识:每个节点自己决定是否接受收到的块 检验块的有效性 如果接受,就把收到的该块作为最新块加到自己本地的区块链尾部来更新本地区块链,并在更新后的链的基础上再挖矿 如果不接受,则仍然以本地当前的区块链为基础继续挖矿 共识的结果: 系统中诚实节点占“大多数”的话,则所有节点本地的共识区块链是一致的。 诚实节点:遵循比特币协议的节点 大多数:并不是节点大多数、身份大多数等,而是“算力”大多数 所有节点达成共识:数据不与系统共识区块链一致的节点,其后继处理的交易、块等并不会被其他节点接受、纳入共识区块链。

8 Bitcoin Consensus Why does a node behave honestly? 比特币共识机制
Once the proposed block is accepted by whole network, the miner will obtain the block reward and transaction fee If put invalid transaction in its block, the block may be accepted by the colluding miners, but the honest miners will not accept the block, and the reward and transaction fee can not be spent. How about all colluding miners continue mining on this ‘invalid’ block? 比特币共识机制 比特币网络节点为什么要诚实? 区块被整个网络接受后能获得区块奖励和交易费:经济刺激 如果把无效的交易放到自己提出的块中,这个块虽然可以被自己以及合谋的节点纳入各自的本地链中,但其他的诚实的节点是不会接收这个含有无效的交易的块的,诚实节点挖矿时不会在这样的“无效块”的基础上挖,其中的区块奖励自然也就花不出去了 只要合谋的节点后面继续在这个“无效块”的基础上挖就行了? 在一次竞争“提出块”的过程中,赢得竞争的概率等于算力占全系统算力的百分比。 所以,“大多数”是算力大多数,而不是节点个数 如果算力占到系统总算力的大多数,以当前情况来看,在计算资源的投入上已经很大了。如果去做恶意的、不诚实的行为,会导致比特币价格下跌甚至崩溃,那么这些投入的资源、以及已经取得的比特币的价值也就随之下跌了。会这样去做吗?

9 Mining ecosystem health
Bitcoin Consensus The reason that Bitcoin consensus works is the financial incentive. Bitcoin’s Security Mining ecosystem health Bitcoin’s Price more computation power are invested to bitcoins, and more honest miners, more secure More secure, higher price 越多算力投比入到比特币系统中、越多诚实用户,比特币安全性越好 比特币价值越高,越吸引更多的算力投入到比特币挖矿、越多的用户诚实的执行比特币协议 比特币安全性越好,其价值越高 比特币共识机制的成功的根本原因:经济刺激 三者互相依赖 正向:正向促进 反向:任何一个环节出问题,会导致整个系统崩溃 比特币最初并不具备任何一个条件 比特币是幸运的,安全地度过了其脆弱的“婴儿期” 后来的AltCoin怎么办? Higher price, more computation power are invested to bitcoins, and more honest miners

10 Bitcoin Consensus PoW (Proof of Work) Implicit Consensus
When the new block will cause a fork of the blockchain, before finding a valid new block, the miner receiver two blocks with the same height, Follow the first received Tx23 1 …… 100 101 Tx1 Tx2 102 Tx21 Tx22 101 Tx5 Tx6

11 Bitcoin Consensus PoW (Proof of Work) Implicit Consensus
When the new block will cause a fork of the blockchain, before finding a valid new block, the miner receiver two blocks with the different heights, Tx23 1 …… 100 101 Tx1 Tx2 102 Tx21 Tx22 101 Tx5 Tx6 102 Tx7 Tx8

12 Bitcoin Consensus PoW (Proof of Work) Implicit Consensus
When the new block will cause a fork of the blockchain, before finding a valid new block, the miner receiver two blocks with the different heights, Follow the longest chain Tx23 1 …… 100 101 Tx1 Tx2 102 Tx21 Tx22 101 Tx5 Tx6 102 Tx7 Tx8

13 Bitcoin Consensus PoW (Proof of Work) Implicit Consensus
When the new block will cause a fork of the blockchain, before finding a valid new block, the miner receiver two blocks with the different heights, Follow the longest chain Tx23 1 …… 100 101 Tx1 Tx2 103 Tx21 Tx22 101 Tx5 Tx6 102 Tx7 Tx8

14 Bitcoin Consensus Why follow the longest chain?
Each block implies corresponding computation power has been invested on the block. Longer chain implies more computation power (nodes) accepting the chain, and implies bigger probability these blocks are accepted by the consensus blockchain. And the blocks not on the longest chain will be “discarded” (not accepted by the nodes). Tx23 1 …… 100 101 Tx1 Tx2 103 Tx21 Tx22 挖到一个块是相当困难的,每一个块都证明了有相应的算力已经“投资”在该块上,“长链”意味着有更多的算力(节点)认可了该链,最终这些块被纳入最终链的可能性更大;而不与最长链在一起的,则会被“抛弃”(网络内节点不认可) 101 Tx5 Tx6 102 Tx7 Tx8

15 Bitcoin Consensus The blocks on chain may be discarded. So, when do the blocks achieve finality and become one part of the consensus blockchain? Transaction’s Confirm times:when the block containing the transaction is broadcast to the network, the confirmation time becomes 1. Then each time the block is directly or indirectly accepted by a new block, the confirmation times increments 1. Bitcoins thinks it is safe after 6 confirmations. 1 …… 100 101 Tx1 Tx2 102 Tx11 Tx12 103 Tx21 Tx22 104 Tx31 Tx32 105 Tx41 Tx42 已经上链的也可能因为会被丢弃,什么时候才真正的被纳入最终共识链、不会再被丢弃? Alice向Bob买书、并通过比特币支付,什么时候Bob才放心给Alice发货? 交易的多次确认:包含交易的块上链是第1次确认,在这个块后每增加一个新块,确认次数加1(每多一次确认,意味着更多的算力(节点)认可了该交易) 比特币认为6次确认后,交易就无法篡改了。(除非攻击者达到算力大多数,否则,攻击者使得相应的块被丢弃的概率可忽略不计,攻击者没有能力连追6个块制造出一条更长链) 101 Tx5 Tx6 102 Tx7 Tx8

16 Transactions Block Hash  validity Block chain PoW-based Consensus
Signature  validity Block Hash  validity Block chain PoW-based Consensus

17 Bitcoin Limitations The total number of Bitcoins
The community has basically agreed that it will not change. Transaction throughput This limitation comes from the hard coded limit on the size of blocks. 1M/Block, 256bytes/Transaction, 10min/Block 7 transactions per second Visa’s network handles about 2,000 transactions per second, and capable of handling 10,000 transactions per second during busy periods. Paypal, which is newer and smaller than Visa, can handle 100 transactions per second at peak times.

18 Bitcoin Limitations The cryptographic algorithms update
The algorithms might be broken

19 Change the protocol How to introduce new features into the Bitcoin protocol? just release a new version of the software, and tell all nodes to upgrade? Hard Fork Soft Fork

20 Change the protocol Hard Fork:
The change introduces new features that were previously considered invalid the new version of the software would recognize blocks as valid that the old software would reject when most nodes have upgraded, but some have not. The longest branch will contain blocks that are considered invalid by the old nodes. The old nodes will go off and work on a branch of the block chain that excludes blocks with the new feature. Until they upgrade their software, they’ll consider their (shorter) branch to be the longest valid branch. it makes the block chain split, and it makes the block chain split.

21 Change the protocol Soft Fork:
The change adds features that make validation rules stricter. The old version would accept all of the blocks, whereas the new version would reject some. Provided that the majority of nodes switch over to the new software, these nodes will be able to enforce the new rules. There is a risk that old miners might mine invalid blocks because they include some transactions that are invalid under the new, stricter, rules. But the old nodes will at least figure out that some of their blocks are being rejected, even if they don’t understand the reason. This might prompt their operators to upgrade their software. there won’t be a hard fork; instead, there will be many small, temporary forks.

22 Change the protocol Hard Fork: Soft Fork:
Unacceptable Soft Fork: Changing the block size from 1M to 2M is hard fork or soft fork?

23 Mining Pools The variance for a small miner is quite high.

24 Mining Pools The variance for a small miner is quite high. When small business people faced a lot of risk, they formed mutual insurance companies to lower that risk. A mining pool is exactly that — mutual insurance for Bitcoin miners. A group of miners will form a pool and all attempt to mine a block with a designated coinbase recipient. That recipient is called the pool manager.

25 Mining Pools No matter who actually finds the block, the pool manager will receive the rewards. The pool manager will take that revenue and distribute it to all the participants in the pool based on how much work each participant actually performed. The pool manager will also probably take some kind of cut for their service of managing the pool.

26 Mining Pools What does the pool manager do?
What do the pool participants do?

27 Mining Pools How does a pool manager know how much work each member of the pool is actually performing? Mining Shares near‐valid blocks Miners can show these nearly valid blocks to prove that they are indeed working

28 Mining Pools How does exactly the pool manager calculates how much to pay each miner based on the shares they submit? Pay-per-share the pool manager pays a flat fee for every share above a certain difficulty for the block that the pool is working on. miners can send their shares to the pool manager right away and get paid without waiting for the pool to find a block. The pool manager essentially absorbs all of the risk. the pool manager will probably charge higher fees as compared with other models.

29 Mining Pools How does exactly the pool manager calculates how much to pay each miner based on the shares they submit? Proportional The amount of payment depends on whether or not the pool actually found a valid block. Every time a valid block is found the rewards from that block are distributed to the members proportional to how much work they actually did.

30 Mining Pools Modify the mining mechanism of Bitcoin, so that it can prevent the miners from forming a mining pool.

31 Summary Block Mining Bitcoin Network Bitcoin Consensus Protocol Change
Merkle Tree Coinbase Transaction Mining Bitcoin Network Bitcoin Consensus Protocol Change Hard fork Software fork Mining Pool


Download ppt "刘振 上海交通大学 计算机科学与工程系 电信群楼3-509"

Similar presentations


Ads by Google