@@ -42,10 +42,20 @@ type LogConfig struct {
42
42
VerifierKeys []string
43
43
}
44
44
45
- func logIDFromOrigin (origin string ) [sha256 .Size ]byte {
45
+ func logIDFromOrigin (config * Config , origin string ) [sha256 .Size ]byte {
46
46
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 )
48
50
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
+
49
59
h .Write ([]byte (origin ))
50
60
return [32 ]byte (h .Sum (nil ))
51
61
}
@@ -85,7 +95,7 @@ func NewWitness(ctx context.Context, config *Config) (*Witness, error) {
85
95
verifiers = append (verifiers , v )
86
96
}
87
97
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 ))
89
99
if err != nil && ! errors .Is (err , ctlog .ErrLogNotFound ) {
90
100
return nil , fmt .Errorf ("couldn't fetch checkpoint for log %q: %w" , log .Origin , err )
91
101
}
@@ -279,13 +289,13 @@ func (w *Witness) updateCheckpoint(ctx context.Context, origin string,
279
289
new := append (noteBytes [:len (noteBytes ):len (noteBytes )], sigs ... )
280
290
281
291
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 )
283
293
if err != nil {
284
294
return nil , errors .New ("internal error: failed to create new checkpoint" )
285
295
}
286
296
// Kinda unclear why [ctlog.LockBackend.Create] doesn't return the
287
297
// [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 ))
289
299
if err != nil {
290
300
return nil , errors .New ("internal error: failed to fetch new checkpoint" )
291
301
}
0 commit comments