From fb5c4d3bc209c9a018f97bfd3db953288a405aa8 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Tue, 13 Oct 2026 18:34:54 -0700 Subject: [PATCH] Add CI check that protocol bumps come with an overlay version bump scripts/check-protocol-overlay-versions.sh fails if the ledger protocol version increases without OVERLAY_PROTOCOL_VERSION increasing in the same change, or if the overlay version is lowered. Runs as a non-blocking protocol-version-check job. --- .github/workflows/build-private.yml | 14 ++++ .github/workflows/build.yml | 18 ++++ scripts/check-protocol-overlay-versions.sh | 96 ++++++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100755 scripts/check-protocol-overlay-versions.sh diff --git a/.github/workflows/build-private.yml b/.github/workflows/build-private.yml index 18091d841a..53bfb00ec0 100644 --- a/.github/workflows/build-private.yml +++ b/.github/workflows/build-private.yml @@ -45,6 +45,20 @@ jobs: - uses: actions/checkout@v4 - uses: stellar/actions/rust-check-git-rev-deps@main + protocol-version-check: + # Check that a bump of MAX_SUPPORTED_PROTOCOL_VERSION is accompanied by + # a bump of OVERLAY_PROTOCOL_VERSION. + if: github.event.repository.visibility == 'private' + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Check protocol bump is accompanied by an overlay version bump + run: | + BASE_SHA='${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}' + ./scripts/check-protocol-overlay-versions.sh "$BASE_SHA" + build: if: github.event.repository.visibility == 'private' runs-on: ubuntu-latest-16-cores diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6f6119a2e8..fce557dc93 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -98,6 +98,24 @@ jobs: mkdir -p build-static-checks echo "${{ github.sha }}" > "build-static-checks/.last-tested-commit-sha" + protocol-version-check: + # Check that a bump of MAX_SUPPORTED_PROTOCOL_VERSION is accompanied by + # a bump of OVERLAY_PROTOCOL_VERSION. Only runs on events that have a + # base revision to compare against (not on branch pushes). Not yet in + # `complete`'s needs, so a failure doesn't block merging. + if: github.event.repository.visibility != 'private' && github.event_name != 'push' + runs-on: + - namespace-profile-noble-24-04-stellar-core-x64-small + steps: + - uses: namespacelabs/nscloud-checkout-action@v7 + with: + fetch-depth: 0 + + - name: Check protocol bump is accompanied by an overlay version bump + run: | + BASE_SHA='${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}' + ./scripts/check-protocol-overlay-versions.sh "$BASE_SHA" + build-linux: if: github.event.repository.visibility != 'private' runs-on: diff --git a/scripts/check-protocol-overlay-versions.sh b/scripts/check-protocol-overlay-versions.sh new file mode 100755 index 0000000000..2af3002cf0 --- /dev/null +++ b/scripts/check-protocol-overlay-versions.sh @@ -0,0 +1,96 @@ +#!/bin/sh + +# This script checks that a change that bumps the ledger protocol version +# (MAX_SUPPORTED_PROTOCOL_VERSION in src/util/ProtocolVersion.h) also bumps +# the maximum supported overlay protocol version +# (OVERLAY_PROTOCOL_VERSION in src/main/Config.cpp), so that peers can tell +# from the overlay handshake whether a node runs software that supports the +# new ledger protocol. +# +# Usage: check-protocol-overlay-versions.sh [] +# +# Compares (or the working tree if is omitted) against +# . Exits with a non-zero status if OVERLAY_PROTOCOL_VERSION was +# lowered, or if the ledger protocol version increased without +# OVERLAY_PROTOCOL_VERSION increasing in the same change. An overlay bump that +# landed separately (before or after an earlier protocol bump) doesn't count, +# since it can't be told apart from one that belongs to the previous protocol. + +set -e + +SRCDIR=$(realpath "$(dirname "$0")/..") +CONFIG_CPP=src/main/Config.cpp +PROTOCOL_H=src/util/ProtocolVersion.h + +if [ $# -lt 1 ] || [ $# -gt 2 ] +then + echo "usage: $0 []" >&2 + exit 2 +fi + +BASE_REV=$1 +HEAD_REV=${2:-} + +cd "$SRCDIR" + +# file_at : print the contents of at , or the +# working tree copy if is empty. +file_at() +{ + if [ -n "$1" ] + then + git show "$1:$2" + else + cat "$2" + fi +} + +# extract : print the numeric value assigned +# to in at , failing unless exactly one assignment is +# found. +extract() +{ + if ! CONTENTS=$(file_at "$1" "$2") + then + echo "error: failed to read $2 at ${1:-working tree}" >&2 + exit 2 + fi + VAL=$(printf '%s\n' "$CONTENTS" | sed -n "$4") + case "$VAL" in + ''|*[!0-9]*) + echo "error: expected exactly one numeric assignment to $3 in $2 at ${1:-working tree}, got '$VAL'" >&2 + echo "(if the definition of $3 changed shape, update $0 to match)" >&2 + exit 2 + ;; + esac + echo "$VAL" +} + +LEDGER_EXPR='s/.*MAX_SUPPORTED_PROTOCOL_VERSION[[:space:]]*=[[:space:]]*\([0-9][0-9]*\).*/\1/p' +OVERLAY_EXPR='s/^[[:space:]]*OVERLAY_PROTOCOL_VERSION[[:space:]]*=[[:space:]]*\([0-9][0-9]*\).*/\1/p' + +# The literal assigned to MAX_SUPPORTED_PROTOCOL_VERSION, i.e. the ledger +# protocol version without the vnext +1. +BASE_LEDGER=$(extract "$BASE_REV" "$PROTOCOL_H" MAX_SUPPORTED_PROTOCOL_VERSION "$LEDGER_EXPR") +BASE_OVERLAY=$(extract "$BASE_REV" "$CONFIG_CPP" OVERLAY_PROTOCOL_VERSION "$OVERLAY_EXPR") +HEAD_LEDGER=$(extract "$HEAD_REV" "$PROTOCOL_H" MAX_SUPPORTED_PROTOCOL_VERSION "$LEDGER_EXPR") +HEAD_OVERLAY=$(extract "$HEAD_REV" "$CONFIG_CPP" OVERLAY_PROTOCOL_VERSION "$OVERLAY_EXPR") + +echo "Ledger protocol version: $BASE_LEDGER -> $HEAD_LEDGER" +echo "OVERLAY_PROTOCOL_VERSION: $BASE_OVERLAY -> $HEAD_OVERLAY" + +if [ "$HEAD_OVERLAY" -lt "$BASE_OVERLAY" ] +then + echo "error: OVERLAY_PROTOCOL_VERSION was lowered from $BASE_OVERLAY to $HEAD_OVERLAY" >&2 + exit 1 +fi + +if [ "$HEAD_LEDGER" -gt "$BASE_LEDGER" ] && [ "$HEAD_OVERLAY" -le "$BASE_OVERLAY" ] +then + echo "error: the ledger protocol version was bumped from $BASE_LEDGER to $HEAD_LEDGER" >&2 + echo "but OVERLAY_PROTOCOL_VERSION was not bumped. A ledger protocol bump must be" >&2 + echo "accompanied by a bump of the maximum overlay protocol version in $CONFIG_CPP." >&2 + exit 1 +fi + +echo "OK"