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..20df7b9792 100644 --- a/retriever/eth/chain_client_test.go +++ b/retriever/eth/chain_client_test.go @@ -28,7 +28,10 @@ func TestFetchBatchHeader(t *testing.T) { {gcommon.BytesToHash(batchHeaderHash)}, } txHash := gcommon.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000") + refBlock := 86 ethClient.On("FilterLogs", ethereum.FilterQuery{ + FromBlock: big.NewInt(int64(refBlock)), + ToBlock: nil, Addresses: []gcommon.Address{serviceManagerAddress}, Topics: topics, }).Return([]types.Log{ @@ -49,7 +52,7 @@ func TestFetchBatchHeader(t *testing.T) { BlobHeadersRoot: [32]byte{0}, QuorumNumbers: []byte{0}, SignedStakeForQuorums: []byte{100}, - ReferenceBlockNumber: 86, + ReferenceBlockNumber: uint32(refBlock), } calldata, err := hex.DecodeString("7794965a000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000560000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000001c01b4136a161225e9cebe4e2c561148043b2fde423fc5b64e01d897d0fb7970a142d5474fb609bda1b747bdb5c47375d5819000e3c5cbc75baf55b19849410a2610de9c40eb95b49aca940e0bec6ae8b2868855a6324d04d864cbfa61128cf06a51c069e5a0c490c5a359086b0a3660c2ea2e4fb50722bec1ef593c5245413e4cd0a3c7e490348fb279ccb58f91a3bd494511c2ab0321e3922a0cd26012ef3133c043acb758e735db805d360196f3fc89a6395a4b174c19b981afb7f64c2b1193e0000000000000000000000000000000000000000000000000000000000000220000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001170c867415fef7db6d88e37598228f43de085616a25939dacbb6b5900f680c7f1d582c9ea38023afb08f368ea93692d17946619d9cf5f3c4d7b3c0cff1a92dff0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000") @@ -73,7 +76,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(int64(refBlock)), nil) assert.Nil(t, err) assert.Equal(t, batchHeader.BlobHeadersRoot, expectedHeader.BlobHeadersRoot) assert.Equal(t, batchHeader.QuorumNumbers, expectedHeader.QuorumNumbers) diff --git a/retriever/mock/chain_client.go b/retriever/mock/chain_client.go index 9e2cb7cbd5..668b62b37f 100644 --- a/retriever/mock/chain_client.go +++ b/retriever/mock/chain_client.go @@ -2,6 +2,7 @@ package mock import ( "context" + "math/big" binding "github.com/Layr-Labs/eigenda/contracts/bindings/EigenDAServiceManager" "github.com/Layr-Labs/eigenda/retriever/eth" @@ -19,7 +20,7 @@ func NewMockChainClient() *MockChainClient { return &MockChainClient{} } -func (c *MockChainClient) FetchBatchHeader(ctx context.Context, serviceManagerAddress gcommon.Address, batchHeaderHash []byte) (*binding.IEigenDAServiceManagerBatchHeader, error) { +func (c *MockChainClient) FetchBatchHeader(ctx context.Context, serviceManagerAddress gcommon.Address, batchHeaderHash []byte, fromBlock *big.Int, toBlock *big.Int) (*binding.IEigenDAServiceManagerBatchHeader, error) { args := c.Called() return args.Get(0).(*binding.IEigenDAServiceManagerBatchHeader), args.Error(1) } 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 }