Home / Docs / Architecture

Architecture

The core node is written in Go (~13,000 lines of source, plus tests and scripts). It uses libp2p for peer-to-peer networking, BadgerDB for persistent storage, blake2b for proof-of-work, and ed25519 for signatures.

Package Map

xe-poc-2/core/
├── cmd/
│   ├── node/       Entry point — interactive CLI, HTTP server, flag parsing
│   └── cli/        Standalone HTTP client for remote node interaction
├── core/           Domain logic — ledger, crypto, encoding, PoW, voting, quorum
├── store/          Pluggable storage — MemStore (testing), BadgerStore (production)
├── net/            libp2p networking — gossip, sync, DHT, marketplace, messaging
├── node/           Orchestration — ties all packages together into a running node
├── api/            HTTP REST API — handler, routes, CORS
├── statechain/     Deterministic state machine — DAO governance, KV store, sync
├── vm/             VM abstraction — manager interface, mock, credentials
├── perf/           Performance certificates — workload benchmark, price multiplier
├── web/            Embedded web UI — HTML + ES modules + CSS, served by xe node --ui
├── client/         Client-side helpers shared by CLI subcommands
├── directory/      P2P account directory — registration, verification, gossip
├── chat/           P2P messaging — envelope format, chat store
└── scripts/        Test and utility scripts — e2e, stress, genesis generation

Core Package Files

FilePurpose
types.goBlock, Vote, Conflict, Lease, PendingSend structs; BlockType constants
ledger.goLedger struct — validates/adds blocks, per-account locking, delegation tracking
crypto.goKeyPair, GenerateKeyPair, HashBlock (SHA-256), SignBlock, VerifyBlock (ed25519)
encoding.goMarshalBlockCanonical (binary encoding), MarshalBlock, UnmarshalBlock; vote encoding
pow.goblake2b PoW — ComputePoW, ComputePoWConcurrent, ComputePoWWithContext, ValidatePoW
vote.goVoteManager — casts and validates votes for conflict resolution
quorum.goQuorumManager — tallies votes, confirms/rejects blocks at 67% weight
conflict.goConflict detection — equivocation checks
attestation.goTimekeeper attestation validation for lease blocks
store.goStore interface and optional interfaces

Block Validation Pipeline

AddBlock(b *Block)
  │
  ├── 1. Normalize hex fields (lowercase)
  ├── 2. VerifyBlock — recompute hash + check ed25519 signature
  ├── 3. ValidatePoW — blake2b(nonce || hash) >= difficulty
  ├── 4. Timestamp check — within ±1 hour of local time
  ├── 5. Duplicate check — block hash not already in store
  ├── 6. Conflict detection — check if Previous hash is shared
  │     ├── No conflict → continue on main chain
  │     └── Conflict → stage block, fire callback, return
  │
  ├── 7. Type-specific validation (per-account lock held)
  │     ├── send     → balance sufficient, frontier matches, amount > 0
  │     ├── receive  → pending send exists, destination matches
  │     ├── claim    → balance = old + 100
  │     ├── lease    → XUSD only, cost formula correct, balance sufficient
  │     ├── lease_accept → lease exists, stake = cost/5, attestations valid
  │     └── lease_settle → lease expired, XE emission formula
  │
  ├── 8. Update in-memory state (asset balances, delegation weights)
  └── 9. Write to store (atomic commit via AtomicBlockStore)

Startup Sequence

  1. Open or create key pair (loads key.seed or generates new)
  2. Open store (BadgerStore at {dataDir}/ledger)
  3. Create libp2p host (TCP, noise encryption, yamux)
  4. Setup pubsub (GossipSub)
  5. Create gossip layers (block, vote, marketplace, directory, state chain)
  6. Setup mDNS
  7. Create ledger (wraps store with validation)
  8. Wire voting (VoteManager + QuorumManager)
  9. Setup frontier sync
  10. Setup DHT (Kademlia)
  11. Create messenger
  12. Initialize state chain
  13. Wire timekeeper config
  14. Register gossip handlers
  15. Dial bootstrap peers
  16. Start background goroutines