温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

比特币代码分析8 区块校验和确认

发布时间:2020-07-18 03:35:33 来源:网络 阅读:604 作者:chajiuke王超 栏目:网络管理

比特币节点接收到一个区块以后,都会进行校验和确认,如下参考网络图:
比特币代码分析8 区块校验和确认

关键看看对区块中的交易进行进一步的校验代码:
1.// First transaction must be coinbase, the rest must not be
2.if (vtx.empty() || !vtx[0].IsCoinBase())

  1. return error("CheckBlock() : first tx is not coinbase");
    4.for (int i = 1; i < vtx.size(); i++)
  2. if (vtx[i].IsCoinBase())
  3. return error("CheckBlock() : more than one coinbase");
  4. 8.// Check transactions 循环检查所有的交易,这一步骤很关键,所以交易不能随便改,大家都在检查
    9.foreach(const CTransaction& tx, vtx)

  5. if (!tx.CheckTransaction())
  6. return error("CheckBlock() : CheckTransaction failed");
  7. 13.// Check proof of work matches claimed amount
    14.if (CBigNum().SetCompact(nBits) > bnProofOfWorkLimit)

  8. return error("CheckBlock() : nBits below minimum work");
    16.if (GetHash() > CBigNum().SetCompact(nBits).getuint256())
  9. return error("CheckBlock() : hash doesn't match nBits");
  10. 19.// Check merkleroot
    20.if (hashMerkleRoot != BuildMerkleTree())

  11. return error("CheckBlock() : hashMerkleRoot mismatch");
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI