Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
58 changes: 58 additions & 0 deletions .github/workflows/update-config-settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Update Config Settings

on:
schedule:
- cron: '0 12 * * 1' # Weekly, Monday
workflow_dispatch:

jobs:

update:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4

- name: Install stellar-cli
uses: stellar/stellar-cli@v26.1.0
Comment thread
leighmcculloch marked this conversation as resolved.

- name: Update config settings
id: update
run: |
dir="$(./.scripts/update-config-settings)"
echo "dir=$dir" >> "$GITHUB_OUTPUT"

- name: Create Pull Request
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DIR: ${{ steps.update.outputs.dir }}
run: |
if [ -z "$(git status --porcelain -- "$DIR")" ]; then
echo "Config settings already in sync"
exit 0
fi

git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

hash="$(git hash-object "$DIR/testnet.json" | cut -c1-16)"
branch="update-config-settings/${hash}"

# Check if PR already exists for this exact update
if gh pr list --head "$branch" --state open --json number --jq '.[0].number' | grep -q .; then
echo "PR already exists for this update"
exit 0
fi

git checkout -b "$branch"
git add "$DIR"
git commit -m "Update testnet config settings (${hash})"
git push -u origin "$branch"

gh pr create \
--title "Update testnet config settings (${hash})" \
--body "This PR was automatically generated by the Update Config Settings workflow because the committed testnet config settings drifted from live testnet. Please review the value changes before merging." \
--base main \
--head "$branch"
86 changes: 86 additions & 0 deletions .scripts/update-config-settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env bash
# Regenerates the testnet config settings for the protocol version that testnet
# is currently running.
#
# Fetches testnet's upgradeable Soroban config settings as a ConfigUpgradeSet
# (the format consumed by `stellar-xdr encode --type ConfigUpgradeSet` in the
# start script) and writes them, sorted for stable output, to testnet.json for
# the protocol version in effect when retrieved. Internally-maintained,
# non-upgradeable settings are excluded (no --internal).
#
# unlimited.json is regenerated alongside it: it is testnet.json with a set of
# "unlimited" scalar overrides applied (cost-param arrays carry through from
# testnet unchanged). The overrides are taken from this protocol's own committed
# unlimited.json, preserving its hand-tuning; for a protocol the repo has no
# directory for yet, they are taken from the most recent prior protocol, and
# settings introduced by the new protocol keep their testnet values until tuned
# by hand in the resulting PR.
#
# Usage: ./.scripts/update-config-settings
set -euo pipefail

config_settings_dir="local/core/etc/config-settings"

protocol="$(stellar ledger latest --network testnet --output json | jq -r '.protocolVersion')"
if ! [[ "$protocol" =~ ^[0-9]+$ ]]; then
echo "error: could not determine testnet protocol version (got '$protocol')" >&2
exit 1
fi

# stellar-cli's major version tracks the protocol it supports. If testnet has
# advanced beyond it, `stellar network settings` silently omits settings the
# older XDR doesn't know about, so fail loudly to prompt bumping the pinned CLI.
cli_protocol="$(stellar version | head -n1 | sed -E 's/^stellar ([0-9]+).*/\1/')"
if [ "$protocol" -gt "$cli_protocol" ]; then
echo "error: testnet is on protocol $protocol but stellar-cli supports protocol $cli_protocol; bump the pinned stellar-cli version" >&2
exit 1
fi

dir="$config_settings_dir/p$protocol"
mkdir -p "$dir"

# Pick the source of the unlimited overrides before overwriting anything: this
# protocol's own committed pair if present, else the most recent prior protocol.
override_t=""
override_u=""
if [ -f "$dir/testnet.json" ] && [ -f "$dir/unlimited.json" ]; then
override_t="$dir/testnet.json"
override_u="$dir/unlimited.json"
else
for ((v = protocol - 1; v >= 20; v--)); do
if [ -f "$config_settings_dir/p$v/testnet.json" ] && [ -f "$config_settings_dir/p$v/unlimited.json" ]; then
override_t="$config_settings_dir/p$v/testnet.json"
override_u="$config_settings_dir/p$v/unlimited.json"
break
fi
done
fi
if [ -z "$override_u" ]; then
echo "error: no protocol with testnet.json and unlimited.json to derive unlimited overrides from" >&2
exit 1
fi

# Fetch testnet's settings, sorted for stable output.
testnet="$(stellar network settings --network testnet --output json | jq -S .)"

# unlimited.json = testnet.json with the unlimited overrides (the leaf fields
# where the override source's unlimited.json differs from its testnet.json).
unlimited="$(printf '%s' "$testnet" | jq -S --slurpfile t "$override_t" --slurpfile u "$override_u" '
( $t[0].updated_entry | map({(keys[0]): .[keys[0]]}) | add ) as $T
| ( $u[0].updated_entry | map({(keys[0]): .[keys[0]]}) | add ) as $U
| { updated_entry: ( .updated_entry | map(
(keys[0]) as $n | .[$n] as $v
| { ($n):
( if ($U[$n] == null) or ($T[$n] == null) then $v
elif ($U[$n] | type) == "object"
then reduce ($U[$n] | paths(scalars)) as $p
($v;
if ($U[$n] | getpath($p)) != ($T[$n] | getpath($p)?)
then setpath($p; ($U[$n] | getpath($p))) else . end)
else (if $U[$n] != $T[$n] then $U[$n] else $v end)
end ) } ) ) }
')"

printf '%s\n' "$testnet" > "$dir/testnet.json"
printf '%s\n' "$unlimited" > "$dir/unlimited.json"
echo "$dir"
2 changes: 2 additions & 0 deletions local/core/etc/config-settings/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# config-settings
This directory contains Soroban settings upgrade files for each default protocol version (set with the arg `PROTOCOL_VERSION_DEFAULT`) specified on each on the three builds (`latest`, `testing`, and `future`). They need to be separated by protocol version because the number of cost types is dependant on protocol, and we specifically want to capture the cpu cost type changes we make outside of protocol boundaries.

The `testnet.json` and `unlimited.json` for the protocol version testnet is currently running are kept up to date by the `Update Config Settings` workflow, which opens a PR when the committed values drift.
Loading