Skip to content

Commit

Permalink
Merge pull request #31 from rollkit/tux/gas-price
Browse files Browse the repository at this point in the history
da: replace submit options with gas price
  • Loading branch information
tuxcanfly authored Jan 10, 2024
2 parents 704b67e + 0707fa9 commit 755acd2
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 333 deletions.
17 changes: 1 addition & 16 deletions da.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package da

// SubmitOptions contains the information about fee and gas price in order to configure the
// Submit request.
type SubmitOptions struct {
Fee int64
Gas uint64
}

// DA defines very generic interface for interaction with Data Availability layers.
type DA interface {
// MaxBlobSize returns the max blob size
Expand All @@ -29,7 +22,7 @@ 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(blobs []Blob, options *SubmitOptions) ([]ID, []Proof, error)
Submit(blobs []Blob, gasPrice float64) ([]ID, []Proof, error)

// Validate validates Commitments against the corresponding Proofs. This should be possible without retrieving the Blobs.
Validate(ids []ID, proofs []Proof) ([]bool, error)
Expand All @@ -46,11 +39,3 @@ type Commitment = []byte

// Proof should contain serialized proof of inclusion (publication) of Blob in Data Availability layer.
type Proof = []byte

// DefaultSubmitOptions creates a default fee and gas price values.
func DefaultSubmitOptions() *SubmitOptions {
return &SubmitOptions{
Fee: -1,
Gas: 0,
}
}
8 changes: 1 addition & 7 deletions proto/da/da.proto
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,10 @@ message CommitResponse {
repeated Commitment commitments = 1;
}

// SubmitOptions is the options type for the Submit method.
message SubmitOptions {
int64 fee = 1;
uint64 gas = 2;
}

// SubmitRequest is the request type for the Submit rpc method.
message SubmitRequest {
repeated Blob blobs = 1;
SubmitOptions options = 2;
double gas_price = 2;
}

// SubmitResponse is the response type for the Submit rpc method.
Expand Down
6 changes: 3 additions & 3 deletions proxy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ func (c *Client) Commit(blobs []da.Blob) ([]da.Commitment, error) {
}

// Submit submits the Blobs to Data Availability layer.
func (c *Client) Submit(blobs []da.Blob, options *da.SubmitOptions) ([]da.ID, []da.Proof, error) {
func (c *Client) Submit(blobs []da.Blob, gasPrice float64) ([]da.ID, []da.Proof, error) {
req := &pbda.SubmitRequest{
Blobs: blobsDA2PB(blobs),
Options: optionsDA2PB(options),
Blobs: blobsDA2PB(blobs),
GasPrice: gasPrice,
}

resp, err := c.client.Submit(context.TODO(), req)
Expand Down
3 changes: 1 addition & 2 deletions proxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ 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)
options := optionsPB2DA(request.GetOptions())

ids, proofs, err := p.target.Submit(blobs, options)
ids, proofs, err := p.target.Submit(blobs, request.GasPrice)
if err != nil {
return nil, err
}
Expand Down
20 changes: 0 additions & 20 deletions proxy/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,6 @@ func blobsPB2DA(pb []*pbda.Blob) []da.Blob {
return blobs
}

func optionsDA2PB(options *da.SubmitOptions) *pbda.SubmitOptions {
if options != nil {
return &pbda.SubmitOptions{
Fee: options.Fee,
Gas: options.Gas,
}
}
return &pbda.SubmitOptions{Fee: -1}
}

func optionsPB2DA(pb *pbda.SubmitOptions) *da.SubmitOptions {
if pb != nil {
return &da.SubmitOptions{
Fee: pb.Fee,
Gas: pb.Gas,
}
}
return da.DefaultSubmitOptions()
}

func idsPB2DA(pb []*pbda.ID) []da.ID {
ids := make([]da.ID, len(pb))
for i := range ids {
Expand Down
2 changes: 1 addition & 1 deletion test/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (d *DummyDA) Commit(blobs []da.Blob) ([]da.Commitment, error) {
}

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

id1, proof1, err := da.Submit([]Blob{msg1}, nil)
id1, proof1, err := da.Submit([]Blob{msg1}, -1)
assert.NoError(t, err)
assert.NotEmpty(t, id1)
assert.NotEmpty(t, proof1)

id2, proof2, err := da.Submit([]Blob{msg2}, nil)
id2, proof2, err := da.Submit([]Blob{msg2}, -1)
assert.NoError(t, err)
assert.NotEmpty(t, id2)
assert.NotEmpty(t, proof2)

id3, proof3, err := da.Submit([]Blob{msg1}, nil)
id3, proof3, err := da.Submit([]Blob{msg1}, -1)
assert.NoError(t, err)
assert.NotEmpty(t, id3)
assert.NotEmpty(t, proof3)
Expand Down Expand Up @@ -110,7 +110,7 @@ func CheckErrors(t *testing.T, da da.DA) {
func GetIDsTest(t *testing.T, da da.DA) {
msgs := [][]byte{[]byte("msg1"), []byte("msg2"), []byte("msg3")}

ids, proofs, err := da.Submit(msgs, nil)
ids, proofs, err := da.Submit(msgs, -1)
assert.NoError(t, err)
assert.Len(t, ids, len(msgs))
assert.Len(t, proofs, len(msgs))
Expand Down Expand Up @@ -162,7 +162,7 @@ func ConcurrentReadWriteTest(t *testing.T, da da.DA) {
go func() {
defer wg.Done()
for i := uint64(1); i <= 100; i++ {
_, _, err := da.Submit([][]byte{[]byte("test")}, nil)
_, _, err := da.Submit([][]byte{[]byte("test")}, -1)
assert.NoError(t, err)
}
}()
Expand Down
Loading

0 comments on commit 755acd2

Please sign in to comment.