Skip to content

Conversation

@FiloSottile
Copy link
Owner

No description provided.

@FiloSottile FiloSottile requested a review from Copilot November 8, 2025 00:32
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the witness implementation to support dynamic log discovery by pulling logs from a network log list instead of requiring static configuration.

  • Key changes include storing witness configuration (log origins and verifier keys) in the backend, implementing a PullLogList method that periodically fetches and parses log lists to add new logs dynamically, and improving metrics collection
  • The database schema is updated to use BLOB NOT NULL instead of TEXT for checkpoint storage with proper NULL handling
  • The witness configuration now takes a log list URL instead of a static list of known logs

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
internal/witness/witness.go Major refactoring to support dynamic log list loading from a URL, store witness config in backend, defer checkpoint fetching, add RWMutex for thread-safe log access, implement parseLogList parser, and improve metrics
internal/witness/metrics.go Add new metrics for known logs count, log size per origin, and add-checkpoint request counts with error/origin/progress labels
internal/ctlog/sqlite.go Update schema to BLOB NOT NULL, add NULL-to-empty-slice conversion for consistency in Create and Replace methods
internal/ctlog/cache.go Update cache schema to use NOT NULL constraints and STRICT mode
cmd/sunlight/sunlight.go Replace static KnownLogs config with LogList URL, add periodic log list pulling with SIGHUP reload support, refactor home page data structure
cmd/sunlight/home.html Move witness information section and add log list source display
README.md Update database creation command to reflect new BLOB NOT NULL STRICT schema

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +250 to +253
}
w.verifiers = verifiers
w.checkpoints = checkpoints
w.m.KnownLogs.Set(float64(len(w.verifiers)))
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logsMu lock is held while performing multiple blocking I/O operations (Backend.Create, Backend.Fetch at lines 213-221, and Backend.Fetch/Replace at lines 227-249). This can block concurrent read operations (verifiersForOrigin, checkpointForOrigin, Logs) for an extended period. Consider releasing the lock before the backend operations and re-acquiring it only for the final update of w.verifiers and w.checkpoints at lines 251-253.

Suggested change
}
w.verifiers = verifiers
w.checkpoints = checkpoints
w.m.KnownLogs.Set(float64(len(w.verifiers)))
}
w.logsMu.Lock()
w.verifiers = verifiers
w.checkpoints = checkpoints
w.m.KnownLogs.Set(float64(len(w.verifiers)))
w.logsMu.Unlock()

Copilot uses AI. Check for mistakes.
When passing nil to Create or Replace, it was stored as NULL, but then
was fetched as []byte("") by Fetch, which then didn't compare equal to
NULL in Replace, making it always fail.

This was made harder to debug by two things:

 1. in the CLI, NULL and empty are both shown as empty by default;

 2. I tried to fix it by running

       "UPDATE checkpoints SET body = '' WHERE body IS NULL;"

    which put empty TEXT in those columns, which does not compare equal
    to empty BLOB. They were both allowed in the same column by the
    non-STRICT table.
@FiloSottile FiloSottile merged commit 25950ee into main Nov 27, 2025
12 checks passed
@FiloSottile FiloSottile deleted the push-qzzyxxprnvpp branch November 27, 2025 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants