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

Redundant write on EigenDA failure #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions store/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"

"github.com/Layr-Labs/eigenda-proxy/commitments"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
)

Expand Down Expand Up @@ -123,6 +124,17 @@ func (m *Manager) Put(ctx context.Context, cm commitments.CommitmentMode, key, v
}

if err != nil {
log.Error("Failed to write to EigenDA backend", "err", err)
// write to EigenDA failed, which shouldn't happen if the backend is functioning properly
// use the payload as the key to avoid data loss
if m.secondary.Enabled() {
redundantErr := m.secondary.HandleRedundantWrites(ctx, value, value)
if redundantErr != nil {
log.Error("Failed to write to redundant backends", "err", redundantErr)
return nil, redundantErr
}
return crypto.Keccak256(value), nil
}
return nil, err
}

Expand Down
20 changes: 19 additions & 1 deletion store/secondary.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package store

import (
"bytes"
"context"
"errors"
"net/http"
"sync"

"github.com/Layr-Labs/eigenda-proxy/metrics"
verifypackage "github.com/Layr-Labs/eigenda-proxy/verify"
"github.com/ethereum-optimism/optimism/op-service/retry"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"

"github.com/ethereum/go-ethereum/log"
)
Expand Down Expand Up @@ -150,6 +153,14 @@ func (sm *SecondaryManager) MultiSourceRead(ctx context.Context, commitment []by
}

key := crypto.Keccak256(commitment)

// check if key is an RLP encoded certificate, if not, assume it's an s3 key
var cert verifypackage.Certificate
err := rlp.DecodeBytes(commitment, &cert)
if err != nil {
key = commitment
}

for _, src := range sources {
cb := sm.m.RecordSecondaryRequest(src.BackendType().String(), http.MethodGet)
data, err := src.Get(ctx, key)
Expand All @@ -167,7 +178,14 @@ func (sm *SecondaryManager) MultiSourceRead(ctx context.Context, commitment []by

// verify cert:data using provided verification function
sm.verifyLock.Lock()
err = verify(ctx, commitment, data)

if bytes.Equal(key, commitment) {
err = src.Verify(ctx, commitment, data)
} else {
// verify cert:data using EigenDA verification checks
err = verify(ctx, commitment, data)
}

Comment on lines +181 to +188
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Optimize lock scope and improve verification logic.

The verification lock's scope is wider than necessary, and the branching logic could be more explicit.

-        sm.verifyLock.Lock()
+        var verifyErr error
+        sm.verifyLock.Lock()
         if bytes.Equal(key, commitment) {
-            err = src.Verify(ctx, commitment, data)
+            verifyErr = src.Verify(ctx, commitment, data)
         } else {
             // verify cert:data using EigenDA verification checks
-            err = verify(ctx, commitment, data)
+            verifyErr = verify(ctx, commitment, data)
         }
+        sm.verifyLock.Unlock()

-        if err != nil {
+        if verifyErr != nil {
             cb(Failed)
-            log.Warn("Failed to verify blob", "err", err, "backend", src.BackendType())
-            sm.verifyLock.Unlock()
+            log.Warn("Failed to verify blob", "err", verifyErr, "backend", src.BackendType(), "using_direct_key", bytes.Equal(key, commitment))
             continue
         }
-        sm.verifyLock.Unlock()

Committable suggestion skipped: line range outside the PR's diff.

if err != nil {
cb(Failed)
log.Warn("Failed to verify blob", "err", err, "backend", src.BackendType())
Expand Down
Loading