Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cache and fallback only work for OptimismGeneric and SimpleCommitment modes #156

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions store/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,31 +117,29 @@

// 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OptimismKeccak mode never reaches this code. I'm confused by this comment.

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)
// and returns an error if NONE of them succeed
Expand Down
Loading