diff --git a/.ots/810d26b7af9c5d306e77fec290d360c7ac876b2e.ots b/.ots/810d26b7af9c5d306e77fec290d360c7ac876b2e.ots new file mode 100644 index 0000000..43650e5 Binary files /dev/null and b/.ots/810d26b7af9c5d306e77fec290d360c7ac876b2e.ots differ diff --git a/.ots/commit-chain.txt b/.ots/commit-chain.txt index d0f9c04..a6fee65 100644 --- a/.ots/commit-chain.txt +++ b/.ots/commit-chain.txt @@ -7,3 +7,9 @@ c0685dabfb48360a3abc103b75357f94e9f054b2:46aded7b9582bbed673843e2cf8a3f8fa742ad9 4a6f5ed0c12315b0bc8a0fa5815ada1bd20e5963:db6f29e01a33d8ed8f127ff169d9f91d55e8a229 db6f29e01a33d8ed8f127ff169d9f91d55e8a229:392ee723c3cf626d0e5281aa94771d7133bb345e 392ee723c3cf626d0e5281aa94771d7133bb345e:392ee723c3cf626d0e5281aa94771d7133bb345e^1 +810d26b7af9c5d306e77fec290d360c7ac876b2e:c0685dabfb48360a3abc103b75357f94e9f054b2 +c0685dabfb48360a3abc103b75357f94e9f054b2:46aded7b9582bbed673843e2cf8a3f8fa742ad91 +46aded7b9582bbed673843e2cf8a3f8fa742ad91:4a6f5ed0c12315b0bc8a0fa5815ada1bd20e5963 +4a6f5ed0c12315b0bc8a0fa5815ada1bd20e5963:db6f29e01a33d8ed8f127ff169d9f91d55e8a229 +db6f29e01a33d8ed8f127ff169d9f91d55e8a229:392ee723c3cf626d0e5281aa94771d7133bb345e +392ee723c3cf626d0e5281aa94771d7133bb345e:392ee723c3cf626d0e5281aa94771d7133bb345e^1 diff --git a/.ots/prev-commit.txt b/.ots/prev-commit.txt index 79c74df..8b45759 100644 --- a/.ots/prev-commit.txt +++ b/.ots/prev-commit.txt @@ -1 +1 @@ -c0685dabfb48360a3abc103b75357f94e9f054b2 +810d26b7af9c5d306e77fec290d360c7ac876b2e diff --git a/.ots/proof.ots b/.ots/proof.ots index 407ebcf..fbc62a4 100644 Binary files a/.ots/proof.ots and b/.ots/proof.ots differ diff --git a/backfill-proofs.sh b/backfill-proofs.sh index 81ea0aa..a859ec4 100755 --- a/backfill-proofs.sh +++ b/backfill-proofs.sh @@ -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 diff --git a/test6.txt b/test6.txt new file mode 100644 index 0000000..b351a1d --- /dev/null +++ b/test6.txt @@ -0,0 +1 @@ +# Second test with cache