目录
3.全节点full node(fully validating node)
1.分布式的共识(distributed consensus)
3.比特币中的共识协议Consensus in Bitcoin
? ? ?本文为整理记录学习比特币的共识协议的笔记。图片清晰度可能不够高,希望这不影响您的观看体验。如果有任何错误,请随时指出,感谢您的阅读
♪ ♪ ♪ This paper is a note for documenting a consensus agreement to learn bitcoin. The picture may not be clear enough xff0c; hopefully this will not affect your viewing experience. ♪ xff0c; indicate xff0c; thank you for your reading. ♪
? ? ? ?通过某种方法,用户A获得了发行货币的权利
♪ ♪ By some method ♪ #xff0c; User A gets the right to issue money
? ? ? ?①A把钱转给B,需要有A的签名和B的地址?
♪ ♪ ♪ strong < strong > 1 strong strong > A transfers money to Bxff0c; requires A's signature and B's address?
? ? ? ?在比特币系统中,收款的地址是通过公钥推算(用B的公钥取哈希,然后经过转换得到)
♪ ♪ in the bitcoin system ♪ #xff0c; the address of the receipt is calculated by the public key ♪ #xff08; the public key of B is used to fetch Hashi #xff0c; then converted to xff09;
? ? ? ?②交易过程中,A的公钥要让B和所有节点知道
♪ ♪ strong ♪ ♪ strong < < / strong < / strong < / strong > ♪ #xff0c; A's public key to let B and all nodes know
? ? ? ?原因:验证A的签名,A用私钥签名,B用公钥验证 交易时,A要用B的公钥加密,收到后B用自己的私钥解密
♪ ♪ Reason ♪ xff1a; Authentication A xff0c; A private key signature xff0c; B public key authentication xff0c; A public key encryption xff0c; received B decrypting with its own private key
? ? ? ?③在交易中可以避免有人故意伪造A的签名:coinbase tx(左边那个框框)的输出存有A的公钥的哈希它一定要=转账交易内的A的公钥,否则交易无法进行
♪ ♪ strong
以下图片是一个铸币交易
Here's a picture of a sculptor trade.
简单解释如下图
A simple explanation is given below.
? ? ?把交易写在区块链里,然后A拿到钱后给B和C各5个比特币 该交易要有A的签名,证明是经过A同意的,同时这个交易还要说明从哪而来
♪ ♪ Write the deal in the block chain ♪ #xff0c; then A gets the money and gives B and C five bitcoins each with A's signature ♪ #xff0c; attests to A's consent ♪ #xff0c; and the transaction also shows where it comes from. ♪
? ? ?比特币系统中,每个交易都包含输入和输出两个部分
♪ ♪ #xff0c in the bitcoin system; each transaction contains
图中有两种哈希指针
There's two Haci's fingers in the picture.
? ? ?一种是连接各个区块,串起来变成一个 。一种是指向前面某个交易(图中后面的c指向前面的c)
♪ One that connects blocks ♪ #xff0c; stringed together into one. One that points to a previous transaction ♪ #xff08; the c at the back of the graph points to the cxff09;
? ? ?这二种指针说明币的来源是有记录的,同时可以防范双花攻击
♪ ♪ These two fingers show that the money comes from a record ♪ #xff0c; it also protects against double flower attacks
? ? ?double spend attack 简单来讲是,一笔钱被花了两次
♪ Doubly spend attention ♪ simply ♪ ♪ ♪ xff0c; a sum of money is spent twice
包含宏观信息
Include macro information
? ? ? ?①比特币的版本协议(version)
♪ ♪ 1 bitcoin version protocol ♪ #xff08; version)
? ? ? ?②区块链中指向前一个区块的指针(hash of previous block number)
♪ Hash of previous block number ♪
? ? ? ?③默克尔树的根哈希值(Merkle root hash)(保证块身里面的交易列表无法被篡改)
♪ ♪ 3 Merkel tree root value ♪ ♪ ♪ ♪ ♪ xff08; Merkle root Hash& #xff09; #xff08; guarantee that the list of transactions in the pieces cannot be tampered with ♪ xff09;
? ? ? ?④挖矿的难度目标域值(target)
♪ ♪ ♪ 4 difficulty area value ♪ #xff08; target)
? ? ? ?⑤随机数(nonce)
♪ ♪ ♪ 5 random numbers ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ a random number ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ a random number ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ a random number ♪ ♪ ♪ ♪ ♪ ♪ ♪ a random number ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ a random number ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ a ff ♪ ♪ ♪ ♪ ♪ ♪ a ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪
? ? ? ?⑥H(block header)≤target中这个目标域值的编码(nBits)
♪ 6H (block header) code for this target domain value ♪ ♪ ♪ ♪ 6H (block header) #xff08; nBits)
? ? ?交易列表(transaction list)
♪ ♪ list of transactions ♪ ♪ xff08; trading list ♪ xff09;
? ? ?数目少,保存区块链的所有信息,验证每一个交易
♪ ♪ small number of xff0c; all the information that keeps the block chain xff0c; authenticating every transaction ♪
? ? ?数目多,不能独立验证交易的合法性,比如是否是双花攻击
♪ ♪ The number is high ♪ #xff0c; the legitimacy of the transaction cannot be independently verified ♪ #xff0c; for example, is a double flower attack
? ? ?简单例子:分布式的哈希表(distributed hash table)
♪ ♪ Simple example ♪ #xff1a; distributed Hashi table ♪ #xff08; distributed hashtable)
? ? ?系统里有很多机器,共同维护一个全局的哈希表。此时需要取得的共识内容是key-value pair(键值对),比如有的人在a这台机器插入value pair('a'→12345),别人在另一台机器也能读出
♪ There's a lot of machines in the system ♪ ♪ xff0c; together maintaining a global Hashi watch. The consensus that needs to be reached at this point is that the key-value pair (key pair) #xff0c; for example, someone inserts a value pair (#39; a#39; ##12345) xff0c; someone else can read it in another machine.
? ? ?拓展:CAP Theorem ?
♪ ♪Span style="color: #be191c;" ♪expand ♪ ♪/span #xff1a; CAP Theorem ♪
? ? ?3个性质--C:Consistency ?A:Availability P:Partition tolerance ?
♪ ♪ three properties ♪ C: Consistency ♪ Availability P: Partition tolerance ♪
? ? ?任何一个分布式系统,比如说分布式哈希表,三个性质最多只能满足两个
♪ ♪ Any distribution system ♪ #xff0c; for example, distributional Hash table ♪ #xff0c; three properties can only satisfy two
? ? ?比特币中的共识是去中心化账本里的内容(内容由有记账权的节点决定)获得记账权方法:靠算力 (puzzle friendly),每秒钟可以试多少nonce,称为hash rate
♪ ♪ The consensus in bitcoin is to decentralize the contents of the books ♪ #xff08; content is determined by the nodes with rights ♪ ♪ xff1a ♪ ♪ how much money ♪ #xff0c; called ash rate ♪
? ? ?账户数量的多少不会影响hash rate,也不会受到女巫攻击的影响
♪ ♪ How many accounts do not affect hash ratte, nor will they be affected by witch attacks
? ? ?比特币争夺记账权的过程:挖矿mining
♪ ♪ The process of Bitcoin competing for bookkeeping ♪ ♪ ♪ xff1a; digging mine ♪
? ? ?争夺记账节点的人:矿工miner
♪ ♪ vying for account nodes ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ vying for account nodes ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ ♪ the miner ♪ ♪ ♪ ♪ the miner ♪
? ? ?女巫攻击(sybil attack):在投票中,故意弄出超过总数一半的账号,操纵投票结构
♪ ♪ witch attack (sybil attack): in the vote ♪ #xff0c; deliberately deposing more than half of the accounts ♪ ♪ xff0c; manipulation of voting structures
? ? ?存在的原因:在比特币系统中,某些节点可能是有恶意的
♪ ♪ The cause of existence ♪ ♪ xff1a; in the bitcoin system ♪ ♪ ♪ ♪ xff0c; some nodes may be malicious
? ? ?存在恶意节点如何设置共识协议:按照算力来决定,每个节点都可以在本地组装出一个候选区块把它认为合法的交易放进,然后开始尝试nonce值。成功的获得记账权
♪ ♪ How to set a consensus agreement ♪ #xff1a ♪ where there are malicious nodes ♪ #xff0c ♪ based on arithmetic; each node can assemble a candidate block locally and place it in #xff0c; then start trying noce. Successfully earned rights to account.
如下图
Here's the figure.
? ? ?如果两个节点同时获得记账权,会出现两个等长的分叉 。此时,该接收哪个呢?
♪ ♪ ♪ If two nodes are given rights to account at the same time ♪xff0c; there will be two long splits. ♪ #xff0c; which one to receive #xff1f;
? ? ?比特币缺省情况下,每个节点接收自己最早收到的那个节点,不同节点根据在网络中位置的不同
♪ ♪ Bitcoin default ♪ #xff0c; each node receives the first node ♪ #xff0c; different nodes depend on their location in the network
? ? ?接受/不接收区块 接收区块:沿着你的区块往下继续扩展。不接收则反之
♪ ♪ Accept/not receive blocks ♪ #xff1a; continue to expand down your blocks.
? ? ?出现两个节点同时获得记账权的情况,这种等长的临时性的分叉会维持一段时间,直到某个节点胜出 胜出的是最长合法链,输掉的是orphan block,会被丢弃掉
♪ ♪ There's a situation where two nodes are given the right to account at the same time ♪ #xff0c; this kind of long temporary split lasts for some time ♪ #xff0c; until a certain node is won, the longest legal chain ♪ #xff0c; lost is orphan Block #xff0c; abandoned
? ? ?获得记账权的节点可以决定哪些交易被写进下一个区块。但是比特币想要合法的交易都可以被写进。比特币协议中就规定获得记账权的节点在发布的区块里,可以有一个特殊的交易(铸币交易),在该交易里可以发布一定数量的比特币
♪ ♪ The node to get rights to account can determine which transactions are written into the next block. ♪ But any transaction that Bitcoin wants to be legal can be written. ♪ #xff0c in the bitcoin agreement provides for the right to account in the published block ♪ #xff08; #xff09; #xff0c; a certain amount of bitcoins can be issued in the transaction
? ? ?铸币交易是比特币系统中发行新的比特币的东西
♪ The sedentary deal is the new bitcoin issue in the bitcoin system
? ? ?唯一方法:最初每次能造50比特币(初次奖励),但在21万比特币后,奖励减半
♪ ♪ The only method ♪ #xff1a; initially 50 bits of xff08; first reward ♪ #xff09; xff0c; but halved after 210,000 bits of xff0c;
注册有任何问题请添加 微信:MVIP619 拉你进入群
打开微信扫一扫
添加客服
进入交流群
发表评论