forked from Rockachopa/Timmy-time-dashboard
This commit implements six major features: 1. Event Log System (src/swarm/event_log.py) - SQLite-based audit trail for all swarm events - Task lifecycle tracking (created, assigned, completed, failed) - Agent lifecycle tracking (joined, left, status changes) - Integrated with coordinator for automatic logging - Dashboard page at /swarm/events 2. Lightning Ledger (src/lightning/ledger.py) - Transaction tracking for Lightning Network payments - Balance calculations (incoming, outgoing, net, available) - Integrated with payment_handler for automatic logging - Dashboard page at /lightning/ledger 3. Semantic Memory / Vector Store (src/memory/vector_store.py) - Embedding-based similarity search for Echo agent - Fallback to keyword matching if sentence-transformers unavailable - Personal facts storage and retrieval - Dashboard page at /memory 4. Cascade Router Integration (src/timmy/cascade_adapter.py) - Automatic LLM failover between providers (Ollama → AirLLM → API) - Circuit breaker pattern for failing providers - Metrics tracking per provider (latency, error rates) - Dashboard status page at /router/status 5. Self-Upgrade Approval Queue (src/upgrades/) - State machine for self-modifications: proposed → approved/rejected → applied/failed - Human approval required before applying changes - Git integration for branch management - Dashboard queue at /self-modify/queue 6. Real-Time Activity Feed (src/events/broadcaster.py) - WebSocket-based live activity streaming - Bridges event_log to dashboard clients - Activity panel on /swarm/live Tests: - 101 unit tests passing - 4 new E2E test files for Selenium testing - Run with: SELENIUM_UI=1 pytest tests/functional/ -v --headed Documentation: - 6 ADRs (017-022) documenting architecture decisions - Implementation summary in docs/IMPLEMENTATION_SUMMARY.md - Architecture diagram in docs/architecture-v2.md
2.4 KiB
2.4 KiB
ADR 018: Lightning Network Transaction Ledger
Status
Accepted
Context
The system needed to track all Lightning Network payments (incoming and outgoing) for accounting, dashboard display, and audit purposes. The existing payment handler created invoices but didn't persist transaction history.
Decision
Implement a SQLite-based ledger (ledger table) that tracks all Lightning transactions with their lifecycle status.
Transaction Types
| Type | Description |
|---|---|
incoming |
Invoice created (we're receiving payment) |
outgoing |
Payment sent (we're paying someone) |
Transaction Status
| Status | Description |
|---|---|
pending |
Awaiting settlement |
settled |
Payment completed |
failed |
Payment failed |
expired |
Invoice expired |
Schema
CREATE TABLE ledger (
id TEXT PRIMARY KEY,
tx_type TEXT NOT NULL,
status TEXT NOT NULL DEFAULT 'pending',
payment_hash TEXT UNIQUE NOT NULL,
amount_sats INTEGER NOT NULL,
memo TEXT,
invoice TEXT,
preimage TEXT,
source TEXT NOT NULL,
task_id TEXT,
agent_id TEXT,
created_at TEXT NOT NULL,
settled_at TEXT,
fee_sats INTEGER DEFAULT 0
);
Usage
from lightning.ledger import (
create_invoice_entry,
mark_settled,
get_balance,
)
# Create invoice record
entry = create_invoice_entry(
payment_hash=invoice.payment_hash,
amount_sats=1000,
memo="API access",
source="payment_handler",
task_id=task.id,
)
# Mark as paid
mark_settled(payment_hash, preimage="secret")
# Get balance
balance = get_balance()
print(f"Net: {balance['net_sats']} sats")
Integration
The PaymentHandler automatically:
- Creates ledger entries when invoices are created
- Updates status when payments are checked/settled
- Tracks fees for outgoing payments
Balance Calculation
{
"incoming_total_sats": total_received,
"outgoing_total_sats": total_sent,
"fees_paid_sats": total_fees,
"net_sats": incoming - outgoing - fees,
"pending_incoming_sats": pending_received,
"pending_outgoing_sats": pending_sent,
"available_sats": net - pending_outgoing,
}
Consequences
- Positive: Complete payment history, balance tracking, audit trail
- Negative: Additional DB writes, must keep in sync with actual Lightning node
Future Work
- Reconciliation job to sync with LND node
- Export to accounting formats (CSV, QIF)