Test with attestation cache
This commit is contained in:
parent
3b54e0cb8c
commit
ed2cd259e9
6 changed files with 59 additions and 5 deletions
|
|
@ -37,6 +37,39 @@ chmod +x "$GENERATE_SCRIPT"
|
|||
# Ensure .ots directory exists
|
||||
mkdir -p .ots
|
||||
|
||||
# Cache file for attestation status (avoids repeated ots info calls)
|
||||
STATUS_CACHE=".ots/.attestation-cache"
|
||||
if [ ! -f "$STATUS_CACHE" ]; then
|
||||
echo "# Attestation status cache" > "$STATUS_CACHE"
|
||||
echo "# Format: commit-hash:status:timestamp" >> "$STATUS_CACHE"
|
||||
fi
|
||||
|
||||
# Function to check cached status
|
||||
get_cached_status() {
|
||||
local commit="$1"
|
||||
local cache_line=$(grep "^$commit:" "$STATUS_CACHE" 2>/dev/null | tail -1)
|
||||
if [ -n "$cache_line" ]; then
|
||||
local status=$(echo "$cache_line" | cut -d: -f2)
|
||||
local timestamp=$(echo "$cache_line" | cut -d: -f3)
|
||||
local now=$(date +%s)
|
||||
local age=$((now - timestamp))
|
||||
# Cache valid for 1 hour (3600 seconds)
|
||||
if [ "$age" -lt 3600 ]; then
|
||||
echo "$status"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
# Function to cache status
|
||||
cache_status() {
|
||||
local commit="$1"
|
||||
local status="$2"
|
||||
local now=$(date +%s)
|
||||
echo "$commit:$status:$now" >> "$STATUS_CACHE"
|
||||
}
|
||||
|
||||
echo "[ots-backfill] Scanning commit history..."
|
||||
|
||||
# Get all commit hashes (oldest to newest)
|
||||
|
|
@ -55,18 +88,31 @@ for COMMIT in $COMMITS; do
|
|||
PROOF_FILE=".ots/${COMMIT}.ots"
|
||||
|
||||
if [ -f "$PROOF_FILE" ]; then
|
||||
# Check if already fully attested
|
||||
STATUS=$(ots info "$PROOF_FILE" 2>&1 | grep -c "PendingAttestation" || echo "0")
|
||||
# Check cached status first
|
||||
CACHED_STATUS=$(get_cached_status "$COMMIT" || echo "")
|
||||
|
||||
if [ "$STATUS" -eq 0 ]; then
|
||||
echo " ✓ Already attested (skipping)"
|
||||
if [ "$CACHED_STATUS" = "attested" ]; then
|
||||
echo " ✓ Already attested (cached, skipping)"
|
||||
continue
|
||||
fi
|
||||
|
||||
# Check if already fully attested (only if not cached or cache expired)
|
||||
PENDING_COUNT=$(ots info "$PROOF_FILE" 2>&1 | grep -c "PendingAttestation" || echo "0")
|
||||
|
||||
if [ "$PENDING_COUNT" -eq 0 ]; then
|
||||
echo " ✓ Already attested"
|
||||
cache_status "$COMMIT" "attested"
|
||||
continue
|
||||
fi
|
||||
|
||||
# Cache as pending
|
||||
cache_status "$COMMIT" "pending"
|
||||
|
||||
# Try to upgrade existing proof (only contacts calendars if pending)
|
||||
echo " Upgrading pending proof..."
|
||||
if ots upgrade "$PROOF_FILE" 2>/dev/null; then
|
||||
echo " ✓ Upgraded to attested"
|
||||
cache_status "$COMMIT" "attested"
|
||||
UPDATED=$((UPDATED + 1))
|
||||
else
|
||||
echo " - Still pending (no upgrade available yet)"
|
||||
|
|
@ -76,6 +122,7 @@ for COMMIT in $COMMITS; do
|
|||
echo " Generating new proof..."
|
||||
"$GENERATE_SCRIPT" "$COMMIT" "$PROOF_FILE" >/dev/null 2>&1
|
||||
echo " ✓ Generated proof"
|
||||
cache_status "$COMMIT" "pending"
|
||||
UPDATED=$((UPDATED + 1))
|
||||
fi
|
||||
done
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue