Skip to content

fix: back up Anchor slashing protection and builder definitions - #32

Merged
3alpha merged 3 commits into
mainfrom
fix/backup-slashing-protection
Nov 23, 2026
Merged

3alpha merged 3 commits into
mainfrom
fix/backup-slashing-protection

Conversation

@3alpha

@3alpha 3alpha commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Problem

The manifest backup only covers the operator key (/root/keys) and the DKG output (/data/dkg/output). Anchor's data dir /root/.anchor (volume operator-data) is not covered, so a DAppNode full backup (and the package Backup tab) loses Anchor's slashing protection database. After a restore on a new machine the operator starts with an empty slashing protection history.

What is in /root/.anchor

From Anchor v1.4.1 (anchor/common/global_config/src/data_dir.rs; the entrypoint passes --data-dir=/root/.anchor, so files sit directly in it on both variants):

Path Content Recreatable
anchor_db.sqlite (WAL) SSV network state (operators, clusters, validators, shares, last processed block) from contract events Yes, re-synced from the execution client
slashing_protection.sqlite Lighthouse SlashingDatabase (signed blocks and attestations per validator), rollback journal, locking_mode=EXCLUSIVE No
builder_definitions.yml Direct builder configuration (Gloas/ePBS), created empty on first start, edited by the user No, if edited
network/key, network/enr.dat, public_key.txt libp2p identity, ENR, operator public key Yes, regenerated
logs/, .lock Logs and the data dir lock Not needed

Anchor has no EIP-3076 export or import command, and it holds an exclusive SQLite lock on the slashing DB for as long as it runs, so the DB cannot be read consistently from outside while Anchor is up.

Approach

  1. Add two single-file items on the operator service. The rest of /root/.anchor stays out, so the network DB is not copied.
    • slashing-protection: /root/.anchor/slashing_protection.sqlite
    • builder-definitions: /root/.anchor/builder_definitions.yml
  2. Add stop_grace_period: 30s to the operator service, so a stop never SIGKILLs Anchor during shutdown.

Why the copy is exact

