Skip to content

Commit ccf2d22

Browse files
committed
Addressed CoPilot review
1 parent 039b71a commit ccf2d22

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

scripts/update-anti-slashing-db.sh

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fi
6868

6969
# Create temporary files for processing
7070
TEMP_FILE=$(mktemp)
71-
trap 'rm -f "$TEMP_FILE" "${TEMP_FILE}.tmp"' EXIT
71+
trap 'rm -f "$TEMP_FILE" "${TEMP_FILE}.tmp"' EXIT INT TERM
7272

7373
# Function to find pubkey in cluster-lock and return validator_index,share_index
7474
# Returns empty string if not found
@@ -116,6 +116,17 @@ echo ""
116116
source_validators=$(jq '.distributed_validators | length' "$SOURCE_LOCK")
117117
target_validators=$(jq '.distributed_validators | length' "$TARGET_LOCK")
118118

119+
# Validate that we got valid numeric values
120+
if [ -z "$source_validators" ] || [ "$source_validators" = "null" ]; then
121+
echo "Error: Source cluster-lock missing 'distributed_validators' field" >&2
122+
exit 1
123+
fi
124+
125+
if [ -z "$target_validators" ] || [ "$target_validators" = "null" ]; then
126+
echo "Error: Target cluster-lock missing 'distributed_validators' field" >&2
127+
exit 1
128+
fi
129+
119130
echo "Source cluster-lock has $source_validators validators"
120131
echo "Target cluster-lock has $target_validators validators"
121132

@@ -147,7 +158,7 @@ if [ -z "$pubkeys" ]; then
147158
exit 0
148159
fi
149160

150-
pubkey_count=$(echo "$pubkeys" | wc -l | tr -d ' ')
161+
pubkey_count=$(echo "$pubkeys" | wc -l | xargs)
151162
echo "Found $pubkey_count unique pubkey(s) to process"
152163
echo ""
153164

@@ -174,10 +185,9 @@ while IFS= read -r old_pubkey; do
174185
echo " Found at distributed_validators[$validator_idx].public_shares[$share_idx]"
175186

176187
# Verify target has sufficient validators
177-
target_validator_count=$(jq '.distributed_validators | length' "$TARGET_LOCK")
178-
if [ "$validator_idx" -ge "$target_validator_count" ]; then
188+
if [ "$validator_idx" -ge "$target_validators" ]; then
179189
echo " Error: Target cluster-lock.json doesn't have validator at index $validator_idx" >&2
180-
echo " Target has only $target_validator_count validators" >&2
190+
echo " Target has only $target_validators validators" >&2
181191
exit 1
182192
fi
183193

0 commit comments

Comments
 (0)