Skip to content

fix: back up node_key.json in the full backup - #125

Open
3alpha wants to merge 1 commit into
mainfrom
fix/backup-near-keys
Open

3alpha wants to merge 1 commit into
mainfrom
fix/backup-near-keys

Conversation

@3alpha

@3alpha 3alpha commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Problem

The DAppNode full backup (DNP_DAPPMANAGER #2511/#2512) copies only the paths a package declares in the manifest backup field. NEAR declares config.json, validator_key.json and latencieslogs.csv, but not node_key.json.

node_key.json is created once by neard init (random ed25519 key, generate_or_load_key in nearcore nearcore/src/config.rs) and is the node's p2p identity (peer ID). start_near.sh also uses its presence to decide whether to run neard init. If it is lost, the node comes back with a new peer ID: anything that references the old one (boot node lists, peering, monitoring) breaks, and it cannot be regenerated.

Approach

Add one backup item, node_key -> /srv/near/node_key.json (service near). Layout of NEAR_HOME=/srv/near (named volume near) and how each file is covered:

Path Origin Backed up
config.json downloaded by neard init --download-config, then edited by start_near.sh and possibly by the user yes (already)
node_key.json random key from neard init, never regenerated yes (added here)
validator_key.json rewritten from ACCOUNT_ID, VALIDATOR_PUBLIC_KEY and VALIDATOR_SECRET_KEY on every start, deleted if they are unset yes (already)
latencieslogs.csv output of neard ping, diagnostic only yes (already, left as is)
genesis.json mainnet genesis is embedded in neard and written by init no, reproducible
data/ chain database, restored from the fastnear snapshot no, reproducible

The validator secret also lives in the package env vars, which the full backup keeps in the package user settings, so after a restore start_near.sh writes the same validator_key.json again; the file item is a second copy.

The existing validator_key item already makes the dappmanager treat NEAR as a validator (backup item name/path contains validator): before restoring it asks the user to confirm the old node is off and it leaves NEAR stopped after restore. That is the behaviour we want here.

Double-signing risk: a restored NEAR node has the same validator key and the same node key as the original. If both run at the same time they produce conflicting blocks, chunks and endorsements under one validator key and fight over one peer ID. The old node must be switched off for good before the restored one is started.

Compatibility with dappmanager versions without full backup

The released Dappmanager only has the per-package Backup tab. The new item works there as is:

  • Backup: docker cp of node_key.json from the running container. The file is written once by neard init and never changed, so the live copy is exact. Items that fail (for example latencieslogs.csv before the first neard ping) are skipped, and the backup fails only if every item fails.
  • Restore: docker cp into the running container, then docker restart. The container runs as root (supervisord, no user=), so the root-owned restored files are fine. neard reads node_key.json only at start and does not write it on shutdown. After the restart start_near.sh finds the file, skips neard init, and the node starts with the restored peer ID.
  • What that Dappmanager does not do: the validator handling described above (confirming that the old node is off and leaving NEAR stopped) only exists with full backup and restore. The Backup tab restarts NEAR immediately after a restore and asks nothing. Switch the old node off before restoring from the tab. This was already true for the existing validator_key item. Also, start_near.sh rewrites validator_key.json from the package env vars on every start (or deletes it when they are unset), so the validator key in use after a Backup tab restore comes from those settings.

Not run: nearprotocol/nearcore is amd64-only and this check ran on an arm64 host, so the above is from the Dappmanager source (backupGet.ts, backupRestore.ts, packageRestart.ts on develop), start_near.sh, the supervisord config and the image config.

No version bump: the field takes effect in the next release built from main.

Test instructions

  1. Build and install this package on a DAppNode running a dappmanager with the full backup feature, with a validator account and keys in the setup wizard.
  2. Note the contents of /srv/near/node_key.json and /srv/near/validator_key.json (docker exec DAppNodePackage-near.near.dnp.dappnode.eth cat /srv/near/node_key.json).
  3. Create a full backup and check that it contains packages/near.dnp.dappnode.eth/backup/node_key.tar, validator_key.tar and config.tar, with no warning for node_key.
  4. Restore it on a clean DAppNode. Confirm the dappmanager asks to confirm the old node is off, and that NEAR is left stopped afterwards.
  5. Check that node_key.json, validator_key.json and config.json match the originals, then start the package and check that the peer ID in the logs is the original one.

node_key.json is generated once by neard init and holds the node's p2p identity; it cannot be recreated. config.json and validator_key.json were already covered.
@tropibot

tropibot Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

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

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

  1. Package near.dnp.dappnode.eth

Install link

Hash: /ipfs/QmdsCn5wjg1MeSpoKwx11GRPZttL9wHW5GW7CpWvVnXZ2K

(by dappnodebot/build-action)

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