<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def sync_virtualchain(blockchain_opts, last_block, state_engine, expected_snapshots={}, tx_filter=None ):
 """ Synchronize the virtual blockchain state up until a given block. Obtain the operation sequence from the blockchain, up to and including last_block. That is, go and fetch each block we haven't seen since the last call to this method, extract the operations from them, and record in the given working_dir where we left off while watching the blockchain. Store the state engine state, consensus snapshots, and last block to the working directory. Return True on success Return False if we're supposed to stop indexing Abort the program on error. The implementation should catch timeouts and connection errors """


    rc = False
    start = datetime.datetime.now()
    while True:
        try:

            # advance state
            rc = indexer.StateEngine.build(blockchain_opts, last_block + 1, state_engine, expected_snapshots=expected_snapshots, tx_filter=tx_filter )
            break
        
        except Exception, e:
            log.exception(e)
            log.error("Failed to synchronize chain; exiting to safety")
            os.abort()

    time_taken = "%s seconds" % (datetime.datetime.now() - start).seconds
    log.info(time_taken)

    return rc