Skip to content

Commit

Permalink
Remove compact ranges from the persistence layer
Browse files Browse the repository at this point in the history
  • Loading branch information
mhutchinson committed Oct 23, 2024
1 parent 70d4c7a commit 02e4ab6
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 19 deletions.
8 changes: 0 additions & 8 deletions internal/feeder/sumdb/sumdb_feeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/persistence/inmemory/inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion internal/persistence/inmemory/inmemory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
Expand Down
5 changes: 2 additions & 3 deletions internal/persistence/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions internal/persistence/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/persistence/testonly/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions internal/witness/witness.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 02e4ab6

Please sign in to comment.