# Vexon Pool Deploy

Private deployment package for running the Vexon mining pool.

This repository is the operational pool stack for Vexon:

- Stratum mining endpoint
- share validation and accounting
- block submission
- miner balances and payout accounting
- backend statistics loops
- Vexon Pool public interface
- Vexon Docs static website for miner and wallet documentation

The implementation may contain legacy internal module names while the system is
being stabilized, but the product name and deployment surface are **Vexon Pool**.

This repository must not contain live wallet seeds, RPC passwords, TLS keys,
database dumps, blockchain data, or pool backup archives.

The public VEX supply and treasury policy is documented in
[`TOKENOMICS.md`](TOKENOMICS.md). Keep the website, docs site, and this policy
file aligned before every public release.

## Release Inputs

The normal pre-launch stack uses:

- `vexon-core` release: `v0.1.0-prelaunch`
- `vexon-wallet` release: `v0.1.0-prelaunch`
- Vexon Pool deployment scripts from this repository

## One Server Install

Target OS: Ubuntu 20.04 LTS is recommended for the current pool stack.

The recommended path is to upload the bundled server package generated on the
development machine. It contains the deploy scripts, Linux amd64 Vexon binaries,
and Vexon Stratum source, so the server does not need GitHub CLI authentication
for the first install.

On the new server:

```bash
apt-get update
apt-get install -y unzip curl git screen

cd /root
unzip VEXON_POOL_SERVER_DEPLOY_COEXIST.zip
cd /root/vexon-pool-deploy
cp .env.example .env
nano .env

chmod +x install.sh scripts/*.sh
scripts/preflight.sh
bash install.sh
```

The installer clones these private Vexon repositories by default:

- `vexonexchange-sudo/vexon-core`
- `vexonexchange-sudo/vexon-wallet`
- `vexonexchange-sudo/vexon-stratum`

Set `VEX_CORE_REF`, `VEX_WALLET_REF`, and `VEX_STRATUM_REF` in `.env` when you
want to pin the deployment to a branch or release tag.

`scripts/preflight.sh` checks the `.env` values, template files, shell syntax,
GitHub authentication, private repository access, and backup archive path before
the installer changes the server.

After install:

```bash
cd /root/vexon-pool-deploy
scripts/status.sh
```

Point the miner to:

```text
stratum+tcp://YOUR_SERVER_IP:4499
```

Worker example:

```text
VEX_ADDRESS.001
```

Public web URLs:

- Pool: `https://pool.vexonus.com`
- Docs: `https://docs.vexonus.com`
- Wallet: `https://wallet.vexonus.com`

When nginx vhosts are enabled and both DNS records point at the server, enable
HTTPS with:

```bash
cd /root/vexon-pool-deploy
sudo bash scripts/install-https.sh
```

The documentation website is deployed from `files/docs-site` into
`/opt/vexon-pool/docs` by default. It is a static site and can also be served by
any panel-managed vhost with this document root:

```text
/opt/vexon-pool/docs
```

Operational helpers:

```bash
cd /root/vexon-pool-deploy
scripts/start-pool.sh
scripts/stop-pool.sh
scripts/status.sh
scripts/deploy-web.sh
scripts/doctor.sh
sudo scripts/doctor.sh --fix
scripts/health-check.sh
scripts/miner-watch.sh 222.86.244.202
scripts/payout-status.sh
scripts/payout-closed-loop-check.sh
scripts/repair-vex-coin.sh
scripts/repair-miner-address.sh --restart VEX_ADDRESS
scripts/probe-miner-submit.sh 222.86.244.202
scripts/reset-prelaunch-chain-data.sh
```

If a miner connects but Stratum returns `authorize result:false` or logs
`bad mining address`, repair the miner account binding:

```bash
cd /root/vexon-pool-deploy
scripts/repair-miner-address.sh --restart VEX_ADDRESS
```

If a miner is authorized and receiving jobs but shows zero hashrate, prove
whether the miner is submitting shares:

```bash
cd /root/vexon-pool-deploy
scripts/probe-miner-submit.sh 222.86.244.202
```

If the probe shows `mining.notify` but no `mining.submit`, the pool is sending
work and the next check is the miner algorithm mode, firmware, hardware state,
or another known-good Blake256r14 miner.

## Final Mainnet Cutover

Use this only after Vexon Core final tokenomics have been applied with the six
offline launch allocation addresses and a final release binary has been built.
The Core-side runbook is `docs/vexon-mainnet-finalization.md` in the
`vexon-core` repository.

Prelaunch chain data must not be reused for the public network. Preview the
server reset plan first:

```bash
cd /root/vexon-pool-deploy
scripts/reset-prelaunch-chain-data.sh
```

