feat: index v0.1.34 settlement events#80
Merged
Conversation
Support the consensus-breaking event-payload additions shipped in poktroll v0.1.34 (pokt-network/poktroll#1952). - New EventValidatorRewardDistribution entity + handler. Emitted once per bonded validator per op_reason per settlement block, it carries the canonical per-validator commission/delegator split. Build "VALIDATOR vs DELEGATOR" reward totals from this event rather than EventSettlementBatch: when a pokt address is both a validator account and a delegator on another validator, the bank-batch stream keys on (recipient, op_reason) and over-counts the validator side. Registered in EventHandlers and dispatched in indexRelays. - Prefer chain-emitted num_estimated_relays (field 13) in the EventClaimCreated and EventClaimExpired paths via _computeNumEstimatedRelays. Removes the divide-by-zero the raw CUPR math hits when num_relays == 0; falls back to deriving from compute units for pre-upgrade blocks. - Prefer chain-emitted supplier_stake_after_slash (EventSupplierSlashed field 9) for afterStakeAmount. Falls back to tracked stake minus penalty for pre-upgrade events; also robust when tracked stake drifts on pruned nodes. All additions are backward-compatible: new fields are nullable/optional and the handlers fall back to the prior derivation when a field is absent. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
4498234 to
29bb349
Compare
Addresses code review findings on the v0.1.34 indexing changes: - suppliers: derive previousStakeAmount from the chain-emitted post-slash stake (after + penalty, both chain-sourced) when available, so previousStakeAmount - afterStakeAmount === proofMissingPenalty holds by construction and no longer drifts with the indexer-tracked stake. - relays (EventValidatorRewardDistribution): fail fast on malformed events (missing validator operator/account address, NaN num_delegators) instead of silently persisting empty/zero rows; warn on an unknown op_reason that resolves to UNSPECIFIED to surface protocol drift. - relays (_computeNumEstimatedRelays): guard numRelays == 0 and a zero CUPR divisor that would otherwise make BigInt() throw on the pre-upgrade fallback path; correct the now-inaccurate call-site comments. - relays: hoist blockId out of the per-event map in the reward handler. - consolidate the duplicated local parseAttribute (relays, grants) onto the canonical utils/json implementation.
Sync the two v0.1.34 additions into the vendored tokenomics proto so the generated proto-interfaces match what the chain emits (the mappings read raw attributes, so this is for consistency, not a runtime dependency): - EventSupplierSlashed: add field 9 supplier_stake_after_slash (Next index 10). - Add message EventValidatorRewardDistribution. Both copied verbatim from pokt-network/poktroll@v0.1.34. Only the tokenomics event.proto is touched; a full proto re-sync (12+ files drift across modules) is left as a separate, build-verified change.
Full sync of proto/pocket/ from pokt-network/poktroll@v0.1.34 via scripts/copy-poktroll-files.sh, bringing the vendored protobufs in line with the chain version the indexer targets. Supersedes the earlier surgical tokenomics/event.proto edit. 12 files updated (additive: new fields/messages across application, proof, service, session, shared, supplier, and tokenomics). Validated end-to-end by building the production indexer image (subql codegen + eslint + subql build all pass, 0 errors).
jorgecuesta
approved these changes
Jun 9, 2026
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
Indexes the consensus-breaking event-payload additions shipped in poktroll v0.1.34 (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
EventValidatorRewardDistributionentity + handlerEmitted once per bonded validator per
op_reasonper 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:handleEventValidatorRewardDistributionparses all 11 attributes (*_upokt= bare integer strings,commission_rate= decimal string,op_reason= enum name,session_end_block_height= int64-as-string).handlers.tsEventHandlers; dispatched inindexer.manager.tsindexRelays.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 samepoktaddress is both a validator account and a delegator on another validator, its income is bucketed under the validator-sideop_reason— over-counting VALIDATOR, under-counting DELEGATOR. This event gives the unambiguous per-validator split. The entity doc-comment inschema.graphqlrecords the caveat.2. Prefer chain
num_estimated_relays(field 13)EventClaimCreated(_handleMsgCreateClaim) andEventClaimExpired(_handleEventClaimExpired) computednum_estimated_relaysvia rawCUPR = floor(claimed / numRelays)— divide-by-zero whennum_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).EventClaimSettledalready did this.3. Prefer chain
supplier_stake_after_slash(field 9)EventSupplierSlashed.afterStakeAmountnow prefers the chain-emitted post-slash stake; falls back totrackedStake − penaltyfor pre-upgrade events (also robust when tracked stake drifts on pruned nodes).Notes
schema.graphqlis the tracked source of truth —subql codegenconfirmed clean (EventValidatorRewardDistribution generated !).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_summarizedrollup (#79) to source VALIDATOR-vs-DELEGATOR totals fromEventValidatorRewardDistributioninstead ofEventSettlementBatch. The data is now indexed; the rollup change is left as a separate scoped change.🤖 Generated with Claude Code