From ed946dd6dff9b5bb5833b4160407431652ea67c2 Mon Sep 17 00:00:00 2001 From: Ian Shim Date: Thu, 6 Jun 2024 05:29:43 +0900 Subject: [PATCH] fix retrieval client --- api/clients/retrieval_client.go | 8 ++++---- retriever/cmd/main.go | 2 +- retriever/eth/chain_client.go | 10 +++++++--- retriever/eth/chain_client_test.go | 2 +- retriever/server.go | 3 ++- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/api/clients/retrieval_client.go b/api/clients/retrieval_client.go index cb9f0d4cf5..70693787b2 100644 --- a/api/clients/retrieval_client.go +++ b/api/clients/retrieval_client.go @@ -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...) diff --git a/retriever/cmd/main.go b/retriever/cmd/main.go index dda8967ace..ab03ec6eff 100644 --- a/retriever/cmd/main.go +++ b/retriever/cmd/main.go @@ -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) } diff --git a/retriever/eth/chain_client.go b/retriever/eth/chain_client.go index 785027c4db..5660fdf9ca 100644 --- a/retriever/eth/chain_client.go +++ b/retriever/eth/chain_client.go @@ -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" @@ -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 { @@ -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}, diff --git a/retriever/eth/chain_client_test.go b/retriever/eth/chain_client_test.go index b79ee577ad..0b3c3c9e20 100644 --- a/retriever/eth/chain_client_test.go +++ b/retriever/eth/chain_client_test.go @@ -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) diff --git a/retriever/server.go b/retriever/server.go index 190c9fa177..d49f8dbf7f 100644 --- a/retriever/server.go +++ b/retriever/server.go @@ -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" @@ -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 }