The DAppManager full backup (dappnode/DNP_DAPPMANAGER#2511) and the package Backup tab stop validator packages gracefully before copying their backup paths, and copy from the stopped containers. Anchor is detected as a validator package through the slashing-protection item name. On SIGTERM, Anchor shuts down cleanly and leaves a complete database file:

  • The entrypoint ends with exec anchor node ..., so Anchor is PID 1 and receives SIGTERM directly. Anchor registers SIGTERM/SIGINT/SIGHUP handlers (anchor/src/environment.rs).
  • On the signal, Anchor fires the task executor's exit signal: async tasks are cancelled at their next await point, so no new duty reaches signing. Every slashing DB write is one synchronous SQLite transaction (Lighthouse with_transaction, no await inside), either inside one task poll (blocks) or in a blocking task (attestations, pruning). A poll cannot be interrupted, and tokio's shutdown_timeout waits up to 15 s (MAXIMUM_SHUTDOWN_TIME) for blocking tasks. So the process exits between transactions.
  • When the runtime drops its tasks, the connection pool is dropped and SQLite closes the database: the -journal file (kept with a zeroed header while running, because of the exclusive lock) is deleted, and anchor_db.sqlite-wal is checkpointed.
  • Docker's default stop timeout is 10 s, below Anchor's 15 s worst case, hence the 30 s grace period. docker stop without -t (the DAppManager passes the dockerTimeout label, which this package does not set) and docker compose stop both use it.

Measured locally with this branch's operator image (hoodi, freshly created operator, no validators): SIGTERM to "Shutdown complete" took 3 ms, docker stop returned in 0.07 s with exit code 0. Afterwards /root/.anchor had no slashing_protection.sqlite-journal and no WAL file, and the copied slashing_protection.sqlite passed PRAGMA integrity_check (journal_mode = delete). With duties running the shutdown can take longer; the 15 s runtime cap bounds it.

With a DAppManager without full backup, the Backup tab copies from the running package: see "Compatibility with dappmanager versions without full backup" below.

Restore

Restore extracts each file into /root/.anchor with the package stopped and overwrites it, leaving anchor_db.sqlite and the rest alone. Anchor re-syncs the network state and re-registers validators in the slashing DB, which keeps the existing rows.

The item name contains slashing, so the DAppManager full restore (#2511, #2512) now treats Anchor as a validator package: it asks the user to confirm the old node is off and leaves Anchor stopped after restore until the user starts it. Before this change anchor.dnp.dappnode.eth matched neither the validator name pattern nor the item pattern, so the operator started right after restore.

The README "Backup your key" section lists the new items, says the copy is exact when DAppNode stops Anchor first, and says to switch off the old operator before restoring. A "Compatibility with DAppManager versions without full backup" note says what to do with an older DAppManager.

No version bump: the existing paths and services are unchanged and the new items need no image change.

Compatibility with dappmanager versions without full backup

The package release may ship before dappnode/DNP_DAPPMANAGER#2511 and #2512. Today's DAppManager only has the per-package Backup tab: backup runs docker cp <container>:<path> on each item from the running containers (it fails only if every item fails); restore runs docker exec <container> mkdir -p <dir> (needs a running container), docker cps each item into the running container, then docker restarts every container of the package. Checked against that flow with sigp/anchor:v1.4.1 (arm64, --network none, no beacon node, so no duties ran):

  • Backup from the running package: best-effort. The live copy of slashing_protection.sqlite passed PRAGMA integrity_check, but Anchor writes it with a rollback journal that the copy does not include, so a copy taken while a commit writes pages can be inconsistent. docker cp also works on a stopped container: after docker stop (exit code 0) no -journal is left and the copy is exact. The README note therefore says to stop Anchor before Download backup, and to leave it stopped when moving the operator to another machine.
  • Restore into the running package: works. docker cp replaces slashing_protection.sqlite and builder_definitions.yml with new files (new inodes). The running Anchor keeps writing to the old, unlinked database; on docker restart it shuts down cleanly ("Shutdown complete" 1 ms after SIGTERM) and deletes the old database's journal, so no stale journal is rolled into the restored file. After the restart the restored database (with a marker validator and attestation added to it) and builder_definitions.yml were intact and Anchor opened them. Anchor runs as root, so root-owned restored files are fine. Only a SIGKILL during a commit could leave a hot journal next to the restored file; stop_grace_period: 30s also applies to this restart, since the package sets no dockerTimeout.
  • The package starts right after the restore, so the README note says to switch off the old operator at least a couple of epochs before restoring.
  • Older archives: archives taken before this PR (only keys and dkg-output) still restore, because missing items are logged and skipped. A missing builder_definitions.yml in the container only fails that item.

Test

On a node running anchor-hoodi built from this branch, after Anchor has been up for a few minutes with duties:

  1. Graceful stop: docker stop DAppNodePackage-operator.anchor-hoodi.dnp.dappnode.eth (the container name may differ). The logs end with Shutting down... reason=Success("Received SIGTERM") and Shutdown complete, the exit code is 0, and docker inspect shows StopTimeout: 30. With the container stopped, /root/.anchor has no slashing_protection.sqlite-journal. Start it again.
  2. Backup tab: download the backup. It contains keys/, dkg-output/, slashing-protection and builder-definitions, and no anchor_db.sqlite. Run sqlite3 slashing-protection "PRAGMA integrity_check; SELECT count(*) FROM validators; SELECT max(target_epoch) FROM signed_attestations;": ok, and the counts match the operator's validators.
  3. Full backup (DAppManager with #2511): create a backup. Anchor is stopped before its items are copied, the Anchor entry has the four items and no warnings, and Anchor is started again afterwards.
  4. Restore (DAppManager with #2512) on a node with the same package version, after switching off Anchor on the source node: the restore asks to confirm the old node is off, and Anchor stays stopped afterwards. In the operator container, ls -l /root/.anchor shows the restored slashing_protection.sqlite and builder_definitions.yml. Wait a couple of epochs, start the package, and check the logs: Anchor opens the slashing DB without errors, re-syncs the network state, and performs duties.
  5. Backup tab restore: upload the backup from step 2. The files land in /root/.anchor and the package restarts and runs.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Dappnode bot has built and pinned the built packages to an IPFS node, for commit: ae548c8

This is a development version and should only be installed for testing purposes.

  1. Package anchor.dnp.dappnode.eth

Install link

Hash: /ipfs/QmVqQCHpEk6zyC6VvVE93DYHdQWcau2mXfpArHCES3Bb5w

(by dappnodebot/build-action)

…ackup

Older DAppManager versions copy the Backup tab items from the running package and restore into the running package before restarting it. Say to stop Anchor before downloading for an exact slashing protection copy, and to switch off the old operator before restoring.
@3alpha
3alpha merged commit 580a74d into main Nov 23, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant