1010# Usage: check-protocol-overlay-versions.sh <base-rev> [<head-rev>]
1111#
1212# Compares src/main/Config.cpp at <head-rev> (or the working tree copy if
13- # <head-rev> is omitted) against <base-rev>, and exits with a non-zero
14- # status if CURRENT_LEDGER_PROTOCOL_VERSION increased without
15- # OVERLAY_PROTOCOL_VERSION increasing as well.
13+ # <head-rev> is omitted) against <base-rev>. If CURRENT_LEDGER_PROTOCOL_VERSION
14+ # increased, exits with a non-zero status unless OVERLAY_PROTOCOL_VERSION is
15+ # higher than it was when <base-rev>'s ledger protocol version was introduced.
16+ # Comparing against that commit rather than <base-rev> means a change doesn't
17+ # need to bump the overlay version again if it was already bumped since the
18+ # previous protocol bump. It also doesn't depend on release tags, which may not
19+ # be public yet when the next protocol bump lands.
20+ #
21+ # Requires the history of <base-rev> back to its last ledger protocol bump.
1622
1723set -e
1824
@@ -63,6 +69,29 @@ extract()
6369 echo " $VAL "
6470}
6571
72+ # Print the oldest commit in <base-rev>'s history from which
73+ # CURRENT_LEDGER_PROTOCOL_VERSION has had the value it has at <base-rev>.
74+ ledger_bump_commit ()
75+ {
76+ FOUND=
77+ for C in $( git log --format=%H -G ' CURRENT_LEDGER_PROTOCOL_VERSION[[:space:]]*=' " $BASE_REV " -- " $CONFIG_CPP " )
78+ do
79+ if [ " $( extract " $C " CURRENT_LEDGER_PROTOCOL_VERSION " $LEDGER_EXPR " ) " != " $BASE_LEDGER " ]
80+ then
81+ break
82+ fi
83+ FOUND=$C
84+ done
85+ # A commit with no parent available is a shallow clone boundary, not
86+ # necessarily the commit that introduced the protocol version.
87+ if [ -z " $FOUND " ] || ! git rev-parse -q --verify " $FOUND ^" > /dev/null
88+ then
89+ echo " error: could not find the commit that set CURRENT_LEDGER_PROTOCOL_VERSION to $BASE_LEDGER in the history of $BASE_REV (shallow clone?)" >&2
90+ exit 2
91+ fi
92+ echo " $FOUND "
93+ }
94+
6695LEDGER_EXPR=' s/.*Config::CURRENT_LEDGER_PROTOCOL_VERSION[[:space:]]*=[[:space:]]*\([0-9][0-9]*\).*/\1/p'
6796OVERLAY_EXPR=' s/^[[:space:]]*OVERLAY_PROTOCOL_VERSION[[:space:]]*=[[:space:]]*\([0-9][0-9]*\).*/\1/p'
6897
@@ -74,13 +103,20 @@ HEAD_OVERLAY=$(extract "$HEAD_REV" OVERLAY_PROTOCOL_VERSION "$OVERLAY_EXPR")
74103echo " CURRENT_LEDGER_PROTOCOL_VERSION: $BASE_LEDGER -> $HEAD_LEDGER "
75104echo " OVERLAY_PROTOCOL_VERSION: $BASE_OVERLAY -> $HEAD_OVERLAY "
76105
77- if [ " $HEAD_LEDGER " -gt " $BASE_LEDGER " ] && [ " $HEAD_OVERLAY " -le " $BASE_OVERLAY " ]
106+ if [ " $HEAD_LEDGER " -gt " $BASE_LEDGER " ]
78107then
79- echo " error: CURRENT_LEDGER_PROTOCOL_VERSION was bumped from $BASE_LEDGER to $HEAD_LEDGER " >&2
80- echo " without bumping OVERLAY_PROTOCOL_VERSION (still $HEAD_OVERLAY )." >&2
81- echo " A ledger protocol bump must be accompanied by a bump of the maximum" >&2
82- echo " overlay protocol version in $CONFIG_CPP ." >&2
83- exit 1
108+ BUMP_COMMIT=$( ledger_bump_commit)
109+ BUMP_OVERLAY=$( extract " $BUMP_COMMIT " OVERLAY_PROTOCOL_VERSION " $OVERLAY_EXPR " )
110+ echo " Protocol $BASE_LEDGER was introduced in $( git log -1 --format=' %h (%s)' " $BUMP_COMMIT " ) "
111+ echo " with OVERLAY_PROTOCOL_VERSION $BUMP_OVERLAY "
112+ if [ " $HEAD_OVERLAY " -le " $BUMP_OVERLAY " ]
113+ then
114+ echo " error: CURRENT_LEDGER_PROTOCOL_VERSION was bumped from $BASE_LEDGER to $HEAD_LEDGER " >&2
115+ echo " but OVERLAY_PROTOCOL_VERSION ($HEAD_OVERLAY ) has not been bumped since protocol" >&2
116+ echo " $BASE_LEDGER was introduced. A ledger protocol bump must be accompanied by a" >&2
117+ echo " bump of the maximum overlay protocol version in $CONFIG_CPP ." >&2
118+ exit 1
119+ fi
84120fi
85121
86122echo " OK"
0 commit comments