Skip to content

Commit

Permalink
changing submitoptions to gasprice,ns
Browse files Browse the repository at this point in the history
  • Loading branch information
distractedm1nd committed Jan 29, 2024
1 parent 049a87e commit 1520e98
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 35 deletions.
8 changes: 1 addition & 7 deletions da.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,12 @@ type DA interface {
// This method is synchronous. Upon successful submission to Data Availability layer, it returns ID identifying blob
// in DA and Proof of inclusion.
// If options is nil, default options are used.
Submit(ctx context.Context, blobs []Blob, opts *SubmitOptions) ([]ID, []Proof, error)
Submit(ctx context.Context, blobs []Blob, gasPrice float64, namespace Namespace) ([]ID, []Proof, error)

// Validate validates Commitments against the corresponding Proofs. This should be possible without retrieving the Blobs.
Validate(ctx context.Context, ids []ID, proofs []Proof) ([]bool, error)
}

// SubmitOptions are the parameters used for blob submission.
type SubmitOptions struct {
GasPrice float64
Namespace Namespace
}

// Namespace is an optional parameter used to set the location a blob should be
// posted to, for DA layers supporting the functionality.
type Namespace = []byte
Expand Down
6 changes: 3 additions & 3 deletions proxy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ func (c *Client) Commit(ctx context.Context, blobs []da.Blob, namespace da.Names
}

// Submit submits the Blobs to Data Availability layer.
func (c *Client) Submit(ctx context.Context, blobs []da.Blob, opts *da.SubmitOptions) ([]da.ID, []da.Proof, error) {
func (c *Client) Submit(ctx context.Context, blobs []da.Blob, gasPrice float64, namespace da.Namespace) ([]da.ID, []da.Proof, error) {
req := &pbda.SubmitRequest{
Blobs: blobsDA2PB(blobs),
GasPrice: opts.GasPrice,
Namespace: &pbda.Namespace{Value: opts.Namespace},
GasPrice: gasPrice,
Namespace: &pbda.Namespace{Value: namespace},
}

resp, err := c.client.Submit(ctx, req)
Expand Down
5 changes: 1 addition & 4 deletions proxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ func (p *proxySrv) Commit(ctx context.Context, request *pbda.CommitRequest) (*pb
func (p *proxySrv) Submit(ctx context.Context, request *pbda.SubmitRequest) (*pbda.SubmitResponse, error) {
blobs := blobsPB2DA(request.Blobs)

ids, proofs, err := p.target.Submit(ctx, blobs, &da.SubmitOptions{
GasPrice: request.GasPrice,
Namespace: request.Namespace.GetValue(),
})
ids, proofs, err := p.target.Submit(ctx, blobs, request.GasPrice, request.Namespace.GetValue())
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion test/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (d *DummyDA) Commit(ctx context.Context, blobs []da.Blob, _ da.Namespace) (
}

// Submit stores blobs in DA layer.
func (d *DummyDA) Submit(ctx context.Context, blobs []da.Blob, opts *da.SubmitOptions) ([]da.ID, []da.Proof, error) {
func (d *DummyDA) Submit(ctx context.Context, blobs []da.Blob, gasPrice float64, namespace da.Namespace) ([]da.ID, []da.Proof, error) {
d.mu.Lock()
defer d.mu.Unlock()
ids := make([]da.ID, len(blobs))
Expand Down
25 changes: 5 additions & 20 deletions test/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,17 @@ func BasicDATest(t *testing.T, d da.DA) {
msg2 := []byte("message 2")

ctx := context.TODO()
id1, proof1, err := d.Submit(ctx, []da.Blob{msg1}, &da.SubmitOptions{
GasPrice: 0,
Namespace: []byte{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
})
id1, proof1, err := d.Submit(ctx, []da.Blob{msg1}, 0, []byte{9, 8, 7, 6, 5, 4, 3, 2, 1, 0})
assert.NoError(t, err)
assert.NotEmpty(t, id1)
assert.NotEmpty(t, proof1)

id2, proof2, err := d.Submit(ctx, []da.Blob{msg2}, &da.SubmitOptions{
GasPrice: 0,
Namespace: []byte{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
})
id2, proof2, err := d.Submit(ctx, []da.Blob{msg2}, 0, []byte{9, 8, 7, 6, 5, 4, 3, 2, 1, 0})
assert.NoError(t, err)
assert.NotEmpty(t, id2)
assert.NotEmpty(t, proof2)

id3, proof3, err := d.Submit(ctx, []da.Blob{msg1}, &da.SubmitOptions{
GasPrice: 0,
Namespace: []byte{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
})
id3, proof3, err := d.Submit(ctx, []da.Blob{msg1}, 0, []byte{9, 8, 7, 6, 5, 4, 3, 2, 1, 0})
assert.NoError(t, err)
assert.NotEmpty(t, id3)
assert.NotEmpty(t, proof3)
Expand Down Expand Up @@ -115,10 +106,7 @@ func GetIDsTest(t *testing.T, d da.DA) {
msgs := [][]byte{[]byte("msg1"), []byte("msg2"), []byte("msg3")}

ctx := context.TODO()
ids, proofs, err := d.Submit(ctx, msgs, &da.SubmitOptions{
GasPrice: 0,
Namespace: []byte{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
})
ids, proofs, err := d.Submit(ctx, msgs, 0, []byte{9, 8, 7, 6, 5, 4, 3, 2, 1, 0})
assert.NoError(t, err)
assert.Len(t, ids, len(msgs))
assert.Len(t, proofs, len(msgs))
Expand Down Expand Up @@ -172,10 +160,7 @@ func ConcurrentReadWriteTest(t *testing.T, d da.DA) {
go func() {
defer wg.Done()
for i := uint64(1); i <= 100; i++ {
_, _, err := d.Submit(ctx, [][]byte{[]byte("test")}, &da.SubmitOptions{
GasPrice: 0,
Namespace: []byte{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
})
_, _, err := d.Submit(ctx, [][]byte{[]byte("test")}, 0, []byte{9, 8, 7, 6, 5, 4, 3, 2, 1, 0})
assert.NoError(t, err)
}
}()
Expand Down

0 comments on commit 1520e98

Please sign in to comment.