Skip to content

Commit

Permalink
fix!(blob/module): fix api by changing variadic params to a slice (#2298
Browse files Browse the repository at this point in the history
)
  • Loading branch information
vgonkivs authored Jun 1, 2023
1 parent 218ab99 commit c77f6db
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 50 deletions.
2 changes: 1 addition & 1 deletion api/gateway/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (h *Handler) handleSubmitPFB(w http.ResponseWriter, r *http.Request) {
}

// perform request
txResp, err := h.state.SubmitPayForBlob(r.Context(), fee, req.GasLimit, blob)
txResp, err := h.state.SubmitPayForBlob(r.Context(), fee, req.GasLimit, []*apptypes.Blob{blob})
if err != nil {
writeError(w, http.StatusInternalServerError, submitPFBEndpoint, err)
return
Expand Down
6 changes: 3 additions & 3 deletions blob/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewService(
// 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.
func (s *Service) Submit(ctx context.Context, blobs ...*Blob) (uint64, error) {
func (s *Service) Submit(ctx context.Context, blobs []*Blob) (uint64, error) {
log.Debugw("submitting blobs", "amount", len(blobs))

var (
Expand All @@ -66,7 +66,7 @@ func (s *Service) Submit(ctx context.Context, blobs ...*Blob) (uint64, error) {
b[i] = &blob.Blob
}

resp, err := s.accessor.SubmitPayForBlob(ctx, types.NewInt(fee), gasLimit, b...)
resp, err := s.accessor.SubmitPayForBlob(ctx, types.NewInt(fee), gasLimit, b)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -99,7 +99,7 @@ func (s *Service) GetProof(

// GetAll returns all blobs under the given namespaces at the given height.
// GetAll can return blobs and an error in case if some requests failed.
func (s *Service) GetAll(ctx context.Context, height uint64, nIDs ...namespace.ID) ([]*Blob, error) {
func (s *Service) GetAll(ctx context.Context, height uint64, nIDs []namespace.ID) ([]*Blob, error) {
header, err := s.headerGetter(ctx, height)
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions blob/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestBlobService_Get(t *testing.T) {
{
name: "get all with the same nID",
doFn: func() (interface{}, error) {
b, err := service.GetAll(ctx, 1, blobs1[0].Namespace())
b, err := service.GetAll(ctx, 1, []namespace.ID{blobs1[0].Namespace()})
return b, err
},
expectedResult: func(res interface{}, err error) {
Expand All @@ -93,7 +93,7 @@ func TestBlobService_Get(t *testing.T) {
{
name: "get all with different nIDs",
doFn: func() (interface{}, error) {
b, err := service.GetAll(ctx, 1, blobs0[0].Namespace(), blobs0[1].Namespace())
b, err := service.GetAll(ctx, 1, []namespace.ID{blobs0[0].Namespace(), blobs0[1].Namespace()})
return b, err
},
expectedResult: func(res interface{}, err error) {
Expand Down Expand Up @@ -257,7 +257,7 @@ func TestBlobService_Get(t *testing.T) {
name: "get all not found",
doFn: func() (interface{}, error) {
nID := tmrand.Bytes(appconsts.NamespaceSize)
return service.GetAll(ctx, 1, nID)
return service.GetAll(ctx, 1, []namespace.ID{nID})
},
expectedResult: func(i interface{}, err error) {
blobs, ok := i.([]*Blob)
Expand Down Expand Up @@ -406,7 +406,7 @@ func TestService_GetAllWithoutPadding(t *testing.T) {

service := NewService(nil, getters.NewIPLDGetter(bs), fn)

_, err = service.GetAll(ctx, 1, blobs[0].Namespace(), blobs[1].Namespace())
_, err = service.GetAll(ctx, 1, []namespace.ID{blobs[0].Namespace(), blobs[1].Namespace()})
require.NoError(t, err)
}

Expand Down
16 changes: 8 additions & 8 deletions nodebuilder/blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ 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) (height uint64, _ error)
// Get retrieves the blob by commitment under the given namespace and height.
Get(_ context.Context, height uint64, _ namespace.ID, _ blob.Commitment) (*blob.Blob, error)
// GetAll returns all blobs under the given namespaces and height.
GetAll(_ context.Context, height uint64, _ ...namespace.ID) ([]*blob.Blob, error)
GetAll(_ context.Context, height uint64, _ []namespace.ID) ([]*blob.Blob, error)
// GetProof retrieves proofs in the given namespaces at the given height by commitment.
GetProof(_ context.Context, height uint64, _ namespace.ID, _ blob.Commitment) (*blob.Proof, error)
// Included checks whether a blob's given commitment(Merkle subtree root) is included at
Expand All @@ -31,16 +31,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) (uint64, error) `perm:"write"`
Get func(context.Context, uint64, namespace.ID, blob.Commitment) (*blob.Blob, error) `perm:"read"`
GetAll func(context.Context, uint64, ...namespace.ID) ([]*blob.Blob, error) `perm:"read"`
GetAll func(context.Context, uint64, []namespace.ID) ([]*blob.Blob, error) `perm:"read"`
GetProof func(context.Context, uint64, namespace.ID, blob.Commitment) (*blob.Proof, error) `perm:"read"`
Included func(context.Context, uint64, namespace.ID, *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) (uint64, error) {
return api.Internal.Submit(ctx, blobs)
}

func (api *API) Get(
Expand All @@ -52,8 +52,8 @@ func (api *API) Get(
return api.Internal.Get(ctx, height, nID, commitment)
}

func (api *API) GetAll(ctx context.Context, height uint64, nIDs ...namespace.ID) ([]*blob.Blob, error) {
return api.Internal.GetAll(ctx, height, nIDs...)
func (api *API) GetAll(ctx context.Context, height uint64, nIDs []namespace.ID) ([]*blob.Blob, error) {
return api.Internal.GetAll(ctx, height, nIDs)
}

func (api *API) GetProof(
Expand Down
26 changes: 8 additions & 18 deletions nodebuilder/blob/mocks/api.go

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

13 changes: 4 additions & 9 deletions nodebuilder/state/mocks/api.go

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

8 changes: 4 additions & 4 deletions nodebuilder/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type Module interface {
ctx context.Context,
fee state.Int,
gasLim uint64,
blobs ...*apptypes.Blob,
blobs []*apptypes.Blob,
) (*state.TxResponse, error)

// CancelUnbondingDelegation cancels a user's pending undelegation from a validator.
Expand Down Expand Up @@ -114,7 +114,7 @@ type API struct {
ctx context.Context,
fee state.Int,
gasLim uint64,
blobs ...*apptypes.Blob,
blobs []*apptypes.Blob,
) (*state.TxResponse, error) `perm:"write"`
CancelUnbondingDelegation func(
ctx context.Context,
Expand Down Expand Up @@ -192,9 +192,9 @@ func (api *API) SubmitPayForBlob(
ctx context.Context,
fee state.Int,
gasLim uint64,
blobs ...*apptypes.Blob,
blobs []*apptypes.Blob,
) (*state.TxResponse, error) {
return api.Internal.SubmitPayForBlob(ctx, fee, gasLim, blobs...)
return api.Internal.SubmitPayForBlob(ctx, fee, gasLim, blobs)
}

func (api *API) CancelUnbondingDelegation(
Expand Down
43 changes: 43 additions & 0 deletions nodebuilder/tests/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,60 @@ package tests

import (
"context"
"fmt"
"testing"

"github.com/filecoin-project/go-jsonrpc/auth"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/stretchr/testify/require"

"github.com/celestiaorg/celestia-node/api/rpc/client"
"github.com/celestiaorg/celestia-node/blob"
"github.com/celestiaorg/celestia-node/blob/blobtest"
"github.com/celestiaorg/celestia-node/libs/authtoken"
"github.com/celestiaorg/celestia-node/nodebuilder"
"github.com/celestiaorg/celestia-node/nodebuilder/node"
"github.com/celestiaorg/celestia-node/nodebuilder/tests/swamp"
)

// TestBlobRPC ensures that blobs can be submited via rpc
func TestBlobRPC(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), swamp.DefaultTestTimeout)
t.Cleanup(cancel)

sw := swamp.NewSwamp(t, swamp.WithBlockTime(btime))

// start a bridge node
bridge := sw.NewBridgeNode()
err := bridge.Start(ctx)
require.NoError(t, err)

signer := bridge.AdminSigner
bridgeAddr := "http://" + bridge.RPCServer.ListenAddr()
fmt.Println("bridgeAddr: ", bridgeAddr)

jwt, err := authtoken.NewSignedJWT(signer, []auth.Permission{"public", "read", "write", "admin"})
require.NoError(t, err)

client, err := client.NewClient(ctx, bridgeAddr, jwt)
require.NoError(t, err)

appBlobs, err := blobtest.GenerateBlobs([]int{8}, false)
require.NoError(t, err)

newBlob, err := blob.NewBlob(
appBlobs[0].ShareVersion,
append([]byte{appBlobs[0].NamespaceVersion}, appBlobs[0].NamespaceID...),
appBlobs[0].Data,
)
require.NoError(t, err)

height, err := client.Blob.Submit(ctx, []*blob.Blob{newBlob})
require.NoError(t, err)
require.True(t, height != 0)
}

// TestHeaderSubscription ensures that the header subscription over RPC works
// as intended and gets canceled successfully after rpc context cancellation.
func TestHeaderSubscription(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions nodebuilder/tests/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"
"time"

"github.com/celestiaorg/nmt/namespace"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -54,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)
require.NoError(t, err)

_, err = fullNode.HeaderServ.WaitForHeight(ctx, height)
Expand All @@ -77,7 +78,7 @@ func TestBlobModule(t *testing.T) {
{
name: "GetAll",
doFn: func(t *testing.T) {
newBlobs, err := fullNode.BlobServ.GetAll(ctx, height, blobs[0].Namespace())
newBlobs, err := fullNode.BlobServ.GetAll(ctx, height, []namespace.ID{blobs[0].Namespace()})
require.NoError(t, err)
require.Len(t, newBlobs, len(appBlobs0))
require.True(t, bytes.Equal(blobs[0].Commitment, newBlobs[0].Commitment))
Expand Down
2 changes: 1 addition & 1 deletion state/core_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (ca *CoreAccessor) SubmitPayForBlob(
ctx context.Context,
fee Int,
gasLim uint64,
blobs ...*apptypes.Blob,
blobs []*apptypes.Blob,
) (*TxResponse, error) {
if len(blobs) == 0 {
return nil, errors.New("state: no blobs provided")
Expand Down

0 comments on commit c77f6db

Please sign in to comment.