// selects min number of batch and system witnesses that are required to fulfill witness policy.
selects min number of batch and system witnesses that are required to fulfill witness policy.
// selects min number of batch and system witnesses that are required to fulfill witness policy .
func (wp *WitnessPolicy) selectBatchAndSystemWitnesses(witnesses []*proof.Witness, 
	cfg *config.WitnessPolicyConfig, exclude ...*proof.Witness) ([]*proof.Witness, []*proof.Witness, error) {
	logger.Debugf("selecting minimum number of batch and system witnesses based on cfg[%s] and witnesses: %+v",
		cfg, witnesses)
	var eligibleBatchWitnesses []*proof.Witness
	var eligibleSystemWitnesses []*proof.Witness
	totalSystemWitnesses := 0
	totalBatchWitnesses := 0
	for _, w := range witnesses {
		logOK := checkLog(cfg.LogRequired, w.HasLog)
		switch w.Type {
		case proof.WitnessTypeBatch:
			totalBatchWitnesses++
			if logOK && !isExcluded(w, exclude...) {
				eligibleBatchWitnesses = append(eligibleBatchWitnesses, w)
			}
		case proof.WitnessTypeSystem:
			totalSystemWitnesses++
			if logOK && !isExcluded(w, exclude...) {
				eligibleSystemWitnesses = append(eligibleSystemWitnesses, w)
			}
		}
	}
	logger.Debugf("selecting minimum number of witnesses based on cfg[%s] and eligible batch%s and system witnesses%s",
		cfg, eligibleBatchWitnesses, eligibleSystemWitnesses)
	var selectedBatchWitnesses []*proof.Witness
	var commonWitnesses []*proof.Witness
	if cfg.Operator == config.AND {
		commonWitnesses = intersection(eligibleBatchWitnesses, eligibleSystemWitnesses)
	}
	if len(eligibleBatchWitnesses) != 0 {
		var err error
		selectedBatchWitnesses, err = wp.selectMinWitnesses(eligibleBatchWitnesses, cfg.MinNumberBatch,
			cfg.MinPercentBatch, totalBatchWitnesses, commonWitnesses...)
		if err != nil {
			return nil, nil, fmt.Errorf("select batch witnesses based on witnesses%s, eligible%s, exclude%s common%s, total[%d], policy[%s]: %w", 
				witnesses, eligibleBatchWitnesses, exclude, commonWitnesses, totalBatchWitnesses, cfg, err)
		}
	}
	logger.Debugf("selected %d batch witnesses: %v", len(selectedBatchWitnesses), selectedBatchWitnesses)
	selectedSystemWitnesses, err := wp.selectMinWitnesses(eligibleSystemWitnesses, cfg.MinNumberSystem,
		cfg.MinPercentSystem, totalSystemWitnesses, commonWitnesses...)
	if err != nil {
		return nil, nil, fmt.Errorf("select system witnesses based on witnesses%s, eligible%s, common%s, total[%d], policy[%s]: %w", 
			witnesses, eligibleSystemWitnesses, commonWitnesses, totalSystemWitnesses, cfg, err)
	}
	logger.Debugf("selected %d system witnesses: %v", len(selectedSystemWitnesses), selectedSystemWitnesses)
	return selectedBatchWitnesses, selectedSystemWitnesses, nil
}
func ( wp * WitnessPolicy ) selectBatchAndSystemWitnesses ( witnesses [ ] * proof . Witness , cfg * config . WitnessPolicyConfig , exclude ... * proof . Witness ) ( [ ] * proof . Witness , [ ] * proof . Witness , error ) { logger . Debugf ( " " , cfg , witnesses ) var eligibleBatchWitnesses [ ] * proof . Witness var eligibleSystemWitnesses [ ] * proof . Witness totalSystemWitnesses := 0 totalBatchWitnesses := 0 for _ , w := range witnesses { logOK := checkLog ( cfg . LogRequired , w . HasLog ) switch w . Type { case proof . WitnessTypeBatch : totalBatchWitnesses ++ if logOK && ! isExcluded ( w , exclude ... ) { eligibleBatchWitnesses = append ( eligibleBatchWitnesses , w ) } case proof . WitnessTypeSystem : totalSystemWitnesses ++ if logOK && ! isExcluded ( w , exclude ... ) { eligibleSystemWitnesses = append ( eligibleSystemWitnesses , w ) } } } logger . Debugf ( " " , cfg , eligibleBatchWitnesses , eligibleSystemWitnesses ) var selectedBatchWitnesses [ ] * proof . Witness var commonWitnesses [ ] * proof . Witness if cfg . Operator == config . AND { commonWitnesses = intersection ( eligibleBatchWitnesses , eligibleSystemWitnesses ) } if len ( eligibleBatchWitnesses ) != 0 { var err error selectedBatchWitnesses , err = wp . selectMinWitnesses ( eligibleBatchWitnesses , cfg . MinNumberBatch , cfg . MinPercentBatch , totalBatchWitnesses , commonWitnesses ... ) if err != nil { return nil , nil , fmt . Errorf ( " " , witnesses , eligibleBatchWitnesses , exclude , commonWitnesses , totalBatchWitnesses , cfg , err ) } } logger . Debugf ( " " , len ( selectedBatchWitnesses ) , selectedBatchWitnesses ) selectedSystemWitnesses , err := wp . selectMinWitnesses ( eligibleSystemWitnesses , cfg . MinNumberSystem , cfg . MinPercentSystem , totalSystemWitnesses , commonWitnesses ... ) if err != nil { return nil , nil , fmt . Errorf ( " " , witnesses , eligibleSystemWitnesses , commonWitnesses , totalSystemWitnesses , cfg , err ) } logger . Debugf ( " " , len ( selectedSystemWitnesses ) , selectedSystemWitnesses ) return selectedBatchWitnesses , selectedSystemWitnesses , nil }
selects min number of batch and system witnesses that are required to fulfill witness policy.
selects min number of batch and system witnesses that are required to fulfill witness policy .
// nolint:funlen,gocyclo,cyclop // it is possible to have 0 zero eligible batch witnesses //nolint:lll //nolint:lll