Skip to content

Commit e72be3c

Browse files
msbrogliclaude
andcommitted
feat(docker): add hathor-ct-crypto Rust library build to Dockerfile
Install Rust via rustup (distro cargo is too old for PyO3 0.22) and build the confidential transaction crypto bindings with maturin so hathor_ct_crypto is available in the production Docker image. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 21db83e commit e72be3c

File tree

19 files changed

+664
-2
lines changed

19 files changed

+664
-2
lines changed

.claude/skills/consensus/SKILL.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
description: "Investigate the consensus algorithm, voided transactions, best chain selection, reorgs, and accumulated weight in the DAG"
3+
---
4+
5+
# Consensus Algorithm
6+
7+
When the user asks about consensus, voided transactions, best chain, or reorgs, follow these steps:
8+
9+
## Step 1: Read the consensus core
10+
- `hathor/consensus/consensus.py` — main `Consensus` class, entry point for consensus updates
11+
- `hathor/consensus/block_consensus.py` — block consensus (best chain selection, reorgs)
12+
- `hathor/consensus/transaction_consensus.py` — transaction consensus (conflict resolution, voidance)
13+
14+
## Step 2: Understand voidance
15+
A vertex becomes "voided" when:
16+
- It conflicts with another vertex (double-spend) and loses
17+
- It is in a side chain (not on the best block chain)
18+
- Its parents/inputs are voided (voidance propagates)
19+
Check `transaction_metadata.py` for the `voided_by` field and how it's updated.
20+
21+
## Step 3: Understand best chain selection
22+
The best chain is determined by accumulated weight:
23+
- Each block accumulates the weight of itself plus all transactions that confirm it
24+
- The chain with highest accumulated weight wins
25+
- Reorgs happen when a competing chain surpasses the current best chain
26+
27+
## Step 4: Check related files
28+
- `hathor/transaction/transaction_metadata.py` — metadata fields: `voided_by`, `first_block`, `accumulated_weight`
29+
- `hathor/consensus/consensus_algorithm.py` — if it exists, may contain additional logic
30+
- `hathor/indexes/` — indexes that track consensus state
31+
32+
## Step 5: Explain the specific scenario
33+
If the user is asking about a specific scenario (e.g., why a tx was voided, how a reorg works), trace through the consensus code path step by step.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
description: "Investigate DAG architecture, parent selection, weight/difficulty calculation, DAA algorithm, and graph traversal"
3+
---
4+
5+
# DAG Architecture & Weight
6+
7+
When the user asks about the DAG structure, weight, difficulty, or parent selection, follow these steps:
8+
9+
## Step 1: Understand the DAG model
10+
- Hathor uses a DAG (Directed Acyclic Graph) where both blocks and transactions are vertices
11+
- Each vertex references parent vertices (blocks reference block parents, transactions reference tx parents)
12+
- Read `hathor/transaction/base_transaction.py` for the parent fields
13+
14+
## Step 2: Read the DAA (Difficulty Adjustment Algorithm)
15+
- `hathor/daa.py` — DAA calculates mining difficulty
16+
- Understand how weight/difficulty is adjusted based on block timestamps
17+
- Check the target time between blocks and adjustment window
18+
19+
## Step 3: Understand weight
20+
- Each vertex has a `weight` field representing the computational work
21+
- Blocks have higher minimum weight than transactions
22+
- Accumulated weight is used for consensus (best chain selection)
23+
24+
## Step 4: Check parent selection
25+
- How are parents selected for new transactions and blocks?
26+
- Transactions select tips from the mempool
27+
- Blocks select the best block as parent
28+
- Look for parent selection logic in vertex creation code
29+
30+
## Step 5: Check graph traversal utilities
31+
- Look for BFS/DFS traversal utilities
32+
- How are ancestors and descendants found?
33+
- `hathor/consensus/` uses graph traversal extensively
34+
35+
## Step 6: Explain
36+
Present the DAG mechanism or calculation relevant to the user's question with specific code references.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
description: "Investigate the event system, WebSocket protocol, pub/sub, event types, and event streaming in hathor-core"
3+
---
4+
5+
# Event System & WebSocket
6+
7+
When the user asks about events, WebSocket, or pub/sub, follow these steps:
8+
9+
## Step 1: Read the event module
10+
- `hathor/event/` — event system implementation
11+
- Understand event types and how they're generated
12+
- Check event storage and retrieval
13+
14+
## Step 2: Read the WebSocket module
15+
- `hathor/websocket/` — WebSocket protocol implementation
16+
- Understand the WebSocket message format
17+
- Check subscription/filtering mechanisms
18+
19+
## Step 3: Read the pub/sub system
20+
- `hathor/pubsub.py` — publish/subscribe system for internal event distribution
21+
- How components subscribe to and emit events
22+
- Event propagation flow
23+
24+
## Step 4: Understand event types
25+
- What events are emitted (new vertex, confirmation, reorg, etc.)
26+
- Event payload structure
27+
- How events relate to the transaction lifecycle
28+
29+
## Step 5: Check event streaming
30+
- How events are streamed to external consumers
31+
- Event ordering guarantees
32+
- Replay and catch-up mechanisms
33+
34+
## Step 6: Explain
35+
Present the event mechanism, WebSocket protocol detail, or pub/sub flow relevant to the user's question.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
description: "Investigate the feature activation system, bit signaling, feature states, and feature-gated behavior in hathor-core"
3+
---
4+
5+
# Feature Activation System
6+
7+
When the user asks about feature activation, bit signaling, or feature flags, follow these steps:
8+
9+
## Step 1: Read the core feature activation files
10+
- `hathor/feature_activation/feature.py``Feature` enum listing all features and their activation parameters
11+
- `hathor/feature_activation/feature_service.py``FeatureService` manages feature state transitions
12+
- `hathor/feature_activation/bit_signaling_service.py` — handles miner bit signaling in blocks
13+
14+
## Step 2: Understand the state machine
15+
Features follow this state machine:
16+
```
17+
DEFINED → STARTED → MUST_SIGNAL → LOCKED_IN → ACTIVE
18+
→ FAILED
19+
```
20+
- `hathor/feature_activation/model/feature_state.py``FeatureState` enum with all states
21+
- Each state transition depends on block heights and signaling thresholds
22+
23+
## Step 3: Understand bit signaling
24+
- Miners signal support for features by setting bits in block headers
25+
- Each feature is assigned a specific bit position
26+
- The signaling service counts bits over evaluation windows to determine if threshold is met
27+
28+
## Step 4: Check feature-gated behavior
29+
Search the codebase for uses of the feature activation system:
30+
- Look for `is_feature_active()` or similar checks
31+
- Features gate new behavior that should only activate after network consensus
32+
33+
## Step 5: Check feature configuration
34+
- Features have parameters: start height, timeout height, threshold percentage
35+
- These may differ between mainnet, testnet, and other networks
36+
- Check settings/configuration files for network-specific feature parameters
37+
38+
## Step 6: Explain
39+
Present the feature's current state, activation criteria, and any gated behavior relevant to the user's question.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
description: "Diagnose why a vertex was rejected from the mempool, including acceptance criteria, validation params, and rejection reasons"
3+
---
4+
5+
# Why a Vertex Was Refused from Mempool
6+
7+
When the user asks why a transaction or vertex was rejected from the mempool, follow these steps:
8+
9+
## Step 1: Read the vertex handler
10+
- `hathor/vertex_handler/vertex_handler.py``VertexHandler` is the main entry point for accepting vertices into the node
11+
- Look for the `on_new_vertex` method and its validation pipeline
12+
13+
## Step 2: Check acceptance criteria
14+
The vertex handler applies several checks before accepting a vertex:
15+
1. **Already exists** — vertex is already in storage
16+
2. **Verification failure** — basic or full verification fails (see verification skill)
17+
3. **Timestamp validation** — vertex timestamp must be within acceptable bounds
18+
4. **Parents validation** — parents must exist and be valid
19+
5. **Mempool-specific limits** — max mempool size, per-address limits, rate limiting
20+
6. **Hardened validation params** — stricter params for mempool acceptance vs. sync
21+
22+
## Step 3: Check P2P mempool sync
23+
- `hathor/p2p/sync_v2/mempool.py` — mempool sync protocol, may reject vertices during sync
24+
- Check for peer-level rejection reasons
25+
26+
## Step 4: Check mempool tips index
27+
- `hathor/indexes/mempool_tips_index.py` — tracks mempool tip transactions
28+
- May provide clues about why a transaction can't enter the mempool
29+
30+
## Step 5: Check hardened vs. relaxed validation
31+
The node may use different validation parameters for:
32+
- Mempool acceptance (stricter) — e.g., tighter timestamp bounds
33+
- Sync acceptance (relaxed) — accepts vertices that are already confirmed
34+
Look for `HardenedVertex` or validation parameter differences.
35+
36+
## Step 6: Explain
37+
Present the specific rejection reason, the check that failed, and any relevant thresholds or configuration values.

