比特币源码分析(十二) - 数据目录维护(data directory maintenance)

接下来主要是分析Bitcoin Core初始化中的数据目录维护过程,对应的源码是src/init.cpp的AppInitMain()方法的Step 9: data directory maintenance这部分,详见:https://github.com/bitcoin/bitcoin/blob/v0.16.1/src/init.cpp

    // ********************************************************* Step 9: data directory maintenance

    // if pruning, unset the service bit and perform the initial blockstore prune
    // after any wallet rescanning has taken place.
    if (fPruneMode) {
        LogPrintf("Unsetting NODE_NETWORK on prune mode\n");
        nLocalServices = ServiceFlags(nLocalServices & ~NODE_NETWORK);
        if (!fReindex) {
            uiInterface.InitMessage(_("Pruning blockstore..."));
            PruneAndFlush();
        }
    }

    if (chainparams.GetConsensus().vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout != 0) {
        // Only advertise witness capabilities if they have a reasonable start time.
        // This allows us to have the code merged without a defined softfork, by setting its
        // end time to 0.
        // Note that setting NODE_WITNESS is never required: the only downside from not
        // doing so is that after activation, no upgraded nodes will fetch from you.
        nLocalServices = ServiceFlags(nLocalServices | NODE_WITNESS);
    }

源码主要是两大逻辑:修剪区块数据文件 和 隔离见证兼容性处理。

修剪区块数据文件

如果实在Prune Mode模式下,并且fReindex为fasle,则开始修剪区块数据文件,并更新状态到磁盘中。

隔离见证激活的兼容性处理

通过这种处理方式可以避免软分叉。

发布了496 篇原创文章 · 获赞 88 · 访问量 72万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览