def update_leases(transform, persistence_service):
    """
    Update the leases configuration in the persistence service.

    :param transform: A function to execute on the currently configured
        leases to manipulate their state.
    :param persistence_service: The persistence service to which the
        updated configuration will be saved.

    :return Deferred: Fires with the new ``Leases`` instance when the
        persistence service has saved.
    """
    config = persistence_service.get()
    new_config = config.set("leases", transform(config.leases))
    d = persistence_service.save(new_config)
    d.addCallback(lambda _: new_config.leases)
    return d