def current_state(self, cluster: Cluster) -> _SyncState:
        """Find the best candidates to be the synchronous standbys.

        Current synchronous standby is always preferred, unless it has disconnected or does not want to be a
        synchronous standby any longer.

        Standbys are selected based on values from the global configuration:

            - ``maximum_lag_on_syncnode``: would help swapping unhealthy sync replica in case it stops
              responding (or hung). Please set the value high enough, so it won't unnecessarily swap sync
              standbys during high loads. Any value less or equal to ``0`` keeps the behavior backwards compatible.
              Please note that it will also not swap sync standbys when all replicas are hung.

            - ``synchronous_node_count``: controls how many nodes should be set as synchronous.

        :param cluster: current cluster topology from DCS

        :returns: current synchronous replication state as a :class:`_SyncState` object
        """
        self._handle_synchronous_standby_names_change()

        replica_list = _ReplicaList(self._postgresql, cluster)
        self._process_replica_readiness(cluster, replica_list)

        active = CaseInsensitiveSet()
        sync_confirmed = CaseInsensitiveSet()

        sync_node_count = global_config.synchronous_node_count if self._postgresql.supports_multiple_sync else 1
        sync_node_maxlag = global_config.maximum_lag_on_syncnode

        # Prefer members without nofailover tag. We are relying on the fact that sorts are guaranteed to be stable.
        for replica in sorted(replica_list, key=lambda x: x.nofailover):
            if sync_node_maxlag <= 0 or replica_list.max_lsn - replica.lsn <= sync_node_maxlag:
                if global_config.is_quorum_commit_mode:
                    # We do not add nodes with `nofailover` enabled because that reduces availability.
                    # We need to check LSN quorum only among nodes that are promotable because
                    # there is a chance that a non-promotable node is ahead of a promotable one.
                    if not replica.nofailover or len(active) < sync_node_count:
                        if replica.application_name in self._ready_replicas:
                            sync_confirmed.add(replica.application_name)
                        active.add(replica.application_name)
                else:
                    active.add(replica.application_name)
                    if replica.sync_state == 'sync' and replica.application_name in self._ready_replicas:
                        sync_confirmed.add(replica.application_name)
                    if len(active) >= sync_node_count:
                        break

        return _SyncState(
            self._ssn_data.sync_type,
            self._ssn_data.num,
            CaseInsensitiveSet() if self._ssn_data.has_star else self._ssn_data.members,
            sync_confirmed,
            active)
Find the best candidates to be the synchronous standbys.

        Current synchronous standby is always preferred, unless it has disconnected or does not want to be a
        synchronous standby any longer.

        Standbys are selected based on values from the global configuration:

            - ``maximum_lag_on_syncnode``: would help swapping unhealthy sync replica in case it stops
              responding (or hung). Please set the value high enough, so it won't unnecessarily swap sync
              standbys during high loads. Any value less or equal to ``0`` keeps the behavior backwards compatible.
              Please note that it will also not swap sync standbys when all replicas are hung.

            - ``synchronous_node_count``: controls how many nodes should be set as synchronous.

        :param cluster: current cluster topology from DCS

        :returns: current synchronous replication state as a :class:`_SyncState` object
        
patroni/postgresql/sync.py