Skip to content
Open
Show file tree
Hide file tree
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
22 changes: 22 additions & 0 deletions extract_rejection_logs_fast.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/zsh

# First, extract all rejection lines from signer.log into a temporary file
# This is much faster than running rg for each hash
rg "Broadcasting block response to stacks node: Rejected" ~/signer.log > /tmp/all_rejections.txt

# Now read hashes and find matches
while IFS= read -r hash; do
# Search in the pre-filtered file
result=$(grep "$hash" /tmp/all_rejections.txt | head -1)

# Print hash and result
if [ -n "$result" ]; then
echo "$hash | $result"
else
echo "$hash | "
fi
done < locally_rejected_hashes.txt > locally_rejected_hashes_with_logs.txt

rm /tmp/all_rejections.txt
echo "Done! Results saved to locally_rejected_hashes_with_logs.txt"
wc -l locally_rejected_hashes_with_logs.txt
21 changes: 21 additions & 0 deletions extract_rejection_reasons.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/zsh

# First, extract all rejection lines from signer.log into a temporary file
rg "Broadcasting block response to stacks node: Rejected" ~/signer.log > /tmp/all_rejections.txt

# Now read hashes and find matches, extracting just the reason field
while IFS= read -r hash; do
# Search in the pre-filtered file and extract reason field using sed
result=$(grep "$hash" /tmp/all_rejections.txt | head -1 | sed -n 's/.*reason: "\([^"]*\)".*/\1/p')

# Print hash and reason
if [ -n "$result" ]; then
echo "$hash | \"$result\""
else
echo "$hash | "
fi
done < locally_rejected_hashes.txt > locally_rejected_hashes_with_logs.txt

rm /tmp/all_rejections.txt
echo "Done! Results saved to locally_rejected_hashes_with_logs.txt"
wc -l locally_rejected_hashes_with_logs.txt
100 changes: 100 additions & 0 deletions find_newblock_after_rejection.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/bash

# Script to find NewBlock events that occur AFTER block rejections for each signer_sighash
# Usage: ./find_newblock_after_rejection.sh

SIGNER_LOG="$HOME/signer.log"
INPUT_FILE="locally_rejected_hashes_with_logs.txt"
OUTPUT_FILE="newblock_after_rejection.txt"

# Check if files exist
if [[ ! -f "$SIGNER_LOG" ]]; then
echo "Error: $SIGNER_LOG not found"
exit 1
fi

if [[ ! -f "$INPUT_FILE" ]]; then
echo "Error: $INPUT_FILE not found"
exit 1
fi

# Clear output file
> "$OUTPUT_FILE"

echo "Processing signer signature hashes..."
echo ""

# Counter for progress
count=0
total=$(wc -l < "$INPUT_FILE")

# Read each line from the input file
while IFS='|' read -r sighash reason; do
# Trim whitespace
sighash=$(echo "$sighash" | xargs)
reason=$(echo "$reason" | xargs)

((count++))
echo -n "Processing $count/$total: $sighash..."

# Use rg to find all lines with this sighash, then filter for NewBlock and Rejected
all_events=$(rg -F -e "$sighash" "$SIGNER_LOG" | grep -e "Processing event: Some(NewBlock" -e "Broadcasting block response to stacks node: Rejected")

if [[ -z "$all_events" ]]; then
echo " (not found)"
echo "=== $sighash ===" >> "$OUTPUT_FILE"
echo "Rejection reason: $reason" >> "$OUTPUT_FILE"
echo "ERROR: No events found in signer.log" >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
echo "----------------------------------------" >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
continue
fi

# Find the rejection line
rejection_found=$(echo "$all_events" | grep -n "Broadcasting block response to stacks node: Rejected" | head -1)

if [[ -z "$rejection_found" ]]; then
echo " (no rejection found)"
echo "=== $sighash ===" >> "$OUTPUT_FILE"
echo "Rejection reason: $reason" >> "$OUTPUT_FILE"
echo "ERROR: No rejection found" >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
echo "----------------------------------------" >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
continue
fi

# Get the line number of the rejection within the filtered events
rejection_line_num=$(echo "$rejection_found" | cut -d: -f1)

# Get NewBlock events that appear AFTER the rejection
newblock_events=$(echo "$all_events" | tail -n +$((rejection_line_num + 1)) | grep "Processing event: Some(NewBlock")

# Write results
echo "=== $sighash ===" >> "$OUTPUT_FILE"
echo "Rejection reason: $reason" >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"
echo "Rejection:" >> "$OUTPUT_FILE"
echo "$rejection_found" | cut -d: -f2- >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"

if [[ -z "$newblock_events" ]]; then
echo "No NewBlock events found after rejection" >> "$OUTPUT_FILE"
echo " (no NewBlock after)"
else
echo "NewBlock events after rejection:" >> "$OUTPUT_FILE"
echo "$newblock_events" >> "$OUTPUT_FILE"
newblock_count=$(echo "$newblock_events" | wc -l)
echo " (found $newblock_count)"
fi

echo "" >> "$OUTPUT_FILE"
echo "----------------------------------------" >> "$OUTPUT_FILE"
echo "" >> "$OUTPUT_FILE"

done < "$INPUT_FILE"

echo ""
echo "Done! Results written to $OUTPUT_FILE"
echo "Total: $count hashes"
Loading