Skip to content

Align sequence locks and unknown covenant handling with hsd#53

Merged
wolf31o2 merged 2 commits into
mainfrom
fix/hsd-sequence-unknown-covenants
Jul 14, 2026
Merged

Align sequence locks and unknown covenant handling with hsd#53
wolf31o2 merged 2 commits into
mainfrom
fix/hsd-sequence-unknown-covenants

Conversation

@wolf31o2

@wolf31o2 wolf31o2 commented Jul 13, 2026

Copy link
Copy Markdown
Member

Summary

  • Apply Handshake sequence locks and OP_CSV semantics to all non-coinbase transaction versions.
  • Permit future unknown covenant types while enforcing hsd-style item count and size bounds.
  • Keep known covenant validation unchanged and add unknown covenant round-trip and spend tests.

Validation

  • go test ./wire ./txscript ./blockchain
  • git diff --check

Review notes

Consensus-critical. This removes inherited Bitcoin tx-version gates and avoids rejecting reserved future covenant types at wire/sanity layers.


Summary by cubic

Aligns consensus with hsd by applying sequence locks/OP_CHECKSEQUENCEVERIFY to all non-coinbase transactions and permitting unknown covenants under hsd stack and serialized-size bounds. Fixes unknown covenant size checks to match hsd’s MAX_COVENANT_SIZE.

  • New Features

    • Sequence locks and OP_CHECKSEQUENCEVERIFY apply to all tx versions in blockchain/txscript (removed version ≥2 gate); added version-0 engine test.
    • Unknown covenants accepted in wire (no type cap; IsKnown/IsUnknown helpers); bounds enforced: MaxCovenantItems=1000, per-item ≤585 bytes, and hsd-style max serialized size in blockchain; allow unknown→NONE, reject unknown→known name; tests added.
  • Bug Fixes

    • Correct unknown covenant serialized-size checks and add boundary tests to align with hsd limits.

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

Review in cubic

Summary by CodeRabbit

  • New Features

    • Added support for unknown covenant types within defined item-count and size limits.
    • Added covenant helpers to identify whether a covenant type is known or unknown.
    • Increased supported covenant item and payload limits.
  • Bug Fixes

    • Sequence locks and OP_CHECKSEQUENCEVERIFY now work correctly for transactions of all versions.
    • Unknown covenant spends are validated with appropriate rules.

Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Sequence-lock semantics no longer depend on transaction version, allowing version-zero transactions in chain calculation and OP_CHECKSEQUENCEVERIFY. Covenant wire handling now accepts unknown covenant types within expanded item limits, exposes known/unknown classification helpers, and validates unknown covenant size and item-count bounds during blockchain checks. Tests cover sequence locks, covenant encoding, type classification, sanity validation, and covenant spending.

