class BlockchainBranchComparator {

    public BlockFork calculateFork(Block fromBlock, Block toBlock) {
        List<Block> oldBlocks = new LinkedList<>();
        List<Block> newBlocks = new LinkedList<>();

        Block oldBlock = fromBlock;
        Block newBlock = toBlock;

        if (oldBlock.isParentOf(newBlock)) {
            newBlocks.add(newBlock);
            return new BlockFork(oldBlock, oldBlocks, newBlocks);
        }

        while (newBlock.getNumber() > oldBlock.getNumber()) {
            newBlocks.add(0, newBlock);
            newBlock = blockStore.getBlockByHash(newBlock.getParentHash().getBytes());
        }

        while (oldBlock.getNumber() > newBlock.getNumber()) {
            oldBlocks.add(0, oldBlock);
            oldBlock = blockStore.getBlockByHash(oldBlock.getParentHash().getBytes());
        }

        while (!oldBlock.getHash().equals(newBlock.getHash())) {
            newBlocks.add(0, newBlock);
            newBlock = blockStore.getBlockByHash(newBlock.getParentHash().getBytes());
            oldBlocks.add(0, oldBlock);
            oldBlock = blockStore.getBlockByHash(oldBlock.getParentHash().getBytes());
        }

        return new BlockFork(oldBlock, oldBlocks, newBlocks);
    }

    public  BlockchainBranchComparator(BlockStore blockStore);

}