From c93ce632a19f821d8f417bba3d05e77f3f413416 Mon Sep 17 00:00:00 2001 From: Alex Todorov Date: Wed, 20 Nov 2024 13:52:51 +0200 Subject: [PATCH] Make checks more robust - exclude unmodified lines from the diff context by searching for lines which explicitly start with + or -, meaning added/removed lines. This will prevent the script to trigger when adding/modifying other constants in the vicinity of the ones that we check for! - as an extra measure search only for modified lines which also contain the word "const" inside of them! This will prevent the script to trigger when modifying function calls which merely use the value of the constants that we check for! - as more extra measure examine diff only on the runtime/ directory to avoid triggering by changes in this script itself or other files which may be referencing a constant name, e.g. text documentation. NOTE: the script can still trigger with a false positive if for example you modify a definition for a different constant, whose value is an expression consuming the constants we check for. For example: -const CTC_REWARD_PER_BLOCK: Balance = 2 * CTC; +const CTC_REWARD_PER_BLOCK: Balance = 2 * CTC * EPOCH_DURATION_IN_BLOCKS; will trigger the script! Improve by diffing only runtime/ --- .github/check-for-changes-in-epoch-duration.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/check-for-changes-in-epoch-duration.sh b/.github/check-for-changes-in-epoch-duration.sh index 5dc0b7c4..a28d3bb5 100755 --- a/.github/check-for-changes-in-epoch-duration.sh +++ b/.github/check-for-changes-in-epoch-duration.sh @@ -20,7 +20,7 @@ check_block_time() { from=$1 to=$2 - if git --no-pager diff "${from}...${to}" | grep 'MILLISECS_PER_BLOCK'; then + 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 @@ -34,7 +34,7 @@ check_blocks_for_faster_epoch() { from=$1 to=$2 - if git --no-pager diff "${from}...${to}" | grep 'BLOCKS_FOR_FASTER_EPOCH'; then + 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 @@ -48,7 +48,7 @@ check_epoch_duration() { from=$1 to=$2 - if git --no-pager diff "${from}...${to}" | grep 'EPOCH_DURATION'; then + 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 @@ -62,7 +62,7 @@ check_slot_duration() { from=$1 to=$2 - if git --no-pager diff "${from}...${to}" | grep 'SLOT_DURATION'; then + 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