Skip to content

geewallet bug 320 #376

Open
Open

Description

@knocte

This bug nblockchain/geewallet#320 needs attention.

Activity

  1. deleted a comment from nodefect on Sep 27, 2026
  2. knocte commented on Sep 27, 2026

    @knocte
    MemberAuthor

    /pi please analyze geewallet bug 320 (nblockchain/geewallet#320), and then analyze geewallet source code (cloning it from https://github.com/nblockchain/geewallet/ , preferably the stable branch because this is where the bugfix will land). Don't code yet a fix for the bug, just tell me possible ways to fix it. Elaborate different approaches for me to choose the best one.

  3. nodefect commented on Sep 27, 2026

    @nodefect
    Contributor

    After analyzing the issue geewallet #320 and the geewallet source code, I have identified the cause of the bug and several potential ways to fix it.

    Analysis of the Bug

    The bug occurs when FaultTolerantParallelClient is used with the OneServerConsistentWithCertainValueOrTwoServers consistency mode, typically during balance checks.

    1. FaultTolerantParallelClient Logic:

      • The WhenSomeInternal function collects results from parallel jobs.
      • When a new result is obtained, it calls MeasureConsistency to count occurrences of each result.
      • If OneServerConsistentWithCertainValueOrTwoServers is used, it returns a ConsistentResult if:
        a) The new result matches a "certain value" (e.g., cached balance).
        b) There are at least two consistent results (even if they don't match the cached value).
      • If no consistent result is found yet, and there are still tasks running or jobs to launch, it continues waiting.
      • If all jobs have finished and no consistency was reached, it returns InconsistentOrNotEnoughResults.
    2. Inconsistency Handling:

      • In QueryInternalImplementation, if the result is InconsistentOrNotEnoughResults, it checks how many successful results were obtained.
      • If some results were obtained, it attempts to wrap the settings to throw a ResultInconsistencyException or NotEnoughAvailableException.
      • It currently uses a "HACK" (line 618 of FaultTolerantParallelClient.fs) that converts OneServerConsistentWithCertainValueOrTwoServers into SpecificNumberOfConsistentResponsesRequired 2u for the purpose of generating the exception.
    3. The Crash:

      • The crash reported in the issue (System.ArgumentException: number of funcs must be equal or higher than numberOfConsistentResponsesRequired) happens because when it retries due to inconsistency, it uses the wrapped settings (SpecificNumberOfConsistentResponsesRequired 2u) but might have fewer than 2 servers available to query (e.g., if some servers were discarded or if the total number of servers for that currency is 1).

    Proposed Approaches for Fix

    Here are three ways to fix this, ranging from surgical to more architectural:

    Approach 1: Fix the Hack in QueryInternalImplementation

    Modify the retry logic in QueryInternalImplementation to be aware of the OneServerConsistentWithCertainValueOrTwoServers mode instead of blindly wrapping it to 2u. If the total number of available servers is less than 2, it should either:

    • Downgrade the requirement to 1 (risky for consistency).
    • Correctly throw a NotEnoughAvailableException instead of letting the ArgumentException trigger during the retry call.

    Pros: Low risk, localized change.
    Cons: Keeps the "hacky" wrapping logic.

    Approach 2: Validate Server Count before Wrapping

    In QueryInternalImplementation, before calling QueryInternalImplementation recursively for a retry, check if the number of available funcs is at least as many as numberOfConsistentResponsesRequired. If not, throw NotEnoughAvailableException immediately.

    Pros: Prevents the ArgumentException by providing a more meaningful domain exception.
    Cons: Still relies on the 2u wrapping which might not be strictly correct for all modes.

    Approach 3: Implement Proper Exception Handling for the New Mode

    Instead of the HACK that converts the mode to SpecificNumberOfConsistentResponsesRequired 2u, add explicit support for OneServerConsistentWithCertainValueOrTwoServers in the exception generation logic. This would involve:

    1. Removing the HACK at line 618.
    2. Adding a match arm for OneServerConsistentWithCertainValueOrTwoServers in the exception handling section (around line 628).
    3. Ensuring that if a retry is triggered, it uses the original consistency settings rather than the wrapped ones.

    Pros: Cleanest architecture, removes technical debt ("HACK" comment).
    Cons: Slightly more complex as it requires touching multiple match statements.

    Approach 4: Relax Preconditions for Retries

    Modify the ArgumentException check at the beginning of QueryInternalImplementation to allow numberOfConsistentResponsesRequired to be greater than the number of functions only if it's a retry and we are in a specific recovery state. (Not recommended as it might mask other bugs).

    Recommendation

    I recommend Approach 3. It addresses the root cause (the inaccurate wrapping of consistency settings) and removes the technical debt acknowledged in the source code. This will allow the system to correctly identify that it doesn't have enough servers to satisfy the "2-server consistency" rule and throw a proper NotEnoughAvailableException instead of crashing with an ArgumentException.


    View action run | Model: ppq/auto | Time: 46s | Tokens: 205.8K | Cost: $0.06 | Pi SDK v0.85.1 | Action v2.28.0-unknown (unknown @ unknown)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions