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 9d57b06
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 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
7 changes: 5 additions & 2 deletions retriever/eth/chain_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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")

Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion retriever/mock/chain_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}
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 9d57b06

Please sign in to comment.