@Test public void testDifficultyAboveBlock3MShouldTriggerExplosion() throws Exception { ByzantiumConfig byzantiumConfig = new ByzantiumConfig(new TestBlockchainConfig()); int parentDifficulty = 268_435_456; BlockHeader parent = new BlockHeaderBuilder(FAKE_HASH, 4_000_000, parentDifficulty).build(); BlockHeader current = new BlockHeaderBuilder(parent.getHash(), 4_000_001, -1).build(); int actualDifficulty = byzantiumConfig.calcDifficulty(current, parent).intValue(); int differenceWithoutExplosion = actualDifficulty - parentDifficulty; assertEquals(262_400, differenceWithoutExplosion); parent = new BlockHeaderBuilder(FAKE_HASH, 5_000_000, parentDifficulty).build(); current = new BlockHeaderBuilder(parent.getHash(), 5_000_001, -1).build(); actualDifficulty = byzantiumConfig.calcDifficulty(current, parent).intValue(); differenceWithoutExplosion = actualDifficulty - parentDifficulty; assertEquals(524_288, differenceWithoutExplosion); parent = new BlockHeaderBuilder(FAKE_HASH, 6_000_000, parentDifficulty).build(); current = new BlockHeaderBuilder(parent.getHash(), 6_000_001, -1).build(); actualDifficulty = byzantiumConfig.calcDifficulty(current, parent).intValue(); differenceWithoutExplosion = actualDifficulty - parentDifficulty; assertEquals(268_697_600, differenceWithoutExplosion); }
@Override public BigInteger calcDifficulty(BlockHeader curBlock, BlockHeader parent) { BigInteger pd = parent.getDifficultyBI(); BigInteger quotient = pd.divide(getConstants().getDIFFICULTY_BOUND_DIVISOR()); BigInteger sign = getCalcDifficultyMultiplier(curBlock, parent); BigInteger fromParent = pd.add(quotient.multiply(sign)); BigInteger difficulty = max(getConstants().getMINIMUM_DIFFICULTY(), fromParent); int explosion = getExplosion(curBlock, parent); if (explosion >= 0) { difficulty = max(getConstants().getMINIMUM_DIFFICULTY(), difficulty.add(BigInteger.ONE.shiftLeft(explosion))); } return difficulty; }
ByzantiumConfig extends Eip160HFConfig { @Override public BigInteger calcDifficulty(BlockHeader curBlock, BlockHeader parent) { BigInteger pd = parent.getDifficultyBI(); BigInteger quotient = pd.divide(getConstants().getDIFFICULTY_BOUND_DIVISOR()); BigInteger sign = getCalcDifficultyMultiplier(curBlock, parent); BigInteger fromParent = pd.add(quotient.multiply(sign)); BigInteger difficulty = max(getConstants().getMINIMUM_DIFFICULTY(), fromParent); int explosion = getExplosion(curBlock, parent); if (explosion >= 0) { difficulty = max(getConstants().getMINIMUM_DIFFICULTY(), difficulty.add(BigInteger.ONE.shiftLeft(explosion))); } return difficulty; } }
ByzantiumConfig extends Eip160HFConfig { @Override public BigInteger calcDifficulty(BlockHeader curBlock, BlockHeader parent) { BigInteger pd = parent.getDifficultyBI(); BigInteger quotient = pd.divide(getConstants().getDIFFICULTY_BOUND_DIVISOR()); BigInteger sign = getCalcDifficultyMultiplier(curBlock, parent); BigInteger fromParent = pd.add(quotient.multiply(sign)); BigInteger difficulty = max(getConstants().getMINIMUM_DIFFICULTY(), fromParent); int explosion = getExplosion(curBlock, parent); if (explosion >= 0) { difficulty = max(getConstants().getMINIMUM_DIFFICULTY(), difficulty.add(BigInteger.ONE.shiftLeft(explosion))); } return difficulty; } ByzantiumConfig(BlockchainConfig parent); }
ByzantiumConfig extends Eip160HFConfig { @Override public BigInteger calcDifficulty(BlockHeader curBlock, BlockHeader parent) { BigInteger pd = parent.getDifficultyBI(); BigInteger quotient = pd.divide(getConstants().getDIFFICULTY_BOUND_DIVISOR()); BigInteger sign = getCalcDifficultyMultiplier(curBlock, parent); BigInteger fromParent = pd.add(quotient.multiply(sign)); BigInteger difficulty = max(getConstants().getMINIMUM_DIFFICULTY(), fromParent); int explosion = getExplosion(curBlock, parent); if (explosion >= 0) { difficulty = max(getConstants().getMINIMUM_DIFFICULTY(), difficulty.add(BigInteger.ONE.shiftLeft(explosion))); } return difficulty; } ByzantiumConfig(BlockchainConfig parent); @Override Constants getConstants(); @Override BigInteger calcDifficulty(BlockHeader curBlock, BlockHeader parent); @Override BigInteger getCalcDifficultyMultiplier(BlockHeader curBlock, BlockHeader parent); @Override boolean eip198(); @Override boolean eip206(); @Override boolean eip211(); @Override boolean eip212(); @Override boolean eip213(); @Override boolean eip214(); @Override boolean eip658(); }
ByzantiumConfig extends Eip160HFConfig { @Override public BigInteger calcDifficulty(BlockHeader curBlock, BlockHeader parent) { BigInteger pd = parent.getDifficultyBI(); BigInteger quotient = pd.divide(getConstants().getDIFFICULTY_BOUND_DIVISOR()); BigInteger sign = getCalcDifficultyMultiplier(curBlock, parent); BigInteger fromParent = pd.add(quotient.multiply(sign)); BigInteger difficulty = max(getConstants().getMINIMUM_DIFFICULTY(), fromParent); int explosion = getExplosion(curBlock, parent); if (explosion >= 0) { difficulty = max(getConstants().getMINIMUM_DIFFICULTY(), difficulty.add(BigInteger.ONE.shiftLeft(explosion))); } return difficulty; } ByzantiumConfig(BlockchainConfig parent); @Override Constants getConstants(); @Override BigInteger calcDifficulty(BlockHeader curBlock, BlockHeader parent); @Override BigInteger getCalcDifficultyMultiplier(BlockHeader curBlock, BlockHeader parent); @Override boolean eip198(); @Override boolean eip206(); @Override boolean eip211(); @Override boolean eip212(); @Override boolean eip213(); @Override boolean eip214(); @Override boolean eip658();  }