Repository navigation
fix: back up Anchor slashing protection and builder definitions - #32
Merged
Merged
Conversation
|
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.
Hash: (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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The manifest
backuponly covers the operator key (/root/keys) and the DKG output (/data/dkg/output). Anchor's data dir/root/.anchor(volumeoperator-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/.anchorFrom 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):anchor_db.sqlite(WAL)slashing_protection.sqliteSlashingDatabase(signed blocks and attestations per validator), rollback journal,locking_mode=EXCLUSIVEbuilder_definitions.ymlnetwork/key,network/enr.dat,public_key.txtlogs/,.lockAnchor 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
operatorservice. The rest of/root/.anchorstays out, so the network DB is not copied.slashing-protection:/root/.anchor/slashing_protection.sqlitebuilder-definitions:/root/.anchor/builder_definitions.ymlstop_grace_period: 30sto theoperatorservice, 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
backuppaths, and copy from the stopped containers. Anchor is detected as a validator package through theslashing-protectionitem name. On SIGTERM, Anchor shuts down cleanly and leaves a complete database file:exec anchor node ..., so Anchor is PID 1 and receives SIGTERM directly. Anchor registers SIGTERM/SIGINT/SIGHUP handlers (anchor/src/environment.rs).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'sshutdown_timeoutwaits up to 15 s (MAXIMUM_SHUTDOWN_TIME) for blocking tasks. So the process exits between transactions.-journalfile (kept with a zeroed header while running, because of the exclusive lock) is deleted, andanchor_db.sqlite-walis checkpointed.docker stopwithout-t(the DAppManager passes thedockerTimeoutlabel, which this package does not set) anddocker compose stopboth use it.Measured locally with this branch's operator image (hoodi, freshly created operator, no validators): SIGTERM to "Shutdown complete" took 3 ms,
docker stopreturned in 0.07 s with exit code 0. Afterwards/root/.anchorhad noslashing_protection.sqlite-journaland no WAL file, and the copiedslashing_protection.sqlitepassedPRAGMA 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/.anchorwith the package stopped and overwrites it, leavinganchor_db.sqliteand 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 changeanchor.dnp.dappnode.ethmatched 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 runsdocker exec <container> mkdir -p <dir>(needs a running container),docker cps each item into the running container, thendocker restarts every container of the package. Checked against that flow withsigp/anchor:v1.4.1(arm64,--network none, no beacon node, so no duties ran):slashing_protection.sqlitepassedPRAGMA 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 cpalso works on a stopped container: afterdocker stop(exit code 0) no-journalis left and the copy is exact. The README note therefore says to stop Anchor beforeDownload backup, and to leave it stopped when moving the operator to another machine.docker cpreplacesslashing_protection.sqliteandbuilder_definitions.ymlwith new files (new inodes). The running Anchor keeps writing to the old, unlinked database; ondocker restartit 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) andbuilder_definitions.ymlwere 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: 30salso applies to this restart, since the package sets nodockerTimeout.keysanddkg-output) still restore, because missing items are logged and skipped. A missingbuilder_definitions.ymlin the container only fails that item.Test
On a node running
anchor-hoodibuilt from this branch, after Anchor has been up for a few minutes with duties:docker stop DAppNodePackage-operator.anchor-hoodi.dnp.dappnode.eth(the container name may differ). The logs end withShutting down... reason=Success("Received SIGTERM")andShutdown complete, the exit code is 0, anddocker inspectshowsStopTimeout: 30. With the container stopped,/root/.anchorhas noslashing_protection.sqlite-journal. Start it again.keys/,dkg-output/,slashing-protectionandbuilder-definitions, and noanchor_db.sqlite. Runsqlite3 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.ls -l /root/.anchorshows the restoredslashing_protection.sqliteandbuilder_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./root/.anchorand the package restarts and runs.