Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Auto-generated from all feature plans. Last updated: 2026-04-12
- N/A (CI configuration only, no persistent storage) (013-ci-cd-pipeline)
- GitHub-Flavored Markdown (documentation-only feature; no C++ changes) + N/A (Markdown files only; Mermaid diagrams rendered natively by GitHub) (014-documentation-developer-guide)
- N/A (no persistence changes) (014-documentation-developer-guide)
- C++20 (`-std=c++20`) + Boost (Asio, Serialization, Program Options), OpenSSL, nlohmann/json (vendored), Catch2 (test) (015-compile-time-optimization)
- N/A (build-system-only change) (015-compile-time-optimization)

- C++20 (`-std=c++20`) + Boost (Asio, Serialization), OpenSSL, nlohmann/json (vendored `src/json.hpp`), Catch2 (test only) (001-code-constitution-audit)

Expand Down Expand Up @@ -45,9 +47,9 @@ C++20 (`-std=c++20`): Follow standard conventions
- Do not include task numbers (e.g. T001, T010) in code comments. Comments should describe *what* or *why*, not reference planning artifacts.

## Recent Changes
- 015-compile-time-optimization: Added C++20 (`-std=c++20`) + Boost (Asio, Serialization, Program Options), OpenSSL, nlohmann/json (vendored), Catch2 (test)
- 014-documentation-developer-guide: Added GitHub-Flavored Markdown (documentation-only feature; no C++ changes) + N/A (Markdown files only; Mermaid diagrams rendered natively by GitHub)
- 013-ci-cd-pipeline: Added YAML (GitHub Actions workflow), C++20 (project under test) + GitHub Actions, MSYS2 (Windows), apt (Linux), Homebrew (macOS)
- 012-integration-test-suite: Added C++20 (`-std=c++20`) + Boost (Asio, Serialization), OpenSSL (EVP SHA-256, X.509 cert generation), nlohmann/json (vendored `src/json.hpp`), Catch2 (test framework)


<!-- MANUAL ADDITIONS START -->
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6

- name: Install dependencies (Linux)
if: runner.os == 'Linux'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ src/network/.dirstamp
# Compiled binaries
blockchain
src/blockchain
src/libblockchain_core.a
test-chain

# Test binaries
Expand Down
2 changes: 1 addition & 1 deletion .specify/feature.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"feature_directory": "specs/014-documentation-developer-guide"
"feature_directory": "specs/015-compile-time-optimization"
}
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.71])
AC_INIT([blockchain], [0.0.1], [tim@metaverse.systems])
AC_INIT([blockchain], [0.5.0], [tim@metaverse.systems])
AC_CONFIG_SRCDIR([src/main.cpp])
AC_CONFIG_HEADERS([config.h])

# Checks for programs.
AC_PROG_CXX
AC_PROG_RANLIB
AM_INIT_AUTOMAKE([subdir-objects])

# Checks for libraries.
Expand Down
16 changes: 12 additions & 4 deletions docs/ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Last updated: 2026-04-12
| 012 | Integration Test Suite | End-to-end Catch2 integration tests over real TLS: 19 RPC endpoint tests (all JSON-RPC methods with positive/negative cases), 3 P2P tests (single-block propagation, multi-block propagation, 3-node relay), shared test infrastructure (TLS cert generation, in-process NodeInstance, synchronous RpcTestClient), bug fixes in BlockPropagation consensus config and PeerClient read loop |
| 013 | CI/CD Pipeline | GitHub Actions workflow with matrix build (Linux GCC/Clang, macOS Clang, Windows MSYS2), per-binary test execution, MSYS2 caching, Catch2-from-source on Windows |
| 014 | Documentation & Developer Guide | Expanded README with cross-platform build instructions and two-node quickstart, configuration reference (9 CLI flags, 30 config.json fields, TLS setup), RPC API reference (20 methods with curl examples), architecture overview with Mermaid diagrams, contributing guide |
| 015 | Compile-Time Optimization | Shared static archive (`libblockchain_core.a`) eliminates redundant compilation of 11 core source files across 14 build targets, reducing compilation units from ~177 to ~34 (~81% reduction), clean build time from ~16 min to ~2.5 min |

