在checkConnectBlock(...)方法中,找到了如下的判斷規(guī)則: 如果當(dāng)前處于某個(gè)checkpoint范圍內(nèi)并且當(dāng)前需要檢測(cè)的區(qū)塊高度比這個(gè)chekpoint的高度低,則認(rèn)為這是一個(gè)安全的區(qū)塊,不進(jìn)行script的校驗(yàn)。
// Don't run scripts if this node is before the latest known good
// checkpoint since the validity is verified via the checkpoints (all
// transactions are included in the merkle root hash and any changes
// will therefore be detected by the next checkpoint). This is a huge
// optimization because running the scripts is the most time consuming
// portion of block handling.
checkpoint := b.LatestCheckpoint()
runScripts := true
if checkpoint != nil && node.height <= checkpoint.Height {
runScripts = false
}
....
// 下面提到ECDSA signature 檢查是非常耗費(fèi)CPU資源的。
// Now that the inexpensive checks are done and have passed, verify the
// transactions are actually allowed to spend the coins by running the
// expensive ECDSA signature check scripts. Doing this last helps
// prevent CPU exhaustion attacks.
if runScripts {
err := checkBlockScripts(block, view, scriptFlags, b.sigCache,
b.hashCache)
if err != nil {
return err
}
}