private BlockHeader getParentHeader(final BlockData blockData, final List<Block> importedBlocks) {
    if (blockData.getParentHash().isPresent()) {
      final Hash parentHash = blockData.getParentHash().get();
      return controller
          .getProtocolContext()
          .getBlockchain()
          .getBlockHeader(parentHash)
          .orElseThrow(
              () -> new IllegalArgumentException("Unable to locate block parent at " + parentHash));
    }

    if (importedBlocks.size() > 0 && blockData.getNumber().isPresent()) {
      final long targetParentBlockNumber = blockData.getNumber().get() - 1L;
      final Optional<BlockHeader> maybeHeader =
          importedBlocks.stream()
              .map(Block::getHeader)
              .filter(h -> h.getNumber() == targetParentBlockNumber)
              .findFirst();
      if (maybeHeader.isPresent()) {
        return maybeHeader.get();
      }
    }

    final long blockNumber;
    if (blockData.getNumber().isPresent()) {
      blockNumber = blockData.getNumber().get() - 1L;
    } else if (importedBlocks.size() > 0) {
      // If there is no number or hash, import blocks in order
      blockNumber = importedBlocks.get(importedBlocks.size() - 1).getHeader().getNumber();
    } else {
      blockNumber = BlockHeader.GENESIS_BLOCK_NUMBER;
    }

    if (blockNumber < BlockHeader.GENESIS_BLOCK_NUMBER) {
      throw new IllegalArgumentException("Invalid block number: " + (blockNumber + 1));
    }

    return controller
        .getProtocolContext()
        .getBlockchain()
        .getBlockHeader(blockNumber)
        .orElseThrow(
            () -> new IllegalArgumentException("Unable to locate block parent at " + blockNumber));
  }
Import chain.

@param chainJson the chain json
@throws IOException the io exception
app/src/main/java/org/hyperledger/besu/chainimport/JsonBlockImporter.java