@@ -42,10 +42,20 @@ type LogConfig struct {
4242 VerifierKeys []string
4343}
4444
45- func logIDFromOrigin (origin string ) [sha256 .Size ]byte {
45+ func logIDFromOrigin (config * Config , origin string ) [sha256 .Size ]byte {
4646 h := sha256 .New ()
47- h .Write (asn1 .NullBytes ) // Domain separation from [ctlog.logIDFromKey].
47+
48+ // Domain separation from [ctlog.logIDFromKey].
49+ h .Write (asn1 .NullBytes )
4850 h .Write ([]byte ("Sunlight witness\n " ))
51+
52+ // Let multiple witnesses share the same LockBackend without affecting each
53+ // other's state. This is undesirable for logs we operate, where we are in
54+ // charge of preventing split-views, but for witnesses it would mostly cause
55+ // conflicts as it would invalidate the client's view of the witness state.
56+ h .Write ([]byte (config .Name ))
57+ h .Write ([]byte ("\n " ))
58+
4959 h .Write ([]byte (origin ))
5060 return [32 ]byte (h .Sum (nil ))
5161}
@@ -85,7 +95,7 @@ func NewWitness(ctx context.Context, config *Config) (*Witness, error) {
8595 verifiers = append (verifiers , v )
8696 }
8797 l [log .Origin ] = note .VerifierList (verifiers ... )
88- c , err := config .Backend .Fetch (ctx , logIDFromOrigin (log .Origin ))
98+ c , err := config .Backend .Fetch (ctx , logIDFromOrigin (config , log .Origin ))
8999 if err != nil && ! errors .Is (err , ctlog .ErrLogNotFound ) {
90100 return nil , fmt .Errorf ("couldn't fetch checkpoint for log %q: %w" , log .Origin , err )
91101 }
@@ -279,13 +289,13 @@ func (w *Witness) updateCheckpoint(ctx context.Context, origin string,
279289 new := append (noteBytes [:len (noteBytes ):len (noteBytes )], sigs ... )
280290
281291 if lock .LockedCheckpoint == nil {
282- err := w .c .Backend .Create (ctx , logIDFromOrigin (origin ), new )
292+ err := w .c .Backend .Create (ctx , logIDFromOrigin (w . c , origin ), new )
283293 if err != nil {
284294 return nil , errors .New ("internal error: failed to create new checkpoint" )
285295 }
286296 // Kinda unclear why [ctlog.LockBackend.Create] doesn't return the
287297 // [ctlog.LockedCheckpoint], but a race here would be harmless anyway.
288- newLock , err := w .c .Backend .Fetch (ctx , logIDFromOrigin (origin ))
298+ newLock , err := w .c .Backend .Fetch (ctx , logIDFromOrigin (w . c , origin ))
289299 if err != nil {
290300 return nil , errors .New ("internal error: failed to fetch new checkpoint" )
291301 }
0 commit comments