Skip to content

feat(rewarding): EpochDrainCursor scaffolding for IIP-59 era drain (PR C1)#4941

Closed
envestcc wants to merge 1 commit into
iip-59/pr4prime-block-reward-foldingfrom
iip-59/pr-c1-cursor-era-pivot
Closed

feat(rewarding): EpochDrainCursor scaffolding for IIP-59 era drain (PR C1)#4941
envestcc wants to merge 1 commit into
iip-59/pr4prime-block-reward-foldingfrom
iip-59/pr-c1-cursor-era-pivot

Conversation

@envestcc

Copy link
Copy Markdown
Member

Summary

Adds the state schema + Go helpers for a multi-block era-boundary drain
of `PendingBlockRewardPool` balances into voter accounts. This PR is
additive only — the cursor is not yet read or written by
`GrantEpochReward`. That wiring lands in PR C2. Splitting it off
isolates the schema/helper piece so the follow-up refactor diff stays
readable.

What's in

  • `proto EpochDrainCursor {target_era, delegate_index, repeated
    EpochDrainDelegateWork}` and `EpochDrainDelegateWork` in
    `rewardingpb/rewarding.proto`.
  • `state.EpochDrainCursorKey` (singleton `"edc"` in
    `RewardingNamespace`, mirroring the sentinel patterns for block/epoch
    reward history already there).
  • `action/protocol/rewarding/epoch_drain_cursor.go` — cursor Go type,
    Serialize/Deserialize, and read/write/delete helpers
    (`readEpochDrainCursor` returns `(nil, nil)` when absent; delete is
    idempotent via the existing `deleteState` `ErrStateNotExist`
    swallow).

Test plan

  • `go test -run TestEpochDrainCursor -count=1 -v` — 6 passed:
    round-trip, empty delegate list, zero pool amount, missing-key
    returns nil, write→read→delete lifecycle + idempotent second delete,
    write overwrites rather than merges.
  • `go test ./action/protocol/rewarding/... -count=1` — 109 passed
  • `go build ./...` clean
  • `go vet` clean on `rewarding/` and `state/`

Stack

Explicitly deferred (PR C2 / C3)

  • `GrantEpochReward` refactor into chunked Phase A/B/C
  • `CreatePostSystemActions` continuation dispatch keyed off cursor
    presence
  • `IsEraBoundary` gate wiring
  • `EpochDrainChunkSize` / `CompoundBatchSize` genesis field usage
  • End-to-end "chunked matches single" byte-equivalence test

🤖 Generated with Claude Code

Introduces the state schema + Go helpers for a multi-block era-boundary
drain of PendingBlockRewardPool balances into voter accounts, without
wiring it into GrantEpochReward yet. The wiring lands in the next
change; this PR isolates the additive schema/helper piece so the diff
stays readable.

Additions:

  proto rewardingpb.EpochDrainCursor {target_era, delegate_index,
    repeated EpochDrainDelegateWork} — cursor payload persisted at
    state.EpochDrainCursorKey (singleton in RewardingNamespace).
    Absence = no drain in progress. Presence carries the frozen work
    list captured at Phase A so chunks in later blocks read stable
    inputs even if the live pool keeps accruing behind the drain.

  proto rewardingpb.EpochDrainDelegateWork {candidate_identifier,
    pool_amount_frozen} — one frozen per-delegate work item.

  state.EpochDrainCursorKey — singleton key prefix "edc" in
    RewardingNamespace, mirroring the sentinel patterns already in
    state/tables.go for block/epoch reward history.

  action/protocol/rewarding/epoch_drain_cursor.go — cursor Go struct
    + Serialize / Deserialize + readEpochDrainCursor(returns nil,nil
    when absent) / writeEpochDrainCursor(overwrites) /
    deleteEpochDrainCursor (idempotent via existing deleteState
    ErrStateNotExist swallow).

Test coverage:

  round-trip (target_era, delegate_index, delegate list, big.Int pool
    amounts including zero); empty delegate list; missing key returns
    (nil, nil); write→read→delete lifecycle; second delete no-ops;
    write overwrites rather than merges.

Explicitly deferred (follow-up PRs):
  - GrantEpochReward refactor into chunked Phase A/B/C
  - CreatePostSystemActions continuation dispatch on cursor presence
  - IsEraBoundary gate (arrives with the PR A era genesis params)
  - EpochDrainChunkSize genesis field / CompoundBatchSize wiring

Depends on: IIP-59 PR A (#4939) for the IsEraBoundary helper the
follow-up chunked-drain PR will use.
@sonarqubecloud

Copy link
Copy Markdown

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.

1 participant