Skip to content

feat: index v0.1.34 settlement events#80

Merged
jorgecuesta merged 4 commits into
mainfrom
feat/v0.1.34-events
Jun 9, 2026
Merged

feat: index v0.1.34 settlement events#80
jorgecuesta merged 4 commits into
mainfrom
feat/v0.1.34-events

Conversation

@oten91

@oten91 oten91 commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

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 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

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>
@oten91 oten91 force-pushed the feat/v0.1.34-events branch from 4498234 to 29bb349 Compare June 2, 2026 14:14
@oten91 oten91 requested a review from jorgecuesta June 2, 2026 14:14
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 jorgecuesta merged commit b35d7e9 into main Jun 9, 2026
3 checks passed
@jorgecuesta jorgecuesta deleted the feat/v0.1.34-events branch June 9, 2026 02:54
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.

2 participants