Skip to content

Commit

Permalink
improvement!(blob/service): add options to submit (#2630)
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs authored Sep 7, 2023
1 parent cb46dc1 commit 9957618
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 16 deletions.
22 changes: 20 additions & 2 deletions blob/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,32 @@ func NewService(
}
}

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

// DefaultSubmitOptions creates a default fee and gas price values.
func DefaultSubmitOptions() *SubmitOptions {
return &SubmitOptions{
Fee: -1,
GasLimit: 0,
}
}

// Submit sends PFB transaction and reports the height in which it was included.
// Allows sending multiple Blobs atomically synchronously.
// Uses default wallet registered on the Node.
// Handles gas estimation and fee calculation.
func (s *Service) Submit(ctx context.Context, blobs []*Blob) (uint64, error) {
func (s *Service) Submit(ctx context.Context, blobs []*Blob, options *SubmitOptions) (uint64, error) {
log.Debugw("submitting blobs", "amount", len(blobs))

resp, err := s.blobSubmitter.SubmitPayForBlob(ctx, types.OneInt().Neg(), 0, blobs)
if options == nil {
options = DefaultSubmitOptions()
}

resp, err := s.blobSubmitter.SubmitPayForBlob(ctx, types.NewInt(options.Fee), options.GasLimit, blobs)
if err != nil {
return 0, err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/celestia/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ var submitCmd = &cobra.Command{
return fmt.Errorf("error creating a blob:%v", err)
}

height, err := client.Blob.Submit(cmd.Context(), []*blob.Blob{parsedBlob})
height, err := client.Blob.Submit(cmd.Context(), []*blob.Blob{parsedBlob}, nil)

response := struct {
Height uint64 `json:"height"`
Expand Down
8 changes: 4 additions & 4 deletions nodebuilder/blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Module interface {
// Submit sends Blobs and reports the height in which they were included.
// Allows sending multiple Blobs atomically synchronously.
// Uses default wallet registered on the Node.
Submit(_ context.Context, _ []*blob.Blob) (height uint64, _ error)
Submit(_ context.Context, _ []*blob.Blob, _ *blob.SubmitOptions) (height uint64, _ error)
// Get retrieves the blob by commitment under the given namespace and height.
Get(_ context.Context, height uint64, _ share.Namespace, _ blob.Commitment) (*blob.Blob, error)
// GetAll returns all blobs under the given namespaces and height.
Expand All @@ -30,16 +30,16 @@ type Module interface {

type API struct {
Internal struct {
Submit func(context.Context, []*blob.Blob) (uint64, error) `perm:"write"`
Submit func(context.Context, []*blob.Blob, *blob.SubmitOptions) (uint64, error) `perm:"write"`
Get func(context.Context, uint64, share.Namespace, blob.Commitment) (*blob.Blob, error) `perm:"read"`
GetAll func(context.Context, uint64, []share.Namespace) ([]*blob.Blob, error) `perm:"read"`
GetProof func(context.Context, uint64, share.Namespace, blob.Commitment) (*blob.Proof, error) `perm:"read"`
Included func(context.Context, uint64, share.Namespace, *blob.Proof, blob.Commitment) (bool, error) `perm:"read"`
}
}

func (api *API) Submit(ctx context.Context, blobs []*blob.Blob) (uint64, error) {
return api.Internal.Submit(ctx, blobs)
func (api *API) Submit(ctx context.Context, blobs []*blob.Blob, options *blob.SubmitOptions) (uint64, error) {
return api.Internal.Submit(ctx, blobs, options)
}

func (api *API) Get(
Expand Down
11 changes: 5 additions & 6 deletions nodebuilder/blob/mocks/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion nodebuilder/node/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/celestiaorg/celestia-node/libs/authtoken"
)

const APIVersion = "v0.2.1"
const APIVersion = "v0.2.2"

type module struct {
tp Type
Expand Down
2 changes: 1 addition & 1 deletion nodebuilder/tests/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestBlobRPC(t *testing.T) {
)
require.NoError(t, err)

height, err := client.Blob.Submit(ctx, []*blob.Blob{newBlob})
height, err := client.Blob.Submit(ctx, []*blob.Blob{newBlob}, nil)
require.NoError(t, err)
require.True(t, height != 0)
}
Expand Down
2 changes: 1 addition & 1 deletion nodebuilder/tests/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestBlobModule(t *testing.T) {
lightNode := sw.NewNodeWithConfig(node.Light, lightCfg)
require.NoError(t, lightNode.Start(ctx))

height, err := fullNode.BlobServ.Submit(ctx, blobs)
height, err := fullNode.BlobServ.Submit(ctx, blobs, nil)
require.NoError(t, err)

_, err = fullNode.HeaderServ.WaitForHeight(ctx, height)
Expand Down

0 comments on commit 9957618

Please sign in to comment.