feat(sui-indexer): maintain per-network presign pool for redeems#319
Merged
feat(sui-indexer): maintain per-network presign pool for redeems#319
Conversation
Signed-off-by: sczembor <stanislaw.czembor@gmail.com>
Contributor
Reviewer's GuideImplements proactive creation and pooling of Sui presign objects in the redeem cron job, adding storage support to count existing presigns and wiring the pool maintenance into the main redeem solver flow with tests. Sequence diagram for proactive presign pool refill in redeem cron jobsequenceDiagram
participant Runner as RedeemCron
participant Service as RedeemService
participant Storage as D1Storage
participant SuiClient as SuiClient
participant Logger as Logger
Runner->>Service: refillPresignPool(activeNetworks)
loop for each network in activeNetworks
Service->>Storage: getPresignCount(network)
Storage-->>Service: count
alt count < PRESIGN_POOL_MIN
Service->>Service: compute needed = PRESIGN_POOL_TARGET - count
Service->>Service: toCreate = min(needed, MAX_CREATE_PER_RUN)
Service->>Logger: debug F"Filling presign pool" with network, currentCount, creating
loop for i from 0 to toCreate - 1
Service->>Service: client = getSuiClient(network)
Service->>SuiClient: requestIkaPresign()
SuiClient-->>Service: presignId
Service->>Storage: insertPresignObject(presignId, network)
Service->>Logger: debug "Created presign object" with network, presignId
opt error during creation
Service->>Logger: logError "Failed to create presign object" with method maintainPresignPool, network
Service->>Service: break
end
end
else count >= PRESIGN_POOL_MIN
Service->>Service: skip creation for network
end
end
Class diagram for RedeemService and D1Storage presign pool changesclassDiagram
class RedeemService {
+RedeemService(storage D1Storage, suiClients Map~SuiNet, SuiClient~)
+refillPresignPool(activeNetworks SuiNet[]) Promise~void~
+processPendingRedeems() Promise~void~
+solveReadyRedeems() Promise~void~
+broadcastReadyRedeems() Promise~void~
+getSuiClient(network SuiNet) SuiClient
-storage D1Storage
-suiClients Map~SuiNet, SuiClient~
}
class D1Storage {
+getPresignCount(network SuiNet) Promise~number~
+popPresignObject(network SuiNet) Promise~string | null~
+insertPresignObject(presignId string, network SuiNet) Promise~void~
-db D1Database
}
class Logger {
+debug(data any) void
}
class SuiClient {
+requestIkaPresign() Promise~string~
}
RedeemService --> D1Storage : uses
RedeemService --> SuiClient : uses
RedeemService --> Logger : logs
D1Storage --> D1Database : persists
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
Author
|
@sourcery-ai title |
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
refillPresignPool, the error log usesmethod: "maintainPresignPool"which no longer matches the function name; consider updating this torefillPresignPool(or a shared constant) to keep logs consistent and searchable. - In
getPresignCount, D1/SQLite often returns aggregate values as strings; to avoid subtle type issues, consider explicitly casting withNumber(result?.count ?? 0)instead of relying on the inferred{ count: number }type.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `refillPresignPool`, the error log uses `method: "maintainPresignPool"` which no longer matches the function name; consider updating this to `refillPresignPool` (or a shared constant) to keep logs consistent and searchable.
- In `getPresignCount`, D1/SQLite often returns aggregate values as strings; to avoid subtle type issues, consider explicitly casting with `Number(result?.count ?? 0)` instead of relying on the inferred `{ count: number }` type.
## Individual Comments
### Comment 1
<location> `packages/sui-indexer/src/storage.ts:245-248` </location>
<code_context>
}
+ async getPresignCount(network: SuiNet): Promise<number> {
+ const result = await this.db
+ .prepare("SELECT COUNT(*) as count FROM presign_objects WHERE sui_network = ?")
+ .bind(network)
+ .first<{ count: number }>();
+ return result?.count || 0;
+ }
</code_context>
<issue_to_address>
**issue (bug_risk):** Be careful with the type of COUNT(*) results; they may come back as strings from the driver.
Since the driver may return `COUNT(*)` as a string, typing `first<{ count: number }>()` and then using `result?.count || 0` could hide a mismatch (e.g. `"0"`). Consider using `first<{ count: string | number }>()` and coercing with `Number(result?.count) || 0` to make the conversion explicit and robust to driver behavior.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Signed-off-by: sczembor <stanislaw.czembor@gmail.com>
Signed-off-by: sczembor <stanislaw.czembor@gmail.com>
Signed-off-by: sczembor <stanislaw.czembor@gmail.com>
Signed-off-by: sczembor <stanislaw.czembor@gmail.com>
robert-zaremba
approved these changes
Feb 3, 2026
Contributor
robert-zaremba
left a comment
There was a problem hiding this comment.
pre-approving, we can handle the PTB in other PR if you want
Co-authored-by: Robert Zaremba <robert@zaremba.ch> Signed-off-by: sczembor <43810037+sczembor@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes: #282
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!to the type prefix if API or client breaking changeCHANGELOG.mdSummary by Sourcery
Maintain a pool of pre-created presign objects during the redeem solver cron job to ensure availability for active Sui networks.
New Features:
Enhancements:
Tests: