From fdc259d295961d409ad8a2ce11b5dc48afdb32ba Mon Sep 17 00:00:00 2001 From: archbear Date: Fri, 21 Jun 2024 16:58:51 -0400 Subject: [PATCH 1/3] s(he) be(lie)ve(d) --- beacond/cmd/main.go | 24 ++--- contracts/lib/forge-std | 2 +- contracts/lib/solady | 2 +- mod/cli/pkg/builder/builder.go | 13 ++- mod/cli/pkg/builder/options.go | 8 +- mod/cli/pkg/commands/root.go | 7 +- mod/cli/pkg/commands/{utils.go => setup.go} | 9 -- mod/cli/pkg/components/client_context.go | 8 +- mod/cli/pkg/config/client.go | 31 ++++++ ...extended_options.go => baseapp_options.go} | 7 +- mod/node-core/pkg/builder/builder.go | 81 +++++++++++++++- mod/node-core/pkg/builder/creator.go | 97 ------------------- mod/node-core/pkg/builder/empty_components.go | 60 ------------ mod/node-core/pkg/builder/options.go | 6 +- mod/node-core/pkg/node/node.go | 39 ++++---- mod/node-core/pkg/types/interfaces.go | 18 +++- 16 files changed, 183 insertions(+), 229 deletions(-) rename mod/cli/pkg/commands/{utils.go => setup.go} (90%) create mode 100644 mod/cli/pkg/config/client.go rename mod/node-core/pkg/builder/{extended_options.go => baseapp_options.go} (92%) delete mode 100644 mod/node-core/pkg/builder/creator.go delete mode 100644 mod/node-core/pkg/builder/empty_components.go diff --git a/beacond/cmd/main.go b/beacond/cmd/main.go index 644c572cd0..a8f06fcbc7 100644 --- a/beacond/cmd/main.go +++ b/beacond/cmd/main.go @@ -44,10 +44,10 @@ func run() error { // Build the node using the node-core. nb := nodebuilder.New( // Set the DepInject Configuration to the Default. - nodebuilder.WithDepInjectConfig[types.NodeI]( + nodebuilder.WithDepInjectConfig[types.Node]( nodebuilder.DefaultDepInjectConfig()), // Set the Runtime Components to the Default. - nodebuilder.WithComponents[types.NodeI]( + nodebuilder.WithComponents[types.Node]( nodecomponents.DefaultComponentsWithStandardTypes(), ), ) @@ -55,15 +55,15 @@ func run() error { // Build the root command using the builder cb := clibuilder.New( // Set the Name to the Default. - clibuilder.WithName[types.NodeI](nodebuilder.DefaultAppName), + clibuilder.WithName[types.Node](nodebuilder.DefaultAppName), // Set the Description to the Default. - clibuilder.WithDescription[types.NodeI](nodebuilder.DefaultDescription), + clibuilder.WithDescription[types.Node](nodebuilder.DefaultDescription), // Set the DepInject Configuration to the Default. - clibuilder.WithDepInjectConfig[types.NodeI]( + clibuilder.WithDepInjectConfig[types.Node]( nodebuilder.DefaultDepInjectConfig(), ), // Set the Runtime Components to the Default. - clibuilder.WithComponents[types.NodeI]( + clibuilder.WithComponents[types.Node]( append( clicomponents.DefaultClientComponents(), // TODO: remove these, and eventually pull cfg and chainspec @@ -73,21 +73,17 @@ func run() error { nodecomponents.ProvideChainSpec, ), ), - clibuilder.SupplyModuleDeps[types.NodeI]( + clibuilder.SupplyModuleDeps[types.Node]( beacon.SupplyModuleDependencies(), ), // Set the Run Handler to the Default. - clibuilder.WithRunHandler[types.NodeI]( + clibuilder.WithRunHandler[types.Node]( server.InterceptConfigsPreRunHandler, ), - // Set the AppCreator to the NodeBuilder AppCreator. - clibuilder.WithAppCreator[types.NodeI](nb.AppCreator), + // Set the NodeBuilderFunc to the NodeBuilder Build. + clibuilder.WithNodeBuilderFunc[types.Node](nb.Build), ) - // we never have to call nb.build() because this function is passed - // to the cli through the clibuilder.WithAppCreator option, eventually to be - // called by the cosmos-sdk - cmd, err := cb.Build() if err != nil { return err diff --git a/contracts/lib/forge-std b/contracts/lib/forge-std index 19891e6a0b..6e05729b76 160000 --- a/contracts/lib/forge-std +++ b/contracts/lib/forge-std @@ -1 +1 @@ -Subproject commit 19891e6a0b5474b9ea6827ddb90bb9388f7acfc0 +Subproject commit 6e05729b76f1ae0d437e74951aef1ca987788ab3 diff --git a/contracts/lib/solady b/contracts/lib/solady index 003df77af7..678c916355 160000 --- a/contracts/lib/solady +++ b/contracts/lib/solady @@ -1 +1 @@ -Subproject commit 003df77af7bb45b107ee89642435786f30620808 +Subproject commit 678c9163550810b08f0ffb09624c9f7532392303 diff --git a/mod/cli/pkg/builder/builder.go b/mod/cli/pkg/builder/builder.go index 01b41e038d..ddf28137ac 100644 --- a/mod/cli/pkg/builder/builder.go +++ b/mod/cli/pkg/builder/builder.go @@ -48,16 +48,15 @@ type CLIBuilder[T servertypes.Application] struct { // components is a list of component providers for depinject. components []any // suppliers is a list of suppliers for depinject. - suppliers []any + suppliers []any + // runHandler is a function to set up run handlers for the command. runHandler runHandler - // appCreator is a function that builds the Node, eventually called by the - // cosmos-sdk. + // nodeBuilderFunc is a function that builds the Node, + // eventually called by the cosmos-sdk. // TODO: CLI should not know about the AppCreator - appCreator servertypes.AppCreator[T] + nodeBuilderFunc servertypes.AppCreator[T] // rootCmdSetup is a function that sets up the root command. rootCmdSetup rootCmdSetup[T] - // logger is the logger - // logger log.Logger } // New returns a new CLIBuilder with the given options. @@ -119,7 +118,7 @@ func (cb *CLIBuilder[T]) Build() (*cmdlib.Root, error) { cmdlib.DefaultRootCommandSetup( rootCmd, mm, - cb.appCreator, + cb.nodeBuilderFunc, chainSpec, ) diff --git a/mod/cli/pkg/builder/options.go b/mod/cli/pkg/builder/options.go index 8d0c71b3e0..f1174be692 100644 --- a/mod/cli/pkg/builder/options.go +++ b/mod/cli/pkg/builder/options.go @@ -88,11 +88,11 @@ func WithDefaultRootCommandSetup[T servertypes.Application]() Opt[T] { } } -// WithAppCreator sets the cosmos app creator for the CLIBuilder. -func WithAppCreator[T servertypes.Application]( - appCreator servertypes.AppCreator[T], +// WithNodeBuilderFunc sets the cosmos app creator for the CLIBuilder. +func WithNodeBuilderFunc[T servertypes.Application]( + nodeBuilderFunc servertypes.AppCreator[T], ) Opt[T] { return func(cb *CLIBuilder[T]) { - cb.appCreator = appCreator + cb.nodeBuilderFunc = nodeBuilderFunc } } diff --git a/mod/cli/pkg/commands/root.go b/mod/cli/pkg/commands/root.go index f7963da6f3..45868d3852 100644 --- a/mod/cli/pkg/commands/root.go +++ b/mod/cli/pkg/commands/root.go @@ -21,8 +21,9 @@ package commands import ( + "github.com/berachain/beacon-kit/mod/cli/pkg/config" sdkclient "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/config" + sdkconfig "github.com/cosmos/cosmos-sdk/client/config" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" "github.com/spf13/cobra" ) @@ -57,9 +58,9 @@ func New(name string, return err } - customClientTemplate, customClientConfig := InitClientConfig() + customClientTemplate, customClientConfig := config.InitClientConfig() // Update the client context with the default custom config - clientCtx, err = config.CreateClientConfig( + clientCtx, err = sdkconfig.CreateClientConfig( clientCtx, customClientTemplate, customClientConfig, diff --git a/mod/cli/pkg/commands/utils.go b/mod/cli/pkg/commands/setup.go similarity index 90% rename from mod/cli/pkg/commands/utils.go rename to mod/cli/pkg/commands/setup.go index dfce65427b..1d83778e42 100644 --- a/mod/cli/pkg/commands/utils.go +++ b/mod/cli/pkg/commands/setup.go @@ -29,7 +29,6 @@ import ( "github.com/berachain/beacon-kit/mod/cli/pkg/commands/jwt" "github.com/berachain/beacon-kit/mod/cli/pkg/flags" "github.com/berachain/beacon-kit/mod/primitives/pkg/common" - "github.com/cosmos/cosmos-sdk/client/config" "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/client/pruning" "github.com/cosmos/cosmos-sdk/client/snapshot" @@ -84,11 +83,3 @@ func DefaultRootCommandSetup[T servertypes.Application]( version.NewVersionCommand(), ) } - -// InitClientConfig sets up the default client configuration, allowing for -// overrides. -func InitClientConfig() (string, interface{}) { - clientCfg := config.DefaultConfig() - clientCfg.KeyringBackend = "test" - return config.DefaultClientConfigTemplate, clientCfg -} diff --git a/mod/cli/pkg/components/client_context.go b/mod/cli/pkg/components/client_context.go index cd070b9901..9f61f4c007 100644 --- a/mod/cli/pkg/components/client_context.go +++ b/mod/cli/pkg/components/client_context.go @@ -25,9 +25,9 @@ import ( "path/filepath" "cosmossdk.io/core/address" - "github.com/berachain/beacon-kit/mod/cli/pkg/commands" + "github.com/berachain/beacon-kit/mod/cli/pkg/config" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/config" + sdkconfig "github.com/cosmos/cosmos-sdk/client/config" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" ) @@ -66,8 +66,8 @@ func ProvideClientContext( // Read the config to overwrite the default values with the values from the // config file - customClientTemplate, customClientConfig := commands.InitClientConfig() - clientCtx, err = config.ReadDefaultValuesFromDefaultClientConfig( + customClientTemplate, customClientConfig := config.InitClientConfig() + clientCtx, err = sdkconfig.ReadDefaultValuesFromDefaultClientConfig( clientCtx, customClientTemplate, customClientConfig, diff --git a/mod/cli/pkg/config/client.go b/mod/cli/pkg/config/client.go new file mode 100644 index 0000000000..20066b5040 --- /dev/null +++ b/mod/cli/pkg/config/client.go @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2024, Berachain Foundation. All rights reserved. +// Use of this software is governed by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + +package config + +import "github.com/cosmos/cosmos-sdk/client/config" + +// InitClientConfig sets up the default client configuration, allowing for +// overrides. +func InitClientConfig() (string, interface{}) { + clientCfg := config.DefaultConfig() + clientCfg.KeyringBackend = "test" + return config.DefaultClientConfigTemplate, clientCfg +} diff --git a/mod/node-core/pkg/builder/extended_options.go b/mod/node-core/pkg/builder/baseapp_options.go similarity index 92% rename from mod/node-core/pkg/builder/extended_options.go rename to mod/node-core/pkg/builder/baseapp_options.go index a6bca76290..e307f06e25 100644 --- a/mod/node-core/pkg/builder/extended_options.go +++ b/mod/node-core/pkg/builder/baseapp_options.go @@ -29,10 +29,12 @@ import ( // This file contains Options that extend our default baseapp options to be // called by cosmos when building the app. +// TODO: refactor into consensus_options for serverv2 migration. // WithCometParamStore sets the param store to the comet consensus engine. func WithCometParamStore( - chainSpec common.ChainSpec) func(bApp *baseapp.BaseApp) { + chainSpec common.ChainSpec, +) func(bApp *baseapp.BaseApp) { return func(bApp *baseapp.BaseApp) { bApp.SetParamStore(comet.NewConsensusParamsStore(chainSpec)) } @@ -58,7 +60,8 @@ func WithProcessProposal( // WithPreBlocker sets the pre-blocker to the baseapp. func WithPreBlocker( - preBlocker sdk.PreBlocker) func(bApp *baseapp.BaseApp) { + preBlocker sdk.PreBlocker, +) func(bApp *baseapp.BaseApp) { return func(bApp *baseapp.BaseApp) { bApp.SetPreBlocker(preBlocker) } diff --git a/mod/node-core/pkg/builder/builder.go b/mod/node-core/pkg/builder/builder.go index 3029ce2894..4475667c98 100644 --- a/mod/node-core/pkg/builder/builder.go +++ b/mod/node-core/pkg/builder/builder.go @@ -21,15 +21,27 @@ package builder import ( + "context" + "io" + "cosmossdk.io/depinject" + "cosmossdk.io/log" + "github.com/berachain/beacon-kit/mod/node-core/pkg/app" + "github.com/berachain/beacon-kit/mod/node-core/pkg/components" "github.com/berachain/beacon-kit/mod/node-core/pkg/node" "github.com/berachain/beacon-kit/mod/node-core/pkg/types" + "github.com/berachain/beacon-kit/mod/primitives/pkg/common" + "github.com/berachain/beacon-kit/mod/runtime/pkg/service" + dbm "github.com/cosmos/cosmos-db" + "github.com/cosmos/cosmos-sdk/runtime" + "github.com/cosmos/cosmos-sdk/server" + servertypes "github.com/cosmos/cosmos-sdk/server/types" ) // TODO: #Make nodebuilder build a node. Currently this is just a builder for // the AppCreator function, which is eventually called by cosmos to build a // node. -type NodeBuilder[NodeT types.NodeI] struct { +type NodeBuilder[NodeT types.Node] struct { node NodeT // depinjectCfg holds is an extendable config container used by the // depinject framework. @@ -39,7 +51,7 @@ type NodeBuilder[NodeT types.NodeI] struct { } // New returns a new NodeBuilder. -func New[NodeT types.NodeI](opts ...Opt[NodeT]) *NodeBuilder[NodeT] { +func New[NodeT types.Node](opts ...Opt[NodeT]) *NodeBuilder[NodeT] { nb := &NodeBuilder[NodeT]{ node: node.New[NodeT](), } @@ -48,3 +60,68 @@ func New[NodeT types.NodeI](opts ...Opt[NodeT]) *NodeBuilder[NodeT] { } return nb } + +// Build uses the node builder options and runtime parameters to +// build a new instance of the node. +// It is necessary to adhere to the types.AppCreator[T] interface. +func (nb *NodeBuilder[NodeT]) Build( + logger log.Logger, + db dbm.DB, + traceStore io.Writer, + appOpts servertypes.AppOptions, +) NodeT { + // Check for goleveldb cause bad project. + if appOpts.Get("app-db-backend") == "goleveldb" { + panic("goleveldb is not supported") + } + + // variables to hold the components needed to set up BeaconApp + var ( + chainSpec common.ChainSpec + appBuilder *runtime.AppBuilder + abciMiddleware *components.ABCIMiddleware + serviceRegistry *service.Registry + ) + + // build all node components using depinject + if err := depinject.Inject( + depinject.Configs( + nb.depInjectCfg, + depinject.Provide( + nb.components..., + ), + depinject.Supply( + appOpts, + logger, + ), + ), + &appBuilder, + &chainSpec, + &abciMiddleware, + &serviceRegistry, + ); err != nil { + panic(err) + } + + // set the application to a new BeaconApp with necessary ABCI handlers + nb.node.RegisterApp( + app.NewBeaconKitApp( + db, traceStore, true, appBuilder, + append( + server.DefaultBaseappOptions(appOpts), + WithCometParamStore(chainSpec), + WithPrepareProposal(abciMiddleware.PrepareProposal), + WithProcessProposal(abciMiddleware.ProcessProposal), + WithPreBlocker(abciMiddleware.PreBlock), + )..., + ), + ) + nb.node.SetServiceRegistry(serviceRegistry) + + // TODO: put this in some post node creation hook/listener. + if err := nb.node.Start(context.Background()); err != nil { + logger.Error("failed to start node", "err", err) + panic(err) + } + return nb.node +} diff --git a/mod/node-core/pkg/builder/creator.go b/mod/node-core/pkg/builder/creator.go deleted file mode 100644 index da5b37c675..0000000000 --- a/mod/node-core/pkg/builder/creator.go +++ /dev/null @@ -1,97 +0,0 @@ -// SPDX-License-Identifier: BUSL-1.1 -// -// Copyright (C) 2024, Berachain Foundation. All rights reserved. -// Use of this software is governed by the Business Source License included -// in the LICENSE file of this repository and at www.mariadb.com/bsl11. -// -// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY -// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER -// VERSIONS OF THE LICENSED WORK. -// -// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF -// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF -// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). -// -// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON -// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, -// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND -// TITLE. - -package builder - -import ( - "context" - "io" - - "cosmossdk.io/depinject" - "cosmossdk.io/log" - "github.com/berachain/beacon-kit/mod/node-core/pkg/app" - "github.com/berachain/beacon-kit/mod/primitives/pkg/common" - dbm "github.com/cosmos/cosmos-db" - "github.com/cosmos/cosmos-sdk/server" - servertypes "github.com/cosmos/cosmos-sdk/server/types" -) - -// AppCreator is a function that creates an application and starts the bkRuntime -// services. -// It is necessary to adhere to the types.AppCreator[T] interface. -func (nb *NodeBuilder[NodeT]) AppCreator( - logger log.Logger, - db dbm.DB, - traceStore io.Writer, - appOpts servertypes.AppOptions, -) NodeT { - // Check for goleveldb cause bad project. - if appOpts.Get("app-db-backend") == "goleveldb" { - panic("goleveldb is not supported") - } - - // variables to hold the components needed to set up BeaconApp - var chainSpec common.ChainSpec - appBuilder := emptyAppBuilder() - abciMiddleware := emptyABCIMiddleware() - serviceRegistry := emptyServiceRegistry() - - // build all node components using depinject - if err := depinject.Inject( - depinject.Configs( - nb.depInjectCfg, - depinject.Provide( - nb.components..., - ), - depinject.Supply( - appOpts, - logger, - ), - ), - &appBuilder, - &chainSpec, - &abciMiddleware, - &serviceRegistry, - ); err != nil { - panic(err) - } - - // set the application to a new BeaconApp with necessary ABCI handlers - nb.node.SetApplication( - app.NewBeaconKitApp( - db, traceStore, true, appBuilder, - append( - server.DefaultBaseappOptions(appOpts), - WithCometParamStore(chainSpec), - WithPrepareProposal(abciMiddleware.PrepareProposal), - WithProcessProposal(abciMiddleware.ProcessProposal), - WithPreBlocker(abciMiddleware.PreBlock), - )..., - ), - ) - - // TODO: put this in some post node creation hook/listener - // start all services - if err := serviceRegistry.StartAll(context.Background()); err != nil { - logger.Error("failed to start runtime services", "err", err) - panic(err) - } - return nb.node -} diff --git a/mod/node-core/pkg/builder/empty_components.go b/mod/node-core/pkg/builder/empty_components.go deleted file mode 100644 index 66329243b7..0000000000 --- a/mod/node-core/pkg/builder/empty_components.go +++ /dev/null @@ -1,60 +0,0 @@ -// SPDX-License-Identifier: BUSL-1.1 -// -// Copyright (C) 2024, Berachain Foundation. All rights reserved. -// Use of this software is governed by the Business Source License included -// in the LICENSE file of this repository and at www.mariadb.com/bsl11. -// -// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY -// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER -// VERSIONS OF THE LICENSED WORK. -// -// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF -// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF -// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). -// -// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON -// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, -// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND -// TITLE. - -package builder - -import ( - "github.com/berachain/beacon-kit/mod/consensus-types/pkg/genesis" - "github.com/berachain/beacon-kit/mod/consensus-types/pkg/types" - dastore "github.com/berachain/beacon-kit/mod/da/pkg/store" - datypes "github.com/berachain/beacon-kit/mod/da/pkg/types" - "github.com/berachain/beacon-kit/mod/node-core/pkg/components" - "github.com/berachain/beacon-kit/mod/runtime/pkg/middleware" - "github.com/berachain/beacon-kit/mod/runtime/pkg/service" - sdkruntime "github.com/cosmos/cosmos-sdk/runtime" -) - -// These functions return the addresses to empty node components. -// Typically used when supplying empty values to depinject, or as receiving -// addresses for constructed depinject values. - -// emptyABCIMiddleware return an address pointing to an empty BeaconState. -func emptyABCIMiddleware() *components.ABCIMiddleware { - return &middleware.ABCIMiddleware[ - *dastore.Store[*types.BeaconBlockBody], - *types.BeaconBlock, - components.BeaconState, - *datypes.BlobSidecars, - *types.Deposit, - *types.ExecutionPayload, - *genesis.Genesis[*types.Deposit, *types.ExecutionPayloadHeader], - ]{} -} - -// emptyAppBuilder returns an address pointing to an empty AppBuilder. -func emptyAppBuilder() *sdkruntime.AppBuilder { - return &sdkruntime.AppBuilder{} -} - -// emptyServiceRegistry returns an address pointing to an empty -// service.Registry. -func emptyServiceRegistry() *service.Registry { - return &service.Registry{} -} diff --git a/mod/node-core/pkg/builder/options.go b/mod/node-core/pkg/builder/options.go index decd0894df..76d4c99ec1 100644 --- a/mod/node-core/pkg/builder/options.go +++ b/mod/node-core/pkg/builder/options.go @@ -26,18 +26,18 @@ import ( ) // Opt is a type that defines a function that modifies NodeBuilder. -type Opt[NodeT types.NodeI] func(*NodeBuilder[NodeT]) +type Opt[NodeT types.Node] func(*NodeBuilder[NodeT]) // WithDepInjectConfig is a function that sets the dependency injection // configuration for the NodeBuilder. -func WithDepInjectConfig[NodeT types.NodeI](cfg depinject.Config) Opt[NodeT] { +func WithDepInjectConfig[NodeT types.Node](cfg depinject.Config) Opt[NodeT] { return func(nb *NodeBuilder[NodeT]) { nb.depInjectCfg = cfg } } // WithComponents is a function that sets the components for the NodeBuilder. -func WithComponents[NodeT types.NodeI](components []any) Opt[NodeT] { +func WithComponents[NodeT types.Node](components []any) Opt[NodeT] { return func(nb *NodeBuilder[NodeT]) { nb.components = components } diff --git a/mod/node-core/pkg/node/node.go b/mod/node-core/pkg/node/node.go index 4de1f53c23..0ad3f5b7d1 100644 --- a/mod/node-core/pkg/node/node.go +++ b/mod/node-core/pkg/node/node.go @@ -21,37 +21,42 @@ package node import ( + "context" + "github.com/berachain/beacon-kit/mod/node-core/pkg/app" "github.com/berachain/beacon-kit/mod/node-core/pkg/types" + "github.com/berachain/beacon-kit/mod/runtime/pkg/service" servertypes "github.com/cosmos/cosmos-sdk/server/types" ) -// Node represents the node application. -type Node struct { - *app.BeaconApp +// Compile-time assertion that node implements the NodeI interface. +var _ types.Node = (*node)(nil) - // name and description of the application. - name string - description string -} +// node is the hard-type representation of the beacon-kit node. +type node struct { + *app.BeaconApp -// New returns a new Node. -func New[NodeT types.NodeI]() NodeT { - return types.NodeI(&Node{}).(NodeT) + // registry is the node's service registry. + registry *service.Registry } -// SetAppName sets the name of the application. -func (n *Node) SetAppName(name string) { - n.name = name +// New returns a new node. +func New[NodeT types.Node]() NodeT { + return types.Node(&node{}).(NodeT) } -// SetAppDescription sets the description of the application. -func (n *Node) SetAppDescription(description string) { - n.description = description +// Start starts the node. +func (n *node) Start(ctx context.Context) error { + return n.registry.StartAll(ctx) } // SetApplication sets the application. -func (n *Node) SetApplication(a servertypes.Application) { +func (n *node) RegisterApp(a servertypes.Application) { //nolint:errcheck // BeaconApp is our servertypes.Application n.BeaconApp = a.(*app.BeaconApp) } + +// SetServiceRegistry sets the service registry. +func (n *node) SetServiceRegistry(registry *service.Registry) { + n.registry = registry +} diff --git a/mod/node-core/pkg/types/interfaces.go b/mod/node-core/pkg/types/interfaces.go index 6eba566cf1..763abf526a 100644 --- a/mod/node-core/pkg/types/interfaces.go +++ b/mod/node-core/pkg/types/interfaces.go @@ -21,14 +21,22 @@ package types import ( + "context" + + "github.com/berachain/beacon-kit/mod/runtime/pkg/service" servertypes "github.com/cosmos/cosmos-sdk/server/types" ) -// NodeI defines the API for the node application. +// Node defines the API for the node application. // It extends the Application interface from the Cosmos SDK. -type NodeI interface { +type Node interface { servertypes.Application - SetAppName(name string) - SetAppDescription(description string) - SetApplication(app servertypes.Application) + + // Start starts the node. + Start(ctx context.Context) error + + // RegisterApp sets the node's application. + RegisterApp(app servertypes.Application) + // SetServiceRegistry sets the node's service registry. + SetServiceRegistry(registry *service.Registry) } From 122984b9738401bde50d29f0fbd1cf0d30b20dc6 Mon Sep 17 00:00:00 2001 From: archbear Date: Fri, 21 Jun 2024 17:01:42 -0400 Subject: [PATCH 2/3] oops i did it again --- contracts/lib/solady | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/lib/solady b/contracts/lib/solady index 003df77af7..3e8031b164 160000 --- a/contracts/lib/solady +++ b/contracts/lib/solady @@ -1 +1 @@ -Subproject commit 003df77af7bb45b107ee89642435786f30620808 +Subproject commit 3e8031b16417154dc2beae71b7b45f415d29566b From 68011e333cf3130aeb09a2556c01608e2a0f85ae Mon Sep 17 00:00:00 2001 From: archbear Date: Fri, 21 Jun 2024 17:03:24 -0400 Subject: [PATCH 3/3] what are u doing kurtosis --- .../src/nodes/consensus/beacond/launcher.star | 8 -------- kurtosis/src/nodes/execution/execution.star | 19 ------------------- 2 files changed, 27 deletions(-) diff --git a/kurtosis/src/nodes/consensus/beacond/launcher.star b/kurtosis/src/nodes/consensus/beacond/launcher.star index 4b37bdf7df..f5f0b27554 100644 --- a/kurtosis/src/nodes/consensus/beacond/launcher.star +++ b/kurtosis/src/nodes/consensus/beacond/launcher.star @@ -119,14 +119,6 @@ def get_persistent_peers(plan, peers): persistent_peers[i] = persistent_peers[i] + "@" + peer_service.ip_address + ":26656" return ",".join(persistent_peers) -def create_node(plan, node_struct, peers, paired_el_client_name, jwt_file = None, kzg_trusted_setup_file = None): - beacond_config = create_node_config(plan, node_struct, peers, paired_el_client_name, jwt_file, kzg_trusted_setup_file) - - return plan.add_service( - name = node_struct.cl_service_name, - config = beacond_config, - ) - def init_consensus_nodes(): genesis_file = "{}/config/genesis.json".format("$BEACOND_HOME") diff --git a/kurtosis/src/nodes/execution/execution.star b/kurtosis/src/nodes/execution/execution.star index 5bdb9aaa4f..1d65dcb750 100644 --- a/kurtosis/src/nodes/execution/execution.star +++ b/kurtosis/src/nodes/execution/execution.star @@ -107,14 +107,6 @@ def add_bootnodes(node_module, config, bootnodes): return config -def deploy_node(plan, config): - service_config = service_config_lib.create_from_config(config) - - return plan.add_service( - name = config["name"], - config = service_config, - ) - def deploy_nodes(plan, configs): service_configs = {} for config in configs: @@ -137,17 +129,6 @@ def generate_node_config(plan, node_modules, node_struct, bootnode_enode_addrs = return el_service_config_dict -def create_node(plan, node_modules, node_struct, bootnode_enode_addrs = []): - el_service_config_dict = generate_node_config(plan, node_modules, node_struct, bootnode_enode_addrs) - el_client_service = deploy_node(plan, el_service_config_dict) - - enode_addr = get_enode_addr(plan, node_struct.el_service_name) - return { - "name": node_struct.el_service_name, - "service": el_client_service, - "enode_addr": enode_addr, - } - def add_metrics(metrics_enabled_services, node, el_service_name, el_client_service, node_modules): if node.el_type != "ethereumjs": metrics_enabled_services.append({