def _update_sid_to_last_existing_pid_map(pid):
    """Set chain head PID to the last existing object in the chain to which ``pid``
    belongs. If SID has been set for chain, it resolves to chain head PID.

    Intended to be called in MNStorage.delete() and other chain manipulation.

    Preconditions:
    - ``pid`` must exist and be verified to be a PID.
      d1_gmn.app.views.asserts.is_existing_object()

    """
    last_pid = _find_head_or_latest_connected(pid)
    chain_model = _get_chain_by_pid(last_pid)
    if not chain_model:
        return
    chain_model.head_pid = d1_gmn.app.did.get_or_create_did(last_pid)
    chain_model.save()