-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add checks for version & epoch duration
- Loading branch information
Showing
3 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/bin/bash | ||
|
||
set -xeuo pipefail | ||
|
||
# Colorful output. | ||
function greenprint { | ||
echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" | ||
} | ||
|
||
check_block_time() { | ||
# WARNING: exits on error | ||
from=$1 | ||
to=$2 | ||
|
||
if git --no-pager diff "${from}...${to}" | grep 'MILLISECS_PER_BLOCK'; then | ||
greenprint "FAIL: MILLISECS_PER_BLOCK has been modified! This will brick the blockchain!" | ||
exit 1 | ||
else | ||
greenprint "PASS: MILLISECS_PER_BLOCK has not been modified!" | ||
fi | ||
} | ||
|
||
check_epoch_duration() { | ||
# WARNING: exits on error | ||
from=$1 | ||
to=$2 | ||
|
||
if git --no-pager diff "${from}...${to}" | grep 'EPOCH_DURATION'; then | ||
greenprint "FAIL: EPOCH_DURATION has been modified! This will brick the blockchain!" | ||
exit 1 | ||
else | ||
greenprint "PASS: EPOCH_DURATION has not been modified!" | ||
fi | ||
} | ||
|
||
check_slot_duration() { | ||
# WARNING: exits on error | ||
from=$1 | ||
to=$2 | ||
|
||
if git --no-pager diff "${from}...${to}" | grep 'SLOT_DURATION'; then | ||
greenprint "FAIL: SLOT_DURATION has been modified! This will brick the blockchain!" | ||
exit 1 | ||
else | ||
greenprint "PASS: SLOT_DURATION has not been modified!" | ||
fi | ||
} | ||
|
||
|
||
#### main part | ||
|
||
FROM=$(git rev-parse "${1:-origin/dev}") | ||
TO=$(git rev-parse "${2:-HEAD}") | ||
|
||
greenprint "DEBUG: Inspecting range $FROM..$TO" | ||
|
||
if [ -z "$FROM" ]; then | ||
echo "ERROR: FROM is empty. Exiting..." | ||
exit 2 | ||
fi | ||
|
||
if [ -z "$TO" ]; then | ||
echo "ERROR: TO is empty. Exiting..." | ||
exit 2 | ||
fi | ||
|
||
if git --no-pager diff --name-only "${FROM}"..."${TO}" | grep -e '^runtime'; then | ||
greenprint "INFO: runtime/ has been modified. Checking for changes in EPOCH_DURATION!" | ||
check_block_time "${FROM}" "${TO}" | ||
check_epoch_duration "${FROM}" "${TO}" | ||
check_slot_duration "${FROM}" "${TO}" | ||
else | ||
greenprint "INFO: runtime/ has NOT been modified. Will NOT check for changes in EPOCH_DURATION!" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/bin/bash | ||
|
||
set -xeuo pipefail | ||
|
||
# Colorful output. | ||
function greenprint { | ||
echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" | ||
} | ||
|
||
check_version() { | ||
# WARNING: exits on error | ||
from=$1 | ||
to=$2 | ||
|
||
if git --no-pager diff "${from}...${to}" | grep '^diff --git' | grep 'runtime/src/version.rs'; then | ||
greenprint "PASS: version.rs was modified!" | ||
else | ||
greenprint "FAIL: version.rs was not modified!" | ||
exit 1 | ||
fi | ||
} | ||
|
||
#### main part | ||
|
||
VERSION_FROM_CARGO_TOML=$(grep "^version =" Cargo.toml | cut -f2 -d'=' | tr -d "' \"") | ||
|
||
SPEC_VERSION=$(grep spec_version: runtime/src/version.rs | cut -f2 -d: | tr -d " ,") | ||
IMPL_VERSION=$(grep impl_version: runtime/src/version.rs | cut -f2 -d: | tr -d " ,") | ||
VERSION_FROM_VERSION_RS="2.$SPEC_VERSION.$IMPL_VERSION" | ||
|
||
# Since PR #969 version strings in Cargo.toml and version.rs should be in sync | ||
echo "INFO: Cargo.toml version is $VERSION_FROM_CARGO_TOML" | ||
echo "INFO: version.rs version is $VERSION_FROM_VERSION_RS" | ||
if [ "$VERSION_FROM_CARGO_TOML" != "$VERSION_FROM_VERSION_RS" ]; then | ||
echo "FAIL: Versions in Cargo.toml and runtime/src/version.rs are not in sync" | ||
exit 2 | ||
fi | ||
|
||
|
||
FROM=$(git rev-parse "${1:-origin/dev}") | ||
TO=$(git rev-parse "${2:-HEAD}") | ||
|
||
greenprint "DEBUG: Inspecting range $FROM..$TO" | ||
|
||
if [ -z "$FROM" ]; then | ||
echo "ERROR: FROM is empty. Exiting..." | ||
exit 2 | ||
fi | ||
|
||
if [ -z "$TO" ]; then | ||
echo "ERROR: TO is empty. Exiting..." | ||
exit 2 | ||
fi | ||
|
||
if git --no-pager diff --name-only "${FROM}"..."${TO}" | grep -e '^runtime'; then | ||
greenprint "INFO: runtime/src/ has been modified" | ||
check_version "${FROM}" "${TO}" | ||
else | ||
greenprint "INFO: runtime/src/ didn't change. Will inspect Cargo.lock" | ||
if git --no-pager diff "${FROM}"..."${TO}" Cargo.lock | grep '+source = "git+https://github.com/paritytech'; then | ||
echo "INFO: Cargo.lock references to `frontier` or `polkadot-sdk` have been modified" | ||
check_version "${FROM}" "${TO}" | ||
else | ||
greenprint "INFO: Cargo.lock references to Substrate did not change" | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
name: Check runtime changes | ||
|
||
on: | ||
pull_request: | ||
branches: [dev, testnet, main] | ||
|
||
permissions: read-all | ||
|
||
jobs: | ||
check-version: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Check if version.rs was modified | ||
run: | | ||
./.github/check-version.sh "remotes/origin/$GITHUB_BASE_REF" "$GITHUB_SHA" | ||
# dangerous conditions that will brick the blockchain | ||
danger-will-brick-the-blockchain: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Check for changes in Proof-of-Stake EPOCH duration | ||
run: | | ||
./.github/check-for-changes-in-epoch-duration.sh "remotes/origin/$GITHUB_BASE_REF" "$GITHUB_SHA" |