code: def borrow_readwrite_instance(cls, working_dir, block_number, expected_snapshots={}):
          
  
          global blockstack_db, blockstack_db_lastblock, blockstack_db_lock
  
          import virtualchain_hooks
          db_path = virtualchain.get_db_filename(virtualchain_hooks, working_dir)
          
          blockstack_db_lock.acquire()
  
          try:
              assert blockstack_db is None, "Borrowing violation"
          except Exception, e:
              log.exception(e)
              log.error("FATAL: Borrowing violation")
              os.abort()
  
          db = BlockstackDB(db_path, DISPOSITION_RW, working_dir, get_genesis_block(), expected_snapshots=expected_snapshots)
          rc = db.db_setup()
          if not rc:
              db.close()
              blockstack_db_lock.release()
              log.error("Failed to set up virtualchain state engine")
              return None
  
          blockstack_db = db
          blockstack_db_lastblock = block_number
          blockstack_db_lock.release()
  
          return blockstack_db
docs: Get a read/write database handle to the blockstack db.
          At most one such handle can exist within the program.
  
          When the caller is done with the handle, it should call release_readwrite_instance()
  
          Returns the handle on success
          Returns None if we can't set up the db.
          Aborts if there is another read/write handle out there somewhere.