Skip to content

Commit d76d6d4

Browse files
committed
separate out client v2 package
1 parent 7b12ebf commit d76d6d4

19 files changed

+96
-74
lines changed
File renamed without changes.
File renamed without changes.

api/clients/disperser_client_v2.go renamed to api/clients/v2/disperser_client.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ import (
1616
"google.golang.org/grpc"
1717
)
1818

19-
type DisperserClientV2Config struct {
19+
type DisperserClientConfig struct {
2020
Hostname string
2121
Port string
2222
UseSecureGrpcFlag bool
2323
}
2424

25-
type DisperserClientV2 interface {
25+
type DisperserClient interface {
2626
Close() error
2727
DisperseBlob(ctx context.Context, data []byte, blobVersion corev2.BlobVersion, quorums []core.QuorumID, salt uint32) (*dispv2.BlobStatus, corev2.BlobKey, error)
2828
GetBlobStatus(ctx context.Context, blobKey corev2.BlobKey) (*disperser_rpc.BlobStatusReply, error)
2929
GetBlobCommitment(ctx context.Context, data []byte) (*disperser_rpc.BlobCommitmentReply, error)
3030
}
3131

32-
type disperserClientV2 struct {
33-
config *DisperserClientV2Config
32+
type disperserClient struct {
33+
config *DisperserClientConfig
3434
signer corev2.BlobRequestSigner
3535
initOnce sync.Once
3636
conn *grpc.ClientConn
@@ -39,18 +39,18 @@ type disperserClientV2 struct {
3939
accountant *Accountant
4040
}
4141

42-
var _ DisperserClientV2 = &disperserClientV2{}
42+
var _ DisperserClient = &disperserClient{}
4343

44-
// DisperserClientV2 maintains a single underlying grpc connection to the disperser server,
44+
// DisperserClient maintains a single underlying grpc connection to the disperser server,
4545
// through which it sends requests to disperse blobs and get blob status.
4646
// The connection is established lazily on the first method call. Don't forget to call Close(),
4747
// which is safe to call even if the connection was never established.
4848
//
49-
// DisperserClientV2 is safe to be used concurrently by multiple goroutines.
49+
// DisperserClient is safe to be used concurrently by multiple goroutines.
5050
//
5151
// Example usage:
5252
//
53-
// client := NewDisperserClientV2(config, signer)
53+
// client := NewDisperserClient(config, signer)
5454
// defer client.Close()
5555
//
5656
// // The connection will be established on the first call
@@ -61,7 +61,7 @@ var _ DisperserClientV2 = &disperserClientV2{}
6161
//
6262
// // Subsequent calls will use the existing connection
6363
// status2, blobKey2, err := client.DisperseBlob(ctx, data, blobHeader)
64-
func NewDisperserClientV2(config *DisperserClientV2Config, signer corev2.BlobRequestSigner, prover encoding.Prover, accountant *Accountant) (*disperserClientV2, error) {
64+
func NewDisperserClient(config *DisperserClientConfig, signer corev2.BlobRequestSigner, prover encoding.Prover, accountant *Accountant) (*disperserClient, error) {
6565
if config == nil {
6666
return nil, api.NewErrorInvalidArg("config must be provided")
6767
}
@@ -75,7 +75,7 @@ func NewDisperserClientV2(config *DisperserClientV2Config, signer corev2.BlobReq
7575
return nil, api.NewErrorInvalidArg("signer must be provided")
7676
}
7777

78-
return &disperserClientV2{
78+
return &disperserClient{
7979
config: config,
8080
signer: signer,
8181
prover: prover,
@@ -85,7 +85,7 @@ func NewDisperserClientV2(config *DisperserClientV2Config, signer corev2.BlobReq
8585
}
8686

8787
// PopulateAccountant populates the accountant with the payment state from the disperser.
88-
func (c *disperserClientV2) PopulateAccountant(ctx context.Context) error {
88+
func (c *disperserClient) PopulateAccountant(ctx context.Context) error {
8989
paymentState, err := c.GetPaymentState(ctx)
9090
if err != nil {
9191
return fmt.Errorf("error getting payment state for initializing accountant: %w", err)
@@ -100,7 +100,7 @@ func (c *disperserClientV2) PopulateAccountant(ctx context.Context) error {
100100

101101
// Close closes the grpc connection to the disperser server.
102102
// It is thread safe and can be called multiple times.
103-
func (c *disperserClientV2) Close() error {
103+
func (c *disperserClient) Close() error {
104104
if c.conn != nil {
105105
err := c.conn.Close()
106106
c.conn = nil
@@ -110,7 +110,7 @@ func (c *disperserClientV2) Close() error {
110110
return nil
111111
}
112112

113-
func (c *disperserClientV2) DisperseBlob(
113+
func (c *disperserClient) DisperseBlob(
114114
ctx context.Context,
115115
data []byte,
116116
blobVersion corev2.BlobVersion,
@@ -217,7 +217,7 @@ func (c *disperserClientV2) DisperseBlob(
217217
}
218218

219219
// GetBlobStatus returns the status of a blob with the given blob key.
220-
func (c *disperserClientV2) GetBlobStatus(ctx context.Context, blobKey corev2.BlobKey) (*disperser_rpc.BlobStatusReply, error) {
220+
func (c *disperserClient) GetBlobStatus(ctx context.Context, blobKey corev2.BlobKey) (*disperser_rpc.BlobStatusReply, error) {
221221
err := c.initOnceGrpcConnection()
222222
if err != nil {
223223
return nil, api.NewErrorInternal(err.Error())
@@ -230,7 +230,7 @@ func (c *disperserClientV2) GetBlobStatus(ctx context.Context, blobKey corev2.Bl
230230
}
231231

232232
// GetPaymentState returns the payment state of the disperser client
233-
func (c *disperserClientV2) GetPaymentState(ctx context.Context) (*disperser_rpc.GetPaymentStateReply, error) {
233+
func (c *disperserClient) GetPaymentState(ctx context.Context) (*disperser_rpc.GetPaymentStateReply, error) {
234234
err := c.initOnceGrpcConnection()
235235
if err != nil {
236236
return nil, api.NewErrorInternal(err.Error())
@@ -257,7 +257,7 @@ func (c *disperserClientV2) GetPaymentState(ctx context.Context) (*disperser_rpc
257257
// While the blob commitment can be calculated by anyone, it requires SRS points to
258258
// be loaded. For service that does not have access to SRS points, this method can be
259259
// used to calculate the blob commitment in blob header, which is required for dispersal.
260-
func (c *disperserClientV2) GetBlobCommitment(ctx context.Context, data []byte) (*disperser_rpc.BlobCommitmentReply, error) {
260+
func (c *disperserClient) GetBlobCommitment(ctx context.Context, data []byte) (*disperser_rpc.BlobCommitmentReply, error) {
261261
err := c.initOnceGrpcConnection()
262262
if err != nil {
263263
return nil, api.NewErrorInternal(err.Error())
@@ -271,7 +271,7 @@ func (c *disperserClientV2) GetBlobCommitment(ctx context.Context, data []byte)
271271

272272
// initOnceGrpcConnection initializes the grpc connection and client if they are not already initialized.
273273
// If initialization fails, it caches the error and will return it on every subsequent call.
274-
func (c *disperserClientV2) initOnceGrpcConnection() error {
274+
func (c *disperserClient) initOnceGrpcConnection() error {
275275
var initErr error
276276
c.initOnce.Do(func() {
277277
addr := fmt.Sprintf("%v:%v", c.config.Hostname, c.config.Port)

api/clients/mock/node_client_v2.go renamed to api/clients/v2/mock/node_client.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ package mock
33
import (
44
"context"
55

6-
"github.com/Layr-Labs/eigenda/api/clients"
6+
"github.com/Layr-Labs/eigenda/api/clients/v2"
77
"github.com/Layr-Labs/eigenda/core"
88
corev2 "github.com/Layr-Labs/eigenda/core/v2"
99
"github.com/stretchr/testify/mock"
1010
)
1111

12-
type MockNodeClientV2 struct {
12+
type MockNodeClient struct {
1313
mock.Mock
1414
}
1515

16-
var _ clients.NodeClientV2 = (*MockNodeClientV2)(nil)
16+
var _ clients.NodeClient = (*MockNodeClient)(nil)
1717

18-
func NewNodeClientV2() *MockNodeClientV2 {
19-
return &MockNodeClientV2{}
18+
func NewNodeClient() *MockNodeClient {
19+
return &MockNodeClient{}
2020
}
2121

22-
func (c *MockNodeClientV2) StoreChunks(ctx context.Context, batch *corev2.Batch) (*core.Signature, error) {
22+
func (c *MockNodeClient) StoreChunks(ctx context.Context, batch *corev2.Batch) (*core.Signature, error) {
2323
args := c.Called()
2424
var signature *core.Signature
2525
if args.Get(0) != nil {
@@ -28,7 +28,7 @@ func (c *MockNodeClientV2) StoreChunks(ctx context.Context, batch *corev2.Batch)
2828
return signature, args.Error(1)
2929
}
3030

31-
func (c *MockNodeClientV2) Close() error {
31+
func (c *MockNodeClient) Close() error {
3232
args := c.Called()
3333
return args.Error(0)
3434
}

api/clients/mock/relay_client.go renamed to api/clients/v2/mock/relay_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package mock
33
import (
44
"context"
55

6-
"github.com/Layr-Labs/eigenda/api/clients"
6+
"github.com/Layr-Labs/eigenda/api/clients/v2"
77
corev2 "github.com/Layr-Labs/eigenda/core/v2"
88
"github.com/stretchr/testify/mock"
99
)

api/clients/node_client_v2.go renamed to api/clients/v2/node_client.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,37 @@ import (
1212
"google.golang.org/grpc"
1313
)
1414

15-
type NodeClientV2Config struct {
15+
type NodeClientConfig struct {
1616
Hostname string
1717
Port string
1818
UseSecureGrpcFlag bool
1919
}
2020

21-
type NodeClientV2 interface {
21+
type NodeClient interface {
2222
StoreChunks(ctx context.Context, certs *corev2.Batch) (*core.Signature, error)
2323
Close() error
2424
}
2525

26-
type nodeClientV2 struct {
27-
config *NodeClientV2Config
26+
type nodeClient struct {
27+
config *NodeClientConfig
2828
initOnce sync.Once
2929
conn *grpc.ClientConn
3030

3131
dispersalClient nodegrpc.DispersalClient
3232
}
3333

34-
var _ NodeClientV2 = (*nodeClientV2)(nil)
34+
var _ NodeClient = (*nodeClient)(nil)
3535

36-
func NewNodeClientV2(config *NodeClientV2Config) (*nodeClientV2, error) {
36+
func NewNodeClient(config *NodeClientConfig) (*nodeClient, error) {
3737
if config == nil || config.Hostname == "" || config.Port == "" {
3838
return nil, fmt.Errorf("invalid config: %v", config)
3939
}
40-
return &nodeClientV2{
40+
return &nodeClient{
4141
config: config,
4242
}, nil
4343
}
4444

45-
func (c *nodeClientV2) StoreChunks(ctx context.Context, batch *corev2.Batch) (*core.Signature, error) {
45+
func (c *nodeClient) StoreChunks(ctx context.Context, batch *corev2.Batch) (*core.Signature, error) {
4646
if len(batch.BlobCertificates) == 0 {
4747
return nil, fmt.Errorf("no blob certificates in the batch")
4848
}
@@ -89,7 +89,7 @@ func (c *nodeClientV2) StoreChunks(ctx context.Context, batch *corev2.Batch) (*c
8989

9090
// Close closes the grpc connection to the disperser server.
9191
// It is thread safe and can be called multiple times.
92-
func (c *nodeClientV2) Close() error {
92+
func (c *nodeClient) Close() error {
9393
if c.conn != nil {
9494
err := c.conn.Close()
9595
c.conn = nil
@@ -99,7 +99,7 @@ func (c *nodeClientV2) Close() error {
9999
return nil
100100
}
101101

102-
func (c *nodeClientV2) initOnceGrpcConnection() error {
102+
func (c *nodeClient) initOnceGrpcConnection() error {
103103
var initErr error
104104
c.initOnce.Do(func() {
105105
addr := fmt.Sprintf("%v:%v", c.config.Hostname, c.config.Port)
File renamed without changes.

api/clients/retrieval_client_v2.go renamed to api/clients/v2/retrieval_client.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77

8+
"github.com/Layr-Labs/eigenda/api/clients"
89
grpcnode "github.com/Layr-Labs/eigenda/api/grpc/node/v2"
910
"github.com/Layr-Labs/eigenda/core"
1011
corev2 "github.com/Layr-Labs/eigenda/core/v2"
@@ -16,30 +17,30 @@ import (
1617
"github.com/gammazero/workerpool"
1718
)
1819

19-
// RetrievalClientV2 is an object that can retrieve blobs from the DA nodes.
20+
// RetrievalClient is an object that can retrieve blobs from the DA nodes.
2021
// To retrieve a blob from the relay, use RelayClient instead.
21-
type RetrievalClientV2 interface {
22+
type RetrievalClient interface {
2223
// GetBlob downloads chunks of a blob from operator network and reconstructs the blob.
2324
GetBlob(ctx context.Context, blobHeader corev2.BlobHeader, referenceBlockNumber uint64, quorumID core.QuorumID) ([]byte, error)
2425
}
2526

26-
type retrievalClientV2 struct {
27+
type retrievalClient struct {
2728
logger logging.Logger
2829
ethClient core.Reader
2930
indexedChainState core.IndexedChainState
3031
verifier encoding.Verifier
3132
numConnections int
3233
}
3334

34-
// NewRetrievalClientV2 creates a new retrieval client.
35-
func NewRetrievalClientV2(
35+
// NewRetrievalClient creates a new retrieval client.
36+
func NewRetrievalClient(
3637
logger logging.Logger,
3738
ethClient core.Reader,
3839
chainState core.IndexedChainState,
3940
verifier encoding.Verifier,
4041
numConnections int,
41-
) RetrievalClientV2 {
42-
return &retrievalClientV2{
42+
) RetrievalClient {
43+
return &retrievalClient{
4344
logger: logger.With("component", "RetrievalClient"),
4445
ethClient: ethClient,
4546
indexedChainState: chainState,
@@ -48,7 +49,7 @@ func NewRetrievalClientV2(
4849
}
4950
}
5051

51-
func (r *retrievalClientV2) GetBlob(ctx context.Context, blobHeader corev2.BlobHeader, referenceBlockNumber uint64, quorumID core.QuorumID) ([]byte, error) {
52+
func (r *retrievalClient) GetBlob(ctx context.Context, blobHeader corev2.BlobHeader, referenceBlockNumber uint64, quorumID core.QuorumID) ([]byte, error) {
5253
blobKey, err := blobHeader.BlobKey()
5354
if err != nil {
5455
return nil, err
@@ -90,7 +91,7 @@ func (r *retrievalClientV2) GetBlob(ctx context.Context, blobHeader corev2.BlobH
9091
}
9192

9293
// Fetch chunks from all operators
93-
chunksChan := make(chan RetrievedChunks, len(operators))
94+
chunksChan := make(chan clients.RetrievedChunks, len(operators))
9495
pool := workerpool.New(r.numConnections)
9596
for opID := range operators {
9697
opID := opID
@@ -139,13 +140,13 @@ func (r *retrievalClientV2) GetBlob(ctx context.Context, blobHeader corev2.BlobH
139140
)
140141
}
141142

142-
func (r *retrievalClientV2) getChunksFromOperator(
143+
func (r *retrievalClient) getChunksFromOperator(
143144
ctx context.Context,
144145
opID core.OperatorID,
145146
opInfo *core.IndexedOperatorInfo,
146147
blobKey corev2.BlobKey,
147148
quorumID core.QuorumID,
148-
chunksChan chan RetrievedChunks,
149+
chunksChan chan clients.RetrievedChunks,
149150
) {
150151
conn, err := grpc.NewClient(
151152
core.OperatorSocket(opInfo.Socket).GetRetrievalSocket(),
@@ -158,7 +159,7 @@ func (r *retrievalClientV2) getChunksFromOperator(
158159
}
159160
}()
160161
if err != nil {
161-
chunksChan <- RetrievedChunks{
162+
chunksChan <- clients.RetrievedChunks{
162163
OperatorID: opID,
163164
Err: err,
164165
Chunks: nil,
@@ -174,7 +175,7 @@ func (r *retrievalClientV2) getChunksFromOperator(
174175

175176
reply, err := n.GetChunks(ctx, request)
176177
if err != nil {
177-
chunksChan <- RetrievedChunks{
178+
chunksChan <- clients.RetrievedChunks{
178179
OperatorID: opID,
179180
Err: err,
180181
Chunks: nil,
@@ -187,7 +188,7 @@ func (r *retrievalClientV2) getChunksFromOperator(
187188
var chunk *encoding.Frame
188189
chunk, err = new(encoding.Frame).DeserializeGnark(data)
189190
if err != nil {
190-
chunksChan <- RetrievedChunks{
191+
chunksChan <- clients.RetrievedChunks{
191192
OperatorID: opID,
192193
Err: err,
193194
Chunks: nil,
@@ -197,7 +198,7 @@ func (r *retrievalClientV2) getChunksFromOperator(
197198

198199
chunks[i] = chunk
199200
}
200-
chunksChan <- RetrievedChunks{
201+
chunksChan <- clients.RetrievedChunks{
201202
OperatorID: opID,
202203
Err: nil,
203204
Chunks: chunks,

api/clients/v2/utils.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package clients
2+
3+
import (
4+
"crypto/tls"
5+
6+
"google.golang.org/grpc"
7+
"google.golang.org/grpc/credentials"
8+
"google.golang.org/grpc/credentials/insecure"
9+
)
10+
11+
func getGrpcDialOptions(useSecureGrpcFlag bool) []grpc.DialOption {
12+
options := []grpc.DialOption{}
13+
if useSecureGrpcFlag {
14+
options = append(options, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})))
15+
} else {
16+
options = append(options, grpc.WithTransportCredentials(insecure.NewCredentials()))
17+
}
18+
return options
19+
}

0 commit comments

Comments
 (0)