.claude/skills/mining/SKILL.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
description: "Investigate mining, stratum protocol, block templates, merge mining, PoW verification, and nonce handling"
3+
---
4+
5+
# Mining, Stratum & Block Templates
6+
7+
When the user asks about mining, stratum, or block templates, follow these steps:
8+
9+
## Step 1: Read the mining module
10+
- `hathor/mining/` — mining-related code
11+
- Understand block template generation
12+
- Check for CPU mining implementation (if any)
13+
14+
## Step 2: Read the stratum protocol
15+
- `hathor/stratum/` — stratum protocol implementation for external miners
16+
- Understand the stratum message flow (subscribe, authorize, notify, submit)
17+
- Check job creation and solution validation
18+
19+
## Step 3: Read merge mining
20+
- `hathor/merged_mining/` — merge mining (AuxPow) support
21+
- How Hathor blocks can be merge-mined with Bitcoin or other chains
22+
- `hathor/transaction/merge_mined_block.py` — merge-mined block structure
23+
24+
## Step 4: Understand PoW verification
25+
- How proof-of-work is verified (hash below target)
26+
- Nonce field and how it's used
27+
- Weight/difficulty relationship to the target
28+
29+
## Step 5: Check block construction
30+
- How transactions are selected from the mempool for inclusion
31+
- Block size limits, fee prioritization
32+
- How the coinbase/reward is constructed
33+
34+
## Step 6: Explain
35+
Present the mining mechanism relevant to the user's question with specific code references.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
description: "Investigate nano contract architecture, blueprints, runner execution, storage layer, actions, and inter-contract calls"
3+
---
4+
5+
# Nano Contract Architecture
6+
7+
When the user asks about nano contracts, blueprints, runner, storage, or actions, follow these steps:
8+
9+
## Step 1: Understand the blueprint system
10+
- `hathor/nanocontracts/` — main nano contracts package
11+
- Blueprints are contract templates that define methods, fields, and behavior
12+
- Look for blueprint base class and how blueprints are registered
13+
14+
## Step 2: Read the runner
15+
- `hathor/nanocontracts/runner/runner.py``Runner` executes contract methods
16+
- Understand the execution model: method dispatch, argument parsing, context injection
17+
- Check how the runner manages contract state during execution
18+
19+
## Step 3: Read the execution layer
20+
- `hathor/nanocontracts/execution/` — block-level execution orchestration
21+
- `hathor/nanocontracts/execution/block_executor.py` — executes NC txs within a block
22+
- Understand ordering, dependency resolution, and rollback on failure
23+
24+
## Step 4: Understand storage
25+
- `hathor/nanocontracts/storage/` — contract storage layer
26+
- How contract fields/state are persisted and retrieved
27+
- Storage key formats, serialization, and caching
28+
29+
## Step 5: Understand actions
30+
Actions represent token movements in NC transactions:
31+
- **Deposit** — tokens flow TO the contract (appears on output side)
32+
- **Withdrawal** — tokens flow FROM the contract (appears on input side)
33+
- **Grant/Acquire** — authority token operations
34+
- Check `hathor/transaction/headers/nano_header.py` for the NanoHeader structure
35+
36+
## Step 6: Check inter-contract calls
37+
- If the user asks about contracts calling other contracts, look for call/invoke mechanisms in the runner
38+
- Check for context propagation and reentrancy protections
39+
40+
## Step 7: Explain
41+
Present the architecture, execution flow, or specific mechanism relevant to the user's question.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
description: "Diagnose why a nano contract transaction failed execution, including NCFail exceptions, runner errors, and fuel/memory limits"
3+
---
4+
5+
# Why a Nano Contract TX Failed
6+
7+
When the user asks why a nano contract transaction failed, follow these steps:
8+
9+
## Step 1: Identify the failure type
10+
Read the exception hierarchy:
11+
- `hathor/nanocontracts/exception.py` — all NC exception types, especially `NCFail` and its subclasses
12+
13+
## Step 2: Check the runner error paths
14+
- `hathor/nanocontracts/runner/runner.py` — the `Runner` class executes contract methods; look for all places that raise `NCFail` or related exceptions
15+
- Check method resolution, argument validation, and return value handling
16+
17+
## Step 3: Check the block executor
18+
- `hathor/nanocontracts/execution/block_executor.py``BlockExecutor` orchestrates NC execution during block processing
19+
- Look for error handling, rollback logic, and how failures are recorded
20+
21+
## Step 4: Common failure causes
22+
Investigate these common failure paths:
23+
1. **Seqnum validation** — NC transactions must have sequential seqnum per contract
24+
2. **Fuel/memory limits** — resource limits that abort execution
25+
3. **Method not found** — calling a non-existent blueprint method
26+
4. **Invalid arguments** — wrong types or number of arguments
27+
5. **Storage errors** — reading non-existent keys, type mismatches
28+
6. **Action validation failures** — insufficient balance for withdrawals, invalid token operations
29+
7. **Blueprint-level assertions** — custom `raise NCFail(...)` in blueprint code
30+
31+
## Step 5: Check the execution result
32+
- Look at how execution results are stored and how the failure is surfaced (metadata, events, API responses)
33+
- Check `hathor/nanocontracts/execution/result.py` if it exists
34+
35+
## Step 6: Explain the failure chain
36+
Present the full failure path: what triggered the error, which check failed, and what the user can do to fix it.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
description: "Investigate why a nano contract transaction was skipped during execution, including skip conditions and seqnum handling"
3+
---
4+
5+
# Why a Nano Contract TX Was Skipped
6+
7+
When the user asks why a nano contract transaction was skipped, follow these steps:
8+
9+
## Step 1: Read the skip logic
10+
- `hathor/nanocontracts/execution/block_executor.py``BlockExecutor` contains the primary skip logic
11+
- `hathor/nanocontracts/execution/consensus_block_executor.py` — consensus-level executor may have additional skip conditions
12+
13+
## Step 2: Understand skip conditions
14+
A nano contract transaction is skipped (not executed) when:
15+
1. **Voided by a previous failure** — if an earlier NC tx in the same block or chain failed, subsequent txs for the same contract may be skipped
16+
2. **Seqnum gap** — if the expected seqnum doesn't match (because a previous tx failed), execution is skipped but seqnum is still consumed
17+
3. **Contract state inconsistency** — the contract's state doesn't allow execution to proceed
18+
19+
## Step 3: Check how skipping differs from failure
20+
- Skipped txs are different from failed txs: they don't execute at all, but their seqnum slot is still consumed
21+
- Look for `NCTxExecutionSkipped` or similar markers in the code
22+
- Check what metadata is set on skipped transactions
23+
24+
## Step 4: Trace the execution flow
25+
Follow the block executor's loop over NC transactions in a block:
26+
1. For each NC tx, check if it should be executed or skipped
27+
2. If skipped, check what state is updated (seqnum counter, metadata)
28+
3. If the user has a specific scenario, trace through with their parameters
29+
30+
## Step 5: Explain
31+
Present the skip condition that was triggered, why it was triggered, and what the downstream effects are (e.g., subsequent txs for the same contract will also be skipped).
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
description: "Investigate the P2P network protocol, peer connections, sync v2, peer discovery, and message propagation"
3+
---
4+
5+
# P2P Network Protocol
6+
7+
When the user asks about P2P networking, peer connections, sync, or message propagation, follow these steps:
8+
9+
## Step 1: Read the core P2P files
10+
- `hathor/p2p/manager.py``ConnectionsManager` manages all peer connections
11+
- `hathor/p2p/protocol.py` — protocol state machine for peer connections
12+
- `hathor/p2p/states/` — protocol states (HELLO, PEER_ID, READY, etc.)
13+
14+
## Step 2: Understand the sync protocol
15+
- `hathor/p2p/sync_v2/` — sync v2 implementation (current sync protocol)
16+
- Look for `SyncV2Protocol` or similar classes
17+
- Understand how nodes exchange block and transaction data
18+
- Check `hathor/p2p/sync_v2/mempool.py` for mempool synchronization
19+
20+
## Step 3: Check peer discovery
21+
- How peers find each other (DNS seeds, bootstrap nodes, peer exchange)
22+
- Peer management: connection limits, peer scoring, ban logic
23+
24+
## Step 4: Check message types
25+
- Look for message definitions and handlers
26+
- Understand the message serialization format
27+
- Check how vertices are propagated to peers
28+
29+
## Step 5: Check connection lifecycle
30+
- Connection establishment (TCP, TLS)
31+
- Handshake protocol (version negotiation, capabilities exchange)
32+
- Connection maintenance (heartbeat/ping-pong)
33+
- Disconnection handling
34+
35+
## Step 6: Explain
36+
Present the relevant P2P mechanism, protocol flow, or configuration based on the user's specific question.

0 commit comments

Comments
 (0)