diff options
| author | tv <tv@krebsco.de> | 2026-11-19 17:48:47 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-19 19:26:03 +0100 |
| commit | b95ba948a6e5ac04a75cd4d28ee3ac966dcc72bb (patch) | |
| tree | 54671c4b846511f7601a903b8603ad5e2b4b9909 /scripts/wire-check | |
| parent | 59e889254b1fda2dcc8e3e6d596635d1b77f589f (diff) | |
scripts/wire-check: a swarm of the last release and this tree
Four nodes on this host over libp2p on loopback, two of a release tag's
build and two of this tree's, in turns, each seeded with the one before.
Where the two builds' wire versions meet, each node writes, and the
check is that every node reads what each wrote and that none logs a
peer of another wire version. Where they don't, that the tag's nodes
log this tree's as such, so their operators know to upgrade.
scripts/release runs it against the last release, after saying from
the two builds' --version how the release upgrades: so a release that
says it rolls out node by node has been seen to.
docs/development.md says how a change to the wire format is made: a new
version beside the ones spoken already, the older kept frozen.
Diffstat (limited to 'scripts/wire-check')
| -rwxr-xr-x | scripts/wire-check | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/scripts/wire-check b/scripts/wire-check new file mode 100755 index 0000000..f53dafb --- /dev/null +++ b/scripts/wire-check @@ -0,0 +1,151 @@ +#!/bin/sh +# Runs a swarm of continuum as a release tag builds it and as this tree does, on this +# host over libp2p on loopback, and checks how they get on (docs/development.md: +# Releasing). Where their wire versions meet: every node reads what each wrote, and +# none logs a peer of another wire version. Where they don't: the tag's nodes log this +# tree's as of another wire version, so their operators know to upgrade them. +# +# scripts/wire-check [TAG] +# +# TAG is the latest v* tag unless given. The nodes: a of the tag (the swarm's first), b +# of this tree, c of the tag, d of this tree, each seeded with the one before it. +# CONTINUUM_WIRE_CHECK_FEATURES are the features both are built with, libp2p among them +# (federation,libp2p unless given); the tag's build is kept in CONTINUUM_RELEASE_TARGET +# (~/.cache/continuum/release unless given), as scripts/release keeps it. The nodes +# listen from CONTINUUM_WIRE_CHECK_PORT on (47600 unless given), eight ports. + +set -eu + +cd "$(git rev-parse --show-toplevel)" + +tag=${1:-$(git tag --list 'v[0-9]*.[0-9]*.[0-9]*' --sort=-version:refname | head -n 1)} +if [ -z "$tag" ]; then + echo "wire-check: no v* tag to check against" >&2 + exit 2 +fi +features=${CONTINUUM_WIRE_CHECK_FEATURES:-federation,libp2p} +cache=${XDG_CACHE_HOME:-$HOME/.cache} +target=${CONTINUUM_RELEASE_TARGET:-$cache/continuum/release} +port=${CONTINUUM_WIRE_CHECK_PORT:-47600} +say() { echo "wire-check: $*" >&2; } + +work=$(mktemp -d) +pids="" +failed=false +clean() { + for pid in $pids; do + kill "$pid" 2>/dev/null || true + done + wait 2>/dev/null || true + if $failed; then + for log in "$work"/*/log; do + [ -f "$log" ] || continue + say "the last of $(basename "$(dirname "$log")")'s log:" + tail -n 20 "$log" >&2 + done + fi + git worktree remove --force "$work/tagged" >/dev/null 2>&1 || true + rm -rf "$work" +} +trap clean EXIT +trap 'exit 130' INT TERM +fail() { + failed=true + say "$*" + exit 1 +} + +say "building this tree and $tag (features $features)" +cargo build -q --features "$features" --bin continuum +here_dir=${CARGO_TARGET_DIR:-$(pwd)/target} +cp "$here_dir/debug/continuum" "$work/here" +git worktree add -q --detach "$work/tagged" "$tag" +(cd "$work/tagged" && CARGO_TARGET_DIR=$target cargo build -q --features "$features" --bin continuum) +cp "$target/debug/continuum" "$work/there" + +wire() { "$1" --version | sed -n 's/^wire versions \([0-9]*\) to \([0-9]*\)$/\1 \2/p'; } +set -- $(wire "$work/here") +here_oldest=$1 here_newest=$2 +there=$(wire "$work/there") +if [ -z "$there" ]; then + # Before 0.0.1 a build named no wire versions, and spoke none but its own. + fail "$tag doesn't say which wire versions it speaks" +fi +set -- $there +there_oldest=$1 there_newest=$2 +if [ "$here_oldest" -le "$there_newest" ] && [ "$there_oldest" -le "$here_newest" ]; then + meet=true + say "$tag speaks $there_oldest to $there_newest, this tree $here_oldest to $here_newest: they should talk" +else + meet=false + say "$tag speaks $there_oldest to $there_newest, this tree $here_oldest to $here_newest: they should say they don't" +fi + +http() { echo $((port + $1)); } +p2p() { echo $((port + 4 + $1)); } +seed() { echo "libp2p:/ip4/127.0.0.1/tcp/$(p2p "$1")"; } +start() { # NAME NUMBER BINARY [OPTION...] + name=$1 number=$2 binary=$3 + shift 3 + mkdir "$work/$name" + (cd "$work/$name" && exec "$binary" --bind-addr "127.0.0.1:$(http "$number")" \ + --user-header X-User --node-key-file node.key --node-key-create \ + --state-file state.json --libp2p-enable \ + --libp2p-listen "/ip4/127.0.0.1/tcp/$(p2p "$number")" "$@" >log 2>&1) & + pids="$pids $!" +} +api() { # NUMBER PATH [CURL OPTION...] + number=$1 path=$2 + shift 2 + curl -sf -H 'X-User: wire-check' -H 'Accept: text/plain' "$@" \ + "http://127.0.0.1:$(http "$number")$path" +} +# Whether the command $2... succeeds within $1 seconds, tried every second. +within() { + seconds=$1 + shift + while ! "$@" >/dev/null 2>&1; do + seconds=$((seconds - 1)) + [ "$seconds" -gt 0 ] || return 1 + sleep 1 + done +} + +start a 0 "$work/there" --genesis +within 60 api 0 /ready || fail "a ($tag) isn't ready" +start b 1 "$work/here" --seeds "$(seed 0)" +start c 2 "$work/there" --seeds "$(seed 1)" +start d 3 "$work/here" --seeds "$(seed 2)" + +other_version() { grep -l 'another wire version' "$work"/*/log; } + +if ! $meet; then + # The tag's nodes say so. This tree's say so too where the tag's SPEAKS goes ahead of + # its proofs, as from this tree on. + logged() { grep -q 'another wire version' "$work/a/log" "$work/c/log"; } + within 60 logged || fail "$tag's nodes don't say they share no wire version with this tree's" + say "they share no wire version, and say so:" + grep -h 'another wire version' "$work"/*/log | head -n 4 >&2 + exit 0 +fi + +for number in 1 2 3; do + within 120 api "$number" /ready || fail "node $number isn't ready" +done +for number in 0 1 2 3; do + api "$number" "/store/wire-check/$number" -X PUT -H 'Content-Type: text/plain' \ + -d "written on $number" || fail "node $number didn't take a write" +done +reads_all() { + for number in 0 1 2 3; do + for written in 0 1 2 3; do + [ "$(api "$number" "/store/wire-check/$written")" = "written on $written" ] || + return 1 + done + done +} +within 60 reads_all || fail "not every node reads what each wrote" +if other_version >/dev/null; then + fail "a node logs a peer of another wire version: $(other_version | tr '\n' ' ')" +fi +say "$tag and this tree talk: every node reads what each wrote, and none logs another wire version" |
