# XDC Apothem Testnet Genesis Fix Documentation

## Overview

This document describes the genesis file fix for XDC Apothem testnet (chain ID 51) that was applied to resolve peer connection and sync issues.

## The Problem

**GP5** was initialized with the wrong genesis file from the local repository (`genesis/xdc_apothem.json`), which caused:
- Genesis hash mismatch with the official Apothem network
- Inability to connect to peers
- Sync failure

### Wrong Genesis (Before Fix)
- **File**: `genesis/xdc_apothem.json` (old version)
- **SHA256**: `19a645bb81ca8f8bf811709e22e30f22f4e9e807f83cecd01799e107b05683d0`
- **Source**: Local repository (incorrect)
- **Issue**: Contained `eip1559Block` and different allocation code that didn't match official network

### Correct Genesis (After Fix)
- **File**: `genesis/xdc_apothem.json` (updated)
- **SHA256**: `ca90670b3903ec66382cdf98792c2532e903f504ddbdeedeef42797a1015df01`
- **Source**: [XinFin-Node/testnet/genesis.json](https://github.com/XinFinOrg/XinFin-Node/blob/master/testnet/genesis.json)
- **Genesis Hash**: `0xbdea512b...` (official Apothem genesis hash)

## Key Differences

The main differences between the incorrect and correct genesis files:

1. **Removed `eip1559Block`**: The official Apothem genesis does not include this field
2. **Allocation Code**: Different contract bytecode for the genesis allocation
3. **Storage Layout**: Minor differences in storage slot values

## Official Genesis Sources

| Network | Chain ID | Source Repository | File Path |
|---------|----------|-------------------|-----------|
| Apothem (Testnet) | 51 | XinFin-Node | `testnet/genesis.json` |
| Mainnet | 50 | XinFin-Node | `mainnet/genesis.json` |
| Devnet | 551 | XinFin-Node | `devnet/genesis.json` |

**Official Repository**: https://github.com/XinFinOrg/XinFin-Node

## Fix Application

### Files Updated

1. **genesis/xdc_apothem.json** - Replaced with official XinFin-Node testnet genesis
2. **README.md** - Added genesis documentation section
3. **scripts/init_genesis.sh** - Verified correct genesis path
4. **APO-SETUP-GUIDE.md** - This documentation

### Docker Images

| Image | Tag | Description |
|-------|-----|-------------|
| `anilchinchawale/gx` | `latest` | Fixed genesis version |
| `anilchinchawale/gx` | `apothem-fix-<date>` | Tagged fix release |

## Verification

To verify your node has the correct genesis:

```bash
# Compute SHA256 of genesis file
sha256sum genesis/xdc_apothem.json

# Expected output (correct genesis):
# ca90670b3903ec66382cdf98792c2532e903f504ddbdeedeef42797a1015df01

# Initialize node with correct genesis
XDC init --datadir ~/.xdc genesis/xdc_apothem.json
```

## Impact

- **Nodes initialized before fix**: Will need to resync with correct genesis
- **GP5**: Now connects to official Apothem network and syncs correctly
- **Future nodes**: Will use correct genesis from the start

## References

- [XinFin-Node Repository](https://github.com/XinFinOrg/XinFin-Node)
- [XDC Network Documentation](https://docs.xdc.network)
- [Apothem Faucet](https://faucet.apothem.network)

## Commit Information

- **Commit Hash**: See git log for the fix commit
- **Branch**: `feature/xdpos-consensus`
- **Date**: March 2025

---

*This fix ensures XDC Apothem testnet nodes can properly connect and sync with the official network.*
