Add parallel mod_to_acct_transfers_summarized table#79
Merged
Conversation
Create a new summarized table that groups mod_to_acct_transfers by (block_id, recipient_id, op_reason, denom, service_id), reducing row count ~45x on mainnet. The existing table and all queries are untouched; this writes in parallel for future cutover. - Add createModToAcctTransfersSummarizedTableFn with 3 indexes - Register table creation at startup in createDbFunctions - Add summarizeTransfers pure function and bulkInsertSummarizedTransfers - Wire into handleEventClaimSettled Promise.all
Alann27
approved these changes
Mar 25, 2026
jorgecuesta
added a commit
that referenced
this pull request
Jun 9, 2026
## Summary Indexes the consensus-breaking event-payload additions shipped in poktroll **v0.1.34** ([pokt-network/poktroll#1952](pokt-network/poktroll#1952)). All additive proto fields + one new event; all changes are backward-compatible (handlers fall back to prior derivation when a field is absent). ## Changes ### 1. New `EventValidatorRewardDistribution` entity + handler Emitted once per bonded validator per `op_reason` per settlement block (~40/block, bounded by validator-set size — preserves the #1758 event-count reduction). Carries the canonical per-validator commission / delegator split. - `schema.graphql`: new `@entity` (session end height, op_reason, validator operator/account addrs, commission rate, pool-share / commission / self-delegation / delegators / total-delegated-stake upokt amounts, num delegators). - `relays.ts`: `handleEventValidatorRewardDistribution` parses all 11 attributes (`*_upokt` = bare integer strings, `commission_rate` = decimal string, `op_reason` = enum name, `session_end_block_height` = int64-as-string). - Registered in `handlers.ts` `EventHandlers`; dispatched in `indexer.manager.ts` `indexRelays`. **Why it matters — cross-delegation accounting:** we already bucket validator/delegator rewards from `EventSettlementBatch` (`VALIDATOR_REWARD_OP_REASONS`). The bank-batch accumulator keys on `(recipient, op_reason)`, so when the same `pokt` address is **both** a validator account **and** a delegator on another validator, its income is bucketed under the validator-side `op_reason` — over-counting VALIDATOR, under-counting DELEGATOR. This event gives the unambiguous per-validator split. The entity doc-comment in `schema.graphql` records the caveat. ### 2. Prefer chain `num_estimated_relays` (field 13) `EventClaimCreated` (`_handleMsgCreateClaim`) and `EventClaimExpired` (`_handleEventClaimExpired`) computed `num_estimated_relays` via raw `CUPR = floor(claimed / numRelays)` — **divide-by-zero when `num_relays == 0`**. Both now route through the existing `_computeNumEstimatedRelays` (prefers the chain-emitted value, falls back to deriving from compute units for pre-upgrade blocks). `EventClaimSettled` already did this. ### 3. Prefer chain `supplier_stake_after_slash` (field 9) `EventSupplierSlashed.afterStakeAmount` now prefers the chain-emitted post-slash stake; falls back to `trackedStake − penalty` for pre-upgrade events (also robust when tracked stake drifts on pruned nodes). ## Notes - Generated models / proto-interfaces are gitignored (regenerated at build). `schema.graphql` is the tracked source of truth — `subql codegen` confirmed clean (`EventValidatorRewardDistribution generated !`). - Edited line ranges + the new handler type-check clean. (Full local `tsc`/lint floods on missing generated proto-interfaces, which are produced by the buf + subql codegen pipeline in CI.) ## Follow-up (not in this PR) Rewire the `mod_to_acct_transfers_summarized` rollup (#79) to source VALIDATOR-vs-DELEGATOR totals from `EventValidatorRewardDistribution` instead of `EventSettlementBatch`. The data is now indexed; the rollup change is left as a separate scoped change. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Jorge Cuesta <jorge.s.cuesta@gmail.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.
Summary
mod_to_acct_transfers_summarizedtable that groups by(block_id, recipient_id, op_reason, denom, service_id), reducing row count ~45x on mainnet (1.6M → 36K per settlement block)mod_to_acct_transferstable — no existing queries or functions are modifiedsummarizeTransferspure function that aggregatesamount(BigInt sum) andtransfer_countper group keyFiles changed
src/mappings/dbFunctions/modToAcctTransfers.ts— new table DDL with 3 indexessrc/mappings/dbFunctions/index.ts— register table creation at startupsrc/mappings/pocket/relays.ts— summarization logic + parallel bulk insertValidated in production
sum(transfer_count)match original row counts, allsum(amount)per recipient matchWhat is NOT changed
mod_to_acct_transferstable, functions, queries — all untouched_handleEventClaimSettled— untouchedbulkInsertModToAcctTransfers— untouchedNext steps (future PRs)