Skip to content

Commit 47a40f3

Browse files
committed
Add workflow that opens a PR bumping the min overlay version
Once pubnet is on a new protocol, raises OVERLAY_PROTOCOL_MIN_VERSION to the lowest OVERLAY_PROTOCOL_VERSION among releases supporting it, in a PR that asks the reviewer to verify the versions.
1 parent 66defff commit 47a40f3

2 files changed

Lines changed: 268 additions & 0 deletions

File tree

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Overlay min version
2+
3+
# Once pubnet has upgraded to a new ledger protocol, opens a PR raising
4+
# OVERLAY_PROTOCOL_MIN_VERSION to the lowest overlay version of the releases
5+
# that support that protocol (see scripts/check-overlay-min-version.sh).
6+
7+
on:
8+
schedule:
9+
- cron: '0 15 * * *'
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: write
14+
pull-requests: write
15+
16+
concurrency:
17+
group: ${{ github.workflow }}
18+
cancel-in-progress: false
19+
20+
jobs:
21+
bump-overlay-min-version:
22+
if: github.repository == 'stellar/stellar-core'
23+
runs-on: ubuntu-24.04
24+
env:
25+
BRANCH: bot/bump-overlay-min-version
26+
steps:
27+
- uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
30+
31+
- name: Get pubnet ledger protocol version
32+
id: pubnet
33+
run: |
34+
PROTOCOL=$(curl -sSf --retry 3 https://horizon.stellar.org/ | jq -er '.current_protocol_version | numbers')
35+
echo "Pubnet is on protocol $PROTOCOL"
36+
echo "protocol=$PROTOCOL" >> "$GITHUB_OUTPUT"
37+
38+
- name: Raise OVERLAY_PROTOCOL_MIN_VERSION if possible
39+
env:
40+
PROTOCOL: ${{ steps.pubnet.outputs.protocol }}
41+
run: |
42+
set -o pipefail
43+
./scripts/check-overlay-min-version.sh --apply "$PROTOCOL" | tee "$RUNNER_TEMP/check.txt"
44+
45+
- name: Open or update PR
46+
env:
47+
GH_TOKEN: ${{ github.token }}
48+
PROTOCOL: ${{ steps.pubnet.outputs.protocol }}
49+
BASE: ${{ github.ref_name }}
50+
run: |
51+
if git diff --quiet
52+
then
53+
echo "OVERLAY_PROTOCOL_MIN_VERSION is up to date"
54+
exit 0
55+
fi
56+
MIN=$(sed -n 's/^[[:space:]]*OVERLAY_PROTOCOL_MIN_VERSION[[:space:]]*=[[:space:]]*\([0-9][0-9]*\).*/\1/p' src/main/Config.cpp)
57+
58+
# Leave an open PR alone if it already makes the same change.
59+
OPEN_PR=$(gh pr list --head "$BRANCH" --base "$BASE" --state open --json number --jq '.[].number')
60+
if [ -n "$OPEN_PR" ] &&
61+
git fetch --depth=1 origin "$BRANCH" 2>/dev/null &&
62+
git diff --quiet FETCH_HEAD -- src/main/Config.cpp
63+
then
64+
echo "$BRANCH already raises OVERLAY_PROTOCOL_MIN_VERSION to $MIN"
65+
exit 0
66+
fi
67+
68+
git config user.name 'github-actions[bot]'
69+
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
70+
git checkout -B "$BRANCH"
71+
git commit -qam "Bump OVERLAY_PROTOCOL_MIN_VERSION to $MIN" \
72+
-m "Pubnet is on protocol $PROTOCOL, and no release supporting it has an overlay version below $MIN."
73+
git push -f origin "$BRANCH"
74+
75+
BODY="$RUNNER_TEMP/body.md"
76+
{
77+
echo "Pubnet is on protocol $PROTOCOL, and no release supporting it has an overlay version below $MIN, so this raises \`OVERLAY_PROTOCOL_MIN_VERSION\` to $MIN. Opened by the \`${{ github.workflow }}\` workflow."
78+
echo
79+
echo "**Reviewer:** before merging, verify that pubnet is on protocol $PROTOCOL and that every release supporting it, including any not tagged in this repo, has \`OVERLAY_PROTOCOL_VERSION\` of at least $MIN. Nodes below $MIN will be disconnected."
80+
echo
81+
echo '```'
82+
cat "$RUNNER_TEMP/check.txt"
83+
echo '```'
84+
} > "$BODY"
85+
if [ -z "$OPEN_PR" ]
86+
then
87+
gh pr create --base "$BASE" --head "$BRANCH" \
88+
--title "Bump OVERLAY_PROTOCOL_MIN_VERSION to $MIN" --body-file "$BODY"
89+
else
90+
gh pr edit "$OPEN_PR" \
91+
--title "Bump OVERLAY_PROTOCOL_MIN_VERSION to $MIN" --body-file "$BODY"
92+
fi
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
#!/bin/sh
2+
3+
# This script checks OVERLAY_PROTOCOL_MIN_VERSION (in src/main/Config.cpp)
4+
# against the ledger protocol version a network is running.
5+
#
6+
# Once a network is on ledger protocol P, nodes need software supporting P to
7+
# stay in sync, so the minimum overlay version can be raised to the lowest
8+
# maximum overlay version (OVERLAY_PROTOCOL_VERSION) of any release that
9+
# supports P. It should never be higher than that, or it would disconnect
10+
# nodes running a release that can still follow the network.
11+
#
12+
# Usage: check-overlay-min-version.sh [--apply] <network-protocol>
13+
#
14+
# Looks at the release tags (v<number>...) from the newest version down,
15+
# stopping at the first whose ledger protocol version (MAX_SUPPORTED_PROTOCOL_VERSION
16+
# in src/util/ProtocolVersion.h, or Config::CURRENT_LEDGER_PROTOCOL_VERSION in
17+
# src/main/Config.cpp in older releases) is below <network-protocol>, and
18+
# compares OVERLAY_PROTOCOL_MIN_VERSION in the working tree against the lowest
19+
# OVERLAY_PROTOCOL_VERSION among the releases that support it. Exits with a
20+
# non-zero status if the minimum is too high. If the minimum can be raised,
21+
# says so, and with --apply rewrites it in the working tree.
22+
#
23+
# Requires the release tags to have been fetched.
24+
25+
set -e
26+
27+
SRCDIR=$(realpath "$(dirname "$0")/..")
28+
CONFIG_CPP=src/main/Config.cpp
29+
PROTOCOL_H=src/util/ProtocolVersion.h
30+
31+
APPLY=
32+
if [ "$1" = "--apply" ]
33+
then
34+
APPLY=1
35+
shift
36+
fi
37+
38+
if [ $# -ne 1 ]
39+
then
40+
echo "usage: $0 [--apply] <network-protocol>" >&2
41+
exit 2
42+
fi
43+
44+
NETWORK_LEDGER=$1
45+
case "$NETWORK_LEDGER" in
46+
''|*[!0-9]*)
47+
echo "error: network protocol must be a number, got '$NETWORK_LEDGER'" >&2
48+
exit 2
49+
;;
50+
esac
51+
52+
cd "$SRCDIR"
53+
54+
# file_at <rev> <file>: print the contents of <file> at <rev>, or the
55+
# working tree copy if <rev> is empty.
56+
file_at()
57+
{
58+
if [ -n "$1" ]
59+
then
60+
git show "$1:$2"
61+
else
62+
cat "$2"
63+
fi
64+
}
65+
66+
# extract <rev> <file> <name> <sed-expr>: print the numeric value assigned
67+
# to <name> in <file> at <rev>, failing unless exactly one assignment is
68+
# found.
69+
extract()
70+
{
71+
if ! CONTENTS=$(file_at "$1" "$2")
72+
then
73+
echo "error: failed to read $2 at ${1:-working tree}" >&2
74+
exit 2
75+
fi
76+
VAL=$(printf '%s\n' "$CONTENTS" | sed -n "$4")
77+
case "$VAL" in
78+
''|*[!0-9]*)
79+
echo "error: expected exactly one numeric assignment to $3 in $2 at ${1:-working tree}, got '$VAL'" >&2
80+
echo "(if the definition of $3 changed shape, update $0 to match)" >&2
81+
exit 2
82+
;;
83+
esac
84+
echo "$VAL"
85+
}
86+
87+
# ledger_at <rev>: print the ledger protocol version at <rev> (without the
88+
# vnext +1). It is MAX_SUPPORTED_PROTOCOL_VERSION in ProtocolVersion.h, or
89+
# was assigned directly to Config::CURRENT_LEDGER_PROTOCOL_VERSION in
90+
# Config.cpp before that.
91+
ledger_at()
92+
{
93+
if file_at "$1" "$PROTOCOL_H" 2>/dev/null | grep -q 'MAX_SUPPORTED_PROTOCOL_VERSION[[:space:]]*='
94+
then
95+
extract "$1" "$PROTOCOL_H" MAX_SUPPORTED_PROTOCOL_VERSION "$MAX_SUPPORTED_EXPR"
96+
else
97+
extract "$1" "$CONFIG_CPP" CURRENT_LEDGER_PROTOCOL_VERSION "$LEDGER_EXPR"
98+
fi
99+
}
100+
101+
LEDGER_EXPR='s/.*Config::CURRENT_LEDGER_PROTOCOL_VERSION[[:space:]]*=[[:space:]]*\([0-9][0-9]*\).*/\1/p'
102+
MAX_SUPPORTED_EXPR='s/.*MAX_SUPPORTED_PROTOCOL_VERSION[[:space:]]*=[[:space:]]*\([0-9][0-9]*\).*/\1/p'
103+
OVERLAY_EXPR='s/^[[:space:]]*OVERLAY_PROTOCOL_VERSION[[:space:]]*=[[:space:]]*\([0-9][0-9]*\).*/\1/p'
104+
MIN_EXPR='s/^[[:space:]]*OVERLAY_PROTOCOL_MIN_VERSION[[:space:]]*=[[:space:]]*\([0-9][0-9]*\).*/\1/p'
105+
106+
# List the releases supporting ledger protocol $NETWORK_LEDGER, and set
107+
# TARGET_MIN to the lowest OVERLAY_PROTOCOL_VERSION among them and TARGET_TAG
108+
# to a release that has it. Assumes the ledger protocol version doesn't
109+
# decrease from one release version to the next.
110+
release_target()
111+
{
112+
TARGET_MIN=
113+
TARGET_TAG=
114+
for T in $(git tag -l 'v[0-9]*' --sort=-v:refname)
115+
do
116+
LEDGER=$(ledger_at "$T")
117+
if [ "$LEDGER" -lt "$NETWORK_LEDGER" ]
118+
then
119+
break
120+
fi
121+
OVERLAY=$(extract "$T" "$CONFIG_CPP" OVERLAY_PROTOCOL_VERSION "$OVERLAY_EXPR")
122+
echo " $T: ledger protocol $LEDGER, OVERLAY_PROTOCOL_VERSION $OVERLAY"
123+
if [ -z "$TARGET_MIN" ] || [ "$OVERLAY" -lt "$TARGET_MIN" ]
124+
then
125+
TARGET_MIN=$OVERLAY
126+
TARGET_TAG=$T
127+
fi
128+
done
129+
if [ -z "$TARGET_MIN" ]
130+
then
131+
echo "error: no release tag supports ledger protocol $NETWORK_LEDGER (tags not fetched?)" >&2
132+
exit 2
133+
fi
134+
}
135+
136+
CODE_LEDGER=$(ledger_at "")
137+
CODE_MIN=$(extract "" "$CONFIG_CPP" OVERLAY_PROTOCOL_MIN_VERSION "$MIN_EXPR")
138+
139+
if [ "$NETWORK_LEDGER" -gt "$CODE_LEDGER" ]
140+
then
141+
echo "error: network is on protocol $NETWORK_LEDGER, but the code's ledger protocol version is $CODE_LEDGER" >&2
142+
exit 2
143+
fi
144+
145+
echo "Releases supporting ledger protocol $NETWORK_LEDGER:"
146+
release_target
147+
echo "Lowest OVERLAY_PROTOCOL_VERSION among them: $TARGET_MIN ($TARGET_TAG)"
148+
echo "OVERLAY_PROTOCOL_MIN_VERSION: $CODE_MIN"
149+
150+
if [ "$CODE_MIN" -gt "$TARGET_MIN" ]
151+
then
152+
echo "error: OVERLAY_PROTOCOL_MIN_VERSION ($CODE_MIN) is higher than the overlay version" >&2
153+
echo "of $TARGET_TAG ($TARGET_MIN), which supports protocol $NETWORK_LEDGER, so it would" >&2
154+
echo "disconnect nodes that can still follow the network." >&2
155+
exit 1
156+
fi
157+
158+
if [ "$CODE_MIN" -eq "$TARGET_MIN" ]
159+
then
160+
echo "OK"
161+
exit 0
162+
fi
163+
164+
echo "OVERLAY_PROTOCOL_MIN_VERSION can be raised from $CODE_MIN to $TARGET_MIN"
165+
if [ -n "$APPLY" ]
166+
then
167+
sed "s/^\([[:space:]]*OVERLAY_PROTOCOL_MIN_VERSION[[:space:]]*=[[:space:]]*\)$CODE_MIN;/\1$TARGET_MIN;/" "$CONFIG_CPP" > "$CONFIG_CPP.tmp"
168+
mv "$CONFIG_CPP.tmp" "$CONFIG_CPP"
169+
NEW_MIN=$(extract "" "$CONFIG_CPP" OVERLAY_PROTOCOL_MIN_VERSION "$MIN_EXPR")
170+
if [ "$NEW_MIN" != "$TARGET_MIN" ]
171+
then
172+
echo "error: failed to update OVERLAY_PROTOCOL_MIN_VERSION in $CONFIG_CPP" >&2
173+
exit 2
174+
fi
175+
echo "Updated $CONFIG_CPP"
176+
fi

0 commit comments

Comments
 (0)