Skip to content

Latest commit

 

History

History
115 lines (91 loc) · 4.63 KB

File metadata and controls

115 lines (91 loc) · 4.63 KB

SPEED.md - German Engineering Efficiency Tracker

"Latency is the mind-killer." - GAD-000 Principle 6

The Ouroboros Loop relies on frequency. Slow boot = slow healing.

Current Bottleneck: Parampara Chain Verification

Problem: LineageChain.verify_chain() is called on every boot.

  • Loads ALL 3293 blocks into memory
  • Iterates through each block, recalculating SHA-256 hashes
  • O(n) complexity on every boot = UNACCEPTABLE
# THE CRIME (lineage.py:318-356)
def verify_chain(self) -> bool:
    blocks = self.get_all_blocks()  # LOADS 3293 BLOCKS!
    for i, block in enumerate(blocks):
        calculated_hash = self._calculate_hash(block)  # SHA-256 per block
        # ... verify linkage

Impact:

  • Boot time: ~5-10 seconds (should be <1s)
  • Test suite startup: adds latency to every test
  • NAGA Orchestrator delayed
  • Ouroboros feedback loop slowed

Solution: Merkle Checkpointing (Lazy Parampara)

Principle: Trust the cryptographic seal, not brute-force re-scan.

How It Works

┌─────────────────────────────────────────────────────────────┐
│                    FAST BOOT FLOW                           │
├─────────────────────────────────────────────────────────────┤
│  1. Read tip_hash from lineage.db (single query)            │
│  2. Read cached_hash from .vibe/lineage_checkpoint.json     │
│  3. Compare:                                                │
│     - MATCH → Skip verification (instant boot)              │
│     - MISMATCH → Verify only delta (new blocks)             │
│  4. Update checkpoint after successful verification         │
└─────────────────────────────────────────────────────────────┘

Checkpoint File Format

{
  "verified_tip_hash": "a1b2c3d4...",
  "verified_index": 3293,
  "verified_at": "2026-01-06T12:00:00Z",
  "chain_db_path": "data/lineage.db"
}

Safety Guarantees

  1. Immutability: If ANY old block changes, tip hash changes (blockchain property)
  2. Tamper Detection: Checkpoint file is separate from chain - attacker must modify both
  3. Fallback: If checkpoint missing/corrupt → full verification (safe default)
  4. Delta Verification: New blocks still get full verification

Implementation Status

Component Status Notes
load_checkpoint() DONE Read cached verification state
save_checkpoint() DONE Save after successful verification
get_tip_hash() DONE Fast single-query tip hash (O(1))
get_tip_index() DONE Fast single-query tip index (O(1))
verify_chain_fast() DONE Checkpoint + delta verification
_verify_delta() DONE Verify only new blocks
clear_checkpoint() DONE Force full verify on next boot
LineageProtocol DONE Protocol in vibe_core/protocols/lineage.py
__init__ refactor DONE Uses verify_chain_fast() at boot

Benchmark Results (2026-01-06)

Metric Before After Improvement
Full verification (3293 blocks) 213.7ms 213.7ms Same
Warm boot (checkpoint match) 213.7ms 1.0ms 213x faster
Blocks verified on warm boot 3293 0 -3293

Target exceeded: Wanted 20x, achieved 213x on warm boot.

GAD-000 Alignment

  • Principle 6 (Efficiency): Don't re-verify validated history
  • Principle 2 (Composability): Checkpoint is separate, composable module
  • Principle 4 (Resilience): Fallback to full verify if checkpoint corrupt

Progress Log

2026-01-06: Initial Analysis

  • Identified bottleneck in lineage.py:verify_chain()
  • 3293 blocks verified on every boot
  • O(n) hash calculations per boot

2026-01-06: Implementation Complete

  1. Created LineageProtocol in vibe_core/protocols/lineage.py
    • TypedDict: CheckpointData, VerificationResult, BlockData
    • NullLineageChain (Arjuna Pattern)
  2. Implemented fast methods in LineageChain:
    • get_tip_hash(), get_tip_index() - O(1) queries
    • save_checkpoint(), load_checkpoint(), clear_checkpoint()
    • verify_chain_fast() - checkpoint/delta/full modes
    • _verify_delta() - verify only new blocks since checkpoint
  3. Modified __init__ to use verify_chain_fast() at boot
  4. Result: 213x faster warm boot (1.0ms vs 213.7ms)