Skip to content

Commit

Permalink
fix retrieval client
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-shim committed Jun 5, 2024
1 parent 43b4e97 commit ed946dd
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
8 changes: 4 additions & 4 deletions api/clients/retrieval_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,20 @@ func (r *retrievalClient) RetrieveBlob(
for i := 0; i < len(operators); i++ {
reply := <-chunksChan
if reply.Err != nil {
r.logger.Error("failed to get chunks from operator", "operator", reply.OperatorID, "err", reply.Err)
r.logger.Error("failed to get chunks from operator", "operator", reply.OperatorID.Hex(), "err", reply.Err)
continue
}
assignment, ok := assignments[reply.OperatorID]
if !ok {
return nil, fmt.Errorf("no assignment to operator %v", reply.OperatorID)
return nil, fmt.Errorf("no assignment to operator %s", reply.OperatorID.Hex())
}

err = r.verifier.VerifyFrames(reply.Chunks, assignment.GetIndices(), blobHeader.BlobCommitments, encodingParams)
if err != nil {
r.logger.Error("failed to verify chunks from operator", "operator", reply.OperatorID, "err", err)
r.logger.Error("failed to verify chunks from operator", "operator", reply.OperatorID.Hex(), "err", err)
continue
} else {
r.logger.Info("verified chunks from operator", "operator", reply.OperatorID)
r.logger.Info("verified chunks from operator", "operator", reply.OperatorID.Hex())
}

chunks = append(chunks, reply.Chunks...)
Expand Down
2 changes: 1 addition & 1 deletion retriever/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func RetrieverMain(ctx *cli.Context) error {
}

nodeClient := clients.NewNodeClient(config.Timeout)
v, err := verifier.NewVerifier(&config.EncoderConfig, false)
v, err := verifier.NewVerifier(&config.EncoderConfig, true)
if err != nil {
log.Fatalln("could not start tcp listener", err)
}
Expand Down
10 changes: 7 additions & 3 deletions retriever/eth/chain_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"math/big"

"github.com/Layr-Labs/eigenda/common"
binding "github.com/Layr-Labs/eigenda/contracts/bindings/EigenDAServiceManager"
Expand All @@ -14,7 +15,7 @@ import (
)

type ChainClient interface {
FetchBatchHeader(ctx context.Context, serviceManagerAddress gcommon.Address, batchHeaderHash []byte) (*binding.IEigenDAServiceManagerBatchHeader, error)
FetchBatchHeader(ctx context.Context, serviceManagerAddress gcommon.Address, batchHeaderHash []byte, fromBlock *big.Int, toBlock *big.Int) (*binding.IEigenDAServiceManagerBatchHeader, error)
}

type chainClient struct {
Expand All @@ -31,9 +32,12 @@ func NewChainClient(ethClient common.EthClient, logger logging.Logger) ChainClie

// FetchBatchHeader fetches batch header from chain given a service manager contract address and batch header hash.
// It filters logs by the batch header hashes which are logged as events by the service manager contract.
// From those logs, it identifies corresponding confirmBatch transaction and decodes batch header from the calldata
func (c *chainClient) FetchBatchHeader(ctx context.Context, serviceManagerAddress gcommon.Address, batchHeaderHash []byte) (*binding.IEigenDAServiceManagerBatchHeader, error) {
// From those logs, it identifies corresponding confirmBatch transaction and decodes batch header from the calldata.
// It takes fromBlock and toBlock as arguments to filter logs within a specific block range. This can help with optimizing queries to the chain. nil values for fromBlock and toBlock will default to genesis block and latest block respectively.
func (c *chainClient) FetchBatchHeader(ctx context.Context, serviceManagerAddress gcommon.Address, batchHeaderHash []byte, fromBlock *big.Int, toBlock *big.Int) (*binding.IEigenDAServiceManagerBatchHeader, error) {
logs, err := c.ethClient.FilterLogs(ctx, ethereum.FilterQuery{
FromBlock: fromBlock,
ToBlock: toBlock,
Addresses: []gcommon.Address{serviceManagerAddress},
Topics: [][]gcommon.Hash{
{common.BatchConfirmedEventSigHash},
Expand Down
2 changes: 1 addition & 1 deletion retriever/eth/chain_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestFetchBatchHeader(t *testing.T) {
R: r,
S: s,
}), false, nil)
batchHeader, err := chainClient.FetchBatchHeader(context.Background(), serviceManagerAddress, batchHeaderHash)
batchHeader, err := chainClient.FetchBatchHeader(context.Background(), serviceManagerAddress, batchHeaderHash, big.NewInt(86), nil)
assert.Nil(t, err)
assert.Equal(t, batchHeader.BlobHeadersRoot, expectedHeader.BlobHeadersRoot)
assert.Equal(t, batchHeader.QuorumNumbers, expectedHeader.QuorumNumbers)
Expand Down
3 changes: 2 additions & 1 deletion retriever/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package retriever
import (
"context"
"errors"
"math/big"

"github.com/Layr-Labs/eigenda/api/clients"
pb "github.com/Layr-Labs/eigenda/api/grpc/retriever"
Expand Down Expand Up @@ -56,7 +57,7 @@ func (s *Server) RetrieveBlob(ctx context.Context, req *pb.BlobRequest) (*pb.Blo
var batchHeaderHash [32]byte
copy(batchHeaderHash[:], req.GetBatchHeaderHash())

batchHeader, err := s.chainClient.FetchBatchHeader(ctx, gcommon.HexToAddress(s.config.EigenDAServiceManagerAddr), req.GetBatchHeaderHash())
batchHeader, err := s.chainClient.FetchBatchHeader(ctx, gcommon.HexToAddress(s.config.EigenDAServiceManagerAddr), req.GetBatchHeaderHash(), big.NewInt(int64(req.ReferenceBlockNumber)), nil)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit ed946dd

Please sign in to comment.