Skip to content

Commit c7f52d6

Browse files
authored
Add CI check that protocol bumps come with an overlay version bump (#5316)
# Description Adds a CI check that fails if the ledger protocol version (`MAX_SUPPORTED_PROTOCOL_VERSION`) is bumped without also bumping `OVERLAY_PROTOCOL_VERSION` in the same change. - `scripts/check-protocol-overlay-versions.sh` compares both constants between the PR base and head (can also be run locally, e.g. `./scripts/check-protocol-overlay-versions.sh origin/master`). - New `protocol-version-check` job in `build.yml` (not yet in `complete`'s `needs`, so it doesn't block merges), and a matching standalone job in `build-private.yml`. # Checklist - [x] Reviewed the [contributing](https://github.com/stellar/stellar-core/blob/master/CONTRIBUTING.md#submitting-changes) document - [x] Rebased on top of master (no merge commits) - [x] Ran `clang-format` v8.0.0 (`make format` or the Visual Studio extension) - [x] Compiles - [x] Ran all tests - [ ] If change impacts performance, include supporting evidence per the [performance document](https://github.com/stellar/stellar-core/blob/master/performance-eval/performance-eval.md)
2 parents 983b948 + fb5c4d3 commit c7f52d6

3 files changed

Lines changed: 128 additions & 0 deletions

File tree

‎.github/workflows/build-private.yml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ jobs:
4545
- uses: actions/checkout@v4
4646
- uses: stellar/actions/rust-check-git-rev-deps@main
4747

48+
protocol-version-check:
49+
# Check that a bump of MAX_SUPPORTED_PROTOCOL_VERSION is accompanied by
50+
# a bump of OVERLAY_PROTOCOL_VERSION.
51+
if: github.event.repository.visibility == 'private'
52+
runs-on: ubuntu-24.04
53+
steps:
54+
- uses: actions/checkout@v4
55+
with:
56+
fetch-depth: 0
57+
- name: Check protocol bump is accompanied by an overlay version bump
58+
run: |
59+
BASE_SHA='${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}'
60+
./scripts/check-protocol-overlay-versions.sh "$BASE_SHA"
61+
4862
build:
4963
if: github.event.repository.visibility == 'private'
5064
runs-on: ubuntu-latest-16-cores

‎.github/workflows/build.yml‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,24 @@ jobs:
9898
mkdir -p build-static-checks
9999
echo "${{ github.sha }}" > "build-static-checks/.last-tested-commit-sha"
100100
101+
protocol-version-check:
102+
# Check that a bump of MAX_SUPPORTED_PROTOCOL_VERSION is accompanied by
103+
# a bump of OVERLAY_PROTOCOL_VERSION. Only runs on events that have a
104+
# base revision to compare against (not on branch pushes). Not yet in
105+
# `complete`'s needs, so a failure doesn't block merging.
106+
if: github.event.repository.visibility != 'private' && github.event_name != 'push'
107+
runs-on:
108+
- namespace-profile-noble-24-04-stellar-core-x64-small
109+
steps:
110+
- uses: namespacelabs/nscloud-checkout-action@v7
111+
with:
112+
fetch-depth: 0
113+
114+
- name: Check protocol bump is accompanied by an overlay version bump
115+
run: |
116+
BASE_SHA='${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}'
117+
./scripts/check-protocol-overlay-versions.sh "$BASE_SHA"
118+
101119
build-linux:
102120
if: github.event.repository.visibility != 'private'
103121
runs-on:
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/sh
2+
3+
# This script checks that a change that bumps the ledger protocol version
4+
# (MAX_SUPPORTED_PROTOCOL_VERSION in src/util/ProtocolVersion.h) also bumps
5+
# the maximum supported overlay protocol version
6+
# (OVERLAY_PROTOCOL_VERSION in src/main/Config.cpp), so that peers can tell
7+
# from the overlay handshake whether a node runs software that supports the
8+
# new ledger protocol.
9+
#
10+
# Usage: check-protocol-overlay-versions.sh <base-rev> [<head-rev>]
11+
#
12+
# Compares <head-rev> (or the working tree if <head-rev> is omitted) against
13+
# <base-rev>. Exits with a non-zero status if OVERLAY_PROTOCOL_VERSION was
14+
# lowered, or if the ledger protocol version increased without
15+
# OVERLAY_PROTOCOL_VERSION increasing in the same change. An overlay bump that
16+
# landed separately (before or after an earlier protocol bump) doesn't count,
17+
# since it can't be told apart from one that belongs to the previous protocol.
18+
19+
set -e
20+
21+
SRCDIR=$(realpath "$(dirname "$0")/..")
22+
CONFIG_CPP=src/main/Config.cpp
23+
PROTOCOL_H=src/util/ProtocolVersion.h
24+
25+
if [ $# -lt 1 ] || [ $# -gt 2 ]
26+
then
27+
echo "usage: $0 <base-rev> [<head-rev>]" >&2
28+
exit 2
29+
fi
30+
31+
BASE_REV=$1
32+
HEAD_REV=${2:-}
33+
34+
cd "$SRCDIR"
35+
36+
# file_at <rev> <file>: print the contents of <file> at <rev>, or the
37+
# working tree copy if <rev> is empty.
38+
file_at()
39+
{
40+
if [ -n "$1" ]
41+
then
42+
git show "$1:$2"
43+
else
44+
cat "$2"
45+
fi
46+
}
47+
48+
# extract <rev> <file> <name> <sed-expr>: print the numeric value assigned
49+
# to <name> in <file> at <rev>, failing unless exactly one assignment is
50+
# found.
51+
extract()
52+
{
53+
if ! CONTENTS=$(file_at "$1" "$2")
54+
then
55+
echo "error: failed to read $2 at ${1:-working tree}" >&2
56+
exit 2
57+
fi
58+
VAL=$(printf '%s\n' "$CONTENTS" | sed -n "$4")
59+
case "$VAL" in
60+
''|*[!0-9]*)
61+
echo "error: expected exactly one numeric assignment to $3 in $2 at ${1:-working tree}, got '$VAL'" >&2
62+
echo "(if the definition of $3 changed shape, update $0 to match)" >&2
63+
exit 2
64+
;;
65+
esac
66+
echo "$VAL"
67+
}
68+
69+
LEDGER_EXPR='s/.*MAX_SUPPORTED_PROTOCOL_VERSION[[:space:]]*=[[:space:]]*\([0-9][0-9]*\).*/\1/p'
70+
OVERLAY_EXPR='s/^[[:space:]]*OVERLAY_PROTOCOL_VERSION[[:space:]]*=[[:space:]]*\([0-9][0-9]*\).*/\1/p'
71+
72+
# The literal assigned to MAX_SUPPORTED_PROTOCOL_VERSION, i.e. the ledger
73+
# protocol version without the vnext +1.
74+
BASE_LEDGER=$(extract "$BASE_REV" "$PROTOCOL_H" MAX_SUPPORTED_PROTOCOL_VERSION "$LEDGER_EXPR")
75+
BASE_OVERLAY=$(extract "$BASE_REV" "$CONFIG_CPP" OVERLAY_PROTOCOL_VERSION "$OVERLAY_EXPR")
76+
HEAD_LEDGER=$(extract "$HEAD_REV" "$PROTOCOL_H" MAX_SUPPORTED_PROTOCOL_VERSION "$LEDGER_EXPR")
77+
HEAD_OVERLAY=$(extract "$HEAD_REV" "$CONFIG_CPP" OVERLAY_PROTOCOL_VERSION "$OVERLAY_EXPR")
78+
79+
echo "Ledger protocol version: $BASE_LEDGER -> $HEAD_LEDGER"
80+
echo "OVERLAY_PROTOCOL_VERSION: $BASE_OVERLAY -> $HEAD_OVERLAY"
81+
82+
if [ "$HEAD_OVERLAY" -lt "$BASE_OVERLAY" ]
83+
then
84+
echo "error: OVERLAY_PROTOCOL_VERSION was lowered from $BASE_OVERLAY to $HEAD_OVERLAY" >&2
85+
exit 1
86+
fi
87+
88+
if [ "$HEAD_LEDGER" -gt "$BASE_LEDGER" ] && [ "$HEAD_OVERLAY" -le "$BASE_OVERLAY" ]
89+
then
90+
echo "error: the ledger protocol version was bumped from $BASE_LEDGER to $HEAD_LEDGER" >&2
91+
echo "but OVERLAY_PROTOCOL_VERSION was not bumped. A ledger protocol bump must be" >&2
92+
echo "accompanied by a bump of the maximum overlay protocol version in $CONFIG_CPP." >&2
93+
exit 1
94+
fi
95+
96+
echo "OK"

0 commit comments

Comments
 (0)