Skip to content

Commit

Permalink
fix: cache and fallback only work for OptimismGeneric and SimpleCommi…
Browse files Browse the repository at this point in the history
…tmentMode
  • Loading branch information
mcortesi committed Sep 27, 2024
1 parent d4ef8c5 commit 8d9b5c5
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions store/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,30 +117,28 @@ func (r *Router) Get(ctx context.Context, key []byte, cm commitments.CommitmentM

// Put ... inserts a value into a storage backend based on the commitment mode
func (r *Router) Put(ctx context.Context, cm commitments.CommitmentMode, key, value []byte) ([]byte, error) {
var commit []byte
var err error

switch cm {
case commitments.OptimismKeccak: // caching and fallbacks are unsupported for this commitment mode
return r.putWithKey(ctx, key, value)
case commitments.OptimismGeneric, commitments.SimpleCommitmentMode:
commit, err = r.putWithoutKey(ctx, value)
default:
return nil, fmt.Errorf("unknown commitment mode")
}

if err != nil {
return nil, err
}

if r.cacheEnabled() || r.fallbackEnabled() {
err = r.handleRedundantWrites(ctx, commit, value)
commit, err := r.putWithoutKey(ctx, value)
if err != nil {
log.Error("Failed to write to redundant backends", "err", err)
return nil, err
}

if r.cacheEnabled() || r.fallbackEnabled() {
// FIXME commit here might be nil for OptimismKeccak mode
err = r.handleRedundantWrites(ctx, commit, value)
if err != nil {
log.Error("Failed to write to redundant backends", "err", err)
}
}

return commit, nil
default:
return nil, fmt.Errorf("unknown commitment mode")
}

return commit, nil
}

Check failure on line 142 in store/router.go

View workflow job for this annotation

GitHub Actions / Linter

unnecessary trailing newline (whitespace)

// handleRedundantWrites ... writes to both sets of backends (i.e, fallback, cache)
Expand Down

0 comments on commit 8d9b5c5

Please sign in to comment.