diff --git a/.claude-flow/metrics/system-metrics.json b/.claude-flow/metrics/system-metrics.json new file mode 100644 index 0000000000..4a0e8f9ec5 --- /dev/null +++ b/.claude-flow/metrics/system-metrics.json @@ -0,0 +1,110 @@ +[ + { + "timestamp": 1755890431041, + "memoryTotal": 549755813888, + "memoryUsed": 511922192384, + "memoryFree": 37833621504, + "memoryUsagePercent": 93.11810433864594, + "memoryEfficiency": 6.881895661354065, + "cpuCount": 32, + "cpuLoad": 0.1175994873046875, + "platform": "darwin", + "uptime": 75174 + }, + { + "timestamp": 1755890461042, + "memoryTotal": 549755813888, + "memoryUsed": 512978010112, + "memoryFree": 36777803776, + "memoryUsagePercent": 93.31015646457672, + "memoryEfficiency": 6.689843535423279, + "cpuCount": 32, + "cpuLoad": 0.1191864013671875, + "platform": "darwin", + "uptime": 75204 + }, + { + "timestamp": 1755890491043, + "memoryTotal": 549755813888, + "memoryUsed": 508581625856, + "memoryFree": 41174188032, + "memoryUsagePercent": 92.51045882701874, + "memoryEfficiency": 7.489541172981262, + "cpuCount": 32, + "cpuLoad": 0.11566162109375, + "platform": "darwin", + "uptime": 75234 + }, + { + "timestamp": 1755890521044, + "memoryTotal": 549755813888, + "memoryUsed": 510043963392, + "memoryFree": 39711850496, + "memoryUsagePercent": 92.77645647525787, + "memoryEfficiency": 7.2235435247421265, + "cpuCount": 32, + "cpuLoad": 0.114990234375, + "platform": "darwin", + "uptime": 75264 + }, + { + "timestamp": 1755890551046, + "memoryTotal": 549755813888, + "memoryUsed": 511729025024, + "memoryFree": 38026788864, + "memoryUsagePercent": 93.08296740055084, + "memoryEfficiency": 6.917032599449158, + "cpuCount": 32, + "cpuLoad": 0.1104278564453125, + "platform": "darwin", + "uptime": 75294 + }, + { + "timestamp": 1755890581046, + "memoryTotal": 549755813888, + "memoryUsed": 510072913920, + "memoryFree": 39682899968, + "memoryUsagePercent": 92.78172254562378, + "memoryEfficiency": 7.218277454376221, + "cpuCount": 32, + "cpuLoad": 0.1017913818359375, + "platform": "darwin", + "uptime": 75324 + }, + { + "timestamp": 1755890611047, + "memoryTotal": 549755813888, + "memoryUsed": 509791354880, + "memoryFree": 39964459008, + "memoryUsagePercent": 92.73050725460052, + "memoryEfficiency": 7.269492745399475, + "cpuCount": 32, + "cpuLoad": 0.0872344970703125, + "platform": "darwin", + "uptime": 75354 + }, + { + "timestamp": 1755890641048, + "memoryTotal": 549755813888, + "memoryUsed": 509953163264, + "memoryFree": 39802650624, + "memoryUsagePercent": 92.75994002819061, + "memoryEfficiency": 7.240059971809387, + "cpuCount": 32, + "cpuLoad": 0.0832061767578125, + "platform": "darwin", + "uptime": 75384 + }, + { + "timestamp": 1755890671049, + "memoryTotal": 549755813888, + "memoryUsed": 509911793664, + "memoryFree": 39844020224, + "memoryUsagePercent": 92.75241494178772, + "memoryEfficiency": 7.24758505821228, + "cpuCount": 32, + "cpuLoad": 0.074127197265625, + "platform": "darwin", + "uptime": 75414 + } +] \ No newline at end of file diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000000..4cf9fbc855 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,144 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Project Overview + +Chainweb-node is the implementation of Kadena's Chainweb consensus protocol - a braided, parallelized Proof of Work blockchain architecture. The project is written in Haskell and uses Cabal as the build system. + +## Build Commands + +### Building the project +```bash +# Update cabal package index (do this occasionally) +cabal update + +# Build all components +cabal build all + +# Build specific components +cabal build chainweb # Main library +cabal build chainweb-node # Node executable +cabal build cwtools # Command-line tools +``` + +### Running tests +```bash +# Run all tests +cabal test chainweb-tests + +# Run tests with specific patterns +cabal run chainweb-tests -- --hide-successes -p '!/chainweb216Test/' + +# Run a single test module +cabal test chainweb-tests --test-options="-p 'Chainweb.Test.BlockHeaderDB'" +``` + +### Common development tasks +```bash +# Run the chainweb node +cabal run chainweb-node + +# Get help and configuration options +cabal run chainweb-node -- --help +cabal run chainweb-node -- --print-config > config.yaml + +# Build with optimizations +cabal build -O2 chainweb-node + +# Clean build artifacts +cabal clean +``` + +## Architecture Overview + +### Core Module Structure + +The codebase is organized into several key areas: + +- **src/Chainweb/**: Core blockchain implementation + - `BlockHeader/`: Block header management and genesis blocks + - `BlockHeaderDB/`: Block header database operations + - `CutDB/`: Cut (blockchain state) management + - `Mempool/`: Transaction mempool implementation + - `Miner/`: Mining-related functionality + - `Pact/`: Smart contract (Pact) integration + - `SPV/`: Simple Payment Verification proofs + - `Payload/`: Block payload management + - `RestAPI/`: REST API endpoints + - `VerifierPlugin/`: Pluggable verification systems (e.g., Hyperlane) + +- **src/P2P/**: Peer-to-peer networking layer + - Bootstrap nodes configuration + - Peer discovery and communication + +- **node/**: Chainweb-node executable + - Main entry point is `node/src/ChainwebNode.hs` + +- **cwtools/**: Command-line utilities for debugging and maintenance + +- **test/**: Test suites + - `unit/`: Unit tests + - `pact/`: Pact smart contract tests + - `multinode/`: Multi-node integration tests + +### Key Architectural Concepts + +1. **Chainweb Protocol**: Multiple parallel chains (20 chains in mainnet) that reference each other's block headers, creating a braided structure + +2. **Cut**: The current state across all chains - essentially a snapshot of the latest block header on each chain + +3. **Pact Integration**: Each chain runs its own Pact interpreter for smart contract execution + +4. **P2P Network**: Nodes communicate via a custom P2P protocol for block propagation and synchronization + +5. **Mining API**: Provides endpoints for external miners to get work and submit solutions + +## Working with the Codebase + +### Language Extensions +The project uses many GHC language extensions. Common ones include: +- OverloadedStrings +- LambdaCase +- TypeApplications +- ScopedTypeVariables +- FlexibleContexts + +### External Dependencies +Key external dependencies managed via Cabal: +- pact (smart contract language) +- rocksdb-haskell (database backend) +- servant (REST API framework) +- yet-another-logger (logging) + +Custom forks are specified in `cabal.project` as source-repository-packages. + +### Database Backends +- RocksDB for block headers and payloads +- SQLite for Pact state + +### Testing Approach +- Unit tests use HUnit and QuickCheck +- Integration tests use custom multi-node test framework +- Test data files in `test/pact/` and `test/golden/` +- CI runs tests on multiple GHC versions (9.6, 9.8, 9.10) + +## Network Configuration + +### Networks +- **mainnet01**: Production network +- **testnet04**: Test network +- **development**: Local development network + +### Bootstrap Nodes +Hardcoded in `src/P2P/BootstrapNodes.hs` +- Mainnet: us-[e|w][1-3].chainweb.com, jp[1-3].chainweb.com, fr[1-3].chainweb.com +- Testnet: us[1-2].testnet.chainweb.com, eu[1-2].testnet.chainweb.com, ap[1-2].testnet.chainweb.com + +## Important Files + +- `cabal.project`: Cabal configuration with dependency overrides +- `chainweb.cabal`: Main library package definition +- `node/chainweb-node.cabal`: Node executable package +- `.github/workflows/`: CI/CD workflows +- `src/Chainweb/Version.hs`: Network version definitions \ No newline at end of file diff --git a/flake.lock b/flake.lock index 36825d4335..5ab9ecefb8 100644 --- a/flake.lock +++ b/flake.lock @@ -69,11 +69,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1726560853, - "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "owner": "numtide", "repo": "flake-utils", - "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { @@ -85,11 +85,11 @@ "hackage": { "flake": false, "locked": { - "lastModified": 1744590374, - "narHash": "sha256-47Rb79BhL4QTABSkXwu3+ZHJUdAaTntCBQrmOPQd2RE=", + "lastModified": 1756167970, + "narHash": "sha256-dFrR7KhVWixoNtFrQGnR70a/yeLAUdcfDQqHdJ0HCN8=", "owner": "input-output-hk", "repo": "hackage.nix", - "rev": "4862557beb59a2ee7844a16471cccbeb55354d16", + "rev": "7a672ba177722f6a500060ff7ff19f0a81544ac2", "type": "github" }, "original": { @@ -324,11 +324,11 @@ }, "nix-filter": { "locked": { - "lastModified": 1710156097, - "narHash": "sha256-1Wvk8UP7PXdf8bCCaEoMnOT1qe5/Duqgj+rL8sRQsSM=", + "lastModified": 1731533336, + "narHash": "sha256-oRam5PS1vcrr5UPgALW0eo1m/5/pls27Z/pabHNy2Ms=", "owner": "numtide", "repo": "nix-filter", - "rev": "3342559a24e85fc164b295c3444e8a139924675b", + "rev": "f7653272fd234696ae94229839a99b73c9ab7de0", "type": "github" }, "original": { diff --git a/src/Chainweb/BlockHeaderDB/RestAPI/Server.hs b/src/Chainweb/BlockHeaderDB/RestAPI/Server.hs index 7bda07fa04..dc4b9d6017 100644 --- a/src/Chainweb/BlockHeaderDB/RestAPI/Server.hs +++ b/src/Chainweb/BlockHeaderDB/RestAPI/Server.hs @@ -428,5 +428,7 @@ blockStreamHandler db withPayloads = Tagged $ \req resp -> do } f :: HeaderUpdate -> ServerEvent - f hu = ServerEvent (Just $ fromByteString "BlockHeader") Nothing + f hu = ServerEvent (Just $ fromByteString eventType) Nothing [ fromLazyByteString . encode $ toJSON hu ] + where + eventType = if withPayloads then "Block" else "BlockHeader"