Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
92 changes: 92 additions & 0 deletions .github/workflows/overlay-min-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Overlay min version

# Once pubnet has upgraded to a new ledger protocol, opens a PR raising
# OVERLAY_PROTOCOL_MIN_VERSION to the lowest overlay version of the releases
# that support that protocol (see scripts/check-overlay-min-version.sh).

on:
schedule:
- cron: '0 15 * * *'
workflow_dispatch:

permissions:
contents: write
pull-requests: write

concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false

jobs:
bump-overlay-min-version:
if: github.repository == 'stellar/stellar-core'
Comment thread
sisuresh marked this conversation as resolved.
Resolved
runs-on: ubuntu-24.04
env:
BRANCH: bot/bump-overlay-min-version
steps:
- uses: actions/checkout@v4
Comment thread
sisuresh marked this conversation as resolved.
Resolved
with:
fetch-depth: 0

- name: Get pubnet ledger protocol version
id: pubnet
run: |
PROTOCOL=$(curl -sSf --retry 3 https://horizon.stellar.org/ | jq -er '.current_protocol_version | numbers')
echo "Pubnet is on protocol $PROTOCOL"
echo "protocol=$PROTOCOL" >> "$GITHUB_OUTPUT"
- name: Raise OVERLAY_PROTOCOL_MIN_VERSION if possible
env:
PROTOCOL: ${{ steps.pubnet.outputs.protocol }}
run: |
set -o pipefail
./scripts/check-overlay-min-version.sh --apply "$PROTOCOL" | tee "$RUNNER_TEMP/check.txt"
- name: Open or update PR
env:
GH_TOKEN: ${{ github.token }}
Comment thread
sisuresh marked this conversation as resolved.
Resolved
PROTOCOL: ${{ steps.pubnet.outputs.protocol }}
BASE: ${{ github.ref_name }}
run: |
if git diff --quiet
then
echo "OVERLAY_PROTOCOL_MIN_VERSION is up to date"
exit 0
fi
MIN=$(sed -n 's/^[[:space:]]*OVERLAY_PROTOCOL_MIN_VERSION[[:space:]]*=[[:space:]]*\([0-9][0-9]*\).*/\1/p' src/main/Config.cpp)
# Leave an open PR alone if it already makes the same change.
OPEN_PR=$(gh pr list --head "$BRANCH" --base "$BASE" --state open --json number --jq '.[].number')
if [ -n "$OPEN_PR" ] &&
git fetch --depth=1 origin "$BRANCH" 2>/dev/null &&
git diff --quiet FETCH_HEAD -- src/main/Config.cpp
then
echo "$BRANCH already raises OVERLAY_PROTOCOL_MIN_VERSION to $MIN"
exit 0
fi
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git checkout -B "$BRANCH"
git commit -qam "Bump OVERLAY_PROTOCOL_MIN_VERSION to $MIN" \
-m "Pubnet is on protocol $PROTOCOL, and no release supporting it has an overlay version below $MIN."
git push -f origin "$BRANCH"
BODY="$RUNNER_TEMP/body.md"
{
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."
echo
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."
echo
echo '```'
cat "$RUNNER_TEMP/check.txt"
echo '```'
} > "$BODY"
if [ -z "$OPEN_PR" ]
then
gh pr create --base "$BASE" --head "$BRANCH" \
--title "Bump OVERLAY_PROTOCOL_MIN_VERSION to $MIN" --body-file "$BODY"
else
gh pr edit "$OPEN_PR" \
--title "Bump OVERLAY_PROTOCOL_MIN_VERSION to $MIN" --body-file "$BODY"
fi
Comment thread
Copilot marked this conversation as resolved.
Resolved
176 changes: 176 additions & 0 deletions scripts/check-overlay-min-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#!/bin/sh

# This script checks OVERLAY_PROTOCOL_MIN_VERSION (in src/main/Config.cpp)
# against the ledger protocol version a network is running.
#
# Once a network is on ledger protocol P, nodes need software supporting P to
# stay in sync, so the minimum overlay version can be raised to the lowest
# maximum overlay version (OVERLAY_PROTOCOL_VERSION) of any release that
# supports P. It should never be higher than that, or it would disconnect
# nodes running a release that can still follow the network.
#
# Usage: check-overlay-min-version.sh [--apply] <network-protocol>
#
# Looks at the release tags (v<number>...) from the newest version down,
# stopping at the first whose ledger protocol version (MAX_SUPPORTED_PROTOCOL_VERSION
# in src/util/ProtocolVersion.h, or Config::CURRENT_LEDGER_PROTOCOL_VERSION in
# src/main/Config.cpp in older releases) is below <network-protocol>, and
# compares OVERLAY_PROTOCOL_MIN_VERSION in the working tree against the lowest
# OVERLAY_PROTOCOL_VERSION among the releases that support it. Exits with a
# non-zero status if the minimum is too high. If the minimum can be raised,
# says so, and with --apply rewrites it in the working tree.
#
# Requires the release tags to have been fetched.

set -e

SRCDIR=$(realpath "$(dirname "$0")/..")
CONFIG_CPP=src/main/Config.cpp
PROTOCOL_H=src/util/ProtocolVersion.h

APPLY=
if [ "$1" = "--apply" ]
then
APPLY=1
shift
fi

if [ $# -ne 1 ]
then
echo "usage: $0 [--apply] <network-protocol>" >&2
exit 2
fi

NETWORK_LEDGER=$1
case "$NETWORK_LEDGER" in
''|*[!0-9]*)
echo "error: network protocol must be a number, got '$NETWORK_LEDGER'" >&2
exit 2
;;
esac

cd "$SRCDIR"

# file_at <rev> <file>: print the contents of <file> at <rev>, or the
# working tree copy if <rev> is empty.
file_at()
{
if [ -n "$1" ]
then
git show "$1:$2"
else
cat "$2"
fi
}

# extract <rev> <file> <name> <sed-expr>: print the numeric value assigned
# to <name> in <file> at <rev>, 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_at <rev>: print the ledger protocol version at <rev> (without the
# vnext +1). It is MAX_SUPPORTED_PROTOCOL_VERSION in ProtocolVersion.h, or
# was assigned directly to Config::CURRENT_LEDGER_PROTOCOL_VERSION in
# Config.cpp before that.
ledger_at()
{
if file_at "$1" "$PROTOCOL_H" 2>/dev/null | grep -q 'MAX_SUPPORTED_PROTOCOL_VERSION[[:space:]]*='
then
extract "$1" "$PROTOCOL_H" MAX_SUPPORTED_PROTOCOL_VERSION "$MAX_SUPPORTED_EXPR"
else
extract "$1" "$CONFIG_CPP" CURRENT_LEDGER_PROTOCOL_VERSION "$LEDGER_EXPR"
fi
}

LEDGER_EXPR='s/.*Config::CURRENT_LEDGER_PROTOCOL_VERSION[[:space:]]*=[[:space:]]*\([0-9][0-9]*\).*/\1/p'
Comment thread
Copilot marked this conversation as resolved.
Resolved
MAX_SUPPORTED_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'
MIN_EXPR='s/^[[:space:]]*OVERLAY_PROTOCOL_MIN_VERSION[[:space:]]*=[[:space:]]*\([0-9][0-9]*\).*/\1/p'

# List the releases supporting ledger protocol $NETWORK_LEDGER, and set
# TARGET_MIN to the lowest OVERLAY_PROTOCOL_VERSION among them and TARGET_TAG
# to a release that has it. Assumes the ledger protocol version doesn't
# decrease from one release version to the next.
release_target()
{
TARGET_MIN=
TARGET_TAG=
for T in $(git tag -l 'v[0-9]*' --sort=-v:refname)
do
LEDGER=$(ledger_at "$T")
if [ "$LEDGER" -lt "$NETWORK_LEDGER" ]
then
break
fi
OVERLAY=$(extract "$T" "$CONFIG_CPP" OVERLAY_PROTOCOL_VERSION "$OVERLAY_EXPR")
echo " $T: ledger protocol $LEDGER, OVERLAY_PROTOCOL_VERSION $OVERLAY"
if [ -z "$TARGET_MIN" ] || [ "$OVERLAY" -lt "$TARGET_MIN" ]
then
TARGET_MIN=$OVERLAY
TARGET_TAG=$T
fi
done
if [ -z "$TARGET_MIN" ]
then
echo "error: no release tag supports ledger protocol $NETWORK_LEDGER (tags not fetched?)" >&2
exit 2
fi
}

CODE_LEDGER=$(ledger_at "")
CODE_MIN=$(extract "" "$CONFIG_CPP" OVERLAY_PROTOCOL_MIN_VERSION "$MIN_EXPR")

if [ "$NETWORK_LEDGER" -gt "$CODE_LEDGER" ]
then
echo "error: network is on protocol $NETWORK_LEDGER, but the code's ledger protocol version is $CODE_LEDGER" >&2
exit 2
fi

echo "Releases supporting ledger protocol $NETWORK_LEDGER:"
release_target
echo "Lowest OVERLAY_PROTOCOL_VERSION among them: $TARGET_MIN ($TARGET_TAG)"
echo "OVERLAY_PROTOCOL_MIN_VERSION: $CODE_MIN"

if [ "$CODE_MIN" -gt "$TARGET_MIN" ]
then
echo "error: OVERLAY_PROTOCOL_MIN_VERSION ($CODE_MIN) is higher than the overlay version" >&2
echo "of $TARGET_TAG ($TARGET_MIN), which supports protocol $NETWORK_LEDGER, so it would" >&2
echo "disconnect nodes that can still follow the network." >&2
exit 1
fi

if [ "$CODE_MIN" -eq "$TARGET_MIN" ]
then
echo "OK"
exit 0
fi

echo "OVERLAY_PROTOCOL_MIN_VERSION can be raised from $CODE_MIN to $TARGET_MIN"
if [ -n "$APPLY" ]
then
sed "s/^\([[:space:]]*OVERLAY_PROTOCOL_MIN_VERSION[[:space:]]*=[[:space:]]*\)$CODE_MIN;/\1$TARGET_MIN;/" "$CONFIG_CPP" > "$CONFIG_CPP.tmp"
mv "$CONFIG_CPP.tmp" "$CONFIG_CPP"
NEW_MIN=$(extract "" "$CONFIG_CPP" OVERLAY_PROTOCOL_MIN_VERSION "$MIN_EXPR")
if [ "$NEW_MIN" != "$TARGET_MIN" ]
then
echo "error: failed to update OVERLAY_PROTOCOL_MIN_VERSION in $CONFIG_CPP" >&2
exit 2
fi
echo "Updated $CONFIG_CPP"
fi
Loading