Skip to content

Conversation

@ChipKlutzy
Copy link
Contributor

Problem

The query_pools function had a critical bug where it would attempt to load defunct pools from ACTIVE_POOLS storage, causing queries to fail when defunct pools existed in the system. The function also had inefficient pagination logic that could result in incomplete results when pools were missing from the active pools storage.

Solution

This PR refactors the query_pools function to:

  1. Skip defunct pools gracefully: Uses may_load() instead of load() to handle cases where pools might not exist in ACTIVE_POOLS storage (i.e., defunct pools)
  2. Improve pagination logic: Implements proper pagination that continues searching until the requested limit is reached, rather than stopping at a fixed range
  3. Maintain correct pool ordering: Ensures pools are returned in the correct order while skipping defunct ones

Key Changes

  • contracts/vault/src/contract.rs:
    • Refactored query_pools function to use may_load() and proper pagination logic
    • Added counter-based limit enforcement instead of range-based approach
    • Minor formatting improvements

Testing

  • contracts/vault/tests/query_pools.rs: Added comprehensive test suite covering:
    • Basic pool querying functionality
    • Pagination with various limits and start_after values
    • Defunct pool handling scenarios
    • Edge cases (empty results, limits, boundary conditions)
    • Mixed scenarios with both active and defunct pools

Artifacts Updated

  • Updated dexter_vault.wasm with the fixed contract
  • Updated corresponding checksum in checksums.txt

Impact

This fix ensures that pool queries work reliably even when defunct pools exist in the system, preventing query failures and improving the overall robustness of the vault contract.

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.

2 participants