Bitcoin code analysis 8 block checksum confirmation
Bitcoin node receives a block, will check and confirm, as follows:
The key is to check the transactions in the block further:
1.// First transaction must be coinbase, the rest must not be
2.if (vtx.empty() || ! vtx[0].IsCoinBase())
return error("CheckBlock() : first tx is not coinbase");
4.for (int i = 1; i
< vtx.size(); i++)if (vtx[i].IsCoinBase())return error("CheckBlock() : more than one coinbase"); 8.// Check transactions 循环检查所有的交易,这一步骤很关键,所以交易不能随便改,大家都在检查 9.foreach(const CTransaction& tx, vtx) if (!tx.CheckTransaction())return error("CheckBlock() : CheckTransaction failed"); 13.// Check proof of work matches claimed amount 14.if (CBigNum().SetCompact(nBits) >bnProofOfWorkLimit)
return error("CheckBlock() : nBits below minimum work");
16.if (GetHash() > CBigNum().SetCompact(nBits).getuint256())return error("CheckBlock() : hash doesn't match nBits");
19.// Check merkleroot
20.if (hashMerkleRoot != BuildMerkleTree())
return error("CheckBlock() : hashMerkleRoot mismatch");