.setParentHash(chain.get(commonAncestor).getHash()) .setBlockNumber(forkStart) .setDifficulty(chain.get(forkStart).getHeader().getDifficulty().minus(5L)); forkBlocks.add(gen.block(options)); .setParentHash(forkBlocks.get(0).getHash()) .setBlockNumber(forkStart + 1) .setDifficulty(UInt256.of(10L)); forkBlocks.add(gen.block(options));
.setParentHash(chain.get(commonAncestor).getHash()) .setBlockNumber(forkBlock) .setDifficulty(chain.get(forkBlock).getHeader().getDifficulty().plus(10L)); final Block fork = gen.block(options); final List<TransactionReceipt> forkReceipts = gen.receipts(fork);
.setParentHash(chain.get(commonAncestor).getHash()) .setBlockNumber(forkBlock) .setDifficulty(chain.get(forkBlock).getHeader().getDifficulty().plus(10L)) .addTransaction(overlappingTx) .addTransaction(gen.transaction());
.setParentHash(chain.get(commonAncestor).getHash()) .setBlockNumber(forkStart) .setDifficulty(chain.get(forkStart).getHeader().getDifficulty().minus(5L)); forkBlocks.add(gen.block(options)); .setParentHash(forkBlocks.get(0).getHash()) .setBlockNumber(forkStart + 1) .setDifficulty(remainingDifficultyToOutpace.plus(10L)); forkBlocks.add(gen.block(options));
.setParentHash(chain.get(commonAncestor).getHash()) .setBlockNumber(forkStart) .setDifficulty(chain.get(forkStart).getHeader().getDifficulty().minus(5L)); forkBlocks.add(gen.block(options)); .setParentHash(forkBlocks.get(0).getHash()) .setBlockNumber(forkStart + 1) .setDifficulty(chain.get(forkStart + 1).getHeader().getDifficulty().minus(5L)); forkBlocks.add(gen.block(options)); .setParentHash(chain.get(commonAncestor).getHash()) .setBlockNumber(forkStart) .setDifficulty(chain.get(forkStart).getHeader().getDifficulty().minus(5L)); final Block secondFork = gen.block(options); blockchain.appendBlock(secondFork, gen.receipts(secondFork));
final BlockDataGenerator.BlockOptions options01 = new BlockDataGenerator.BlockOptions() .setDifficulty(UInt256.ONE) .setBlockNumber(i) .setParentHash(remoteBlockchain.getBlockHashByNumber(i - 1).get());
.setDifficulty(UInt256.ONE) // differentiator .setBlockNumber(i) .setParentHash(remoteBlockchain.getBlockHashByNumber(i - 1).get());
final BlockDataGenerator.BlockOptions options01 = new BlockDataGenerator.BlockOptions() .setDifficulty(UInt256.ONE) .setBlockNumber(i) .setParentHash(remoteBlockchain.getBlockHashByNumber(i - 1).get());
final BlockDataGenerator.BlockOptions options01 = new BlockDataGenerator.BlockOptions() .setDifficulty(UInt256.ONE) .setBlockNumber(i) .setParentHash(remoteBlockchain.getBlockHashByNumber(i - 1).get());
final BlockDataGenerator.BlockOptions options01 = new BlockDataGenerator.BlockOptions() .setDifficulty(UInt256.ONE) .setBlockNumber(i) .setParentHash(remoteBlockchain.getBlockHashByNumber(i - 1).get());
.setDifficulty(UInt256.ONE) // differentiator .setBlockNumber(i) .setParentHash(remoteBlockchain.getBlockHashByNumber(i - 1).get());
@Test public void logsShouldBeFlaggedAsRemovedWhenBlockIsNotInCanonicalChain() { // create initial blockchain final BlockchainWithData data = setupBlockchain(3); final Block targetBlock = data.blockData.get(data.blockData.size() - 1).block; // check that logs have removed = false List<LogWithMetadata> logs = data.blockchainQueries.matchingLogs(targetBlock.getHash(), new LogsQuery.Builder().build()); assertThat(logs).isNotEmpty(); assertThat(logs).allMatch(l -> !l.isRemoved()); // Create parallel fork of length 1 final int forkBlock = 2; final int commonAncestor = 1; final BlockOptions options = new BlockOptions() .setParentHash(data.blockchain.getBlockHashByNumber(commonAncestor).get()) .setBlockNumber(forkBlock) .setDifficulty( data.blockchain.getBlockHeader(forkBlock).get().getDifficulty().plus(10L)); final Block fork = gen.block(options); final List<TransactionReceipt> forkReceipts = gen.receipts(fork); // Add fork data.blockchain.appendBlock(fork, forkReceipts); // check that logs have removed = true logs = data.blockchainQueries.matchingLogs(targetBlock.getHash(), new LogsQuery.Builder().build()); assertThat(logs).isNotEmpty(); assertThat(logs).allMatch(LogWithMetadata::isRemoved); }
final Block chainHead = localBlockchain.getChainHeadBlock(); final Block forkBlock = gen.block(gen.nextBlockOptions(chainHead).setDifficulty(UInt256.of(0L))); localBlockchain.appendBlock(forkBlock, gen.receipts(forkBlock));