Skip to content

Commit

Permalink
feat(node): more cleanup (#1875)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsdevbear authored Aug 9, 2024
1 parent 99679c5 commit 015a5df
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 105 deletions.
8 changes: 5 additions & 3 deletions mod/node-core/pkg/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"cosmossdk.io/depinject"
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
"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"
Expand Down Expand Up @@ -75,11 +76,12 @@ func (nb *NodeBuilder[NodeT]) Build(
// variables to hold the components needed to set up BeaconApp
var (
chainSpec common.ChainSpec
appBuilder *runtime.AppBuilder
abciMiddleware *components.ABCIMiddleware
serviceRegistry *service.Registry
consensusEngine *components.ConsensusEngine
apiBackend *components.NodeAPIBackend
storeKey = new(storetypes.KVStoreKey)
storeKeyDblPtr = &storeKey
)

// build all node components using depinject
Expand All @@ -96,7 +98,7 @@ func (nb *NodeBuilder[NodeT]) Build(
SetLoggerConfig,
),
),
&appBuilder,
&storeKeyDblPtr,
&chainSpec,
&abciMiddleware,
&serviceRegistry,
Expand All @@ -109,7 +111,7 @@ func (nb *NodeBuilder[NodeT]) Build(
// set the application to a new BeaconApp with necessary ABCI handlers
nb.node.RegisterApp(
runtime.NewBeaconKitApp(
db, traceStore, true, appBuilder, abciMiddleware,
*storeKeyDblPtr, logger, db, traceStore, true, abciMiddleware,
append(
DefaultBaseappOptions(appOpts),
WithCometParamStore(chainSpec),
Expand Down
1 change: 0 additions & 1 deletion mod/node-core/pkg/components/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func DefaultComponentsWithStandardTypes() []any {
// TODO Hacks
ProvideKVStoreService,
ProvideKVStoreKey,
ProvideApp,
}
components = append(components, DefaultNodeAPIComponents()...)
components = append(components, DefaultNodeAPIHandlers()...)
Expand Down
22 changes: 4 additions & 18 deletions mod/node-core/pkg/components/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,20 @@ import (
"context"

"cosmossdk.io/core/store"
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
"github.com/berachain/beacon-kit/mod/runtime/pkg/cosmos/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func ProvideKVStoreKey(
app *runtime.AppBuilder,
) *storetypes.KVStoreKey {
func ProvideKVStoreKey() **storetypes.KVStoreKey {
storeKey := storetypes.NewKVStoreKey("beacon")
app.App.StoreKeys = append(app.App.StoreKeys, storeKey)
return storeKey
return &storeKey
}

func ProvideKVStoreService(
app *runtime.AppBuilder,
storeKey **storetypes.KVStoreKey,
) store.KVStoreService {
// skips modules that have no store
return kvStoreService{key: ProvideKVStoreKey(app)}
}

func ProvideApp(middleware runtime.Middleware) (
*runtime.AppBuilder,
error,
) {
app := &runtime.App{Middleware: middleware}
app.Logger = log.NewNopLogger()
return &runtime.AppBuilder{App: app}, nil
return kvStoreService{key: *storeKey}
}

func NewKVStoreService(storeKey *storetypes.KVStoreKey) store.KVStoreService {
Expand Down
6 changes: 0 additions & 6 deletions mod/runtime/pkg/cosmos/baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,6 @@ func (app *BaseApp) MountStores(keys ...storetypes.StoreKey) {
switch key.(type) {
case *storetypes.KVStoreKey:
app.MountStore(key, storetypes.StoreTypeIAVL)
case *storetypes.TransientStoreKey:
app.MountStore(key, storetypes.StoreTypeTransient)

case *storetypes.MemoryStoreKey:
app.MountStore(key, storetypes.StoreTypeMemory)

default:
panic(fmt.Sprintf("Unrecognized store key type :%T", key))
}
Expand Down
38 changes: 15 additions & 23 deletions mod/runtime/pkg/cosmos/runtime/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,19 @@ import (
"github.com/berachain/beacon-kit/mod/runtime/pkg/cosmos/baseapp"
abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
dbm "github.com/cosmos/cosmos-db"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/gogoproto/proto"
"github.com/sourcegraph/conc/iter"
)

var _ servertypes.Application = &App{}

// App can be used to create a hybrid app.go setup where some configuration is
// done declaratively with an app config and the rest of it is done the old way.
// See simapp/app.go for an example of this setup.
type App struct {
*baseapp.BaseApp

Middleware Middleware
StoreKeys []storetypes.StoreKey
Logger log.Logger
// initChainer is the init chainer function defined by the app config.
// this is only required if the chain wants to add special InitChainer
// logic.
Expand All @@ -59,40 +55,36 @@ type App struct {

// NewBeaconKitApp returns a reference to an initialized BeaconApp.
func NewBeaconKitApp(
storeKey *storetypes.KVStoreKey,
logger log.Logger,
db dbm.DB,
traceStore io.Writer,
loadLatest bool,
appBuilder *AppBuilder,
middleware Middleware,
baseAppOptions ...func(*baseapp.BaseApp),
) *App {
app := &App{
BaseApp: baseapp.NewBaseApp(
"BeaconKit",
logger,
db,
baseAppOptions...),
Middleware: middleware,
}

// Build the runtime.App using the app builder.
app = appBuilder.Build(db, traceStore, baseAppOptions...)
app.SetVersion(version.Version)
app.MountStore(storeKey, storetypes.StoreTypeIAVL)
app.SetInitChainer(app.InitChainer)
app.SetFinalizeBlocker(app.FinalizeBlocker)

// Load the app.
if err := app.Load(loadLatest); err != nil {
panic(err)
}

return app
}

// Load finishes all initialization operations and loads the app.
func (a *App) Load(loadLatest bool) error {
a.SetInitChainer(a.InitChainer)
a.SetFinalizeBlocker(a.FinalizeBlocker)

if loadLatest {
if err := a.LoadLatestVersion(); err != nil {
return err
if err := app.LoadLatestVersion(); err != nil {
panic(err)
}
}

return nil
return app
}

// FinalizeBlocker application updates every end block.
Expand Down
54 changes: 0 additions & 54 deletions mod/runtime/pkg/cosmos/runtime/builder.go

This file was deleted.

0 comments on commit 015a5df

Please sign in to comment.