Skip to content

Commit

Permalink
feat(rpc): implementing go-da interface (celestiaorg#3146)
Browse files Browse the repository at this point in the history
Integrates go-da directly to eliminate the need for
[celestia-da](https://github.com/rollkit/celestia-da).
  • Loading branch information
distractedm1nd authored and renaynay committed Feb 14, 2024
1 parent b51b825 commit 6c7ddb8
Show file tree
Hide file tree
Showing 15 changed files with 589 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pb-gen:
## openrpc-gen: Generate OpenRPC spec for Celestia-Node's RPC api
openrpc-gen:
@echo "--> Generating OpenRPC spec"
@go run ./cmd/docgen fraud header state share das p2p node blob
@go run ./cmd/docgen fraud header state share das p2p node blob da
.PHONY: openrpc-gen

## lint-imports: Lint only Go imports.
Expand Down
3 changes: 3 additions & 0 deletions api/rpc/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/celestiaorg/celestia-node/api/rpc/perms"
"github.com/celestiaorg/celestia-node/nodebuilder/blob"
"github.com/celestiaorg/celestia-node/nodebuilder/da"
"github.com/celestiaorg/celestia-node/nodebuilder/das"
"github.com/celestiaorg/celestia-node/nodebuilder/fraud"
"github.com/celestiaorg/celestia-node/nodebuilder/header"
Expand All @@ -33,6 +34,7 @@ type Client struct {
P2P p2p.API
Node node.API
Blob blob.API
DA da.API

closer multiClientCloser
}
Expand Down Expand Up @@ -91,5 +93,6 @@ func moduleMap(client *Client) map[string]interface{} {
"p2p": &client.P2P.Internal,
"node": &client.Node.Internal,
"blob": &client.Blob.Internal,
"da": &client.DA.Internal,
}
}
6 changes: 6 additions & 0 deletions api/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"github.com/celestiaorg/celestia-node/nodebuilder"
"github.com/celestiaorg/celestia-node/nodebuilder/blob"
blobMock "github.com/celestiaorg/celestia-node/nodebuilder/blob/mocks"
"github.com/celestiaorg/celestia-node/nodebuilder/da"
daMock "github.com/celestiaorg/celestia-node/nodebuilder/da/mocks"
"github.com/celestiaorg/celestia-node/nodebuilder/das"
dasMock "github.com/celestiaorg/celestia-node/nodebuilder/das/mocks"
"github.com/celestiaorg/celestia-node/nodebuilder/fraud"
Expand Down Expand Up @@ -91,6 +93,7 @@ type api struct {
Node node.Module
P2P p2p.Module
Blob blob.Module
DA da.Module
}

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

// given the behavior of fx.Invoke, this invoke will be called last as it is added at the root
Expand All @@ -310,6 +314,7 @@ func setupNodeWithAuthedRPC(t *testing.T, auth jwt.Signer) (*nodebuilder.Node, *
srv.RegisterAuthedService("p2p", mockAPI.P2P, &p2p.API{})
srv.RegisterAuthedService("node", mockAPI.Node, &node.API{})
srv.RegisterAuthedService("blob", mockAPI.Blob, &blob.API{})
srv.RegisterAuthedService("da", mockAPI.DA, &da.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 @@ -334,4 +339,5 @@ type mockAPI struct {
P2P *p2pMock.MockModule
Node *nodeMock.MockModule
Blob *blobMock.MockModule
DA *daMock.MockModule
}
27 changes: 27 additions & 0 deletions blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,33 @@ type Proof []*nmt.Proof

func (p Proof) Len() int { return len(p) }

func (p Proof) MarshalJSON() ([]byte, error) {
proofs := make([]string, 0, len(p))
for _, proof := range p {
proofBytes, err := proof.MarshalJSON()
if err != nil {
return nil, err
}
proofs = append(proofs, string(proofBytes))
}
return json.Marshal(proofs)
}

func (p *Proof) UnmarshalJSON(b []byte) error {
var proofs []string
if err := json.Unmarshal(b, &proofs); err != nil {
return err
}
for _, proof := range proofs {
var nmtProof nmt.Proof
if err := nmtProof.UnmarshalJSON([]byte(proof)); err != nil {
return err
}
*p = append(*p, &nmtProof)
}
return nil
}

// equal is a temporary method that compares two proofs.
// should be removed in BlobService V1.
func (p Proof) equal(input Proof) error {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ require (
github.com/prometheus/client_golang v1.18.0
github.com/pyroscope-io/client v0.7.2
github.com/pyroscope-io/otel-profiling-go v0.5.0
github.com/rollkit/go-da v0.4.0
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2121,6 +2121,8 @@ github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTE
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/rollkit/go-da v0.4.0 h1:/s7ZrVq7DC2aK8UXIvB7rsXrZ2mVGRw7zrexcxRvhlw=
github.com/rollkit/go-da v0.4.0/go.mod h1:Kef0XI5ecEKd3TXzI8S+9knAUJnZg0svh2DuXoCsPlM=
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U=
github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
Expand Down
54 changes: 54 additions & 0 deletions nodebuilder/da/da.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package da

import (
"context"

"github.com/rollkit/go-da"
)

//go:generate mockgen -destination=mocks/api.go -package=mocks . Module
type Module interface {
da.DA
}

// API is a wrapper around Module for the RPC.
// TODO(@distractedm1nd): These structs need to be autogenerated.
type API struct {
Internal struct {
MaxBlobSize func(ctx context.Context) (uint64, error) `perm:"read"`
Get func(ctx context.Context, ids []da.ID, ns da.Namespace) ([]da.Blob, error) `perm:"read"`
GetIDs func(ctx context.Context, height uint64, ns da.Namespace) ([]da.ID, error) `perm:"read"`
GetProofs func(ctx context.Context, ids []da.ID, ns da.Namespace) ([]da.Proof, error) `perm:"read"`
Commit func(ctx context.Context, blobs []da.Blob, ns da.Namespace) ([]da.Commitment, error) `perm:"read"`
Validate func(context.Context, []da.ID, []da.Proof, da.Namespace) ([]bool, error) `perm:"read"`
Submit func(context.Context, []da.Blob, float64, da.Namespace) ([]da.ID, error) `perm:"write"`
}
}

func (api *API) MaxBlobSize(ctx context.Context) (uint64, error) {
return api.Internal.MaxBlobSize(ctx)
}

func (api *API) Get(ctx context.Context, ids []da.ID, ns da.Namespace) ([]da.Blob, error) {
return api.Internal.Get(ctx, ids, ns)
}

func (api *API) GetIDs(ctx context.Context, height uint64, ns da.Namespace) ([]da.ID, error) {
return api.Internal.GetIDs(ctx, height, ns)
}

func (api *API) GetProofs(ctx context.Context, ids []da.ID, ns da.Namespace) ([]da.Proof, error) {
return api.Internal.GetProofs(ctx, ids, ns)
}

func (api *API) Commit(ctx context.Context, blobs []da.Blob, ns da.Namespace) ([]da.Commitment, error) {
return api.Internal.Commit(ctx, blobs, ns)
}

func (api *API) Validate(ctx context.Context, ids []da.ID, proofs []da.Proof, ns da.Namespace) ([]bool, error) {
return api.Internal.Validate(ctx, ids, proofs, ns)
}

func (api *API) Submit(ctx context.Context, blobs []da.Blob, gasPrice float64, ns da.Namespace) ([]da.ID, error) {
return api.Internal.Submit(ctx, blobs, gasPrice, ns)
}
140 changes: 140 additions & 0 deletions nodebuilder/da/mocks/api.go

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

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

import (
"go.uber.org/fx"
)

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

0 comments on commit 6c7ddb8

Please sign in to comment.