Skip to content

Conversation

@agaffney
Copy link
Contributor

@agaffney agaffney commented Dec 1, 2025


Summary by cubic

Track Handshake name hashes and map them to raw names in state, so the indexer can resolve and log domain names during register/update events.

  • New Features

    • Store sha3-256 name-hash → name mapping in Badger (handshakeNameHashKeyPrefix).
    • On Open/Claim, save the raw name; on Register/Update, resolve the name from the hash and include it in logs.
  • Refactors

    • Replace inline state key strings with constants for record and domain prefixes.

Written for commit ed93565. Summary will update automatically on new commits.

Summary by CodeRabbit

  • New Features

    • Handshake names are now tracked and can be resolved from their hashes, enabling clearer identification in covenant processing.
  • Improvements

    • Improved logging and error propagation during handshake-related operations for more reliable diagnostics and clearer audit trails.
    • Better consistency in domain and record handling resulting in more robust lookup and display behavior.

✏️ Tip: You can customize this high-level summary in your review settings.

@agaffney agaffney requested a review from a team as a code owner December 1, 2025 21:47
@coderabbitai
Copy link

coderabbitai bot commented Dec 1, 2025

📝 Walkthrough

Walkthrough

This PR adds handshake name storage and lookup to the state layer and integrates those calls into the handshake indexer. New Badger key prefixes were introduced: recordKeyPrefix ("r_"), domainKeyPrefix ("d_"), and handshakeNameHashKeyPrefix ("hs_name_hash_"). Two State methods were added: AddHandshakeName (stores SHA3-256(name) -> name) and GetHandshakeNameByHash (retrieves name by hash). The indexer now calls AddHandshakeName when handling OpenCovenant and ClaimCovenant, and resolves names via GetHandshakeNameByHash for logging on RegisterCovenant and UpdateCovenant.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Review consistency of the new key prefixes across state methods (record/domain/handshake hash) and any remaining hard-coded keys.
  • Verify SHA3-256 hashing and key construction in AddHandshakeName and that retrieval in GetHandshakeNameByHash uses the exact same prefix/encoding.
  • Confirm error handling where the indexer calls GetHandshakeNameByHash — ensure logging/resolution failures are handled intentionally and don't obscure other errors.
  • Inspect the handshake indexer changes to ensure AddHandshakeName is called only for appropriate covenant types and that no concurrent-write or duplicate-store concerns are introduced.
  • Files to inspect closely: internal/state/state.go, internal/indexer/handshake.go.

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: track Handshake name hashes' directly aligns with the main objective of the PR, which is to add storage and mapping for Handshake name hashes. It is specific, concise, and clearly summarizes the primary change.
✨ 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 feat/handshake-storage

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.

Copy link

@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: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2e8f3b5 and fd52532.

