Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

da interface: add max blob size method #23

Merged
merged 15 commits into from
Dec 7, 2023
3 changes: 3 additions & 0 deletions da.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package da

// DA defines very generic interface for interaction with Data Availability layers.
type DA interface {
// Config returns the max blob size
Config() (uint64, error)
tuxcanfly marked this conversation as resolved.
Show resolved Hide resolved

// Get returns Blob for each given ID, or an error.
//
// Error should be returned if ID is not formatted properly, there is no Blob for given ID or any other client-level
Expand Down
14 changes: 13 additions & 1 deletion proto/da/da.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package da;

// DAService is the protobuf service definition for interaction with Data Availability layers.
service DAService {
// Config returns the maximum blob size
rpc Config(ConfigRequest) returns (ConfigResponse) {}

// Get returns Blob for each given ID, or an error.
rpc Get(GetRequest) returns (GetResponse) {}

Expand Down Expand Up @@ -39,6 +42,15 @@ message Proof {
bytes value = 1;
}

// ConfigRequest is the request type for the Config rpc method.
message ConfigRequest {
}

// ConfigResponse is the response type for the Config rpc method.
message ConfigResponse {
uint64 max_blob_size = 1;
}

// GetRequest is the request type for the Get rpc method.
message GetRequest {
repeated ID ids = 1;
Expand Down Expand Up @@ -89,4 +101,4 @@ message ValidateRequest {
// ValidateResponse is the response type for the Validate rpc method.
message ValidateResponse {
repeated bool results = 1;
}
}
10 changes: 10 additions & 0 deletions proxy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ func (c *Client) Stop() error {
return c.conn.Close()
}

// Config returns the DA Config
func (c *Client) Config() (uint64, error) {
req := &pbda.ConfigRequest{}
resp, err := c.client.Config(context.TODO(), req)
tuxcanfly marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return 0, err
}
return resp.MaxBlobSize, nil
}

// Get returns Blob for each given ID, or an error.
func (c *Client) Get(ids []da.ID) ([]da.Blob, error) {
req := &pbda.GetRequest{
Expand Down
33 changes: 33 additions & 0 deletions proxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,35 @@ import (
pbda "github.com/rollkit/go-da/types/pb/da"
)

// The following consts are copied from appconsts to avoid dependency hell
const (
tuxcanfly marked this conversation as resolved.
Show resolved Hide resolved
// NamespaceVersionSize is the size of a namespace version in bytes.
NamespaceVersionSize = 1

// NamespaceIDSize is the size of a namespace ID in bytes.
NamespaceIDSize = 28

// NamespaceSize is the size of a namespace (version + ID) in bytes.
NamespaceSize = NamespaceVersionSize + NamespaceIDSize

// ShareSize is the size of a share in bytes.
ShareSize = 512

// ShareInfoBytes is the number of bytes reserved for information. The info
// byte contains the share version and a sequence start idicator.
ShareInfoBytes = 1

// ContinuationSparseShareContentSize is the number of bytes usable for data
// in a continuation sparse share of a sequence.
ContinuationSparseShareContentSize = ShareSize - NamespaceSize - ShareInfoBytes

// DefaultGovMaxSquareSize is the default value for the governance modifiable
// max square size.
DefaultGovMaxSquareSize = 64

DefaultMaxBytes = DefaultGovMaxSquareSize * DefaultGovMaxSquareSize * ContinuationSparseShareContentSize
)

// NewServer creates new gRPC Server configured to serve DA proxy.
func NewServer(d da.DA, opts ...grpc.ServerOption) *grpc.Server {
srv := grpc.NewServer(opts...)
Expand All @@ -24,6 +53,10 @@ type proxySrv struct {
target da.DA
}

func (p *proxySrv) Config(ctx context.Context, request *pbda.ConfigRequest) (*pbda.ConfigResponse, error) {
return &pbda.ConfigResponse{MaxBlobSize: DefaultMaxBytes}, nil
tuxcanfly marked this conversation as resolved.
Show resolved Hide resolved
}

func (p *proxySrv) Get(ctx context.Context, request *pbda.GetRequest) (*pbda.GetResponse, error) {
ids := idsPB2DA(request.Ids)
blobs, err := p.target.Get(ids)
Expand Down
5 changes: 5 additions & 0 deletions test/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ func NewDummyDA() *DummyDA {

var _ da.DA = &DummyDA{}

// Config returns the max blob size in bytes.
func (d *DummyDA) Config() (uint64, error) {
return 64 * 64 * 482, nil
tuxcanfly marked this conversation as resolved.
Show resolved Hide resolved
}

// Get returns Blobs for given IDs.
func (d *DummyDA) Get(ids []da.ID) ([]da.Blob, error) {
d.mu.Lock()
Expand Down
Loading