Skip to content

Commit

Permalink
Redundant write on EigenDA failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Inkvi committed Jan 14, 2025
1 parent ad966a5 commit 0a81b77
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
12 changes: 12 additions & 0 deletions store/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

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

Expand Down Expand Up @@ -124,6 +125,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,15 +1,18 @@
package store

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

"github.com/Layr-Labs/eigenda-proxy/common"
"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 @@ -151,6 +154,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 @@ -168,7 +179,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)
}

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

0 comments on commit 0a81b77

Please sign in to comment.