📒 Files selected for processing (2)
  • internal/indexer/handshake.go (2 hunks)
  • internal/state/state.go (6 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
internal/indexer/handshake.go (2)
internal/handshake/covenant.go (8)
  • OpenCovenant (204-207)
  • OpenCovenant (209-209)
  • ClaimCovenant (161-168)
  • ClaimCovenant (170-170)
  • RegisterCovenant (327-332)
  • RegisterCovenant (334-334)
  • UpdateCovenant (366-370)
  • UpdateCovenant (372-372)
internal/state/state.go (1)
  • GetState (371-373)
🪛 GitHub Actions: golangci-lint
internal/state/state.go

[error] 342-342: golangci-lint: File is not properly formatted (gofumpt).

🪛 GitHub Check: lint
internal/state/state.go

[failure] 343-343:
unnecessary trailing newline (whitespace)


[failure] 342-342:
File is not properly formatted (gofumpt)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Analyze (go)
🔇 Additional comments (10)
internal/state/state.go (5)

11-11: LGTM!

The crypto/sha3 import is correctly added to support SHA-3-256 hashing of handshake names.


31-33: LGTM!

The new key prefix constants provide clear namespacing for Badger storage keys, improving organization and reducing collision risk.


229-235: LGTM!

The record key formatting correctly adopts the new recordKeyPrefix constant while preserving the existing logic.


257-257: LGTM!

The domain tracking key correctly uses domainKeyPrefix and fmt.Appendf for improved efficiency.


298-304: LGTM!

The key prefix construction correctly uses recordKeyPrefix and efficient fmt.Appendf formatting.

internal/indexer/handshake.go (5)

16-16: LGTM!

The internal/state import is correctly added to support handshake name storage and retrieval.


116-119: LGTM!

The OpenCovenant handling correctly stores the handshake name for future lookups and propagates errors appropriately.


120-123: LGTM!

The ClaimCovenant handling correctly stores the handshake name for future lookups and propagates errors appropriately.


124-129: LGTM!

The RegisterCovenant handling correctly retrieves the handshake name by its hash for logging, with appropriate error propagation.


130-135: LGTM!

The UpdateCovenant handling correctly retrieves the handshake name by its hash for logging, with appropriate error propagation.

Signed-off-by: Aurora Gaffney <aurora@blinklabs.io>
@agaffney agaffney force-pushed the feat/handshake-storage branch from fd52532 to ed93565 Compare December 1, 2025 21:57
Copy link

@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

🧹 Nitpick comments (2)
internal/state/state.go (2)

334-347: Hash encoding fix confirmed; consider minor simplification.

The critical hash encoding issue from the previous review has been correctly addressed by using %x format specifier for hex encoding. The implementation is now correct.

Optionally simplify the error handling:

 func (s *State) AddHandshakeName(name string) error {
 	nameHash := sha3.Sum256([]byte(name))
 	nameHashKey := fmt.Sprintf("%s%x", handshakeNameHashKeyPrefix, nameHash)
-	err := s.db.Update(func(txn *badger.Txn) error {
+	return s.db.Update(func(txn *badger.Txn) error {
 		return txn.Set(
 			[]byte(nameHashKey),
 			[]byte(name),
 		)
 	})
-	if err != nil {
-		return err
-	}
-	return nil
 }

349-368: Hash encoding fix confirmed; consider minor simplification.

The critical hash encoding issue from the previous review has been correctly addressed by using %x format specifier. The lookup logic is correct.

Optionally simplify the error handling:

 func (s *State) GetHandshakeNameByHash(nameHash []byte) (string, error) {
 	var ret string
 	nameHashKey := fmt.Sprintf("%s%x", handshakeNameHashKeyPrefix, nameHash)
 	err := s.db.View(func(txn *badger.Txn) error {
 		item, err := txn.Get([]byte(nameHashKey))
 		if err != nil {
 			return err
 		}
 		val, err := item.ValueCopy(nil)
 		if err != nil {
 			return err
 		}
 		ret = string(val)
 		return nil
 	})
-	if err != nil {
-		return "", err
-	}
-	return ret, nil
+	return ret, err
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fd52532 and ed93565.

📒 Files selected for processing (2)
  • internal/indexer/handshake.go (2 hunks)
  • internal/state/state.go (6 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
internal/indexer/handshake.go (2)
internal/handshake/covenant.go (8)
  • OpenCovenant (204-207)
  • OpenCovenant (209-209)
  • ClaimCovenant (161-168)
  • ClaimCovenant (170-170)
  • RegisterCovenant (327-332)
  • RegisterCovenant (334-334)
  • UpdateCovenant (366-370)
  • UpdateCovenant (372-372)
internal/state/state.go (1)
  • GetState (370-372)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (3)
internal/state/state.go (2)

11-11: LGTM!

The addition of the crypto/sha3 import and the new key prefixes is well-structured and supports the handshake name tracking feature.

Also applies to: 31-33


230-231: LGTM!

The refactoring to use named constants (recordKeyPrefix, domainKeyPrefix) instead of hardcoded strings improves maintainability and reduces the risk of typos in key construction.

Also applies to: 257-257, 300-301

internal/indexer/handshake.go (1)

16-16: LGTM!

The integration with the state layer to persist handshake names during OpenCovenant and ClaimCovenant processing is correct. Error handling appropriately propagates failures.

Also applies to: 116-123

Copy link

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

1 issue found across 2 files

Prompt for AI agents (all 1 issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="internal/indexer/handshake.go">

<violation number="1" location="internal/indexer/handshake.go:125">
P1: Register/Update now abort handshake syncing whenever the name cache misses. Because the cache is only filled when future Open/Claim covenants run, every pre-existing domain causes `GetHandshakeNameByHash` to return `badger.ErrKeyNotFound`, which you bubble up and the sync loop stops processing blocks. Handle missing names as a non-fatal condition (log the hash and continue) and only return unexpected state errors.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

}
case *handshake.RegisterCovenant:
slog.Debug("Handshake domain registration", "resdata", c.ResourceData)
name, err := state.GetState().GetHandshakeNameByHash(c.NameHash)
Copy link

@cubic-dev-ai cubic-dev-ai bot Dec 1, 2025

Choose a reason for hiding this comment

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

P1: Register/Update now abort handshake syncing whenever the name cache misses. Because the cache is only filled when future Open/Claim covenants run, every pre-existing domain causes GetHandshakeNameByHash to return badger.ErrKeyNotFound, which you bubble up and the sync loop stops processing blocks. Handle missing names as a non-fatal condition (log the hash and continue) and only return unexpected state errors.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At internal/indexer/handshake.go, line 125:

<comment>Register/Update now abort handshake syncing whenever the name cache misses. Because the cache is only filled when future Open/Claim covenants run, every pre-existing domain causes `GetHandshakeNameByHash` to return `badger.ErrKeyNotFound`, which you bubble up and the sync loop stops processing blocks. Handle missing names as a non-fatal condition (log the hash and continue) and only return unexpected state errors.</comment>

<file context>
@@ -112,10 +113,26 @@ func (i *Indexer) handshakeHandleSync(block *handshake.Block) error {
+				}
 			case *handshake.RegisterCovenant:
-				slog.Debug(&quot;Handshake domain registration&quot;, &quot;resdata&quot;, c.ResourceData)
+				name, err := state.GetState().GetHandshakeNameByHash(c.NameHash)
+				if err != nil {
+					return err
</file context>
Fix with Cubic

@agaffney agaffney merged commit 27202c9 into main Dec 1, 2025
12 checks passed
@agaffney agaffney deleted the feat/handshake-storage branch December 1, 2025 22:24
@agaffney agaffney linked an issue Dec 1, 2025 that may be closed by this pull request
3 tasks
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.

Create the ability to store and retrieve Handshake blockchain data in cDNSd

3 participants