When the plan is correct and the final binaries are ready, move only Vexon node
chain data into a timestamped backup:

```bash
cd /root/vexon-pool-deploy
sudo scripts/reset-prelaunch-chain-data.sh --apply --i-understand-this-resets-vexon-chain
```

The reset script does not touch `/root/.vexonwallet`, wallet seeds, wallet
database files, existing pool paths, or the pool database. After replacing the
binaries, restart and verify:

```bash
sudo systemctl restart vexon-node vexon-node-peer vexon-stratum
scripts/repair-vex-coin.sh
scripts/health-check.sh
scripts/payout-closed-loop-check.sh
```

The default install uses `screen` because it is easy to inspect while the pool is
being brought online. After the pool has accepted shares and `scripts/health-check.sh`
passes, install the production operations layer. It switches the long-running
services to systemd, installs log rotation, daily private backups, SSL renewal
checks, and a health monitor timer:

```bash
cd /root/vexon-pool-deploy
sudo bash scripts/install-ops.sh --enable-now
sudo systemctl status vexon-node vexon-stratum vexon-pool-main --no-pager
sudo systemctl list-timers 'vexon-*' --all
```

Do not run the screen stack and the systemd stack at the same time. The
`--enable-now` mode stops the screen sessions before starting systemd services.
If you only want the systemd services without timers, use
`sudo bash scripts/install-systemd.sh --enable-now`.

## Production Operations

### Health Check

Run this before and after any server change:

```bash
cd /root/vexon-pool-deploy
scripts/health-check.sh
```

It checks:

- Stratum port `4499`
- active Stratum TCP connections
- Vexon node RPC
- node peer count and `getwork`
- VEX coin database configuration
- recent accepted shares
- payout queue and failed payout rows
- pool, explorer, and docs HTTP routes
- public JSON APIs, including diagnostics, explorer, wallet sync, and broadcast

### Post-Deploy Doctor

Use the doctor after copying updates to a server, after SSL/nginx changes, or
whenever the pool shows a white page, stale favicon, permission error, missing
Stratum listener, disabled VEX coin row, or wallet RPC outage.

Check only:

```bash
cd /root/vexon-pool-deploy
scripts/doctor.sh
```

Apply safe repairs:

```bash
cd /root/vexon-pool-deploy
sudo scripts/doctor.sh --fix
```

The repair mode can redeploy the pool/docs web files, render `serverconfig.php`,
restore Yii runtime and log permissions, reload nginx and PHP-FPM, start
memcached, repair the VEX coin database row, restart Stratum, and restart wallet
RPC when `VEX_START_WALLET=1`. It does not modify existing pool paths.

### Deploy Web Updates

After changing the pool UI or docs locally and syncing this repository to the
server, publish the web files with:

```bash
cd /root/vexon-pool-deploy
sudo bash scripts/deploy-web.sh
```

The script updates `/opt/vexon-pool/web` and `/opt/vexon-pool/docs`, renders
`serverconfig.php` from `.env`, restores runtime permissions, and reloads nginx
when it is active.

### Miner Watch

Use this while testing ASIC connectivity:

```bash
cd /root/vexon-pool-deploy
scripts/miner-watch.sh
scripts/miner-watch.sh 222.86.244.202
```

It shows live Stratum TCP sessions, recent worker records, accepted/rejected
shares, estimated accepted hashrate, and the latest Stratum log tail.

### Payout Window

The pool credits shares to account balances after a found block matures. Balances
at or above the configured minimum are paid by the backend main loop during the
scheduled payout window.

Default policy:

- Minimum payout: `0.001 VEX`
- Schedule: `Daily at 08:00 CST`
- Payout source: Vexon wallet RPC, when `VEX_START_WALLET=1` and the wallet is
  restored, unlocked, and connected to the node.

Check payout state:

```bash
cd /root/vexon-pool-deploy
scripts/payout-status.sh
```

Before public launch, run the stricter closed-loop gate:

```bash
cd /root/vexon-pool-deploy
scripts/payout-closed-loop-check.sh
```

It verifies the payout-critical path: node `getwork`, Stratum, backend loops,
VEX coin readiness, block/earning/payout accounting, wallet RPC, and failed
payout rows. Miners being offline is reported as a warning. A disabled or
unreachable wallet RPC is a production failure because automatic payouts cannot
run without it.

If the VEX coin database row is incomplete after a migration or manual import,
repair it with:

```bash
cd /root/vexon-pool-deploy
scripts/repair-vex-coin.sh
```

Enable the real on-chain payout wallet only after the wallet has been created or
restored on the server. The Stratum and block-template path uses the Vexon node
RPC on `18556`; VEX payouts use the Vexon wallet RPC on `18557`.

