Skip to content

feat(router-core): add batch route scoring#699

Merged
Maki-Zeninn merged 2 commits into
Maki-Zeninn:mainfrom
Yasir-TechGuy:fix/batch-score-recompute
Jun 27, 2026
Merged

feat(router-core): add batch route scoring#699
Maki-Zeninn merged 2 commits into
Maki-Zeninn:mainfrom
Yasir-TechGuy:fix/batch-score-recompute

Conversation

@Yasir-TechGuy

Copy link
Copy Markdown

Description

This PR addresses #635 by introducing a batch score-updating mechanism in router-core.

Previously, updating scores sequentially triggered a full $O(n)$ best-route recomputation via recompute_best_route() on every single update, causing massive CPU overhead during multi-route administrative updates.

This change adds set_route_scores_batch(), allowing administrators to submit multiple route score updates in a single transaction. The expensive recompute_best_route() function is now executed exactly once at the end of the entire batch process.

Key Changes

Types & Interfaces

  • Introduced RouteScoreInput: A new #[contracttype] struct to facilitate safe input handling for batch configurations.
  • Added set_route_scores_batch(): The core batch entry point requiring admin authentication.

🛡️ Fail-Fast & Atomic Execution

  • Implemented a two-pass architecture to prevent partial updates.
    1. Validation Pass: The function scans the entire input list first. If any route inside the batch does not exist, it aborts early and returns RouterError::RouteNotFound.
    2. Execution Pass: Once validation succeeds, the state updates are committed, events are published, and recompute_best_route is called exactly once.

Bug Fixes & Refactoring

  • Fixed overlapping discriminant values in RouterError (InvalidAddress changed from 10 to 12; RouteExpired changed from 10 to 13).
  • Cleaned up scoring module calls by using Self::recompute_best_route(&env).

Test Coverage

Added comprehensive unit tests within mod tests:

  • test_set_route_scores_batch: Verifies successful batch updates across multiple legitimate routes.
  • test_set_route_scores_batch_fails_if_route_missing: Assures atomicity by checking that if a single route name is missing, the transaction fails completely and leaves prior scores untouched.

Fixes

Fixes #635

closes #635

@drips-wave

drips-wave Bot commented Jun 26, 2026

Copy link
Copy Markdown

@Yasir-TechGuy Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Yasir-TechGuy

Copy link
Copy Markdown
Author

Hi @Maki-Zeninn Please check it out.

@Maki-Zeninn Maki-Zeninn merged commit 9b31c37 into Maki-Zeninn:main Jun 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(router-core): recompute_best_route called on every individual score change in batch operations

2 participants