From 02e4ab6c3e5236e02679e3d3de959a2d340a22b4 Mon Sep 17 00:00:00 2001 From: Martin Hutchinson Date: Wed, 23 Oct 2024 14:14:52 +0000 Subject: [PATCH] Remove compact ranges from the persistence layer --- internal/feeder/sumdb/sumdb_feeder.go | 8 -------- internal/persistence/inmemory/inmemory.go | 2 +- internal/persistence/inmemory/inmemory_test.go | 2 +- internal/persistence/persistence.go | 5 ++--- internal/persistence/sql/sql.go | 4 ++-- internal/persistence/testonly/persistence.go | 2 +- internal/witness/witness.go | 6 +++--- 7 files changed, 10 insertions(+), 19 deletions(-) diff --git a/internal/feeder/sumdb/sumdb_feeder.go b/internal/feeder/sumdb/sumdb_feeder.go index e50b048..443f26e 100644 --- a/internal/feeder/sumdb/sumdb_feeder.go +++ b/internal/feeder/sumdb/sumdb_feeder.go @@ -22,8 +22,6 @@ import ( "time" "github.com/transparency-dev/formats/log" - "github.com/transparency-dev/merkle/compact" - "github.com/transparency-dev/merkle/rfc6962" "github.com/transparency-dev/witness/internal/client" "github.com/transparency-dev/witness/internal/config" "github.com/transparency-dev/witness/internal/feeder" @@ -36,12 +34,6 @@ const ( leavesPerTile = 1 << tileHeight ) -var ( - rf = &compact.RangeFactory{ - Hash: rfc6962.DefaultHasher.HashChildren, - } -) - // FeedLog continually feeds checkpoints from the given log into the witness. // This method blocks until the context is done. func FeedLog(ctx context.Context, l config.Log, w feeder.Witness, c *http.Client, interval time.Duration) error { diff --git a/internal/persistence/inmemory/inmemory.go b/internal/persistence/inmemory/inmemory.go index 8c8e776..6cd3d78 100644 --- a/internal/persistence/inmemory/inmemory.go +++ b/internal/persistence/inmemory/inmemory.go @@ -121,7 +121,7 @@ func (rw *readWriter) GetLatest() ([]byte, error) { return rw.read.rawChkpt, nil } -func (rw *readWriter) Set(c []byte, rng []byte) error { +func (rw *readWriter) Set(c []byte) error { rw.toStore = &checkpointState{ rawChkpt: c, } diff --git a/internal/persistence/inmemory/inmemory_test.go b/internal/persistence/inmemory/inmemory_test.go index 51cff61..0bdb90c 100644 --- a/internal/persistence/inmemory/inmemory_test.go +++ b/internal/persistence/inmemory/inmemory_test.go @@ -59,7 +59,7 @@ func TestWriteOpsConcurrent(t *testing.T) { } } // Ignore any error on Set because we expect some. - _ = w.Set([]byte(fmt.Sprintf("success %d", i)), nil) + _ = w.Set([]byte(fmt.Sprintf("success %d", i))) return nil }) } diff --git a/internal/persistence/persistence.go b/internal/persistence/persistence.go index 899ca13..4654b2c 100644 --- a/internal/persistence/persistence.go +++ b/internal/persistence/persistence.go @@ -55,10 +55,9 @@ type LogStateReadOps interface { type LogStateWriteOps interface { LogStateReadOps - // Set sets a new checkpoint and (optional) compact range - // for the log. This commits the state to persistence. + // Set sets a new checkpoint for the log, committing the state to persistence. // After this call, only Close() should be called on this object. - Set(checkpointRaw []byte, compactRange []byte) error + Set(checkpointRaw []byte) error // Terminates the write operation, freeing all resources. // This method MUST be called. diff --git a/internal/persistence/sql/sql.go b/internal/persistence/sql/sql.go index c59fe44..5f7f7b5 100644 --- a/internal/persistence/sql/sql.go +++ b/internal/persistence/sql/sql.go @@ -102,8 +102,8 @@ func (w *writer) GetLatest() ([]byte, error) { return getLatestCheckpoint(w.tx.QueryRow, w.logID) } -func (w *writer) Set(c []byte, rng []byte) error { - _, err := w.tx.Exec(`INSERT OR REPLACE INTO chkpts (logID, chkpt, range) VALUES (?, ?, ?)`, w.logID, c, rng) +func (w *writer) Set(c []byte) error { + _, err := w.tx.Exec(`INSERT OR REPLACE INTO chkpts (logID, chkpt) VALUES (?, ?)`, w.logID, c) if err != nil { return fmt.Errorf("Exec(): %v", err) } diff --git a/internal/persistence/testonly/persistence.go b/internal/persistence/testonly/persistence.go index 9896009..842f8cd 100644 --- a/internal/persistence/testonly/persistence.go +++ b/internal/persistence/testonly/persistence.go @@ -97,7 +97,7 @@ func writeCheckpoint(lsp persistence.LogStatePersistence, id string) error { return fmt.Errorf("WriteOps(%s): %v", id, err) } defer writeOps.Close() - if err := writeOps.Set([]byte(fmt.Sprintf("%s cp", id)), nil); err != nil { + if err := writeOps.Set([]byte(fmt.Sprintf("%s cp", id))); err != nil { return fmt.Errorf("Set(%s): %v", id, err) } return nil diff --git a/internal/witness/witness.go b/internal/witness/witness.go index 5b880c4..dad5b22 100644 --- a/internal/witness/witness.go +++ b/internal/witness/witness.go @@ -175,7 +175,7 @@ func (w *Witness) Update(ctx context.Context, logID string, nextRaw []byte, cPro return nil, status.Errorf(codes.Internal, "couldn't sign input checkpoint: %v", err) } - if err := write.Set(signed, nil); err != nil { + if err := write.Set(signed); err != nil { return nil, status.Errorf(codes.Internal, "couldn't set TOFU checkpoint: %v", err) } counterUpdateSuccess.Inc(logID) @@ -210,7 +210,7 @@ func (w *Witness) Update(ctx context.Context, logID string, nextRaw []byte, cPro if err != nil { return nil, status.Errorf(codes.Internal, "couldn't sign input checkpoint: %v", err) } - if err := write.Set(signed, nil); err != nil { + if err := write.Set(signed); err != nil { return nil, status.Errorf(codes.Internal, "couldn't set first non-zero checkpoint: %v", err) } counterUpdateSuccess.Inc(logID) @@ -236,7 +236,7 @@ func (w *Witness) Update(ctx context.Context, logID string, nextRaw []byte, cPro if err != nil { return nil, status.Errorf(codes.Internal, "couldn't sign input checkpoint: %v", err) } - if err := write.Set(signed, nil); err != nil { + if err := write.Set(signed); err != nil { return nil, status.Errorf(codes.Internal, "failed to store new checkpoint: %v", err) } counterUpdateSuccess.Inc(logID)