Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 44 additions & 4 deletions docs/concepts/slashing-protection.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ Set `<data-path>` using the [`--data-path`](../reference/cli/index.md#data-base-

:::

Teku provides command line options to [import] or [export] the slashing protection file.
Teku provides command line options to [import] or [export] the slashing protection file, and to [repair] slashing protection files.

:::warning

If a validator has no slashing protection file, Teku treats it as never having signed anything.
Teku creates the file the first time the validator signs.
When you move validator keys to Teku, import or create their slashing protection files before you start the validator client.

:::

:::tip

Expand Down Expand Up @@ -64,6 +72,35 @@ You can obtain the `genesisValidatorsRoot` value by using the [`/eth/v1/beacon/g

These rules guarantee the validator does not sign anything that is slashable.

## Repair slashing protection files

Use the [`repair`](../how-to/prevent-slashing/repair-slashing-protection.md) command line option to
fix a damaged slashing protection file by writing a minimum slot into it.
The validator can't sign a block or attestation from before that slot.
That protects the validator when Teku has no reliable record of what the validator has already signed.
With [`--update-all-enabled`](../reference/cli/subcommands/slashing-protection.md#update-all-enabled), `repair` also creates a file for a validator key that has none.

The [`repair`](../reference/cli/subcommands/slashing-protection.md#repair) subcommand reads the `<validator-pubkey>.yml` files in the `slashprotection` directory under the validator client data directory.
It ignores files whose name isn't a validator public key.

`repair` sets a repair slot in each file it updates:

- `lastSignedBlockSlot` is set to the repair slot.
- `lastSignedAttestationSourceEpoch` and `lastSignedAttestationTargetEpoch` are set to the epoch of the repair slot.

By default, the repair slot is the current slot plus one epoch, so your validators miss at most one epoch of duties.
Teku determines the current slot from the network's initial state, or from its genesis state if the network has no initial state.
You can set the repair slot yourself with the [`--slot`](../reference/cli/subcommands/slashing-protection.md#slot) option.

`repair` only raises values.
If a file already has a higher value, `repair` keeps it.
This means `repair` can't undo a repair slot that was too high.
To lower the values, [edit the slashing protection files](../how-to/prevent-slashing/repair-slashing-protection.md#lower-the-repair-slot-values).

When Teku determines the repair slot from the network, it also checks that existing files belong to that network.
Teku uses each file's `genesisValidatorsRoot` for that check.
If any file belongs to a different network, `repair` stops without changing anything.

## Migrate the slashing protection file

Use the Teku command line options to [import] or [export] the slashing protection file. Alternatively, you can manually migrate or create the database.
Expand All @@ -76,16 +113,18 @@ For example, to manually move the file from node A to node B:

1. Stop Teku node A and confirm the process has fully exited and won't be restarted.
1. Remove the validator key from node A, for example from the [`--validator-keys`](../reference/cli/index.md#validator-keys) option.
1. Copy the file from `<nodeA-data-path>/validators/slashprotection/` to `<nodeB-data-path>/validators/slashprotection/`.
1. Copy the file from `<nodeA-data-path>/validator/slashprotection/` to `<nodeB-data-path>/validator/slashprotection/`.
1. Start node B with the migrated validator key.
1. Restart node A if required.

### From a non-Teku node

If moving a validator from a different client to Teku, you can do either of the following:
If you move a validator from a different client to Teku, do one of the following:

- Manually [create a new slashing protection file] by setting the values based on the validator's last signing details.
- [Import] the slashing protection file.
- Add the validator keys to the Teku configuration and, before you start the validator client, [repair] with `--update-all-enabled` to create a file for each key.
This blocks your validators from signing until about one epoch after the repair.
- Manually [create a new slashing protection file] by setting the values based on the validator's last signing details.

To manually create the file, stop the other client to ensure it isn't signing, then set the following:

Expand All @@ -98,6 +137,7 @@ Start the Teku node with the validator key.
<!-- links -->

[YAML file is stored per validator]: #validator-slashing-protection-file
[repair]: ../how-to/prevent-slashing/repair-slashing-protection.md
[create a new slashing protection file]: #validator-slashing-protection-file
[import]: ../how-to/prevent-slashing/use-a-slashing-protection-file.md#import-a-slashing-protection-file
[export]: ../how-to/prevent-slashing/use-a-slashing-protection-file.md#export-a-slashing-protection-file
2 changes: 1 addition & 1 deletion docs/how-to/prevent-slashing/detect-doppelgangers.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
description: Check if your validators' keys are already active.
sidebar_position: 2
sidebar_position: 3
---

# Detect doppelgangers
Expand Down
2 changes: 1 addition & 1 deletion docs/how-to/prevent-slashing/detect-slashing.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
description: Shut down Teku if a validator is slashed.
sidebar_position: 3
sidebar_position: 4
---

# Stop Teku when a validator is slashed
Expand Down
172 changes: 172 additions & 0 deletions docs/how-to/prevent-slashing/repair-slashing-protection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
---
description: Repair or create slashing protection files so validators can't sign before a given slot.
sidebar_position: 2
---

# Repair slashing protection files

Use [`teku slashing-protection repair`](../../reference/cli/subcommands/slashing-protection.md#repair) to fix damaged [slashing protection] files.
It writes a minimum slot into each validator's file, so the validator can't sign a block or attestation from before that slot.
With [`--update-all-enabled`](#update-all-files-and-create-missing-ones), `repair` also creates files that are missing.
Before you run `repair`, read [how `repair` sets the repair slot](../../concepts/slashing-protection.md#repair-slashing-protection-files).

Use `repair` when:

- Teku reports that a slashing protection file is empty or can't be read, and refuses to sign for that validator.
- You moved validator keys to Teku without their slashing protection data, and can't [import a slashing protection file].
- Your validators must not sign anything before a given slot, for example after you restore a backup.

:::warning

Teku treats a validator key with no slashing protection file as never having signed anything.
Teku then signs any block or attestation for that key.
If you moved keys without their slashing protection data, add them to the Teku configuration.
Run `repair` with [`--update-all-enabled`](#update-all-files-and-create-missing-ones) before you start the validator client.

:::

## Prerequisites

- Stop your validator client.
A running validator client caches its slashing protection records and overwrites the repaired files.
- Make sure your validators aren't running anywhere else.
`repair` only protects against signing on this node.
- Use the same configuration as the node you're repairing.
Pass it with [`--config-file`](../../reference/cli/subcommands/slashing-protection.md#config-file-2) so `repair` uses that network, data path, and validator keys.

:::caution

If you don't specify `--network`, the default is `mainnet`.
If you repair a testnet validator without specifying its network, the repair slot is mainnet's current slot.
That slot can be years ahead of the testnet.
Your validator then can't sign until the testnet reaches that slot.

:::

## Check files without updating them

Use [`--check-only-enabled`](../../reference/cli/subcommands/slashing-protection.md#check-only-enabled) to see what `repair` would change without changing anything:

```bash
teku slashing-protection repair --config-file=/home/me/me_node/config.yaml --check-only-enabled
```

Teku lists the files it can't read, and the validator keys that have no slashing protection file:

```text
Found 2 validator keys from keystores given by --validator-keys
a3a32b0f...7e4a9b: no slashing protection record
1 validator key has no slashing protection record, so the validator client will treat it as never having signed. --update-all-enabled would create the missing record.
Updates have been skipped as --check-only-enabled was set.
```

See [Find the validator keys repair checks](#find-the-validator-keys-repair-checks) for where Teku finds the keys.

## Repair damaged files

1. Run `repair` with the configuration file of your node:

```bash
teku slashing-protection repair --config-file=/home/me/me_node/config.yaml
```

Teku rewrites files that are empty, can't be read, or are missing a value.
Rewritten files don't keep their `genesisValidatorsRoot`.
Teku adds it again the next time the validator signs.
`repair` doesn't change valid files.

Teku displays the repair slot and its epoch, and asks you to confirm:

```text
Computed hoodi slot 4337768, which will set attestation source/target to epoch 135555
b89bebc6...874a0b: Incomplete or invalid slashing protection data

REMINDER! If the validator is running, you should not be updating slashing protection records.
block slot -> 4337768
attestation source/target -> 135555
Are you sure you wish to continue (yes/no)?
```

1. Type `yes` to update the files.
Any other answer cancels the repair without changing anything.

Teku also lists validator keys that have no slashing protection file.
It doesn't create files for them unless you set `--update-all-enabled`.
If the only issue is a validator key with no file, `repair` changes nothing and doesn't ask for confirmation.
Use `--update-all-enabled` to create the missing file.

## Update all files and create missing ones

Without `--update-all-enabled`, `repair` doesn't create missing files.
Teku creates a validator's file the first time that validator signs.

Use [`--update-all-enabled`](../../reference/cli/subcommands/slashing-protection.md#update-all-enabled) to protect every validator up to the repair slot:

```bash
teku slashing-protection repair --config-file=/home/me/me_node/config.yaml --update-all-enabled
```

In addition to rewriting damaged files, Teku:

- Raises each value in a valid file that's lower than the repair slot or its epoch.
Files keep their `genesisValidatorsRoot`.
- Creates a file for each [validator key it finds](#find-the-validator-keys-repair-checks) that has none.
If the `slashprotection` directory doesn't exist, Teku creates it, as long as it found at least one validator key.

The confirmation shows how many files Teku will create:

```text
All valid slashing protection files will also be updated.
2 new slashing protection records will be created for validator keys that don't have one.
block slot -> 4337768
attestation source/target -> 135555
Are you sure you wish to continue (yes/no)?
```

### Find the validator keys repair checks

Teku finds validator keys in:

- Keystores imported with the [key manager API](https://ethereum.github.io/keymanager-APIs/), in the `key-manager/local` directory under the validator client data directory.
- External signer keys imported with the key manager API, in the `key-manager/remote` directory under the validator client data directory.
- Keystores listed by [`--validator-keys`](../../reference/cli/subcommands/slashing-protection.md#validator-keys).
Teku reads each keystore's public key without decrypting it.
The password files must still exist, but Teku doesn't read them.
- Public keys listed by [`--validators-external-signer-public-keys`](../../reference/cli/subcommands/slashing-protection.md#validators-external-signer-public-keys).

Teku displays how many keys it found in each place.

Teku doesn't check some keys, and lists them as not checked:

- External signer keys given as a URL, or with the `external-signer` keyword, because Teku doesn't fetch them.
- Keys in keystores or key manager files that Teku can't read, and invalid public keys.

Make sure those keys have slashing protection files, or [import a slashing protection file] for them.

If Teku finds no validator keys, it doesn't check for missing files, and displays a message saying so.

## Set the repair slot

Use [`--slot`](../../reference/cli/subcommands/slashing-protection.md#slot) to set the repair slot yourself, for example on a network without an initial or genesis state such as `minimal`:

```bash
teku slashing-protection repair --config-file=/home/me/me_node/config.yaml --slot=1234 --update-all-enabled
```

Choose a slot after your validators last signed anything, on any machine.
When you specify a slot, Teku doesn't check that existing files belong to the network, so check the network yourself.

## Lower the repair slot values

`repair` can't lower values.
If the repair slot was too high, your validators can't sign until the network reaches that slot.

1. Stop your validator client.
1. Edit the affected files by hand.
Set the values to the last block and attestation each validator signed.
See [Validator slashing protection file](../../concepts/slashing-protection.md#validator-slashing-protection-file) for the file format.

<!-- links -->

[slashing protection]: ../../concepts/slashing-protection.md
[import a slashing protection file]: use-a-slashing-protection-file.md#import-a-slashing-protection-file
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ If using an external signer that implements its own slashing protection (for exa

## Import a slashing protection file

When importing the slashing protection file, Teku imports the file to the `<data-path>/validators/slashprotection/` directory in the format `<validator-pubkey>.yml` (with no 0x prefix).
When importing the slashing protection file, Teku imports the file to the `<data-path>/validator/slashprotection/` directory in the format `<validator-pubkey>.yml` (with no `0x` prefix).

```bash title="Example"
teku slashing-protection import --data-path=/home/me/me_node --from=/home/slash/slashing-interchange-format.json
Expand All @@ -30,7 +30,7 @@ In the command line:
- [`--data-path`](../../reference/cli/subcommands/slashing-protection.md#data-path-1) specifies the location of the Teku `data` directory.
- [`--from`](../../reference/cli/subcommands/slashing-protection.md#from) specifies the location of the slashing protection file.

In this example, Teku imports the file to the `/home/me/me_node/data/validators/slashprotection/` directory.
In this example, Teku imports the file to the `/home/me/me_node/validator/slashprotection/` directory.

## Export a slashing protection file

Expand Down
Loading
Loading