diff --git a/blob/service.go b/blob/service.go index 31cd259efc..05139cdfb5 100644 --- a/blob/service.go +++ b/blob/service.go @@ -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 } diff --git a/cmd/celestia/blob.go b/cmd/celestia/blob.go index 8ab130c24d..0d09268257 100644 --- a/cmd/celestia/blob.go +++ b/cmd/celestia/blob.go @@ -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"` diff --git a/nodebuilder/blob/blob.go b/nodebuilder/blob/blob.go index aae502824c..5e29d3b90c 100644 --- a/nodebuilder/blob/blob.go +++ b/nodebuilder/blob/blob.go @@ -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. @@ -30,7 +30,7 @@ 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"` @@ -38,8 +38,8 @@ type API struct { } } -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( diff --git a/nodebuilder/blob/mocks/api.go b/nodebuilder/blob/mocks/api.go index 5cd34b74b6..6a994f4d7c 100644 --- a/nodebuilder/blob/mocks/api.go +++ b/nodebuilder/blob/mocks/api.go @@ -8,10 +8,9 @@ import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" - blob "github.com/celestiaorg/celestia-node/blob" share "github.com/celestiaorg/celestia-node/share" + gomock "github.com/golang/mock/gomock" ) // MockModule is a mock of Module interface. @@ -98,16 +97,16 @@ func (mr *MockModuleMockRecorder) Included(arg0, arg1, arg2, arg3, arg4 interfac } // Submit mocks base method. -func (m *MockModule) Submit(arg0 context.Context, arg1 []*blob.Blob) (uint64, error) { +func (m *MockModule) Submit(arg0 context.Context, arg1 []*blob.Blob, arg2 *blob.SubmitOptions) (uint64, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Submit", arg0, arg1) + ret := m.ctrl.Call(m, "Submit", arg0, arg1, arg2) ret0, _ := ret[0].(uint64) ret1, _ := ret[1].(error) return ret0, ret1 } // Submit indicates an expected call of Submit. -func (mr *MockModuleMockRecorder) Submit(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockModuleMockRecorder) Submit(arg0, arg1, arg2 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Submit", reflect.TypeOf((*MockModule)(nil).Submit), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Submit", reflect.TypeOf((*MockModule)(nil).Submit), arg0, arg1, arg2) } diff --git a/nodebuilder/node/admin.go b/nodebuilder/node/admin.go index c6c97625ef..03c9cf1b52 100644 --- a/nodebuilder/node/admin.go +++ b/nodebuilder/node/admin.go @@ -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 diff --git a/nodebuilder/tests/api_test.go b/nodebuilder/tests/api_test.go index 3a66c4e58c..0e225668bb 100644 --- a/nodebuilder/tests/api_test.go +++ b/nodebuilder/tests/api_test.go @@ -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) } diff --git a/nodebuilder/tests/blob_test.go b/nodebuilder/tests/blob_test.go index a9e3a0464b..80fee071fb 100644 --- a/nodebuilder/tests/blob_test.go +++ b/nodebuilder/tests/blob_test.go @@ -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)