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

feat: add support for Blobstream API #3470

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
dda88ee
feat: add support for the Blobstream API in node
rach-id Jun 4, 2024
41bfd50
chore: add permissions to methods
rach-id Jun 4, 2024
a3a32f3
fix: use the share proofs to generate the commitment proofs
rach-id Jun 5, 2024
e5d2e1d
chore: gofumpt
rach-id Jun 5, 2024
cb6f660
chore: docs
rach-id Jun 5, 2024
8220364
Update nodebuilder/blobstream/service.go
rach-id Jun 5, 2024
4309614
Merge branch 'main' into blobstream--api
rach-id Jun 5, 2024
15b59dd
chore: go mod tidy
rach-id Jun 5, 2024
8231ade
Merge remote-tracking branch 'origin/blobstream--api' into blobstream…
rach-id Jun 5, 2024
d31ee83
chore: lint
rach-id Jun 5, 2024
a784be9
chore: lint
rach-id Jun 5, 2024
4463b4a
chore: gofumpt
rach-id Jun 5, 2024
1953fc5
chore: gofumpt
rach-id Jun 5, 2024
eb0b29e
chore: gofumpt
rach-id Jun 5, 2024
e4c5910
chore: lowercase import
rach-id Jun 7, 2024
f8a3066
chore: internal struct definition inside API
rach-id Jun 7, 2024
a409722
chore: fmt
rach-id Jun 20, 2024
44f17a1
chore: DataCommitment to GetDataCommitment as suggested by @vgonkivs
rach-id Jun 20, 2024
080101a
chore: DataCommitment to GetDataCommitment as suggested by @vgonkivs
rach-id Jun 20, 2024
5fc0203
chore: DataRootInclusionProof to GetDataRootInclusionProof as suggest…
rach-id Jun 20, 2024
350d950
chore: remove todo
rach-id Jun 20, 2024
411fc20
chore: commitment proof pointer receiver
rach-id Jun 20, 2024
9e48e55
fix: subtreeRootProofs instead of SubtreeRoots in error message
rach-id Jun 20, 2024
f24171e
chore: new line
rach-id Jun 20, 2024
9b79dba
chore: revert unnecessary changes
rach-id Jun 20, 2024
7db0ab9
Update nodebuilder/blobstream/service.go
rach-id Jun 20, 2024
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
40 changes: 22 additions & 18 deletions api/rpc/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"net/http"

"github.com/celestiaorg/celestia-node/nodebuilder/blobstream"
rach-id marked this conversation as resolved.
Show resolved Hide resolved

"github.com/filecoin-project/go-jsonrpc"

"github.com/celestiaorg/celestia-node/api/rpc/perms"
Expand All @@ -26,15 +28,16 @@ var (
)

