Skip to content

Commit

Permalink
fix: parity between state.SubmitPayForBlob and blob.Submit blob input…
Browse files Browse the repository at this point in the history
… types
  • Loading branch information
distractedm1nd committed Jun 8, 2023
1 parent ae8db72 commit bc97346
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 58 deletions.
12 changes: 6 additions & 6 deletions api/gateway/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/gorilla/mux"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
apptypes "github.com/celestiaorg/celestia-app/x/blob/types"

"github.com/celestiaorg/celestia-node/blob"
"github.com/celestiaorg/celestia-node/state"
)

Expand Down Expand Up @@ -141,14 +141,14 @@ func (h *Handler) handleSubmitPFB(w http.ResponseWriter, r *http.Request) {
}
fee := types.NewInt(req.Fee)

blob := &apptypes.Blob{
NamespaceId: nID,
Data: data,
ShareVersion: uint32(appconsts.DefaultShareVersion),
constructedBlob, err := blob.NewBlob(appconsts.DefaultShareVersion, nID, data)
if err != nil {
writeError(w, http.StatusBadRequest, submitPFBEndpoint, err)
return
}

// perform request
txResp, txerr := h.state.SubmitPayForBlob(r.Context(), fee, req.GasLimit, []*apptypes.Blob{blob})
txResp, txerr := h.state.SubmitPayForBlob(r.Context(), fee, req.GasLimit, []*blob.Blob{constructedBlob})
if txerr != nil && txResp == nil {
// no tx data to return
writeError(w, http.StatusInternalServerError, submitPFBEndpoint, err)
Expand Down
13 changes: 12 additions & 1 deletion api/gateway/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package gateway

import (
"bytes"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"net/http"
"net/http/httptest"
"testing"
Expand All @@ -12,6 +14,7 @@ import (
"github.com/stretchr/testify/require"

stateMock "github.com/celestiaorg/celestia-node/nodebuilder/state/mocks"
"github.com/celestiaorg/celestia-node/share"
"github.com/celestiaorg/celestia-node/state"
)

Expand All @@ -32,12 +35,20 @@ func TestHandleSubmitPFB(t *testing.T) {
mock.EXPECT().SubmitPayForBlob(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
Return(&txResponse, timedErr)

bs, err := json.Marshal(submitPFBRequest{})
ns, err := share.NewNamespaceV0([]byte("abc"))
require.NoError(t, err)
hexNs := hex.EncodeToString(ns[:])

bs, err := json.Marshal(submitPFBRequest{
NamespaceID: hexNs,
Data: "DEADBEEF",
})
require.NoError(t, err)
httpreq := httptest.NewRequest("GET", "/", bytes.NewReader(bs))
respRec := httptest.NewRecorder()
handler.handleSubmitPFB(respRec, httpreq)

fmt.Println(respRec.Body.String())
var resp state.TxResponse
err = json.NewDecoder(respRec.Body).Decode(&resp)
require.NoError(t, err)
Expand Down
23 changes: 12 additions & 11 deletions blob/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ import (
"fmt"
"sync"

"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/types"
logging "github.com/ipfs/go-log/v2"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/pkg/shares"
apptypes "github.com/celestiaorg/celestia-app/x/blob/types"
"github.com/celestiaorg/nmt/namespace"

"github.com/celestiaorg/celestia-node/header"
"github.com/celestiaorg/celestia-node/share"
"github.com/celestiaorg/celestia-node/state"
)

var (
Expand All @@ -26,22 +25,29 @@ var (
log = logging.Logger("blob")
)

// Submitter is an interface that allows submitting blobs to the celestia-core. It is used to
// avoid a circular dependency between the blob and the state package, since the state package needs
// the blob.Blob type for this signature.
type Submitter interface {
SubmitPayForBlob(ctx context.Context, fee math.Int, gasLim uint64, blobs []*Blob) (*types.TxResponse, error)
}

type Service struct {
// accessor dials the given celestia-core endpoint to submit blobs.
accessor *state.CoreAccessor
blobSumitter Submitter
// shareGetter retrieves the EDS to fetch all shares from the requested header.
shareGetter share.Getter
// headerGetter fetches header by the provided height
headerGetter func(context.Context, uint64) (*header.ExtendedHeader, error)
}

func NewService(
state *state.CoreAccessor,
submitter Submitter,
getter share.Getter,
headerGetter func(context.Context, uint64) (*header.ExtendedHeader, error),
) *Service {
return &Service{
accessor: state,
blobSumitter: submitter,
shareGetter: getter,
headerGetter: headerGetter,
}
Expand All @@ -56,14 +62,9 @@ func (s *Service) Submit(ctx context.Context, blobs []*Blob) (uint64, error) {
var (
gasLimit = estimateGas(blobs...)
fee = int64(appconsts.DefaultMinGasPrice * float64(gasLimit))
b = make([]*apptypes.Blob, len(blobs))
)

for i, blob := range blobs {
b[i] = &blob.Blob
}

resp, err := s.accessor.SubmitPayForBlob(ctx, types.NewInt(fee), gasLimit, b)
resp, err := s.blobSumitter.SubmitPayForBlob(ctx, types.NewInt(fee), gasLimit, blobs)
if err != nil {
return 0, err
}
Expand Down
12 changes: 5 additions & 7 deletions cmd/celestia/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/cosmos/cosmos-sdk/types"
"github.com/spf13/cobra"

apptypes "github.com/celestiaorg/celestia-app/x/blob/types"
"github.com/celestiaorg/nmt/namespace"

"github.com/celestiaorg/celestia-node/api/rpc/client"
Expand Down Expand Up @@ -190,12 +189,11 @@ func parseParams(method string, params []string) []interface{} {
panic("Error decoding blob: base64 string could not be decoded.")
}
}
parsedParams[2] = []*apptypes.Blob{{
NamespaceId: nID[1:],
Data: blobData,
ShareVersion: 0,
NamespaceVersion: 0,
}}
parsedBlob, err := blob.NewBlob(0, nID, blobData)
if err != nil {
panic(fmt.Sprintf("Error creating blob: %v", err))
}
parsedParams[2] = []*blob.Blob{parsedBlob}
return parsedParams[:3]
case "Get":
// 1. Height
Expand Down
3 changes: 1 addition & 2 deletions nodebuilder/blob/mocks/api.go

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

3 changes: 1 addition & 2 deletions nodebuilder/das/mocks/api.go

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

13 changes: 6 additions & 7 deletions nodebuilder/fraud/mocks/api.go

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

18 changes: 16 additions & 2 deletions nodebuilder/header/mocks/api.go

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

3 changes: 1 addition & 2 deletions nodebuilder/node/mocks/api.go

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

3 changes: 1 addition & 2 deletions nodebuilder/share/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/mocks/api.go

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

13 changes: 7 additions & 6 deletions nodebuilder/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (

"github.com/cosmos/cosmos-sdk/x/staking/types"

apptypes "github.com/celestiaorg/celestia-app/x/blob/types"

"github.com/celestiaorg/celestia-node/blob"
"github.com/celestiaorg/celestia-node/state"
)

Expand Down Expand Up @@ -36,7 +35,9 @@ type Module interface {

// Transfer sends the given amount of coins from default wallet of the node to the given account
// address.
Transfer(ctx context.Context, to state.AccAddress, amount, fee state.Int, gasLimit uint64) (*state.TxResponse, error)
Transfer(
ctx context.Context, to state.AccAddress, amount, fee state.Int, gasLimit uint64,
) (*state.TxResponse, error)
// SubmitTx submits the given transaction/message to the
// Celestia network and blocks until the tx is included in
// a block.
Expand All @@ -46,7 +47,7 @@ type Module interface {
ctx context.Context,
fee state.Int,
gasLim uint64,
blobs []*apptypes.Blob,
blobs []*blob.Blob,
) (*state.TxResponse, error)

// CancelUnbondingDelegation cancels a user's pending undelegation from a validator.
Expand Down Expand Up @@ -114,7 +115,7 @@ type API struct {
ctx context.Context,
fee state.Int,
gasLim uint64,
blobs []*apptypes.Blob,
blobs []*blob.Blob,
) (*state.TxResponse, error) `perm:"write"`
CancelUnbondingDelegation func(
ctx context.Context,
Expand Down Expand Up @@ -192,7 +193,7 @@ func (api *API) SubmitPayForBlob(
ctx context.Context,
fee state.Int,
gasLim uint64,
blobs []*apptypes.Blob,
blobs []*blob.Blob,
) (*state.TxResponse, error) {
return api.Internal.SubmitPayForBlob(ctx, fee, gasLim, blobs)
}
Expand Down
3 changes: 1 addition & 2 deletions share/mocks/getter.go

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

Loading

0 comments on commit bc97346

Please sign in to comment.