> For the complete documentation index, see [llms.txt](https://docs.neurochain.ai/nc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.neurochain.ai/nc/neurochainai-guides/operators/validator-operator.md).

# Validator Operator

Complete guide for running a Validator on NCN Network.

***

## Overview

Validators participate in the consensus mechanism by:

* Validating preprocessing requests
* Validating completion results
* Signing consensus messages
* Maintaining network integrity

**Earnings**: Share of \~5% validator fee per inference

***

## Requirements

### Hardware

| Resource | Minimum               | Recommended |
| -------- | --------------------- | ----------- |
| CPU      | 2 cores               | 4 cores     |
| RAM      | 4 GB                  | 8 GB        |
| Storage  | 50 GB SSD             | 100 GB SSD  |
| Network  | 100 Mbps, low latency | 1 Gbps      |

### Capital

* Minimum stake (configurable, check network)
* Gas for registration transactions

### Network

* Stable, low-latency connection
* P2P port (8828) accessible

***

## Setup

### 1. Install Dependencies

```bash
# Update system
sudo apt update && sudo apt upgrade -y

# Install build tools
sudo apt install -y build-essential pkg-config libssl-dev git

# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
```

### 2. Build Registry Node

```bash
# Clone repository
git clone https://github.com/neurochainai/ncn-network-v2-rs.git
cd ncn-network-v2-rs

# Build release
cargo build --release -p p2p_registry_node

# Copy binary
sudo cp target/release/p2p_registry_node /usr/local/bin/
```

### 3. Generate Validator Key

```bash
# Generate new wallet for validation
cast wallet new

# Output:
# Address: 0x...
# Private Key: 0x...

# IMPORTANT: Save this key securely!
```

### 4. Stake Tokens (On-Chain)

```bash
# Approve tokens for staking
cast send $TOKEN_ADDRESS \
  "approve(address,uint256)" \
  $VALIDATOR_REGISTRY_ADDRESS \
  $STAKE_AMOUNT \
  --private-key $YOUR_KEY \
  --rpc-url $RPC_URL

# Register as validator
cast send $VALIDATOR_REGISTRY_ADDRESS \
  "registerValidator(uint256)" \
  $STAKE_AMOUNT \
  --private-key $YOUR_KEY \
  --rpc-url $RPC_URL
```

### 5. Configure Validator

Create `/etc/ncn/validator.env`:

```bash
# Validator Identity
VALIDATOR_PRIVATE_KEY=0x...
VALIDATOR_ADDRESS=0x...

# Network Addresses
GRPC_LISTEN_ADDR=0.0.0.0:50050
P2P_LISTEN_ADDR=/ip4/0.0.0.0/tcp/8828

# Bootstrap Nodes (get from network)
BOOTSTRAP_NODES=/ip4/x.x.x.x/tcp/8828/p2p/12D3KooW...

# Blockchain Configuration
FORKNET_RPC_URL=https://testnet-rpc-1.forknet.io
CHAIN_ID=828
VALIDATOR_REGISTRY_CONTRACT=0x4F11D4cBE08A5aBa052C368C8477412af63a56f3

# Sync Settings
VALIDATOR_SYNC_ENABLED=true
VALIDATOR_SYNC_INTERVAL=60

# Consensus Settings
MIN_VALIDATORS_FOR_CONSENSUS=3

# Logging
RUST_LOG=info
```

### 6. Create Systemd Service

Create `/etc/systemd/system/ncn-validator.service`:

```ini
[Unit]
Description=NCN Validator (P2P Registry) Node
After=network.target

[Service]
Type=simple
User=ncn
EnvironmentFile=/etc/ncn/validator.env
ExecStart=/usr/local/bin/p2p_registry_node \
  --grpc-listen-addr ${GRPC_LISTEN_ADDR} \
  --p2p-listen-addr ${P2P_LISTEN_ADDR}
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
```

### 7. Start Validator

```bash
# Create service user
sudo useradd -r -s /bin/false ncn

# Set permissions
sudo mkdir -p /etc/ncn
sudo chown ncn:ncn /etc/ncn/validator.env
sudo chmod 600 /etc/ncn/validator.env

# Create data directory
sudo mkdir -p /opt/ncn/data
sudo chown ncn:ncn /opt/ncn/data

# Enable and start
sudo systemctl daemon-reload
sudo systemctl enable ncn-validator
sudo systemctl start ncn-validator

# Check status
sudo systemctl status ncn-validator
```

***

## Validator Registration Flow

```
1. Generate validator wallet
          │
          ▼
2. Acquire NCN tokens (testnet faucet or purchase)
          │
          ▼
3. Approve tokens for registry contract
          │
          ▼
4. Call registerValidator() with stake amount
          │
          ▼
5. Start validator node with same private key
          │
          ▼
6. Node syncs with network and joins validator pool
          │
          ▼
7. Start receiving validation requests
```

***

## Operations

### Monitor Validator

```bash
# View logs
sudo journalctl -u ncn-validator -f

# Check peer connections
grep "peer" /var/log/ncn/validator.log

# Check validation activity
grep "validation" /var/log/ncn/validator.log
```

### Check Validator Status

```bash
# On-chain status
cast call $VALIDATOR_REGISTRY_CONTRACT \
  "getValidatorInfo(address)" \
  $VALIDATOR_ADDRESS \
  --rpc-url $RPC_URL

# Check if active
cast call $VALIDATOR_REGISTRY_CONTRACT \
  "isActiveValidator(address)" \
  $VALIDATOR_ADDRESS \
  --rpc-url $RPC_URL
```

### View Reputation

```bash
# Check reputation score
cast call $VALIDATOR_REGISTRY_CONTRACT \
  "getValidatorReputation(address)" \
  $VALIDATOR_ADDRESS \
  --rpc-url $RPC_URL
```

***

## Earnings

### Fee Distribution

For each validated inference:

* **5%** total goes to validators
* Split among participating validators
* More validations = more earnings

### Track Earnings

```bash
# Check wallet balance
cast balance $VALIDATOR_ADDRESS --rpc-url $RPC_URL

# View validation count (from logs)
grep "validation successful" /var/log/ncn/validator.log | wc -l
```

***

## Reputation System

### How Reputation Works

| Action                | Impact     |
| --------------------- | ---------- |
| Successful validation | +1 point   |
| Failed validation     | -2 points  |
| Timeout (no response) | -5 points  |
| Slashing event        | -20 points |

### Maintain High Reputation

1. **Stay Online**: Maximize uptime
2. **Fast Response**: Low-latency connection
3. **Honest Behavior**: Never sign invalid results
4. **Regular Updates**: Keep software current

### Check Reputation

```bash
# Minimum reputation required
MIN_REPUTATION=20

# Your reputation
cast call $VALIDATOR_REGISTRY_CONTRACT \
  "getValidatorReputation(address)" \
  $VALIDATOR_ADDRESS \
  --rpc-url $RPC_URL
```

***

## Avoiding Slashing

### Slashable Offenses

| Offense                  | Penalty    |
| ------------------------ | ---------- |
| Invalid signature        | 50% stake  |
| Approving invalid result | 30% stake  |
| Collusion                | 100% stake |
| Prolonged downtime       | 10% stake  |

### Best Practices

1. **Secure Key**: Protect validator private key
2. **Monitor Health**: Set up alerting
3. **Redundancy**: Consider backup infrastructure
4. **Stay Updated**: Apply security patches

***

## Network Participation

### Bootstrap Nodes

Connect to existing validators:

```bash
# In validator.env
BOOTSTRAP_NODES=/ip4/192.168.1.100/tcp/8828/p2p/12D3KooWA...
```

### Peer Discovery

The P2P network uses Kademlia DHT:

* Automatic peer discovery
* Distributed state replication
* Fault-tolerant messaging

### Check Peers

```bash
# In logs
grep "Connected to peer" /var/log/ncn/validator.log

# Expected: 5-10+ peers for healthy network
```

***

## Maintenance

### Update Validator

```bash
# Stop service
sudo systemctl stop ncn-validator

# Pull updates
cd ncn-network-v2-rs
git pull

# Rebuild
cargo build --release -p p2p_registry_node

# Update binary
sudo cp target/release/p2p_registry_node /usr/local/bin/

# Restart
sudo systemctl start ncn-validator
```

### Add/Withdraw Stake

```bash
# Add more stake
cast send $VALIDATOR_REGISTRY_CONTRACT \
  "addStake(uint256)" \
  $ADDITIONAL_AMOUNT \
  --private-key $YOUR_KEY \
  --rpc-url $RPC_URL

# Withdraw (may have cooldown)
cast send $VALIDATOR_REGISTRY_CONTRACT \
  "withdrawStake(uint256)" \
  $WITHDRAW_AMOUNT \
  --private-key $YOUR_KEY \
  --rpc-url $RPC_URL
```

### Unregister Validator

```bash
# Unregister and withdraw all stake
cast send $VALIDATOR_REGISTRY_CONTRACT \
  "unregisterValidator()" \
  --private-key $YOUR_KEY \
  --rpc-url $RPC_URL
```

***

## Troubleshooting

### "No peers found"

* Check bootstrap nodes are correct
* Verify P2P port (8828) is open
* Check network connectivity

### "Consensus failed"

* Not enough validators online
* Check minimum validators setting
* Verify network health

### "Slashed"

* Review logs for violation
* May need to add more stake
* Contact community for appeal

***

## Security Best Practices

1. **Secure Validator Key**
   * Use HSM for production
   * Never share private key
2. **Firewall**
   * Only expose necessary ports (8828, 50050)
   * Use fail2ban for brute force protection
3. **Monitoring**
   * Alert on reputation drops
   * Monitor for slashing events
4. **Redundancy**
   * Consider backup node
   * Document recovery procedures

***

## Next Steps

* [Monitoring](/nc/neurochainai-guides/operators/monitoring.md) - Set up monitoring
* [Troubleshooting](/nc/neurochainai-guides/troubleshooting/troubleshooting.md) - Common issues
* [Security](/nc/neurochainai-guides/security/security.md) - Security documentation
