def get_index_range(blockchain_name, blockchain_client, impl, working_dir):
    """
    Get the range of block numbers that we need to fetch from the blockchain.
    Requires virtualchain to have been configured with setup_virtualchain() if impl=None
    
    Return None, None if we fail to connect to the blockchain
    """

    start_block = config.get_first_block_id(impl)
    try:
        current_block = get_blockchain_height(blockchain_name, blockchain_client)
    except Exception, e:
        log.exception(e)
        return None, None

    saved_block = StateEngine.get_lastblock(impl, working_dir)

    if saved_block is None:
        saved_block = 0
    elif saved_block == current_block:
        start_block = saved_block
    elif saved_block < current_block:
        start_block = saved_block + 1

    return start_block, current_block