Eddycoin Node - EXPERIMENTAL, for play. Test coin only, no real money.
=======================================================================

Easiest: Eddycoin Node (window, GUI) - just start it
  Windows: "Eddycoin Node Setup.exe" (per-user install, no admin) or the portable "Eddycoin Node.exe".
  Mac: "Eddycoin Node (Mac).zip".  Linux / Pi: python3 eddycoin_node_gui.py  (needs eddycoin_node.py next to it)
  It starts by itself, shows E-Chain, D-Chain and Y-Chain live, finds other nodes automatically (seed servers,
  gossip, LAN discovery on UDP 8769) and lets you add/remove/test nodes and seed servers. Settings are saved.

What is a node?
  A node is a program that keeps its OWN full copy of the Eddycoin blockchain (E-Chain, D-Chain, Y-Chain)
  and checks every block and every transaction itself: proof-of-work, difficulty, Y checkpoints, rewards /
  emission, the 900,000,000 EDDY cap, signatures and balances. Nodes pass new blocks and transactions to
  each other. As long as at least one node runs and someone mines, Eddycoin keeps going - even if the
  main server (https://eddycoin-demo.pages.dev) is switched off.

How it behaves
  * Start: downloads the chain from the seed (the live server) and/or other nodes and re-checks all of it.
  * While the live server is reachable, the node FOLLOWS it: miners connected to your node mine on the
    same chain as everybody else; your node checks their blocks and passes them on.
  * If the server cannot be reached for 60 seconds, the node continues INDEPENDENTLY together with the
    other nodes it knows: it accepts blocks, finalizes checkpoints and pays rewards by the same rules.
  * If two nodes disagree, the valid chain with the most proof-of-work wins.

Requirements
  Python 3.8 or newer. No extra packages (standard library only).
  The window needs tkinter: included in the python.org installers for Windows/macOS;
  on Debian/Ubuntu/Raspberry Pi OS:  sudo apt install python3-tk   (not needed for --headless).
  Windows users can simply use "Eddycoin Node.exe" instead (no Python needed).

Start
  Window:               python3 eddycoin_node.py            (Windows: py eddycoin_node.py)
  Without a window:     python3 eddycoin_node.py --headless
  Check a chain file:   python3 eddycoin_node.py --verify-file eddycoin_chain_export.json

  Then set the "Server" of the CPU miner, the GPU miner or the Eddycoin Wallet to
      http://127.0.0.1:8770
  (miners: Server list -> "Add", then pick it; or --server, repeatable / comma-separated for failover;
   wallet: "Server" button -> "Add" -> "Use". Needs the miner/wallet versions from 27 Oct 2026 or newer.)
  Status page in the browser: http://127.0.0.1:8770/

Connecting nodes (friends)
  No fixed IP address is needed.
  * Your node connects OUT to the seed and to the nodes you list - that works from any internet connection.
      python3 eddycoin_node.py --headless --peer http://192.168.1.20:8770 --peer http://friend.duckdns.org:8770
    (in the window: one URL per line in "Seed + other nodes")
  * Only if you want OTHERS to connect to YOUR node:
      1. start with --listen 0.0.0.0 (window: tick "Allow other computers to connect")
         - inside your home network others can then use http://<your-PC-IP>:8770
      2. for friends over the internet: forward TCP port 8770 on your router to this computer, and
         (optional, because home IPs change) get a free dynamic-DNS name, e.g. duckdns.org / No-IP
      3. start with --public-url http://yourname.duckdns.org:8770 - the node announces this URL to the nodes
         it talks to (GET /api/peers lists only URLs that nodes chose to announce, never visitor IPs).
    Plain HTTP, no passwords or keys are ever sent between nodes - only public blocks and signed transactions.

Cross-checking between nodes (node 1.2, 27 Oct 2026)
  * Every minute the node asks the seed and a sample of other nodes for their checkpoint ids (tip, tip-1..tip-10,
    every 100th) and compares them with its own chain. Differences are logged, shown in the window (tab "Checks",
    warning in the status card) and at GET /api/node/mismatches, and sent to other nodes as an informational notice.
  * Every block / checkpoint received is fully re-validated. Invalid data is refused and the sender loses trust;
    after repeated invalid data it is disconnected and ignored for 1 hour.
  * A different, VALID chain that would replace checkpoints the node already holds is adopted only if it has more
    work AND the seed or at least 2 independent nodes (more than hold ours) have it. One node alone can never switch
    yours; such a fork is quarantined and reported. Reports from other nodes never make a node reject anything.
  * The block / checkpoint rules themselves are unchanged.

Options
  --headless             no window
  --port 8770            HTTP port
  --listen 127.0.0.1     127.0.0.1 = only this computer (default), 0.0.0.0 = other computers too
  --public-url URL       announce your public URL to other nodes
  --peer URL             another node (repeatable)
  --seed URL             seed server/node (default https://eddycoin-demo.pages.dev; repeatable)
  --no-seed              do not use the live server
  --seed-timeout 60      seconds without the seed before continuing independently
  --data DIR             data folder (default: Windows %APPDATA%\EddycoinNode, others ~/.eddycoin_node)
                         (also --data-dir DIR with eddycoin_node_gui.py / Eddycoin Node.exe; the window lets you pick a disk)
  Any port works (--port 9000 ...): nodes store and pass on full addresses like http://host:9000;
  behind a reverse proxy (nginx/caddy) set --public-url https://node.example.com

Raspberry Pi / Linux, run in the background (systemd), example:
  sudo tee /etc/systemd/system/eddycoin-node.service >/dev/null <<'UNIT'
  [Unit]
  Description=Eddycoin Node (test coin)
  After=network-online.target
  [Service]
  User=pi
  ExecStart=/usr/bin/python3 /home/pi/eddycoin_node.py --headless --listen 0.0.0.0
  Restart=on-failure
  [Install]
  WantedBy=multi-user.target
  UNIT
  sudo systemctl enable --now eddycoin-node

API (same as the server, so miners and the wallet work unchanged)
  GET  /api/work?chain=E|D     POST /api/submit/e   POST /api/submit/d
  GET  /api/wallet?addr=...    POST /api/tx         GET  /api/state[?addr=...]
  GET  /api/verify             GET  /api/export     GET  /api/block/E|D|Y/<height>    GET /api/peers
  node-to-node: GET /api/node/info, GET /api/node/segment?from=N, POST /api/node/push, POST /api/node/hello,
                GET /api/node/checkpoints?from=N&to=M (height -> checkpoint id + E/D hashes), GET /api/node/mismatches,
                POST /api/node/report (informational mismatch notice, rate-limited)

Limits of this experimental version (honest list)
  * Plain HTTP between nodes; meant for play among friends, not hardened against attackers.
  * Selling EDDY to the sandbox exchange desk works only on the main server.
  * Block receive times ("recv", used for difficulty retargeting) are taken from the node that first accepted
    the block; other nodes check that they are plausible (within 2 minutes of the block time), not exact.
  * If the main server comes back after the nodes went on without it, the main server cannot switch to
    the nodes' chain; nodes then keep whichever valid chain has more work.
  * The node keeps the full history and re-checks it at every start; a very long chain makes the start slower.