```bash
cd /root/vexon-pool-deploy
chmod 600 .env
nano .env
```

Set:

```bash
VEX_START_WALLET=1
VEX_WALLET_PASSPHRASE='YOUR_PRIVATE_WALLET_PASSPHRASE'
```

Then start and verify the wallet RPC:

```bash
cd /root/vexon-pool-deploy
scripts/start-wallet-rpc.sh
scripts/payout-status.sh
scripts/payout-closed-loop-check.sh
```

If `scripts/start-wallet-rpc.sh` reports that `wallet.db` is missing, create or
restore the payout wallet under `VEX_WALLET_APPDATA` first. Do not commit the
wallet passphrase, wallet seed, or `.env` file.

To let the backend evaluate the scheduled payout window manually:

```bash
cd /root/vexon-pool-deploy
scripts/payout-closed-loop-check.sh --run-backend
```

### Production Backup

Create a private backup before upgrades or server migration:

```bash
cd /root/vexon-pool-deploy
sudo bash scripts/backup-production.sh /root/vexon-pool-production.tar.gz
```

The archive contains credentials and may contain wallet files. Keep it encrypted
and offline. Never publish it under a web document root.

Scheduled backups are installed by:

```bash
cd /root/vexon-pool-deploy
sudo bash scripts/install-ops.sh
systemctl list-timers vexon-pool-backup.timer --all
```

By default, archives are written to `/root/vexon-pool-backups`, retained for 14
days, and exposed through a private `/root/vexon-pool-backups/latest.tar.gz`
symlink.

### Monitoring, Log Rotation, And SSL Renewal

Install or refresh production operations after every deploy:

```bash
cd /root/vexon-pool-deploy
sudo bash scripts/install-ops.sh
```

This installs:

- `vexon-node.service`, `vexon-peer.service`, `vexon-stratum.service`, and pool
  backend services with automatic restart.
- `/etc/logrotate.d/vexon-pool` for pool, Stratum, node, wallet, and monitor
  logs.
- `vexon-pool-monitor.timer`, which runs `scripts/monitor-pool.sh` every five
  minutes and restarts only Vexon services when a hard health failure is found.
- `vexon-pool-backup.timer`, which runs `scripts/run-backup.sh` daily.
- `vexon-ssl-renew.timer`, which runs `scripts/ssl-renew-check.sh` daily. Certbot
  still owns the actual Let's Encrypt renewal logic.

Useful commands:

```bash
sudo bash scripts/monitor-pool.sh
sudo bash scripts/run-backup.sh
sudo bash scripts/ssl-renew-check.sh
journalctl -u vexon-pool-monitor.service -n 100 --no-pager
sudo logrotate -d /etc/logrotate.d/vexon-pool
```

### Pool API

The public pool status endpoint is:

```text
https://pool.vexonus.com/api/pool
```

It returns VEX mining telemetry, payout schedule, node status, recent shares, and
block information without exposing secrets.

The public deployment diagnostics endpoint is:

```text
https://pool.vexonus.com/api/diagnostics
```

It returns launch-readiness flags for the VEX coin row, node RPC, `getwork`,
workers, accepted shares, block accounting, and payout configuration without
exposing wallet seeds, private keys, RPC passwords, or database credentials.

## Migration From The Existing Working Pool

The migration path is an internal bootstrap aid for preserving the known-good
database, Stratum config, and wallet state while Vexon Pool is being brought
online.

On the old working server, create a private backup archive:

```bash
cd /root/vexon-pool-deploy
sudo bash scripts/backup-existing-pool.sh /root/vexon-pool-backup.tar.gz
```

Copy the archive to the new server:

```bash
scp /root/vexon-pool-backup.tar.gz root@NEW_SERVER_IP:/root/
```

On the new server, set this in `.env`:

```bash
POOL_BACKUP_TAR=/root/vexon-pool-backup.tar.gz
```

Then run:

```bash
sudo bash install.sh
```

The backup archive contains live secrets, wallet data, and a database dump. Keep
it private and delete it from the server after the migration is verified.

## Vexon Pool Interface

The public product should be Vexon Pool, not a renamed copy of an old generic
pool page. The public interface should expose:

- pool hashrate and worker status
- blocks found and confirmations
- miner balances and payouts
- connection instructions
- network stats from `vexond`

The operational backend can keep compatibility paths until the pool is stable,
but public pages, docs, and release assets should use Vexon Pool naming.

## Safety

Never commit:

- `.env`
- wallet seeds or wallet databases
- RPC credentials
- TLS private keys
- `/root/.vexond`, `/root/.vexonwallet`
- chain data
- SQL dumps
- backup archives such as `vexon-pool-backup.tar.gz`
