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

fix!(state): use node blob type instead of app type to fix inconsistent unmarshalling #2338

Merged
merged 5 commits into from
Jun 8, 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
12 changes: 12 additions & 0 deletions api/docgen/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ func init() {
}
addToExampleValues(addrInfo)

namespace, err := share.NewNamespaceV0([]byte{0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0x10})
if err != nil {
panic(err)
}
addToExampleValues(namespace)

generatedBlob, err := blob.NewBlob(0, namespace, []byte("This is an example of some blob data"))
if err != nil {
panic(err)
}
addToExampleValues(generatedBlob)

proof := nmt.NewInclusionProof(0, 4, [][]byte{[]byte("test")}, true)
blobProof := &blob.Proof{&proof}
addToExampleValues(blobProof)
Expand Down
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)
distractedm1nd marked this conversation as resolved.
Show resolved Hide resolved
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
11 changes: 10 additions & 1 deletion api/gateway/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gateway

import (
"bytes"
"encoding/hex"
"encoding/json"
"errors"
"net/http"
Expand All @@ -12,6 +13,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,7 +34,14 @@ 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",
distractedm1nd marked this conversation as resolved.
Show resolved Hide resolved
})
require.NoError(t, err)
httpreq := httptest.NewRequest("GET", "/", bytes.NewReader(bs))
respRec := httptest.NewRecorder()
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)
distractedm1nd marked this conversation as resolved.
Show resolved Hide resolved
}

distractedm1nd marked this conversation as resolved.
Show resolved Hide resolved
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.

2 changes: 1 addition & 1 deletion nodebuilder/node/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
logging "github.com/ipfs/go-log/v2"
)

const APIVersion = "v0.1.1"
const APIVersion = "v0.2.0"

type module struct {
tp Type
Expand Down
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