Burstcoin 的 base target
按 Burstcoin 的设计,每 4 分钟出一个块,那么如果出块更快或更慢怎么办呢?就靠这个 base target 去调整啦。Base target 的值越大,难度越低,出块就越快。这个在原理上和比特币以太坊是类似的。
if (block.getId() == Genesis.GENESIS_BLOCK_ID && block.getPreviousBlockId() == 0) {
block.setBaseTarget(Constants.INITIAL_BASE_TARGET);
Block itBlock = previousBlock;
BigInteger avgBaseTarget = BigInteger.valueOf(itBlock.getBaseTarget());
do {
itBlock = downloadCache.getBlock(itBlock.getPreviousBlockId());
avgBaseTarget = avgBaseTarget.add(BigInteger.valueOf(itBlock.getBaseTarget()));
} while (itBlock.getHeight() > block.getHeight() - 4);
avgBaseTarget = avgBaseTarget.divide(BigInteger.valueOf(4));
long curBaseTarget = avgBaseTarget.longValue();
long newBaseTarget = BigInteger.valueOf(curBaseTarget).multiply(BigInteger.valueOf(difTime))
.divide(BigInteger.valueOf(240L * 4)).longValue();
代码中的 newBaseTarget 就是调整过后的 base target。
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!