Skip to content

feat(adder): DRep Registrations and Retiring#615

Merged
arepala-uml merged 2 commits intomainfrom
drep_registration
Feb 16, 2026
Merged

feat(adder): DRep Registrations and Retiring#615
arepala-uml merged 2 commits intomainfrom
drep_registration

Conversation

@arepala-uml
Copy link
Copy Markdown
Contributor

@arepala-uml arepala-uml commented Feb 10, 2026

  1. Made changes for emitting events for the DRep Registration, Update and Deregistration certificates.

Closes #485


Summary by cubic

Adds dedicated events for DRep registration, update, and deregistration, plus filtering by DRep ID so consumers can subscribe. Refactors DRep parsing for reuse. Addresses #485.

  • New Features

    • Emit DRep certificate events: chainsync.drep.registration, chainsync.drep.update, chainsync.drep.deregistration.
    • Add DRepCertificateEvent payload including block hash, DRep hash/ID, deposit, and optional anchor.
    • Add Cardano filter support for DRepCertificateEvent (matches hex and bech32 DRep IDs).
    • Add tests for DRep certificate event filtering.
  • Bug Fixes

    • Use the drep_script bech32 prefix for script-hash DRep credentials.

Written for commit 1720570. Summary will update on new commits.

Summary by CodeRabbit

  • New Features

    • Added support for DRep certificate events (registration, update, deregistration), including extraction and emission alongside existing block/transaction/governance events.
    • Added filtering for DRep certificate events by DRep identifier.
  • Tests

    • Added test coverage for DRep certificate event filtering behavior.

…ation certificates

Signed-off-by: Akhil Repala <arepala@blinklabs.io>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 10, 2026

📝 Walkthrough

Walkthrough

Adds DRep certificate event support: new event constants and a DRepCertificateEvent struct; extraction helpers to pull DRep certificates from transactions and a public ExtractDRepCertificates function; mapping from certificate types to event types; emission of DRep certificate events during block/transaction processing in chainsync; Cardano filter logic to evaluate DRepCertificateEvent payloads; and tests for DRep certificate filtering.

Possibly related PRs

  • blinklabs-io/adder PR 578 — Introduced DRepCertificateData and initial governance/DRep extraction logic that this change reuses and extends to add dedicated DRep certificate events, extraction helpers, filtering, and event emission.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Merge Conflict Detection ⚠️ Warning ❌ Merge conflicts detected (23 files):

⚔️ .gitignore (content)
⚔️ Makefile (content)
⚔️ README.md (content)
⚔️ event/governance.go (content)
⚔️ event/tx.go (content)
⚔️ filter/cardano/cardano.go (content)
⚔️ filter/cardano/cardano_test.go (content)
⚔️ go.mod (content)
⚔️ go.sum (content)
⚔️ input/chainsync/chainsync.go (content)
⚔️ input/chainsync/chainsync_test.go (content)
⚔️ input/chainsync/options.go (content)
⚔️ input/input.go (content)
⚔️ internal/logging/kugoCustomLogger.go (content)
⚔️ internal/logging/logging.go (content)
⚔️ output/log/log.go (content)
⚔️ output/log/options.go (content)
⚔️ output/log/plugin.go (content)
⚔️ output/notify/notify.go (content)
⚔️ output/push/push.go (content)
⚔️ output/telegram/telegram.go (content)
⚔️ output/telegram/telegram_test.go (content)
⚔️ output/webhook/webhook.go (content)

These conflicts must be resolved before merging into main.
Resolve conflicts locally and push changes to this branch.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main feature added: DRep certificate event support for registrations, updates, and deregistrations.
Linked Issues check ✅ Passed The PR implements all required objectives from issue #485: DRep Registration, Update, and Deregistration events are created and properly routed through the event system.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing DRep certificate events and filtering; no unrelated modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 drep_registration
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch drep_registration
  • Create stacked PR with resolved conflicts
  • Post resolved changes as copyable diffs in a comment

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
event/governance.go (2)

462-478: tx.Certificates() called twice — consider caching.

tx.Certificates() is called at line 464 for the length check and again at line 469 for iteration. If Certificates() does any non-trivial work (e.g., CBOR decoding), this duplicates effort. Consider storing the result in a local variable.

Suggested improvement
 func ExtractDRepCertificates(tx ledger.Transaction) []DRepCertificateData {
-	if len(tx.Certificates()) == 0 {
+	certs := tx.Certificates()
+	if len(certs) == 0 {
 		return nil
 	}
 
 	var result []DRepCertificateData
-	for _, cert := range tx.Certificates() {
+	for _, cert := range certs {
 		if data, ok := extractDRepCertificate(cert); ok {
 			result = append(result, data)
 		}

480-485: Replace magic number 1 with named constant lcommon.CredentialTypeScriptHash.

The literal 1 works correctly but is fragile and unclear. The gouroboros library exports CredentialTypeScriptHash = 1 as a named constant, which should be used instead for better code maintainability and readability.

func drepBech32Prefix(cred lcommon.Credential) string {
-	if cred.CredType == 1 {
+	if cred.CredType == lcommon.CredentialTypeScriptHash {
		return "drep_script"
	}
	return "drep"
}

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.

@arepala-uml arepala-uml marked this pull request as ready for review February 10, 2026 16:22
@arepala-uml arepala-uml requested a review from a team as a code owner February 10, 2026 16:22
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@event/governance.go`:
- Around line 480-522: The DRep ID is always encoded with Bech32("drep") causing
wrong IDs for script-hash credentials; in extractDRepCertificate check the
credential type via c.DrepCredential.CredType (0 = key hash, 1 = script hash)
and choose the bech32 prefix accordingly (use "drep" for key-hash and
"drep_script" for script-hash) when setting DRepId for all handled cert structs
(*lcommon.RegistrationDrepCertificate, *lcommon.DeregistrationDrepCertificate,
*lcommon.UpdateDrepCertificate); mirror the same credential-type logic used in
extractVoteDelegation to ensure DRepId matches the precomputed filter variants.
🧹 Nitpick comments (2)
event/governance.go (1)

462-478: Minor: redundant nil-length check.

Lines 474–476 return nil when result is empty, but result is already nil (its zero value) when no certificates match and nothing was appended. The guard is harmless but unnecessary.

input/chainsync/chainsync.go (1)

642-662: Duplicated DRep emission block — consider extracting a helper.

This block is an exact copy of lines 514–534 (the handleRollForward path), differing only in how the event is dispatched (c.eventChan <- vs. tmpEvents = append). The governance event emission has the same duplication, so this is a pre-existing pattern, but as the number of event types grows it will become harder to keep them in sync.

Signed-off-by: Akhil Repala <arepala@blinklabs.io>
@arepala-uml arepala-uml merged commit 5221bed into main Feb 16, 2026
10 checks passed
@arepala-uml arepala-uml deleted the drep_registration branch February 16, 2026 02:43
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.

DRep Registrations and Retiring

3 participants