Skip to content

Fix chain anchor: handle already-registered hashes and gas limit override - #79

Merged
crtahlin merged 5 commits into
mainfrom
development
Mar 2, 2026
Merged

crtahlin merged 5 commits into
mainfrom
development

Conversation

@crtahlin

@crtahlin crtahlin commented Mar 2, 2026

Copy link
Copy Markdown

Summary

  • Handle already-registered hashes (CLI anchor command should handle already-registered hashes gracefully #76): chain anchor now pre-checks if a hash is already registered before sending a transaction, preventing wasted gas and unhelpful revert errors. Shows owner, type, and timestamp in both human-readable and JSON output. chain protect --anchor-new treats already-registered new hash as non-fatal.
  • Gas limit override (CLI anchor command: gas estimation exceeds Base Sepolia per-tx limit #75): Adds --gas option to all chain write commands (anchor, access, status, transfer, delegate, transform, protect) and CHAIN_GAS_LIMIT env var, bypassing RPC estimation that can return values exceeding block limits.
  • Integration tests: Verifies both fixes against local Hardhat and Base Sepolia — including already-registered detection and graceful insufficient-gas handling.

Closes #76
Closes #75

Changes

File Change
exceptions.py Add DataAlreadyRegisteredError with data_hash, owner, timestamp, data_type
core/chain_client.py Pre-check in anchor()/anchor_for(), gas_limit param, skip estimation when explicit
cli.py Error handler for already-registered, --gas on 7 write commands, gas_limit in _chain_config
config.py CHAIN_GAS_LIMIT env var
.env.example Add commented CHAIN_GAS_LIMIT
README.md Config table + usage example
CLAUDE.md Config docs
CHANGELOG.md [0.8.1] and [0.8.2] entries
__init__.py / pyproject.toml Version 0.8.00.8.2
tests/test_chain_client.py Fix 5 existing tests for pre-check, add 6 new tests
tests/test_cli.py 4 new tests (already-registered + gas flag)
tests/test_integration.py 2 new integration tests (Base Sepolia + Hardhat)

Test plan

  • Unit tests: pytest --ignore=tests/test_integration.py — 545 passed
  • Chain client tests: pytest tests/test_chain_client.py — 85 passed
  • CLI chain tests: pytest tests/test_cli.py -k chain — 74 passed
  • Integration: Hardhat — already-registered detection + insufficient gas handling
  • Integration: Base Sepolia — anchor + already-registered detection

crtahlin added 4 commits March 2, 2026 15:16
Add pre-check in anchor()/anchor_for() to detect already-registered
hashes before sending transactions, preventing wasted gas and unhelpful
revert errors. Includes DataAlreadyRegisteredError exception, CLI error
handling with human-readable and JSON output, and non-fatal handling in
chain protect --anchor-new.
RPC gas estimation can return values exceeding block limits. Add --gas
CLI option and CHAIN_GAS_LIMIT env var to set an explicit gas limit,
bypassing estimation. Applied to all chain write commands: anchor,
access, status, transfer, delegate, transform, protect.
Anchors a hash, waits for propagation, then verifies a second anchor
attempt raises DataAlreadyRegisteredError with correct attributes.
Verifies that setting an explicit gas limit too low for a contract call
raises ChainTransactionError gracefully rather than an unhandled crash.
Node rejects pre-broadcast, so no gas is wasted.
dependencies was placed after [project.urls] section header, causing
setuptools to parse it as a URL entry rather than a project dependency
list. CI failed with "project.urls.dependencies must be string".
@crtahlin
crtahlin merged commit 21e49e8 into main Mar 2, 2026
11 checks passed
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.

CLI anchor command should handle already-registered hashes gracefully CLI anchor command: gas estimation exceeds Base Sepolia per-tx limit

1 participant