Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions agent/agent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,32 @@ test('a devnet moves to a newer dashnet only when its plans bind the same node a
writeFileSync(join(root, 'current'), fake(V('20260927T000000Z', 'd'), 'n1'), { mode: 0o755 });
await d.doctor(r).catch(() => {});
assert.match(readFileSync(join(dir, 'dashnet'), 'utf8'), /20260928T120000Z/, 'no downgrade');
// A newer build on another node recipe that lists this devnet's as accepted
// operates its plans: adopt it. The bootstrap recipe must still be the same.
const accepting = (version, bootstrap) => `#!/bin/sh\ncase "$1" in version) echo ${version};; recipes) echo '{"node":"n2","nodeAccepts":"n0,n1","bootstrap":"${bootstrap}"}';; upgrade-plan) echo 'or core (Core only, every node)' >&2;; *) exit 0;; esac\n`;
writeFileSync(join(root, 'current'), accepting(V('20260930T000000Z', 'e'), 'other'), { mode: 0o755 });
await d.doctor(r).catch(() => {});
assert.match(readFileSync(join(dir, 'dashnet'), 'utf8'), /20260928T120000Z/, 'another bootstrap recipe not adopted');
writeFileSync(join(root, 'current'), accepting(V('20260930T000000Z', 'e'), 'b'), { mode: 0o755 });
await d.doctor(r).catch(() => {});
assert.match(readFileSync(join(dir, 'dashnet'), 'utf8'), /20260930T000000Z/, 'accepting newer binary adopted');
assert.ok(logs.some((l) => /accepts this devnet's node recipe/.test(l)));
assert.match(JSON.parse(readFileSync(join(root, 'devnets.json'), 'utf8'))['devnet-x'].dashnet, /^20260930T000000Z/);
});

test('a recipe is accepted when it is the build\'s own or one the build lists', async () => {
const { recipeAccepted } = await import('./devnets.js');
const rec = { node: 'n2', nodeAccepts: 'n0,n1', upgrade: 'u2', upgradeAccepts: '' };
assert.equal(recipeAccepted(rec, 'node', 'n2'), true);
assert.equal(recipeAccepted(rec, 'node', 'n1'), true);
assert.equal(recipeAccepted(rec, 'node', 'n3'), false);
assert.equal(recipeAccepted(rec, 'upgrade', 'u2'), true);
// An empty list accepts nothing, and neither does a missing or malformed one.
for (const digest of ['u1', '', undefined, null]) assert.equal(recipeAccepted(rec, 'upgrade', digest), false);
assert.equal(recipeAccepted({ node: 'n2' }, 'node', 'n1'), false);
assert.equal(recipeAccepted({ node: 'n2', nodeAccepts: ['n1'] }, 'node', 'n1'), false);
assert.equal(recipeAccepted({ node: 'n2', nodeAccepts: 'n1' }, 'node', 'n'), false);
assert.equal(recipeAccepted(null, 'node', 'n1'), false);
});

test('a resumed upgrade moves to a newer dashnet only when the reviewed plan still accepts it', async () => {
Expand Down Expand Up @@ -452,6 +478,10 @@ test('a resumed upgrade moves to a newer dashnet only when the reviewed plan sti
writeFileSync(binary, fake(V('20260929T000000Z', 'b'), 'u1'), { mode: 0o755 });
await d.executeUpgrade(r());
assert.match(used.pop(), /20260929T000000Z/);
// A still newer build on another upgrade recipe that lists the plan's as accepted.
writeFileSync(binary, `#!/bin/sh\ncase "$1" in version) echo ${V('20260930T000000Z', 'c')};; recipes) echo '{"node":"n1","bootstrap":"b","upgrade":"u3","upgradeAccepts":"u1"}';; *) exit 0;; esac\n`, { mode: 0o755 });
await d.executeUpgrade(r());
assert.match(used.pop(), /20260930T000000Z/);
});

test('service images are prebuilt on the wallet host without the chain, best effort', async () => {
Expand Down
26 changes: 19 additions & 7 deletions agent/devnets.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ export { shortName };
// dash-network-go devnets whose services each release's dashmate renders; the
// helper image is then that dashmate, and Platform upgrades re-render with it.
export const DASHMATE_PROFILE = 'devnet-dashmate-compose';

// A build operates plans that bind its own recipe, and any earlier recipe it
// lists as accepted (`dashnet recipes`: nodeAccepts, upgradeAccepts, comma-
// separated). The rule is the engine's; a build that predates those fields
// lists none, and then only the same recipe is compatible.
export function recipeAccepted(recipes, kind, digest) {
if (recipes?.[kind] === digest) return true;
const accepted = recipes?.[`${kind}Accepts`];
return typeof digest === 'string' && digest !== '' && typeof accepted === 'string' && accepted.split(',').includes(digest);
}
// The images a devnet runs now: its network file after any upgrade.
export function imagesOf(yaml) {
const out = {};
Expand Down Expand Up @@ -173,39 +183,41 @@ export function createDevnets({ ctx, dirs, key, pool, getSettings, region, log =
return /or core \(Core only/.test(`${p.stdout}${p.stderr}`) ? ['platform', 'tenderdash', 'core'] : ['platform', 'tenderdash'];
}
// An upgrade runs with the binary that planned it, but a resume may move to a
// strictly newer build whose recipes the plans still accept (same upgrade
// and node recipes), e.g. to pick up a runner fix.
// strictly newer build whose recipes the plans still accept (the same upgrade
// and node recipes, or ones that build lists as accepted), e.g. to pick up a
// runner fix.
function refreshSnapshot(r, dir, plan) {
const dep = readJSON(join(dir, 'deployment.json'));
if (!binary || !existsSync(binary) || !r.artifacts.bin || !dep) return;
const p = spawnSync(binary, ['recipes'], { encoding: 'utf8', timeout: 10_000 });
let rec; try { rec = JSON.parse(p.stdout); } catch { return; }
if (rec.upgrade !== plan.recipeSha256 || rec.node !== dep.recipeSha256 || (plan.rollout?.miningRecipe && rec.mining !== plan.rollout.miningRecipe)) return;
if (!recipeAccepted(rec, 'upgrade', plan.recipeSha256) || !recipeAccepted(rec, 'node', dep.recipeSha256) || (plan.rollout?.miningRecipe && rec.mining !== plan.rollout.miningRecipe)) return;
const [was, now] = [versionOf(r.artifacts.bin), versionOf(binary)];
if (!dated(now) || (dated(was) && dated(was) >= dated(now))) return;
copyFileSync(binary, `${r.artifacts.bin}.next`); chmodSync(`${r.artifacts.bin}.next`, 0o700); renameSync(`${r.artifacts.bin}.next`, r.artifacts.bin);
write(r.id, `resuming with dashnet ${now.slice(0, 16)} (same upgrade and node recipes as the reviewed plan)`);
write(r.id, `resuming with dashnet ${now.slice(0, 16)} (${rec.upgrade === plan.recipeSha256 && rec.node === dep.recipeSha256 ? 'same upgrade and node recipes as' : 'accepts the upgrade and node recipes of'} the reviewed plan)`);
}
const versionOf = (bin) => spawnSync(bin, ['version'], { encoding: 'utf8', timeout: 10_000 }).stdout.trim();
const dated = (v) => /^(\d{8}T\d{6}Z)-[0-9a-f]{40}$/.exec(v || '')?.[1];

// A devnet is pinned to the dashnet that created it: its plans bind that
// binary's recipes. A newer binary reporting the same node and bootstrap
// recipes (dashnet recipes) can operate it, so fixes reach existing devnets.
// recipes (dashnet recipes), or listing the devnet's node recipe as one it
// accepts, can operate it, so fixes reach existing devnets.
function adoptCompatible(r, name) {
const dir = join(dirs.private, 'devnets', name), pinned = join(dir, 'dashnet');
const dep = readJSON(join(dir, 'deployment.json')), boot = readJSON(join(dir, 'bootstrap-plan.json'));
if (!binary || !existsSync(binary) || !existsSync(pinned) || !dep || !boot) return;
const p = spawnSync(binary, ['recipes'], { encoding: 'utf8', timeout: 10_000 });
let rec; try { rec = JSON.parse(p.stdout); } catch { return; }
if (rec.node !== dep.recipeSha256 || rec.bootstrap !== boot.recipeSha256) return;
if (!recipeAccepted(rec, 'node', dep.recipeSha256) || rec.bootstrap !== boot.recipeSha256) return;
// Versions are <commit date>-<commit>; adopt only a strictly newer build
// (never downgrade on an agent rollback; undated pins are older).
const [was, now] = [versionOf(pinned), versionOf(binary)];
if (!dated(now) || (dated(was) && dated(was) >= dated(now))) return;
copyFileSync(binary, `${pinned}.next`); chmodSync(`${pinned}.next`, 0o700); renameSync(`${pinned}.next`, pinned);
register(name, { upgradeScopes: upgradeScopes(name), dashnet: now });
write(r.id, `dashnet ${was.slice(0, 12)} -> ${now.slice(0, 12)} for ${name} (same node and bootstrap recipes)`);
write(r.id, `dashnet ${was.slice(0, 12)} -> ${now.slice(0, 12)} for ${name} (${rec.node === dep.recipeSha256 ? 'same node and bootstrap recipes' : 'accepts this devnet\'s node recipe; same bootstrap recipe'})`);
}

// Current images, and whether dashmate renders the devnet, for the console.
Expand Down
4 changes: 4 additions & 0 deletions docs/rollout-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ toggle. The toggle stages a policy; it does not stop anything while editing or
reviewing a plan. Review shows the plan-bound maximum and exact mining hosts.
Mining automatically resumes on success, failure and cancellation.

The forms start at four nodes at once on a devnet and at one (serial) on
Testnet; either can be changed before the plan is prepared. An API request
that omits the policy keeps the old serial behavior.

Legacy Testnet controls the two discovered, tagged, instance-pinned `miner-1`
and `miner-2` services. Native devnets use the mining host in their deployment
plan; Core handles it last, on its own. An unsafe validator batch is reduced to
Expand Down
6 changes: 4 additions & 2 deletions src/pages/Deploy.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import RolloutOptions from '../RolloutOptions.jsx';
import { useEffect, useMemo, useState } from 'react';
import { api, canOperate, navigate, useResource, useSession, ROLE_LABEL, ago } from '../lib.js';
import { Dot, Empty, Err, Link, Section } from '../ui.jsx';
import { COMPONENTS, OPERABLE, REPOS, cmp, helperFor, imageTag, newestRelease, reported } from '../releases.js';
import { COMPONENTS, OPERABLE, REPOS, cmp, defaultConcurrency, helperFor, imageTag, newestRelease, reported } from '../releases.js';

// Plain-language actions; the dashnet command runs underneath (shown in the header).
const ACTIONS = [
Expand All @@ -22,7 +22,9 @@ export default function Deploy({ name }) {
const [picked, setPicked] = useState(params.get('nodes') ? new Set(params.get('nodes').split(',').filter(Boolean)) : null);
const [components, setComponents] = useState(new Set(params.get('components')?.split(',').filter(Boolean) || []));
const [images, setImages] = useState({});
const [concurrency, setConcurrency] = useState(1);
// No explicit choice yet means the network's default, known once it loads.
const [chosenConcurrency, setConcurrency] = useState(null);
const concurrency = chosenConcurrency ?? defaultConcurrency(n);
const [pauseMining, setPauseMining] = useState(false);
const [window, setWindow] = useState('');
const [timeout, setTimeoutValue] = useState('');
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Network.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Fragment, useEffect, useMemo, useState } from 'react';
import { ago, api, bytes, canOperate, canSee, clock, dash, duration, navigate, num, short, span, useNow, useResource, useSession, ROLE_LABEL } from '../lib.js';
import { Delta, Dot, Empty, EndpointDot, Err, Level, Link, Meter, Section, Stat } from '../ui.jsx';
import Operations from './Operations.jsx';
import { cmp, COMPONENTS, helperFor, imageTag, newestRelease, OPERABLE, reported, REPOS } from '../releases.js';
import { cmp, COMPONENTS, defaultConcurrency, helperFor, imageTag, newestRelease, OPERABLE, reported, REPOS } from '../releases.js';
import Connect from './Connect.jsx';

const ROLE_ORDER = ['validator', 'masternode', 'seed', 'fullnode', 'web', 'wallet', 'miner', 'mixer', 'quorums', 'metrics', 'logs', 'vpn', 'other'];
Expand Down Expand Up @@ -420,7 +420,7 @@ function Updates({ n }) {
const [state, setState] = useState({ network: null, updates: [] });
const [error, setError] = useState(null);
const [busy, setBusy] = useState(false);
const [concurrency, setConcurrency] = useState(1);
const [concurrency, setConcurrency] = useState(() => defaultConcurrency(n));
const [pauseMining, setPauseMining] = useState(false);
const native = n.kind === 'dashnet';
const hosts = n.hosts.filter((h) => OPERABLE.includes(h.role) && !h.duplicate && h.state === 'running' && h.level !== 'unreachable');
Expand Down
6 changes: 6 additions & 0 deletions src/releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
export const COMPONENTS = ['core', 'drive', 'tenderdash', 'dapi', 'gateway', 'helper'];
export const REPOS = { core: 'dashpay/dashd', drive: 'dashpay/drive', tenderdash: 'dashpay/tenderdash', dapi: 'dashpay/rs-dapi', gateway: 'dashpay/envoy', helper: 'dashpay/dashmate-helper' };
export const OPERABLE = ['validator', 'masternode', 'seed'];

// Nodes replaced together unless the operator chooses otherwise. A devnet is
// owned outright and disposable, so it starts at several; the engine still
// trims any batch to what the observed quorum can spare. Testnet stays serial.
export const DEVNET_CONCURRENCY = 4;
export const defaultConcurrency = (network) => (network?.chainType === 'devnet' ? DEVNET_CONCURRENCY : 1);
// Running release per component, from what the nodes report.
const SEMVER = /^v?(\d+)\.(\d+)\.(\d+)(?:-([a-z]+)\.(\d+))?$/;
export function reported(h, c) {
Expand Down
8 changes: 7 additions & 1 deletion src/releases.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { newestRelease, reported } from './releases.js';
import { defaultConcurrency, newestRelease, reported } from './releases.js';

test('a devnet rolls several nodes at once by default; every other network stays serial', () => {
assert.equal(defaultConcurrency({ chainType: 'devnet', kind: 'dashnet' }), 4);
assert.equal(defaultConcurrency({ chainType: 'devnet' }), 4);
for (const network of [{ chainType: 'testnet' }, { chainType: 'mainnet' }, {}, null, undefined]) assert.equal(defaultConcurrency(network), 1);
});

const tags = (...names) => names.map((name) => ({ name }));

Expand Down
Loading