Possibly related PRs

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main changes: sequence-lock behavior and unknown covenant handling aligned with hsd.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/hsd-sequence-unknown-covenants

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@blockchain/names.go`:
- Around line 24-26: Update maxCovenantSize in names.go to derive from hsd’s
current consensus formula, using the existing maxResourceSize value and removing
the stale extra fields. Address the duplicated maxCovenantItems definition
between names.go and wire/covenant.go by centralizing the constant or adding a
clear cross-reference so both packages remain synchronized.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cbea625f-fd63-4563-8f34-ad4a2fc37f94

📥 Commits

Reviewing files that changed from the base of the PR and between f0f9902 and f41c91d.

📒 Files selected for processing (8)
  • blockchain/chain.go
  • blockchain/chain_test.go
  • blockchain/names.go
  • blockchain/names_test.go
  • txscript/engine_test.go
  • txscript/opcode.go
  • wire/covenant.go
  • wire/covenant_test.go
💤 Files with no reviewable changes (1)
  • txscript/opcode.go

Comment thread blockchain/names.go Outdated
Comment on lines +24 to +26
maxCovenantItems = 1000
maxCovenantSize = 1 + 32 + 1 + 4 + 2 + maxResourceSize + 1 + 32

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for maxCovenantSize or maxResourceSize definitions and usage
rg -nP 'maxCovenantSize|maxResourceSize' blockchain/names.go
rg -nP 'maxCovenantItems' blockchain/ wire/

Repository: blinklabs-io/handshake-node

Length of output: 1251


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the relevant logic in the local repository.
sed -n '1,120p' blockchain/names.go
printf '\n---\n'
sed -n '860,910p' blockchain/names.go
printf '\n---\n'
sed -n '1,220p' wire/covenant.go

Repository: blinklabs-io/handshake-node

Length of output: 9338


🌐 Web query:

hsd covenant size limit maxCovenantSize maxResourceSize covenantItemsSize consensus constant

💡 Result:

In the hsd implementation of the Handshake protocol, covenant size limits are governed by constants defined in lib/covenants/rules.js [1][2]. The relevant consensus-related constraints are: MAX_RESOURCE_SIZE: This is set to 512 bytes [1][2]. It defines the maximum allowed size for record data within a covenant (specifically used for items[2] in a covenant) [1][2][3]. MAX_COVENANT_SIZE: This represents the maximum total serialized size of a covenant [1][2]. It is calculated as a constant expression: 2 + MAX_RESOURCE_SIZE + 1 + 32 [1][2]. Given MAX_RESOURCE_SIZE is 512, this results in a maximum size of 547 bytes [1][2]. These rules are enforced during transaction validation to ensure that covenant data, such as DNS resource records, remains within the defined protocol constraints [1][2][3]. While consensus.js manages network-wide constants like block size (1,000,000 bytes) [4][5], the covenant-specific limits are handled within the covenants module to maintain naming system integrity [6][7].

Citations:


🌐 Web query:

hsd lib/covenants/rules.js MAX_COVENANT_SIZE MAX_RESOURCE_SIZE formula unknown covenant items size

💡 Result:

In the hsd library, the file lib/covenants/rules.js manages protocol limits for Handshake name covenants [1][2]. The constants MAX_COVENANT_SIZE and MAX_RESOURCE_SIZE are defined to enforce consensus rules regarding the size of covenants and their embedded resource data [1][3]. MAX_RESOURCE_SIZE is the limit on the size of record data within a covenant. Historically, this limit was 512 bytes [1][3]. Following a protocol hard fork (as noted in recent updates), this limit has been increased to 8,192 bytes to accommodate richer zone files [3][4]. The calculation for MAX_COVENANT_SIZE is defined in the source code as: rules.MAX_COVENANT_SIZE = (0 + 1 + 32 + 2 + rules.MAX_RESOURCE_SIZE + 1 + 32); In this formula, the components represent: - 1: A byte for the covenant type. - 32: A 32-byte hash (typically the name hash). - 2: An overhead allowance (or specific protocol field allocation). - rules.MAX_RESOURCE_SIZE: The maximum size permitted for the resource record data [1][5]. - 1 + 32: Additional structural or metadata padding used in the covenant serialization [1][6]. Essentially, the total covenant size limit is derived from the sum of these fixed-size fields plus the current maximum allowed resource size [1]. Enforcement of these limits occurs during block validation, where the system checks both the length of specific items (like record data) and the total size of the covenant object using these defined constants [1][3].

Citations:


Align maxCovenantSize with hsd's current consensus bound. hsd now derives MAX_COVENANT_SIZE from 1 + 32 + 2 + MAX_RESOURCE_SIZE + 1 + 32, and MAX_RESOURCE_SIZE is 8192 upstream, so the local 1 + 32 + 1 + 4 + 2 + maxResourceSize + 1 + 32 bound is stale and can diverge from consensus for unknown covenants. Also, maxCovenantItems = 1000 is duplicated in wire/covenant.go; add a cross-reference or centralize it to keep the two packages in sync.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@blockchain/names.go` around lines 24 - 26, Update maxCovenantSize in names.go
to derive from hsd’s current consensus formula, using the existing
maxResourceSize value and removing the stale extra fields. Address the
duplicated maxCovenantItems definition between names.go and wire/covenant.go by
centralizing the constant or adding a clear cross-reference so both packages
remain synchronized.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 8 files

You're on the cubic free plan with 11 free PR reviews remaining this month. Upgrade for unlimited reviews.

Re-trigger cubic

Comment thread blockchain/names.go Outdated
Comment thread blockchain/names.go Outdated
Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
@wolf31o2
wolf31o2 merged commit e5d2cc8 into main Jul 14, 2026
12 checks passed
@wolf31o2
wolf31o2 deleted the fix/hsd-sequence-unknown-covenants branch July 14, 2026 13:47
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