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

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

比特币代码分析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");

相关文章

财联社10月10日讯(编辑 赵昊)当地时间周二(10月8日),美...
PANews 9月29日消息,币安前首席执行官赵长鹏在X平台发文称:...
凤凰网科技讯 3月11日,比特币报价突破71000美元,创历史新高...
赵长鹏 凤凰网科技讯 北京时间9月28日,据彭博社报道,美国当...
“前华人首富”赵长鹏的出狱时间或再提前。 Binance(币安)...
财联社5月24日讯(编辑 史正丞)当地时间周四盘后,根据一份...