Skip to content

Commit

Permalink
Make checks more robust
Browse files Browse the repository at this point in the history
- 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/
  • Loading branch information
atodorov committed Nov 20, 2024
1 parent d229264 commit c93ce63
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions .github/check-for-changes-in-epoch-duration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c93ce63

Please sign in to comment.