Repository navigation
fix: wipe the node DB after restoring a backup on ssv >= v2.5.0 - #65
Merged
Merged
Conversation
Contributor
|
Dappnode bot has built and pinned the built packages to an IPFS node, for commit: c4a9ba0 This is a development version and should only be installed for testing purposes.
Hash: (by dappnodebot/build-action) |
node.log keeps the lines of previous runs, so after one key mismatch every later failed start (for example while the beacon node is unreachable) matched the old line and wiped the DB again. Check only the log written since this start.
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
backupfield (used by the Backup tab and by the DAppNode full backup) covers the operator key, its password, the operator ID (/data/operator/config) and the DKG output (/data/dkg/output), but not the node DB/data/operator/db. The question was whether slashing protection needs to be added to it.What SSV v2.5.1 stores and where:
/data/operator/db(db.Path). Slashing protection is not a separate store: it lives in that same DB under the keys<network>signer_data-highest_att-<share pubkey>and<network>signer_data-highest_prop-<share pubkey>(ssvsigner/ekm/signer_storage.go), next to the registry/network state. It only keeps the highest attestation and proposal per share (no history).ssvnodehas no export or import command for it (no EIP-3076 interchange), and BadgerDB cannot be opened by a second process while the node runs, so it cannot be backed up on its own.AddSharecallsBumpSlashingProtection, which sets the highest attestation target to the current epoch and the highest proposal to the current slot, andSetMinParticipationEpoch(current epoch + 1)stops the share from signing until the next epoch (eth/eventhandler/handlers.go, comment: "we don't know if another instance of our operator has been running in the past and potentially signed something conflicting, so we err on the safe side"). The SSV node migration docs also say the DB is optional and can be re-synced from scratch.So a copy of the DB taken while the node runs is both possibly inconsistent and less protective than a re-sync: its watermarks are older than what the old node signed afterwards, and the shares would sign straight away. The manifest
backupshould stay as it is.There is, however, a bug that breaks restore. When the operator key is restored onto a node whose DB was created with another key (the usual case: a fresh install generates a new key and DB before the backup is restored over it), SSV refuses to start. The entrypoint is meant to handle that by wiping the DB and starting again, but it greps for the message logged by SSV < v2.5.0 (
operator private key is not matching the one encrypted the storage). Since v2.5.0 SSV logsoperator private key does not match the one that encrypted the storage, so the wipe never happens and the operator restarts in a loop after a restore.Approach
operator/entrypoint.sh: match both the old and the new message, so a restored key gets a clean DB, which re-syncs and re-bumps the slashing protection to the current epoch.operator/entrypoint.sh: only look for the message in the log lines written by the current run.node.log(/data/operator/logs, on the volume) keeps the lines of previous runs, so once a mismatch had been logged, every later failed start (for examplecould not start node ... failed to create beacon go-clientwhile the beacon node is unreachable, which exits 1) matched the old line and wiped the DB again. The old pattern had the same flaw, but it never matched on v2.5.x, so fixing the message alone would have turned it on.README.md: explain why the node DB is not backed up.No manifest change and no version bump.
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 cpon each item from the running containers; restore runsdocker exec <container> mkdir -p <dir>(needs a running container),docker cps the items into the running containers anddocker restarts the package. This PR works with that flow:ssvnodedoes not rewrite those files, and the restart starts the entrypoint again, which detects the key mismatch and wipes the DB as described above. The operator runs as root, so root-owned restored files are fine.Checked locally with the operator image built from this branch (
ssvlabs/ssv-node:v2.5.1, arm64,--network none): the v2.5.1 binary containsoperator private key does not match the one that encrypted the storage, and fatal start errors are written tonode.log. SSV only checks the key after reaching the beacon node, which is not possible offline, so the entrypoint logic was exercised withssvnode start-nodereplaced by a stub that logs that message and exits 1 when the key does not match the DB:docker cpof/data/operator/configout of a running operator,docker exec mkdir+docker cpinto another running operator with a different key and DB,docker restart. The entrypoint logged the mismatch warning, wiped the DB and started with the restored key. A later start failing with a beacon node error then wiped the DB again before the log fix, and kept it after.Testing
Backup:
ssv-hoodi(registered operator), download a backup from the Backup tab, or create a DAppNode full backup.operator-config(encrypted_private_key.json,private_key_password,operator_id.txt) anddkg-output, and no DB.Restore onto a fresh install (the case this PR fixes):
ssv-hoodipackage) and wait at least one epoch.ssv-hoodibuilt from this branch and let it start once: it generates a new operator key and a DB.[WARN] Detected private key mismatch, probably due to backup restoring. Removing DB and retrying..., thensuccessfully loaded operator keyswith the restored public key, and the registry sync.could not start node ... operator private key does not match the one that encrypted the storage.Restore onto the same node (same key): restoring the backup leaves the DB in place, and the node starts without wiping it.