Skip to the content.

Tree Merge Ceremony

Status: supported one-time migration. This runbook implements design section A9 of Design: Tree Consensus and Threshold Storage Key. It is tested with unit and multi-server tests. It has not run against the live mesh yet.

Table of Contents

Purpose

Before tree operations, each server kept and changed its own permission tree. The trees differ. Tree operations need one tree that every server agrees on. The merge collects every server’s tree once, merges them by a fixed rule, and commits the result as height 1 of the tree log. After the merge, every tree change is a tree operation that Tier 1 consensus orders.

The owner runs one script, nexus-tree-migrate, on the root server: once as a dry run, and once to sign and deliver. Everything else is the normal signed release and the rolling update.

Empty start: no tree data kept

When no tree data needs to survive, skip the merge. The install moves each Tier 1 server’s data/tree (with any tree log) aside. A Tier 1 server with no tree log and an empty tree does not await a merge: it opens a log on the empty base and asks Tier 1 for the EstablishRoot operation of its configured root_pubkey. Tier 1 commits it as height 1, which holds only the application root, owned by the root management key. No command is needed.

The authority is unchanged: a replica accepts EstablishRoot only when it names the replica’s own configured root_pubkey and no root exists, only from a submitter in the block epoch’s Tier 1 set, and only through consensus. It is one-shot: a second root is refused (AlreadyExists).

To check from the root server (ns1), run the one command:

sudo nexus-tree-migrate

It reports that no Tier 1 member awaits a merge and exits. Then GET /api/tree/sync on each Tier 1 server shows "mode": "ops", "height": 1 (or more after the first writes), and the same "state_root".

Move the trees aside on every Tier 1 server or on none: a server that keeps an old tree awaits a merge and withholds its vote, and the script refuses a mix.

What the merge trusts

How a server behaves until the merge

A release with tree operations runs them on every server; there is no setting. When a Tier 1 server holds a tree written before tree operations and no tree log, it awaits the merge:

When the merge commit arrives (by POST /api/tree/merge/commit or by the "tree" stream from another member), the server verifies it, writes it as height 1, and replaces its tree with the merged tree. A crash between the write and the replacement is repaired at the next start from the log.

A server with an empty tree and no log starts a new log normally. A Tier 2 server holds no tree.

Before you start

Step 1: Roll out the release

Publish the release as usual (Releasing). nexus-updater installs it on one server at a time. Each updated Tier 1 server awaits the merge. A server that still runs the old release keeps its direct writes until its turn; those writes are part of its tree when the merge collects it.

Wait until every server runs the release. The script refuses to continue while a Tier 1 member answers the export route with 404 (old release).

Step 2: Dry run on the root server

sudo nexus-tree-migrate \
    --backup /var/lib/lemonade-nexus-backup-20261025-boot/state.tar

The package installs the script as /usr/bin/nexus-tree-migrate. nexus-updater replaces only the server binaries, so on an updated server download scripts/nexus-tree-migrate from the release tag and run it with sudo python3.

The script:

  1. asks the root server for the network, the root key, and the current Tier 1 members;
  2. extracts the backup to /var/lib/lemonade-nexus/tree-migration/backup (regular files and directories only), and has the root server export it with its data key;
  3. for each member, has the root server sign an export request, and sends it to the member’s POST /api/tree/merge/export;
  4. saves the exports in /var/lib/lemonade-nexus/tree-migration/exports.json (mode 0600);
  5. has the root server build the merge and prints the report.

The report lists, for each server, the nodes the merge adds to, removes from, and changes in its tree; every node decided by the tie-break; every dropped node with the reason; and the tree digest. Nothing is signed.

Review it. A dropped device or group joins again after the merge.

Step 3: Sign and deliver

sudo nexus-tree-migrate \
    --backup /var/lib/lemonade-nexus-backup-20261025-boot/state.tar \
    --commit --expect-tree-digest <tree digest from the dry run>

The script collects the exports again. The root server builds the merge again, refuses unless the tree digest equals the one you reviewed, signs the preimage with the root management key, and verifies the signature. The script saves the commit to /var/lib/lemonade-nexus/tree-migration/commit.json and sends it to every member’s POST /api/tree/merge/commit. A member that does not take it directly gets it from the others by replication.

Step 4: Check every Tier 1 server

GET /api/tree/sync on the private API of each Tier 1 server must show "mode": "ops", "healthy": true, "height": 1, and the same "state_root" as the script printed. Tree writes work again.

The merge rule

Per node id, the first rule that decides wins (tree::merge_tree_exports, TreeMerge.hpp):

  1. An operator resolution decides. The supported migration passes none.
  2. The root comes from the root server’s export, when it holds one.
  3. A node that one export holds, or that every holding export holds identically, is taken.
  4. A device comes from the server whose IPAM file records its tunnel allocation (the server it joined).
  5. A group comes from the server whose delta log records its create_node delta (its creator).
  6. Tie-break. Among the copies with rule 4 or 5 evidence when two or more have it, else among all copies: the highest version; then the copy that the most exports hold identically; then the root server’s copy; then the copy whose encoding is first in byte order.

Then, on the selected nodes:

  1. Two nodes that share an endpoint identifier, a mesh key, or a tunnel address (independent IPAM files often gave one address to two devices): the root is kept; otherwise the node whose join an export records, then the node the most exports hold, then the smallest id. The others are dropped.
  2. Every node that does not reach the root through its parents (a missing or dropped parent, or a cycle) is dropped.

The result depends only on the exports: their order, and the order of nodes in them, does not change it. The merge refuses to produce a commit only for malformed input (repeated server labels, more than one root server export, a bad resolution, no root in any export).

Recovery

Test data without encryption

nexus-tree-merge (export, merge, finalize), lemonade-nexus --sign-tree-merge, and --install-tree-merge work on plaintext data directories only. They refuse a data directory whose files are under the data key. Use them for test data; use nexus-tree-migrate for a mesh.

Limits