Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Bitcoin code analysis 8 block checksum confirmation

Shulou Source: shulou.com Published: 2022-06-01 04:38:00 10月05日 Update

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");

Tags: Transactions blocks keys checks codes steps networks nodes enter one reference loop analysis Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Apple Linux Shulou Information OPPO Reno