Skip to content

Conversation

@prajjwalkumar17
Copy link
Member

@prajjwalkumar17 prajjwalkumar17 commented Jul 2, 2025

Description

This PR introduces support for a new routing algorithm variant: DefaultFallback. The purpose of this routing type is to provide a simple, last-resort fallback mechanism when no other routing logic matches or is applicable.

The following updates are included:

  • Added a new variant DefaultFallback in the RoutingType, Output, and StaticRoutingAlgorithm enums.
  • Implemented logic in the Euclid interpreter to handle DefaultFallback by returning the provided connectors directly as eligible connectors.
  • Integrated evaluation support in the routing_evaluate handler.
  • Updated format_output to support serialization of DefaultFallback for API responses.
  • Adjusted rule validation utility to allow DefaultFallback algorithms to pass without evaluation.

Outcomes

  • Enables merchant configurations to specify a static fallback connector list to be used when advanced routing fails or yields no result.
  • Helps improve system reliability and guarantees at least one connector path is available.
  • Keeps evaluation logic modular and easily extensible.

Diff Hunk Explanation

src/euclid/ast.rs

  • Added DefaultFallback as a new variant in RoutingType and Output enums.

src/euclid/types.rs

  • Added DefaultFallback(Vec<ConnectorInfo>) to the StaticRoutingAlgorithm enum.

src/euclid/handlers/routing_rules.rs

  • Handled routing evaluation logic for the new DefaultFallback algorithm.
  • Updated the output formatting (format_output) for DefaultFallback.

src/euclid/interpreter.rs

  • Implemented direct passthrough logic for evaluate_output when using DefaultFallback.

src/euclid/utils.rs

  • Updated validate_routing_rule to accept DefaultFallback as a valid static routing configuration.

This PR is linked to Issue #101 and provides the implementation required to resolve it.

@prajjwalkumar17 prajjwalkumar17 self-assigned this Jul 2, 2025
Copilot AI review requested due to automatic review settings July 2, 2025 10:39
@prajjwalkumar17 prajjwalkumar17 added the rust Pull requests that update rust code label Jul 2, 2025
@prajjwalkumar17 prajjwalkumar17 linked an issue Jul 2, 2025 that may be closed by this pull request
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds a new DefaultFallback routing algorithm to provide a fallback set of connectors for transactions.
Key changes:

  • Introduced DefaultFallback(Vec<ConnectorInfo>) in StaticRoutingAlgorithm, AST enums, and Output.
  • Updated validate_routing_rule and evaluate_output to handle the new variant.
  • Enhanced the routing handler and output formatter to support DefaultFallback.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/euclid/utils.rs Accept DefaultFallback in validate_routing_rule
src/euclid/types.rs Added DefaultFallback variant to StaticRoutingAlgorithm
src/euclid/interpreter.rs Implemented evaluate_output arm for DefaultFallback
src/euclid/handlers/routing_rules.rs Handled DefaultFallback in routing_evaluate and JSON
src/euclid/ast.rs Included DefaultFallback in RoutingType and Output
Comments suppressed due to low confidence (3)

src/euclid/handlers/routing_rules.rs:648

  • There are no existing tests verifying the behavior of the new DefaultFallback in routing_evaluate or format_output. Please add unit tests to cover both success and failure paths for this variant.
        Output::DefaultFallback(connectors) => {

src/euclid/types.rs:50

  • Public API surface was extended with DefaultFallback. Consider adding or updating doc comments in this enum (and any user-facing docs) to explain when and how this fallback is applied.
    DefaultFallback(Vec<ConnectorInfo>),

src/euclid/handlers/routing_rules.rs:591

  • [nitpick] The error context only includes the algorithm’s to_string() output. It may be more helpful to include the connector list or a descriptive message (e.g., number of fallback connectors) to aid debugging.
                    EuclidErrors::FailedToEvaluateOutput(format!(

vec![first_connector.unwrap_or_default()],
))
}
Output::DefaultFallback(connectors) => Ok((connectors.clone(), connectors.to_vec())),
Copy link

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cloning the connectors vector twice causes two allocations. You can clone once and reuse the result, e.g. let cloned = connectors.clone(); Ok((cloned.clone(), cloned)) to reduce overhead.

Suggested change
Output::DefaultFallback(connectors) => Ok((connectors.clone(), connectors.to_vec())),
Output::DefaultFallback(connectors) => {
let cloned = connectors.clone();
Ok((cloned.clone(), cloned))
},

Copilot uses AI. Check for mistakes.
match &rule.algorithm {
StaticRoutingAlgorithm::Single(_)
| StaticRoutingAlgorithm::Priority(_)
| StaticRoutingAlgorithm::DefaultFallback(_)
Copy link

Copilot AI Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DefaultFallback variant is always considered valid, even if its connector list is empty. Consider adding a check to ensure the fallback list is non-empty to prevent downstream runtime errors.

Suggested change
| StaticRoutingAlgorithm::DefaultFallback(_)
| StaticRoutingAlgorithm::DefaultFallback(connectors) => {
if connectors.is_empty() {
return Err(EuclidErrors::InvalidRequest(
"DefaultFallback connector list cannot be empty".to_string(),
)
.into());
}
Ok(())
}

Copilot uses AI. Check for mistakes.
@prajjwalkumar17 prajjwalkumar17 added the Euclid This label refers to the domains owned by PL-v2 routing (euclid). label Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Euclid This label refers to the domains owned by PL-v2 routing (euclid). rust Pull requests that update rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: add support for creator based fallback

2 participants