Skip to content

Commit

Permalink
integrating into fx
Browse files Browse the repository at this point in the history
  • Loading branch information
distractedm1nd committed Jan 31, 2024
1 parent 5d29a7e commit 5a57cd5
Show file tree
Hide file tree
Showing 17 changed files with 173 additions and 21 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
}
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.

126 changes: 126 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
}),
)
}
9 changes: 8 additions & 1 deletion nodebuilder/da/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/celestiaorg/nmt"

"github.com/celestiaorg/celestia-node/blob"
nodeblob "github.com/celestiaorg/celestia-node/nodebuilder/blob"
"github.com/celestiaorg/celestia-node/share"
)

Expand All @@ -26,7 +27,13 @@ var log = logging.Logger("go-da")
const heightLen = 8

type Service struct {
blobServ blob.Service
blobServ nodeblob.Module
}

func NewService(blobMod nodeblob.Module) *Service {
return &Service{
blobServ: blobMod,
}
}

// MaxBlobSize returns the max blob size
Expand Down
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.

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

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

2 changes: 2 additions & 0 deletions nodebuilder/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/celestiaorg/celestia-node/libs/fxutil"
"github.com/celestiaorg/celestia-node/nodebuilder/blob"
"github.com/celestiaorg/celestia-node/nodebuilder/core"
"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/gateway"
Expand Down Expand Up @@ -55,6 +56,7 @@ func ConstructModule(tp node.Type, network p2p.Network, cfg *Config, store Store
das.ConstructModule(tp, &cfg.DASer),
fraud.ConstructModule(tp),
blob.ConstructModule(),
da.ConstructModule(),
node.ConstructModule(tp),
prune.ConstructModule(tp),
rpc.ConstructModule(tp, &cfg.RPC),
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: 3 additions & 0 deletions nodebuilder/rpc/constructors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/celestiaorg/celestia-node/api/rpc"
"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 @@ -24,6 +25,7 @@ func registerEndpoints(
p2pMod p2p.Module,
nodeMod node.Module,
blobMod blob.Module,
daMod da.Module,
serv *rpc.Server,
) {
serv.RegisterAuthedService("fraud", fraudMod, &fraud.API{})
Expand All @@ -34,6 +36,7 @@ func registerEndpoints(
serv.RegisterAuthedService("p2p", p2pMod, &p2p.API{})
serv.RegisterAuthedService("node", nodeMod, &node.API{})
serv.RegisterAuthedService("blob", blobMod, &blob.API{})
serv.RegisterAuthedService("da", daMod, &da.API{})
}

func server(cfg *Config, auth jwt.Signer) *rpc.Server {
Expand Down
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.

5 changes: 2 additions & 3 deletions nodebuilder/state/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 share/availability/mocks/availability.go

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

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.

0 comments on commit 5a57cd5

Please sign in to comment.