type Client struct {
Fraud fraud.API
Header header.API
State state.API
Share share.API
DAS das.API
P2P p2p.API
Node node.API
Blob blob.API
DA da.API
Fraud fraud.API
Header header.API
State state.API
Share share.API
DAS das.API
P2P p2p.API
Node node.API
Blob blob.API
DA da.API
Blobstream blobstream.API

closer multiClientCloser
}
Expand Down Expand Up @@ -85,14 +88,15 @@ func newClient(ctx context.Context, addr string, authHeader http.Header) (*Clien
func moduleMap(client *Client) map[string]interface{} {
// TODO: this duplication of strings many times across the codebase can be avoided with issue #1176
return map[string]interface{}{
"share": &client.Share.Internal,
"state": &client.State.Internal,
"header": &client.Header.Internal,
"fraud": &client.Fraud.Internal,
"das": &client.DAS.Internal,
"p2p": &client.P2P.Internal,
"node": &client.Node.Internal,
"blob": &client.Blob.Internal,
"da": &client.DA.Internal,
"share": &client.Share.Internal,
"state": &client.State.Internal,
"header": &client.Header.Internal,
"fraud": &client.Fraud.Internal,
"das": &client.DAS.Internal,
"p2p": &client.P2P.Internal,
"node": &client.Node.Internal,
"blob": &client.Blob.Internal,
"da": &client.DA.Internal,
"blobstream": &client.Blobstream.Internal,
}
}
43 changes: 25 additions & 18 deletions api/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"testing"
"time"

"github.com/celestiaorg/celestia-node/nodebuilder/blobstream"
rach-id marked this conversation as resolved.
Show resolved Hide resolved

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cristalhq/jwt"
"github.com/golang/mock/gomock"
Expand All @@ -22,6 +24,7 @@ import (
"github.com/celestiaorg/celestia-node/nodebuilder"
"github.com/celestiaorg/celestia-node/nodebuilder/blob"
blobMock "github.com/celestiaorg/celestia-node/nodebuilder/blob/mocks"
blobstreamMock "github.com/celestiaorg/celestia-node/nodebuilder/blobstream/mocks"
"github.com/celestiaorg/celestia-node/nodebuilder/da"
daMock "github.com/celestiaorg/celestia-node/nodebuilder/da/mocks"
"github.com/celestiaorg/celestia-node/nodebuilder/das"
Expand Down Expand Up @@ -85,15 +88,16 @@ func TestRPCCallsUnderlyingNode(t *testing.T) {
// api contains all modules that are made available as the node's
// public API surface
type api struct {
Fraud fraud.Module
Header header.Module
State statemod.Module
Share share.Module
DAS das.Module
Node node.Module
P2P p2p.Module
Blob blob.Module
DA da.Module
Fraud fraud.Module
Header header.Module
State statemod.Module
Share share.Module
DAS das.Module
Node node.Module
P2P p2p.Module
Blob blob.Module
DA da.Module
Blobstream blobstream.Module
}

func TestModulesImplementFullAPI(t *testing.T) {
Expand Down Expand Up @@ -300,6 +304,7 @@ func setupNodeWithAuthedRPC(t *testing.T, auth jwt.Signer) (*nodebuilder.Node, *
nodeMock.NewMockModule(ctrl),
blobMock.NewMockModule(ctrl),
daMock.NewMockModule(ctrl),
blobstreamMock.NewMockModule(ctrl),
}

// given the behavior of fx.Invoke, this invoke will be called last as it is added at the root
Expand All @@ -314,6 +319,7 @@ func setupNodeWithAuthedRPC(t *testing.T, auth jwt.Signer) (*nodebuilder.Node, *
srv.RegisterService("node", mockAPI.Node, &node.API{})
srv.RegisterService("blob", mockAPI.Blob, &blob.API{})
srv.RegisterService("da", mockAPI.DA, &da.API{})
srv.RegisterService("blobstream", mockAPI.Blobstream, &blobstream.API{})
})
// fx.Replace does not work here, but fx.Decorate does
nd := nodebuilder.TestNode(t, node.Full, invokeRPC, fx.Decorate(func() (jwt.Signer, error) {
Expand All @@ -330,13 +336,14 @@ func setupNodeWithAuthedRPC(t *testing.T, auth jwt.Signer) (*nodebuilder.Node, *
}

type mockAPI struct {
State *stateMock.MockModule
Share *shareMock.MockModule
Fraud *fraudMock.MockModule
Header *headerMock.MockModule
Das *dasMock.MockModule
P2P *p2pMock.MockModule
Node *nodeMock.MockModule
Blob *blobMock.MockModule
DA *daMock.MockModule
State *stateMock.MockModule
Share *shareMock.MockModule
Fraud *fraudMock.MockModule
Header *headerMock.MockModule
Das *dasMock.MockModule
P2P *p2pMock.MockModule
Node *nodeMock.MockModule
Blob *blobMock.MockModule
DA *daMock.MockModule
Blobstream *blobstreamMock.MockModule
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/celestiaorg/go-fraud v0.2.1
github.com/celestiaorg/go-header v0.6.2
github.com/celestiaorg/go-libp2p-messenger v0.2.0
github.com/celestiaorg/nmt v0.21.0
github.com/celestiaorg/nmt v0.21.1-0.20240602221058-a81b748b6f51 // TODO replace with release when ready
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will be replaced once we release nmt

github.com/celestiaorg/rsmt2d v0.13.1
github.com/cosmos/cosmos-sdk v0.46.16
github.com/cristalhq/jwt v1.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ github.com/celestiaorg/go-libp2p-messenger v0.2.0 h1:/0MuPDcFamQMbw9xTZ73yImqgTO
github.com/celestiaorg/go-libp2p-messenger v0.2.0/go.mod h1:s9PIhMi7ApOauIsfBcQwbr7m+HBzmVfDIS+QLdgzDSo=
github.com/celestiaorg/merkletree v0.0.0-20230308153949-c33506a7aa26 h1:P2RI1xJ49EZ8cuHMcH+ZSBonfRDtBS8OS9Jdt1BWX3k=
github.com/celestiaorg/merkletree v0.0.0-20230308153949-c33506a7aa26/go.mod h1:2m8ukndOegwB0PU0AfJCwDUQHqd7QQRlSXvQL5VToVY=
github.com/celestiaorg/nmt v0.21.0 h1:81MBqxNn3orByoiCtdNVjwi5WsLgMkzHwP02ZMhTBHM=
github.com/celestiaorg/nmt v0.21.0/go.mod h1:ia/EpCk0enD5yO5frcxoNoFToz2Ghtk2i+blmCRjIY8=
github.com/celestiaorg/nmt v0.21.1-0.20240602221058-a81b748b6f51 h1:vOLlAiHwCtXA7LNsXokDysmPHl2UvorPTARyhHQPQQA=
github.com/celestiaorg/nmt v0.21.1-0.20240602221058-a81b748b6f51/go.mod h1:ia/EpCk0enD5yO5frcxoNoFToz2Ghtk2i+blmCRjIY8=
github.com/celestiaorg/quantum-gravity-bridge/v2 v2.1.2 h1:Q8nr5SAtDW5gocrBwqwDJcSS/JedqU58WwQA2SP+nXw=
github.com/celestiaorg/quantum-gravity-bridge/v2 v2.1.2/go.mod h1:s/LzLUw0WeYPJ6qdk4q46jKLOq7rc9Z5Mdrxtfpcigw=
github.com/celestiaorg/rsmt2d v0.13.1 h1:eRhp79DKTkDojwInKVs1lRK6f6zJc1BVlmZfUfI19yQ=
Expand Down
93 changes: 93 additions & 0 deletions nodebuilder/blobstream/blobstream.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package blobstream

import (
"context"

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

var _ Module = (*API)(nil)

// Module defines the API related to interacting with the proofs
//
//go:generate mockgen -destination=mocks/api.go -package=mocks . Module
type Module interface {
// DataCommitment collects the data roots over a provided ordered range of blocks,
// and then creates a new Merkle root of those data roots. The range is end exclusive.
DataCommitment(ctx context.Context, start, end uint64) (*ResultDataCommitment, error)
rach-id marked this conversation as resolved.
Show resolved Hide resolved

// DataRootInclusionProof creates an inclusion proof for the data root of block
// height `height` in the set of blocks defined by `start` and `end`. The range
// is end exclusive.
DataRootInclusionProof(
rach-id marked this conversation as resolved.
Show resolved Hide resolved
ctx context.Context,
height int64,
start, end uint64,
) (*ResultDataRootInclusionProof, error)

// ProveShares generates a share proof for a share range.
ProveShares(ctx context.Context, height, start, end uint64) (*ResultShareProof, error)
// ProveCommitment generates a commitment proof for a share commitment.
rach-id marked this conversation as resolved.
Show resolved Hide resolved
ProveCommitment(
ctx context.Context,
height uint64,
namespace share.Namespace,
shareCommitment []byte,
) (*ResultCommitmentProof, error)
}

// API is a wrapper around the Module for RPC.
type API struct {
Internal struct {
DataCommitment func(
ctx context.Context,
start, end uint64,
) (*ResultDataCommitment, error) `perm:"read"`
DataRootInclusionProof func(
ctx context.Context,
height int64,
start, end uint64,
) (*ResultDataRootInclusionProof, error) `perm:"read"`
ProveShares func(
ctx context.Context,
height, start, end uint64,
) (*ResultShareProof, error) `perm:"read"`
ProveCommitment func(
ctx context.Context,
height uint64,
namespace share.Namespace,
shareCommitment []byte,
) (*ResultCommitmentProof, error) `perm:"read"`
}
}

func (api *API) DataCommitment(
ctx context.Context,
start, end uint64,
) (*ResultDataCommitment, error) {
return api.Internal.DataCommitment(ctx, start, end)
}

func (api *API) DataRootInclusionProof(
ctx context.Context,
height int64,
start, end uint64,
) (*ResultDataRootInclusionProof, error) {
return api.Internal.DataRootInclusionProof(ctx, height, start, end)
}

func (api *API) ProveShares(
ctx context.Context,
height, start, end uint64,
) (*ResultShareProof, error) {
return api.Internal.ProveShares(ctx, height, start, end)
}

func (api *API) ProveCommitment(
ctx context.Context,
height uint64,
namespace share.Namespace,
shareCommitment []byte,
) (*ResultCommitmentProof, error) {
return api.Internal.ProveCommitment(ctx, height, namespace, shareCommitment)
}
98 changes: 98 additions & 0 deletions nodebuilder/blobstream/mocks/api.go

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

12 changes: 12 additions & 0 deletions nodebuilder/blobstream/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package blobstream

import "go.uber.org/fx"

func ConstructModule() fx.Option {
return fx.Module("blobstream",
fx.Provide(NewService),
fx.Provide(func(serv *Service) Module {
return serv
}),
)
}
Loading
Loading