Skip to content

fix: Drep retirement should clear accounts, not expiration - #744

Closed
gonzalezzfelipe wants to merge 4 commits into
mainfrom
fix/drep-retirement
Closed

fix: Drep retirement should clear accounts, not expiration#744
gonzalezzfelipe wants to merge 4 commits into
mainfrom
fix/drep-retirement

Conversation

@gonzalezzfelipe

@gonzalezzfelipe gonzalezzfelipe commented Oct 3, 2025

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Governance views now use retirement-by-epoch, showing more accurate DRep active/retired status.
    • Added support for additional Conway certificate variants (StakeRegDeleg, StakeVoteRegDeleg) across delegation and account processing.
  • Bug Fixes

    • Corrected DRep expiration and retirement handling to prevent premature or unconditional updates.
    • Account active epoch now falls back to deregistration when registration timing is unavailable, improving timeline accuracy.
  • Refactor

    • Internal DRep lifecycle tracking moved from a boolean flag to epoch-based retirement for clearer state transitions.

@coderabbitai

coderabbitai Bot commented Oct 3, 2025

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

Walkthrough

Refactors DRep lifecycle to use retiring_epoch and deposit, removes deprecated fields, updates serialization indices, and adjusts apply/undo logic and sweep conditions. Extends certificate handling across minibf builders and routes, and updates governance active/retired checks to rely on retiring_epoch and current epoch.

Changes

Cohort / File(s) Summary
Cardano model: DRepState
crates/cardano/src/model.rs
Replaces retired flag and deprecated __drep_id with retiring_epoch: Option and deposit: u64; reorders CBOR indices; updates constructor accordingly.
Roll: DRep registration/unregistration flow
crates/cardano/src/roll/dreps.rs
Introduces epoch-aware unregistration via retiring_epoch; modifies DRepRegistration/DRepUnRegistration apply/undo to track prev_retiring_epoch; DRepStateVisitor propagates epoch and computes retiring_epoch as epoch+1.
Sweep: retire/expire logic
crates/cardano/src/sweep/retires.rs
Adds should_retire_drep; adjusts should_expire_drep to ignore retired; visit_drep now conditionally emits expiration and delegator-drop deltas based on new checks.
Minibf mapping: delegations and stake certs
crates/minibf/src/mapping.rs
Handles ConwayCert StakeRegDeleg and StakeVoteRegDeleg as delegations; expands StakeCertModelBuilder to set registration flags for Reg/RegDeleg/VoteRegDeleg and UnReg.
Minibf routes: accounts
crates/minibf/src/routes/accounts.rs
active_epoch derives from registered_at or deregistered_at; broadens registration handling to Reg, UnReg, StakeRegDeleg, StakeVoteRegDeleg.
Minibf routes: governance
crates/minibf/src/routes/governance.rs
Adds is_drep_retired using retiring_epoch vs current_epoch; updates is_drep_active and Drep model retired field accordingly; preserves special-case handling.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Chain
  participant Visitor as DRepStateVisitor
  participant Roll as DRepRegistration/UnRegistration
  participant State as DRepState

  Note over Chain,Visitor: Process governance certs within a block/epoch
  Chain->>Visitor: visit_root(epoch)
  Note right of Visitor: Store current epoch

  alt Register DRep
    Chain->>Visitor: visit_cert(RegDRep)
    Visitor->>Roll: DRepRegistration::new(drep)
    Roll->>State: apply() sets retiring_epoch=None
  else Unregister DRep
    Chain->>Visitor: visit_cert(UnRegDRep)
    Visitor->>Roll: DRepUnRegistration::new(drep, epoch+1)
    Roll->>State: apply() sets retiring_epoch=Some(epoch+1)
  end

  Note over Roll,State: undo restores prev_retiring_epoch
Loading
sequenceDiagram
  autonumber
  participant Sweep as Sweep::retires
  participant Ctx as SweepCtx
  participant State as DRepState
  participant Delta as Deltas

  Sweep->>Ctx: current starting epoch
  Sweep->>State: read retiring_epoch, last_active_slot
  alt should_retire_drep
    Sweep->>Delta: push DRepDelegatorDrop for each delegator
  end
  alt should_expire_drep
    Sweep->>Delta: push DRepExpiration
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45–60 minutes

Possibly related PRs

Suggested reviewers

  • scarmuega

Poem

I hop through epochs, tick by tick,
Retiring Dreps with a gentle flick.
No more flags, just time’s soft nudge—
A slot, an epoch, ledgers judge.
Delegators drop, expiries chime—
Carrots count deposits, right on time. 🥕⏳

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/drep-retirement

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1c92b7d and 15f211f.

📒 Files selected for processing (6)
  • crates/cardano/src/model.rs (1 hunks)
  • crates/cardano/src/roll/dreps.rs (7 hunks)
  • crates/cardano/src/sweep/retires.rs (2 hunks)
  • crates/minibf/src/mapping.rs (2 hunks)
  • crates/minibf/src/routes/accounts.rs (2 hunks)
  • crates/minibf/src/routes/governance.rs (2 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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