[补丁] 自动验证区块

中本聪SN-2468

那是个麻烦的办法。

That's a difficult approach.

我们需要触发一次重组,把无效链断开。

We need to cause a reorg, which will disconnect the invalid chain.

这段代码很少有机会得到测试,而且相当复杂,所以简单安全的做法最好。

This is code that will rarely ever get tested, and is fairly intricate, so something simple and safe is best.

我的想法是这样。(还没测试过)它检查主链上的所有区块。发现坏的,就把那条链的 bnChainWork 全部置 0,让它无法再成为最佳链,并把最佳链工作量降为分叉点处的值,这样分叉点之后的任何新区块都会触发重组。(不真正做一次重组,它改不了 pindexBest)

Here's what I was thinking of. (I haven't tested this yet) It checks all the blocks in the main chain. If it finds a bad one, it sets all that chain's bnChainWork to 0 so it can't win best chain again, and it reduces best chain work to the fork level so any new block after the fork will cause a reorg. (It can't change pindexBest without actually doing a reorg)

这还不完善。它仍需要收到一个有效区块来触发重组。

This isn't perfect yet. It still needs to receive one valid block to trigger the reorg.

也许可以在检查之后主动调用 AddToBlockIndex 或 Reorganize,但那需要更细致的推敲。我大概应该把 AddToBlockIndex 里设置新的最佳区块的那部分代码拆出来。我最后很可能用那个做法,而非下面的代码。

It would probably be possible to initiate an AddToBlockIndex or Reorganize after the check, but it would require a lot more careful attention. I probably should break out part of AddToBlockIndex that sets the new best block. I'll probably end up doing that instead of the code below.

bool CTxDB::LoadBlockIndex()
{
    ...

    // Verify blocks in the main chain
    vector<CBlockIndex*> vChain;
    for (CBlockIndex* pindex = pindexBest; pindex && pindex->pprev; pindex = pindex->pprev)
    {
        vChain.push_back(pindex);
        CBlock block;
        if (!block.ReadFromDisk(pindex))
            return error("LoadBlockIndex() : block.ReadFromDisk failed");
        if (!block.CheckBlock())
        {
            bnBestChainWork = pindex->pprev->bnChainWork;
            foreach(CBlockIndex* pindex2, vChain)
                pindex2->bnChainWork = 0;
        }
    }

    return true;
}
译文校对、修订与纠错

当前版本尚未建立逐条校对状态记录。来源核验、历史审校与当前译文校对是不同事项。

查看历史审校与代表修订 →

译文内容版本:44dbb7d38e17。用于比对文本,不代表校对等级或更新时间。

准备纠错说明

请填写对应原文、现译文、建议译法和理由。复制后通过你联系本站作者的渠道提交;此处不会自动发送。

来源
英文原标题

[PATCH] Automatic block validation

Bitcointalk · 原始链接 ↗ 记录编号 SN-2468

阅读字号

选择适合你的字号,之后阅读会继续使用。