# Replace an Operator

{% hint style="warning" %}
This is an alpha feature and is not yet recommended for production use.
{% endhint %}

You can replace an operator in your cluster using the `charon alpha edit replace-operator` command. This operation keeps all validators intact whilst swapping one operator for another in the cluster.

## Prerequisites

1. Review the `edit replace-operator` command [CLI reference](https://docs.obol.org/learn/charon/charon-cli-reference#replace-an-operator-in-a-cluster).
2. **For continuing operators**: Keep the DV node running during the process and ensure you have a copy of the current cluster lock file and validator private key shares.
3. **For the new operator**: Obtain a copy of the existing cluster lock file from the continuing operators and have your Charon ENR private key file ready.
4. **For the old operator being replaced**: The operator being replaced should NOT participate in the ceremony.
5. Identify the Charon ENR address of the operator you wish to replace and have the new operator's ENR ready.

{% hint style="info" %}
The ceremony uses a different p2p relay from your running cluster to avoid conflicts. The default relay address is already configured differently, so no special action is required.
{% endhint %}

## Understanding the Replacement Process

The replace-operator ceremony performs a one-for-one swap:

* The **old operator** is completely removed from the cluster and does not participate in the ceremony
* The **new operator** takes over at the same index position as the old operator
* All **continuing operators** must participate with their existing validator keys
* All validator public keys remain unchanged

This is more convenient than `remove-operators` followed by `add-operators`, as it maintains the cluster size and threshold in a single atomic operation.

## Replacing an Operator

All continuing operators and the new operator must run this command. The old operator being replaced should NOT run the command.

### For Continuing Operators

```bash
# Standard usage
charon alpha edit replace-operator --old-operator-enr=enr:-JG4QH... --new-operator-enr=enr:-JG4QK... 

# Docker version
docker run -u $(id -u):$(id -g) --rm -v "$(pwd):/opt/charon" -w "/opt/charon" obolnetwork/charon:latest alpha edit replace-operator --old-operator-enr=enr:-JG4QH... --new-operator-enr=enr:-JG4QK... 
```

### For the New Operator

The new operator being added should run the same command but only needs to provide their private key file and the cluster lock file (they won't have validator keys yet):

```bash
# Standard usage
charon alpha edit replace-operator --old-operator-enr=enr:-JG4QH... --new-operator-enr=enr:-JG4QK... --output-dir=output --lock-file=cluster-lock.json --private-key-file=charon-enr-private-key

# Docker version
docker run -u $(id -u):$(id -g) --rm -v "$(pwd):/opt/charon" -w "/opt/charon" obolnetwork/charon:latest alpha edit replace-operator --old-operator-enr=enr:-HW4...UVM --new-operator-enr=enr:-HW4QB-SH7cQ....2A0g6y0
```

### For the Old Operator Being Replaced

The old operator **should not participate** in the ceremony. Simply do not run the command.

{% hint style="warning" %}
The old operator's ENR and new operator's ENR must be different. The command will fail if they are the same.
{% endhint %}

## Making the DV Stack Use the New Configuration

The example below is designed for the [CDVN repository](https://github.com/ObolNetwork/charon-distributed-validator-node), but the process is similar for other setups.

{% hint style="danger" %}
The old cluster **must be shut down for at least two epochs**. If you're not sure of the epoch boundary, wait 18 minutes from the original cluster going offline until you turn on the modified cluster. **Failure to heed this warning may result in slashing**.
{% endhint %}

### For Continuing Operators and New Operator

1. Stop the current Charon and validator client instances:

```bash
docker compose down
```

2. Back up and remove the existing `.charon` directory, then move the `distributed_validator` directory to `.charon`:

```bash
mv .charon .charon-backup
mv distributed_validator .charon
```

3. Restart the Charon and validator client instances **once at least two epochs of downtime have passed**:

```bash
docker compose up -d 
```

### For the Old Operator Being Replaced

The operator who has been replaced can safely shut down their node after the ceremony completes:

```bash
docker compose down
```

## Current Limitations

* The new cluster configuration will not be reflected on the Launchpad.
* The new cluster configuration will have a new cluster hash, so the observability stack will display new cluster data under a different identifier.
* All continuing operators must have valid validator keys to participate in the replacement ceremony.
* The cluster's threshold value remains unchanged after replacing an operator.
* The new operator's ENR must not already exist in the cluster.
* The old operator's ENR must exist in the current cluster.
