fix(monitoringV2): cast NUMERIC columns to text in challenge raw query#32
Merged
Merged
Conversation
`findActiveWithChallengePeriod` selects `size` and `current_price` from `challenge_states`, both NUMERIC(78,0). Prisma's `$queryRaw` was materialising the values as JS `number`, which loses precision for values beyond 2^53 and serialises them via `.toString()` in scientific notation (e.g. `2.8391...e+22`). `BigInt()` does not accept that format, so the monitoring cycle crashed with "Cannot convert <sci-notation> to a BigInt" on mainnet — JDM has challenges over 28391.7 JUSD (28.4e21 wei), JDT does not, which is why only JDM was affected. Fix mirrors the pattern already used in `position.repository.ts`: explicit `::text` casts in the SQL, typed as `string` in the row shape, then `BigInt(r.size)` directly without an intermediate `.toString()`.
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.
Problem
JDM (mainnet) monitoring container has been in a sustained crash with 14+ consecutive failures:
```
ERROR [MonitoringService] Error occurred while processing blocks (14 consecutive failures):
SyntaxError: Cannot convert 2.83917438483003551495e+22 to a BigInt
at ChallengeRepository.findActiveWithChallengePeriod (challenge.repository.js:85:31)
```
This is a release-blocker for #30 Release: develop → main — if it merges as-is, dfxprd will pick up the same crash the moment a single challenge with size > 2^53 wei (~9 JUSD) lands on the mainnet hub.
Root cause
`findActiveWithChallengePeriod` uses `$queryRaw` to select `size` and `current_price` from `challenge_states`. Both columns are `NUMERIC(78,0)`. Without an explicit cast, Prisma's raw query path returned them as JS `number`, which:
`BigInt()` rejects scientific notation → throw. JDT was unaffected because testnet challenges never crossed 2^53 wei.
Fix
Mirror the pattern already in `position.repository.ts`: explicit `::text` casts in the SQL, typed as `string` in the row shape, then `BigInt(r.size)` directly without an intermediate `.toString()`.
```diff
```
Scope
Test plan