nu-node/CLAUDE.md
Mukan Erkin ec8af8d1c7 feat(node): wire nu-p2p via HTTP publish API
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-24 16:49:37 +03:00

60 lines
1.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# nu-node — CLAUDE.md
L1 node implementasyonu. Consensus, mempool, state, block üretimi, RPC.
## Crate Yapısı
| Crate | Sorumluluk |
|-------|-----------|
| `nu-consensus` | PoN validator seçim, slot sistemi, PoN skoru, oylama scheduler |
| `nu-mempool` | Bekleyen tx havuzu; öncelik: Critical > High > Normal |
| `nu-state` | AccountState, StoryNodeState, NftState; RocksDB backend |
| `nu-block` | BlockBuilder (Merkle root), BlockVerifier |
| `nu-rpc` | JSON-RPC HTTP server + WebSocket subscription |
| `nu-vm` | Tx executor, ödül dağıtımı, slashing |
## Kritik Kurallar
- `unwrap()` / `expect()` sadece test kodunda. Production'da `?` veya açık hata.
- State'e dokunan her fonksiyon: önce **tam doğrulama**, sonra mutation.
- Slashing ve ödül dağıtımı **atomik** — başarısız olursa state değişmez.
- `BURN_WALLET` ve `DEV_WALLET` adresleri env variable; hardcode yasak.
## Sabitler (nu-consensus/src/types.rs)
```
SLOT_DURATION_MS = 6_000
ROUND_SIZE = 21
MIN_VALIDATOR_STAKE = 1_000 NUT
PoN: start=1.0, max=1.8, min=0.5
win=+0.02, lose=-0.05, honest_block=+0.01
WHALE_CAP = 5% of total weight
```
## Geliştirme
```bash
# Devnet (tek validator, consensus devre dışı)
cargo run --bin nu-node -- --dev --validator
# Testleri çalıştır
cargo test
# Lint
cargo fmt && cargo clippy
```
## Faz Durumu
- **Faz 0:** ✅ Scaffold, tipler, modül sınırları.
- **Faz 1:** ✅ Tüm tx tipleri, block loop, JSON-RPC, P2P forwarding (`--p2p-api`).
- **Faz 2 (sıradaki):** Tam PoN consensus (rotation, slashing), 3+ validator testnet.
## P2P Entegrasyonu
nu-node, nu-p2p'ye `reqwest` ile HTTP POST atar. nu-p2p ayrı process olarak çalışır.
```bash
# P2P ile başlat
cargo run -- --dev --validator --p2p-api http://127.0.0.1:30334
```