Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSUB-1379: Make danger check more robust #528

Merged
merged 3 commits into from
Nov 21, 2024
Merged
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
48 changes: 30 additions & 18 deletions .github/check-for-changes-in-epoch-duration.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
#!/bin/bash

set -xeuo pipefail
set -euo pipefail

# Colorful output.
function greenprint {
echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m"
}

function yellowprint {
echo -e "\033[1;33m[$(date -Isecond)] ${1}\033[0m"
}

function redprint {
echo -e "\033[1;31m[$(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!"
if git --no-pager diff "${from}...${to}" -- runtime/ | grep 'MILLISECS_PER_BLOCK' | grep const | grep --regexp='^[\+|\-]'; then
redprint "FAIL: modified line(s) referencing MILLISECS_PER_BLOCK found!"
redprint "FAIL: Don't change the value of this variable! This will brick the blockchain!"
exit 1
else
greenprint "PASS: MILLISECS_PER_BLOCK has not been modified!"
greenprint "PASS: modified lines referencing MILLISECS_PER_BLOCK not found!"
fi
}

Expand All @@ -25,11 +34,12 @@ check_blocks_for_faster_epoch() {
from=$1
to=$2

if git --no-pager diff "${from}...${to}" | grep 'BLOCKS_FOR_FASTER_EPOCH'; then
greenprint "FAIL: BLOCKS_FOR_FASTER_EPOCH has been modified! This will brick Devnet!"
if git --no-pager diff "${from}...${to}" -- runtime/ | grep 'BLOCKS_FOR_FASTER_EPOCH' | grep const | grep --regexp='^[\+|\-]'; then
redprint "FAIL: modified line(s) referencing BLOCKS_FOR_FASTER_EPOCH found!"
redprint "FAIL: Don't change the value of this variable! This will brick Devnet!"
exit 1
else
greenprint "PASS: BLOCKS_FOR_FASTER_EPOCH has not been modified!"
greenprint "PASS: modified lines referencing BLOCKS_FOR_FASTER_EPOCH not found!"
fi
}

Expand All @@ -38,11 +48,12 @@ check_epoch_duration() {
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!"
if git --no-pager diff "${from}...${to}" -- runtime/ | grep 'EPOCH_DURATION' | grep const | grep --regexp='^[\+|\-]'; then
redprint "FAIL: modified line(s) referencing EPOCH_DURATION found!"
redprint "FAIL: Don't change the value of this variable! This will brick the blockchain!"
exit 1
else
greenprint "PASS: EPOCH_DURATION has not been modified!"
greenprint "PASS: modified lines referencing EPOCH_DURATION not found!"
fi
}

Expand All @@ -51,11 +62,12 @@ check_slot_duration() {
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!"
if git --no-pager diff "${from}...${to}" -- runtime/ | grep 'SLOT_DURATION' | grep const | grep --regexp='^[\+|\-]'; then
redprint "FAIL: modified line(s) referencing SLOT_DURATION found!"
redprint "FAIL: Don't change the value of this variable! This will brick the blockchain!"
exit 1
else
greenprint "PASS: SLOT_DURATION has not been modified!"
greenprint "PASS: modified lines referencing SLOT_DURATION not found!"
fi
}

Expand All @@ -65,24 +77,24 @@ check_slot_duration() {
FROM=$(git rev-parse "${1:-origin/dev}")
TO=$(git rev-parse "${2:-HEAD}")

greenprint "DEBUG: Inspecting range $FROM..$TO"
yellowprint "DEBUG: Inspecting range $FROM...$TO"

if [ -z "$FROM" ]; then
echo "ERROR: FROM is empty. Exiting..."
redprint "ERROR: FROM is empty. Exiting..."
exit 2
fi

if [ -z "$TO" ]; then
echo "ERROR: TO is empty. Exiting..."
redprint "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!"
yellowprint "INFO: runtime/ dir has been modified. Checking for critical changes!"
check_block_time "${FROM}" "${TO}"
check_blocks_for_faster_epoch "${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!"
greenprint "INFO: runtime/ dir has NOT been modified. All good!"
fi
Loading