Skip to content

docs(sui-indexer): add coin management notes and confirm no race condition#327

Merged
Rcc999 merged 6 commits intomasterfrom
rayane/coin-race-condition-docs
Jan 29, 2026
Merged

docs(sui-indexer): add coin management notes and confirm no race condition#327
Rcc999 merged 6 commits intomasterfrom
rayane/coin-race-condition-docs

Conversation

@Rcc999
Copy link
Contributor

@Rcc999 Rcc999 commented Jan 28, 2026

Closes: #310

Summary by Sourcery

Document IKA coin management and clarify concurrency guarantees in the sui-indexer.

Enhancements:

  • Clarify concurrency assumptions and usage of fetchAllIkaCoins in code comments for the IKA client.

Documentation:

  • Add README documentation describing IKA coin usage, coin selection flow, and concurrency behavior in the indexer.

…ition

Signed-off-by: Rayane Charif <rayane.charif@gonative.cc>
@Rcc999 Rcc999 requested a review from a team as a code owner January 28, 2026 15:28
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 28, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Documents how IKA coin selection and merging work in the Sui indexer and clarifies that concurrency characteristics of the Cloudflare worker prevent race conditions when selecting coins.

Sequence diagram for IKA coin selection and merging in SuiIndexer

sequenceDiagram
    actor CFWorkerCron
    participant SuiIndexer
    participant IkaClientImp
    participant CoinOps
    participant SuiRPC

    CFWorkerCron->>SuiIndexer: processSolvedRedeems()
    loop each_redeem_request
        SuiIndexer->>IkaClientImp: fetchAllIkaCoins(owner)
        IkaClientImp->>SuiRPC: query IKA coins for owner
        SuiRPC-->>IkaClientImp: CoinStruct[]
        IkaClientImp-->>SuiIndexer: CoinStruct[]

        SuiIndexer->>CoinOps: selectCoins(coins, targetAmount)
        CoinOps-->>SuiIndexer: selectedCoins

        alt multiple_coins_needed
            SuiIndexer->>CoinOps: prepareCoin(selectedCoins)
            CoinOps->>SuiRPC: merge coins on chain
            SuiRPC-->>CoinOps: mergedCoin
            CoinOps-->>SuiIndexer: mergedCoin
        else single_coin_sufficient
            SuiIndexer-->>SuiIndexer: use single coin directly
        end

        SuiIndexer->>SuiRPC: presign/sign transaction using coin
        SuiRPC-->>SuiIndexer: transaction result
    end

    %% Concurrency characteristic: only one CFWorkerCron instance runs
    %% and processSolvedRedeems loop is sequential, so no parallel
    %% coin selection occurs
Loading

Class diagram for IkaClientImp IKA coin management method

classDiagram
    class IkaClientImp {
        +fetchAllIkaCoins(owner string) CoinStruct[]
    }

    class CoinStruct

    IkaClientImp ..> CoinStruct : returns
Loading

File-Level Changes

Change Details Files
Document IKA coin management behavior, selection algorithm, and concurrency guarantees in the Sui indexer README.
  • Added an IKA Coin Management section describing the purpose of IKA coins for presign/sign requests and where the coin selection logic lives.
  • Outlined the step-by-step flow: fetching all IKA coins, selecting coins to meet a target amount, and merging coins when multiple are required.
  • Documented concurrency characteristics, noting that Cloudflare workers run one cron at a time and that processSolvedRedeems processes sequentially, eliminating parallel coin selection.
packages/sui-indexer/README.md
Clarify intended usage and concurrency assumptions of fetchAllIkaCoins in the Ika client implementation.
  • Extended the fetchAllIkaCoins method comment to describe its role in coin selection and merging.
  • Documented the reliance on Cloudflare worker single-cron execution and sequential processSolvedRedeems processing to avoid parallel coin selection.
  • Left a TODO note highlighting the potential need for a maxCoins limit parameter unchanged.
packages/sui-indexer/src/ika_client.ts

Assessment against linked issues

Issue Objective Addressed Explanation
#310 Add an appropriate note or comment in the Ika client explaining the coin selection/merge behavior and its concurrency characteristics.
#310 Determine whether there is a real race condition problem in coin selection (i.e., whether there is any flow where two transactions can select the same coins in parallel without waiting for completion).
#310 If a race condition exists in coin selection, implement a solution to prevent parallel transactions from trying to use the same coins.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The concurrency explanation relies on Cloudflare cron behavior; consider clarifying or linking to the specific CF guarantee and explicitly scoping the assumption (e.g., what happens with manual triggers, multiple environments, or future parallel workers) so the "no race condition" claim remains accurate over time.
  • Since fetchAllIkaCoins is documented as safe because processSolvedRedeems is sequential, it may be worth calling out in the comments that introducing any parallel caller or reusing this helper elsewhere would require revisiting the race-condition assumptions to avoid misuse.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The concurrency explanation relies on Cloudflare cron behavior; consider clarifying or linking to the specific CF guarantee and explicitly scoping the assumption (e.g., what happens with manual triggers, multiple environments, or future parallel workers) so the "no race condition" claim remains accurate over time.
- Since `fetchAllIkaCoins` is documented as safe because `processSolvedRedeems` is sequential, it may be worth calling out in the comments that introducing any parallel caller or reusing this helper elsewhere would require revisiting the race-condition assumptions to avoid misuse.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Rcc999 and others added 5 commits January 29, 2026 11:38
Co-authored-by: Robert Zaremba <robert@zaremba.ch>
Signed-off-by: Shish <rayane.charifchefchaouni@epfl.ch>
Co-authored-by: Robert Zaremba <robert@zaremba.ch>
Signed-off-by: Shish <rayane.charifchefchaouni@epfl.ch>
Signed-off-by: Rayane Charif <rayane.charif@gonative.cc>
@Rcc999 Rcc999 merged commit f3de548 into master Jan 29, 2026
12 checks passed
@Rcc999 Rcc999 deleted the rayane/coin-race-condition-docs branch January 29, 2026 10:44
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.

Workers: check the flows to make parallel transactions when selecting ika coin

2 participants