## Suggested Specs

Expand Down Expand Up @@ -67,19 +68,25 @@ The daemon takes a single positional argument (blockchain directory). Ports are

### Tier 5 — Future / Exploratory

#### 015 — Smart Contract / Scripting Layer
#### 015 — Compile-Time Optimization

*Completed. See spec 015 in Completed table above.*

---

#### 016 — Smart Contract / Scripting Layer

No programmability exists beyond storing opaque data strings. Explore adding a scripting or smart contract layer for programmable on-chain logic.

---

#### 016 — Monitoring, Metrics & Health Endpoint
#### 017 — Monitoring, Metrics & Health Endpoint

No observability. Add a `/health` HTTP endpoint, Prometheus-compatible metrics (block height, peer count, chunk loads), and structured log leveling.

---

#### 017 — Light Client Protocol
#### 018 — Light Client Protocol

No way to verify block inclusion without downloading the full chain. Design a light client protocol using Merkle proofs (depends on 008) for resource-constrained participants.

Expand All @@ -101,7 +108,8 @@ No way to verify block inclusion without downloading the full chain. Design a li
012 Integration Tests ──┐
013 CI/CD Pipeline ─────┼── Tier 4: COMPLETE ✓
014 Documentation ──────┘
015–017 ────────────────── Tier 5: future
015 Compile-Time Opt ───── Tier 4b: COMPLETE ✓
016–018 ────────────────── Tier 5: future
```

Tiers 1–4 are complete. Tier 5 specs (015–017) are exploratory future work.
36 changes: 36 additions & 0 deletions specs/015-compile-time-optimization/checklists/requirements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Specification Quality Checklist: Compile-Time Optimization

**Purpose**: Validate specification completeness and quality before proceeding to planning
**Created**: 2026-04-12
**Feature**: [spec.md](../spec.md)

## Content Quality

- [x] No implementation details (languages, frameworks, APIs)
- [x] Focused on user value and business needs
- [x] Written for non-technical stakeholders
- [x] All mandatory sections completed

## Requirement Completeness

- [x] No [NEEDS CLARIFICATION] markers remain
- [x] Requirements are testable and unambiguous
- [x] Success criteria are measurable
- [x] Success criteria are technology-agnostic (no implementation details)
- [x] All acceptance scenarios are defined
- [x] Edge cases are identified
- [x] Scope is clearly bounded
- [x] Dependencies and assumptions identified

## Feature Readiness

- [x] All functional requirements have clear acceptance criteria
- [x] User scenarios cover primary flows
- [x] Feature meets measurable outcomes defined in Success Criteria
- [x] No implementation details leak into specification

## Notes

- All items pass validation. Spec is ready for `/speckit.clarify` or `/speckit.plan`.
- FR-007 references "Autotools" which is the existing build system (project context, not implementation prescription).
- Key Entities section references specific filenames to precisely define the problem scope, not to prescribe a solution.
68 changes: 68 additions & 0 deletions specs/015-compile-time-optimization/data-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Data Model: Compile-Time Optimization

**Feature**: 015-compile-time-optimization
**Date**: 2026-04-12

## Entities

This feature modifies build system configuration files, not runtime data structures. The "entities" are the build artifacts and their relationships.

### Static Archive: `libblockchain_core.a`

| Attribute | Value |
|-----------|-------|
| Location | `src/` (built by `src/Makefile.am`) |
| Type | `noinst_LIBRARIES` (internal, not installed) |
| Sources | Block.cpp, Blockchain.cpp, Chunk.cpp, utils.cpp, NodeConfig.cpp, PeerManager.cpp, BlockPropagation.cpp, MerkleTree.cpp, network/RpcServer.cpp, network/PeerServer.cpp, network/PeerClient.cpp |
| Flags | `-std=c++20 -Wall -Wextra -pedantic $(BOOST_CPPFLAGS) ${OPENSSL_CFLAGS}` |
| Consumers | `blockchain` (main), all 13 `check_PROGRAMS` |

### Main Binary: `blockchain`

| Attribute | Value |
|-----------|-------|
| Location | `src/` |
| Own sources | `main.cpp`, `CliParser.cpp` |
| Links | `libblockchain_core.a` + OpenSSL + Boost.Serialization + Boost.ProgramOptions + PLATFORM_LIBS |
| Own flags | `-std=c++20 -Wall -Wextra -pedantic -O3 ${OPENSSL_CFLAGS} $(BOOST_CPPFLAGS)` (for main.cpp, CliParser.cpp only) |

### Test Binaries (13 targets)

| Attribute | Value |
|-----------|-------|
| Location | `tests/` |
| Own sources | Each has 1+ test `.cpp` file(s) |
| Links | `../src/libblockchain_core.a` + OpenSSL + Boost.Serialization + Catch2 + PLATFORM_LIBS |
| Exception | `cli_tests` also links Boost.ProgramOptions and compiles `../src/CliParser.cpp` |

## Relationships

```
libblockchain_core.a (11 source files, compiled once)
├── blockchain (links archive + main.cpp + CliParser.cpp)
├── blockchain_tests (links archive + 9 test .cpp files)
├── block_propagation_tests (links archive + 1 test .cpp)
├── block_propagation_integration_tests (links archive + 1 test .cpp)
├── chunk_persistence_tests (links archive + 1 test .cpp)
├── chunk_recovery_tests (links archive + 1 test .cpp)
├── chunk_replace_tests (links archive + 1 test .cpp)
├── merkle_tests (links archive + 1 test .cpp)
├── merkle_rpc_integration_tests (links archive + 1 test .cpp)
├── cli_tests (links archive + CliParser.cpp + 1 test .cpp)
├── rpc_expansion_tests (links archive + 1 test .cpp)
├── lifecycle_tests (links archive + 1 test .cpp)
├── lifecycle_integration_tests (links archive + 1 test .cpp)
├── rpc_integration_tests (links archive + 1 test .cpp)
└── p2p_sync_integration_tests (links archive + 1 test .cpp)
```

## State Transitions

N/A — build artifacts are stateless; they are produced fresh on each build.

## Validation Rules

- The archive MUST contain exactly the 11 core source files (no more, no less)
- `CliParser.cpp` MUST NOT be in the archive (it depends on Boost.ProgramOptions)
- Every binary that previously compiled `../src/*.cpp` directly MUST instead link `libblockchain_core.a`
- All existing tests MUST pass identically after restructuring
73 changes: 73 additions & 0 deletions specs/015-compile-time-optimization/plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Implementation Plan: Compile-Time Optimization

**Branch**: `015-compile-time-optimization` | **Date**: 2026-04-12 | **Spec**: [spec.md](spec.md)
**Input**: Feature specification from `/specs/015-compile-time-optimization/spec.md`

## Summary

Eliminate redundant compilation by extracting the 11 core source files into a shared static archive (`libblockchain_core.a`) built once in `src/Makefile.am`. The main binary and all 13 test binaries link against the archive instead of each independently compiling the same sources. This reduces compilation units from ~177 to ~34 (~81% reduction).

## Technical Context

**Language/Version**: C++20 (`-std=c++20`)
**Primary Dependencies**: Boost (Asio, Serialization, Program Options), OpenSSL, nlohmann/json (vendored), Catch2 (test)
**Storage**: N/A (build-system-only change)
**Testing**: Catch2 via `make -j8 check`; 13 test binaries run individually
**Target Platform**: Linux (GCC, Clang), macOS (Clang), Windows (MinGW-w64/MSYS2)
**Project Type**: CLI / P2P daemon
**Performance Goals**: ≥50% reduction in clean compile time from 13:20 baseline
**Constraints**: Must use GNU Autotools (constitution Principle II); no libtool
**Scale/Scope**: 11 core .cpp files, 1 main binary, 13 test binaries, 2 Makefile.am files modified

## Constitution Check

*GATE: Must pass before Phase 0 research. Re-check after Phase 1 design.*

| Principle | Status | Notes |
|-----------|--------|-------|
| I. Language Standard | PASS | No code changes; C++20 flags preserved |
| II. Build System | PASS | Remains GNU Autotools; `make -j8` preserved |
| III. Full Test Coverage | PASS | No test files added/removed; all existing tests preserved |
| IV. Code Style | PASS | No source code changes |
| V. Minimal Dependencies | PASS | No new dependencies; libtool intentionally avoided |
| VI. Mandatory TLS | PASS | No network changes |
| VII. Cross-Platform Support | PASS | `noinst_LIBRARIES` works on all three CI platforms |
| VIII. Feature Branches | PASS | On branch `015-compile-time-optimization` |
| IX. Pre-1.0 API Stability | PASS | No API changes |
| X. Low-Latency Performance | PASS | No runtime code changes |
| XI. MIT License | PASS | No new files with license implications |
| XII. .gitignore Maintenance | PASS | `libblockchain_core.a` is a build artifact in `src/`; must be added to `.gitignore` |
| XIII. Roadmap Currency | PASS | ROADMAP.md update required on completion |

**Post-Phase-1 Re-check**: All gates still PASS. The design introduces `libblockchain_core.a` as a new build artifact requiring a `.gitignore` entry (XII).

## Project Structure

### Documentation (this feature)

```text
specs/015-compile-time-optimization/
├── plan.md # This file
├── research.md # Phase 0 output
├── data-model.md # Phase 1 output
├── quickstart.md # Phase 1 output
└── tasks.md # Phase 2 output (/speckit.tasks command)
```

### Source Code (files modified)

```text
src/
├── Makefile.am # MODIFIED: add noinst_LIBRARIES, refactor blockchain target
tests/
├── Makefile.am # MODIFIED: all 13 targets drop ../src/*.cpp, link archive
.gitignore # MODIFIED: add src/libblockchain_core.a
docs/
└── ROADMAP.md # MODIFIED: on completion
```

**Structure Decision**: Existing `src/` + `tests/` layout preserved. No new directories. The static archive is built in `src/` alongside the existing binary.

## Complexity Tracking

No constitution violations. Table not applicable.
50 changes: 50 additions & 0 deletions specs/015-compile-time-optimization/quickstart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Quickstart: Compile-Time Optimization

**Feature**: 015-compile-time-optimization

## What Changed

The build system was restructured to compile the 11 core source files (Block, Blockchain, Chunk, utils, NodeConfig, PeerManager, BlockPropagation, MerkleTree, RpcServer, PeerServer, PeerClient) only once into a shared static archive (`libblockchain_core.a`), rather than independently for each of the 14 build targets.

## Before vs After

| Metric | Before | After |
|--------|--------|-------|
| Core file compilations | 154 (11 × 14) | 11 (once) |
| Target-specific compilations | ~23 | ~23 |
| Total compilation units | ~177 | ~34 |

## How to Build

No change to the developer workflow:

```bash
# Clean build (main binary + all tests)
make -j8 check TESTS=

# Incremental rebuild
make -j8

# Run tests individually (per constitution)
./tests/blockchain_tests
./tests/lifecycle_tests
# ... etc.
```

## How to Add a New Test Binary

Before this change, adding a new test binary required listing all 11 core source files in `_SOURCES`. Now:

```makefile
# In tests/Makefile.am:
check_PROGRAMS += my_new_tests
my_new_tests_SOURCES = my_new_tests.cpp
my_new_tests_CXXFLAGS = -std=c++20 -Wall -Wextra -pedantic -I. $(BOOST_CPPFLAGS)
my_new_tests_LDADD = ../src/libblockchain_core.a ${OPENSSL_LIBS} $(BOOST_SERIALIZATION_LIB) ${CATCH2_LIBS} $(PLATFORM_LIBS)
my_new_tests_LDFLAGS = $(BOOST_LDFLAGS)
```

## Files Modified

- `src/Makefile.am` — adds `noinst_LIBRARIES = libblockchain_core.a`; main binary links archive
- `tests/Makefile.am` — all 13 test targets drop `../src/*.cpp` from `_SOURCES`; link `../src/libblockchain_core.a` instead
Loading
Loading