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

improvement!(blob/service): add options to submit #2630

Merged
merged 7 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
vgonkivs marked this conversation as resolved.
Show resolved Hide resolved
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"
vgonkivs marked this conversation as resolved.
Show resolved Hide resolved

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
Loading