Skip to content

Commit

Permalink
wip(deps): remove sdklog & some client context (berachain#1972)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocnc2 authored Aug 25, 2024
1 parent c5184c9 commit 98dbc42
Show file tree
Hide file tree
Showing 34 changed files with 327 additions and 230 deletions.
9 changes: 4 additions & 5 deletions beacond/cmd/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package main

import (
cometbft "github.com/berachain/beacon-kit/mod/consensus/pkg/cometbft/service"
"github.com/berachain/beacon-kit/mod/node-core/pkg/components"
)

Expand Down Expand Up @@ -106,7 +105,7 @@ func DefaultComponents() []any {
*ExecutionPayload, *ExecutionPayloadHeader, *KVStore, *Logger,
],
components.ProvideReportingService[*Logger],
components.ProvideCometBFTService,
components.ProvideCometBFTService[*Logger],
components.ProvideServiceRegistry[
*AvailabilityStore, *BeaconBlock, *BeaconBlockBody,
*BeaconBlockHeader, *BlockStore, *BeaconState,
Expand Down Expand Up @@ -149,7 +148,7 @@ func DefaultComponents() []any {
*AvailabilityStore, *BeaconBlock, *BeaconBlockBody,
*BeaconBlockHeader, *BlockStore, *BeaconState,
*BeaconStateMarshallable, *BlobSidecars, *Deposit, *DepositStore,
*ExecutionPayloadHeader, *KVStore, *cometbft.Service, *StorageBackend,
*ExecutionPayloadHeader, *KVStore, *CometBFTService, *StorageBackend,
],
)

Expand All @@ -159,7 +158,7 @@ func DefaultComponents() []any {
*ExecutionPayloadHeader, *KVStore, NodeAPIContext,
],
components.ProvideNodeAPIBeaconHandler[
*BeaconBlockHeader, *BeaconState, *cometbft.Service, NodeAPIContext,
*BeaconBlockHeader, *BeaconState, *CometBFTService, NodeAPIContext,
],
components.ProvideNodeAPIBuilderHandler[NodeAPIContext],
components.ProvideNodeAPIConfigHandler[NodeAPIContext],
Expand All @@ -168,7 +167,7 @@ func DefaultComponents() []any {
components.ProvideNodeAPINodeHandler[NodeAPIContext],
components.ProvideNodeAPIProofHandler[
*BeaconBlockHeader, *BeaconState, *BeaconStateMarshallable,
*ExecutionPayloadHeader, *KVStore, *cometbft.Service, NodeAPIContext,
*ExecutionPayloadHeader, *KVStore, *CometBFTService, NodeAPIContext,
],
)

Expand Down
1 change: 0 additions & 1 deletion beacond/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func run() error {
clicomponents.DefaultClientComponents(),
// TODO: remove these, and eventually pull cfg and chainspec
// from built node
nodecomponents.ProvideConfig,
nodecomponents.ProvideChainSpec,
),
),
Expand Down
5 changes: 4 additions & 1 deletion beacond/cmd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ type (
*PayloadAttributes,
]

// CometBFTService is a type alias for the CometBFT service.
CometBFTService = cometbft.Service[*Logger]

// ConsensusMiddleware is a type alias for the consensus middleware.
ConsensusMiddleware = cometbft.MiddlewareI

Expand Down Expand Up @@ -348,7 +351,7 @@ type (
*Eth1Data,
*ExecutionPayloadHeader,
*Fork,
*cometbft.Service,
*CometBFTService,
*KVStore,
*StorageBackend,
*Validator,
Expand Down
4 changes: 2 additions & 2 deletions mod/cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ replace (
)

require (
cosmossdk.io/core v1.0.0
cosmossdk.io/depinject v1.0.0
cosmossdk.io/log v1.4.1
github.com/berachain/beacon-kit/mod/config v0.0.0-20240705193247-d464364483df
github.com/berachain/beacon-kit/mod/consensus v0.0.0-20240821053614-036c5d2945f0
github.com/berachain/beacon-kit/mod/consensus-types v0.0.0-20240821182712-08bbb9c7d685
Expand All @@ -43,7 +41,9 @@ require (
)

require (
cosmossdk.io/core v1.0.0 // indirect
cosmossdk.io/errors/v2 v2.0.0-20240731132947-df72853b3ca5 // indirect
cosmossdk.io/log v1.4.1 // indirect
cosmossdk.io/schema v0.1.1 // indirect
github.com/berachain/beacon-kit/mod/beacon v0.0.0-20240821052951-c15422305b4e // indirect
github.com/berachain/beacon-kit/mod/chain-spec v0.0.0-20240705193247-d464364483df // indirect
Expand Down
4 changes: 2 additions & 2 deletions mod/cli/pkg/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type CLIBuilder[
// nodeBuilderFunc is a function that builds the Node,
// eventually called by the cosmos-sdk.
// TODO: CLI should not know about the AppCreator
nodeBuilderFunc servertypes.AppCreator[T]
nodeBuilderFunc servertypes.AppCreator[T, LoggerT]
}

// New returns a new CLIBuilder with the given options.
Expand Down Expand Up @@ -111,7 +111,7 @@ func (cb *CLIBuilder[
// apply default root command setup
cmdlib.DefaultRootCommandSetup[T, ExecutionPayloadT](
rootCmd,
&cometbft.Service{},
&cometbft.Service[LoggerT]{},
cb.nodeBuilderFunc,
chainSpec,
)
Expand Down
2 changes: 1 addition & 1 deletion mod/cli/pkg/builder/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func WithNodeBuilderFunc[
ExecutionPayloadT constraints.EngineType[ExecutionPayloadT],
LoggerT log.AdvancedLogger[LoggerT],
](
nodeBuilderFunc servertypes.AppCreator[T],
nodeBuilderFunc servertypes.AppCreator[T, LoggerT],
) Opt[T, ExecutionPayloadT, LoggerT] {
return func(cb *CLIBuilder[T, ExecutionPayloadT, LoggerT]) {
cb.nodeBuilderFunc = nodeBuilderFunc
Expand Down
4 changes: 2 additions & 2 deletions mod/cli/pkg/commands/genesis/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
"path/filepath"
"strings"

"github.com/berachain/beacon-kit/mod/cli/pkg/context"
"github.com/berachain/beacon-kit/mod/consensus-types/pkg/types"
"github.com/berachain/beacon-kit/mod/errors"
"github.com/berachain/beacon-kit/mod/primitives/pkg/encoding/json"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/spf13/afero"
Expand All @@ -42,7 +42,7 @@ func CollectGenesisDepositsCmd() *cobra.Command {
Use: "collect-premined-deposits",
Short: "adds a validator to the genesis file",
RunE: func(cmd *cobra.Command, _ []string) error {
config := client.GetConfigFromCmd(cmd)
config := context.GetConfigFromCmd(cmd)

appGenesis, err := genutiltypes.AppGenesisFromFile(
config.GenesisFile(),
Expand Down
6 changes: 3 additions & 3 deletions mod/cli/pkg/commands/genesis/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os"
"path/filepath"

"github.com/berachain/beacon-kit/mod/cli/pkg/context"
"github.com/berachain/beacon-kit/mod/cli/pkg/utils/parser"
"github.com/berachain/beacon-kit/mod/consensus-types/pkg/types"
"github.com/berachain/beacon-kit/mod/errors"
Expand All @@ -35,7 +36,6 @@ import (
"github.com/berachain/beacon-kit/mod/primitives/pkg/encoding/json"
"github.com/berachain/beacon-kit/mod/primitives/pkg/math"
"github.com/berachain/beacon-kit/mod/primitives/pkg/version"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/x/genutil"
"github.com/spf13/afero"
Expand All @@ -49,7 +49,7 @@ func AddGenesisDepositCmd(cs common.ChainSpec) *cobra.Command {
Use: "add-premined-deposit",
Short: "adds a validator to the genesis file",
RunE: func(cmd *cobra.Command, _ []string) error {
config := client.GetConfigFromCmd(cmd)
config := context.GetConfigFromCmd(cmd)

_, valPubKey, err := genutil.InitializeNodeValidatorFiles(
config, crypto.CometBLSType,
Expand All @@ -69,7 +69,7 @@ func AddGenesisDepositCmd(cs common.ChainSpec) *cobra.Command {
// Get the BLS signer.
blsSigner, err := components.ProvideBlsSigner(
components.BlsSignerInput{
AppOpts: client.GetViperFromCmd(cmd),
AppOpts: context.GetViperFromCmd(cmd),
},
)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions mod/cli/pkg/commands/genesis/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package genesis
import (
"unsafe"

"github.com/berachain/beacon-kit/mod/cli/pkg/context"
"github.com/berachain/beacon-kit/mod/consensus-types/pkg/types"
engineprimitives "github.com/berachain/beacon-kit/mod/engine-primitives/pkg/engine-primitives"
"github.com/berachain/beacon-kit/mod/errors"
Expand All @@ -32,7 +33,6 @@ import (
"github.com/berachain/beacon-kit/mod/primitives/pkg/encoding/json"
"github.com/berachain/beacon-kit/mod/primitives/pkg/math"
"github.com/berachain/beacon-kit/mod/primitives/pkg/version"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/spf13/afero"
Expand Down Expand Up @@ -65,7 +65,7 @@ func AddExecutionPayloadCmd(chainSpec common.ChainSpec) *cobra.Command {
nil,
).ExecutionPayload

config := client.GetConfigFromCmd(cmd)
config := context.GetConfigFromCmd(cmd)

appGenesis, err := genutiltypes.AppGenesisFromFile(
config.GenesisFile(),
Expand Down
22 changes: 13 additions & 9 deletions mod/cli/pkg/commands/server/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,24 @@ import (

"cosmossdk.io/store"
types "github.com/berachain/beacon-kit/mod/cli/pkg/commands/server/types"
clicontext "github.com/berachain/beacon-kit/mod/cli/pkg/context"
"github.com/berachain/beacon-kit/mod/log"
"github.com/berachain/beacon-kit/mod/storage/pkg/db"
cmtcmd "github.com/cometbft/cometbft/cmd/cometbft/commands"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/client"
"github.com/spf13/cobra"
)

// NewRollbackCmd creates a command to rollback CometBFT and multistore state by
// one height.
func NewRollbackCmd[T interface {
Start(context.Context) error
CommitMultiStore() store.CommitMultiStore
}](
appCreator types.AppCreator[T],
func NewRollbackCmd[
T interface {
Start(context.Context) error
CommitMultiStore() store.CommitMultiStore
},
LoggerT log.AdvancedLogger[LoggerT],
](
appCreator types.AppCreator[T, LoggerT],
) *cobra.Command {
var removeBlock bool

Expand All @@ -56,9 +60,9 @@ restarting CometBFT the transactions in block n will be re-executed against the
application.
`,
RunE: func(cmd *cobra.Command, _ []string) error {
v := client.GetViperFromCmd(cmd)
logger := client.GetLoggerFromCmd(cmd)
cfg := client.GetConfigFromCmd(cmd)
v := clicontext.GetViperFromCmd(cmd)
logger := clicontext.GetLoggerFromCmd[LoggerT](cmd)
cfg := clicontext.GetConfigFromCmd(cmd)

db, err := db.OpenDB(cfg.RootDir, dbm.PebbleDBBackend)
if err != nil {
Expand Down
49 changes: 30 additions & 19 deletions mod/cli/pkg/commands/server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ import (

pruningtypes "cosmossdk.io/store/pruning/types"
types "github.com/berachain/beacon-kit/mod/cli/pkg/commands/server/types"
clicontext "github.com/berachain/beacon-kit/mod/cli/pkg/context"
"github.com/berachain/beacon-kit/mod/log"
"github.com/berachain/beacon-kit/mod/storage/pkg/db"
cmtcmd "github.com/cometbft/cometbft/cmd/cometbft/commands"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/client"
"github.com/spf13/cobra"
)

Expand All @@ -51,30 +52,38 @@ const (

// StartCmdOptions defines options that can be customized in
// `StartCmdWithOptions`,.
type StartCmdOptions[T interface {
Start(context.Context) error
}] struct {
type StartCmdOptions[
T interface {
Start(context.Context) error
},
] struct {
// AddFlags allows adding custom flags to the start command.
AddFlags func(cmd *cobra.Command)
}

// StartCmd runs the service passed in, either stand-alone or in-process with
// CometBFT.
func StartCmd[T interface {
Start(context.Context) error
}](
appCreator types.AppCreator[T],
func StartCmd[
T interface {
Start(context.Context) error
},
LoggerT log.AdvancedLogger[LoggerT],
](
appCreator types.AppCreator[T, LoggerT],
) *cobra.Command {
return StartCmdWithOptions(appCreator, StartCmdOptions[T]{})
return StartCmdWithOptions[T, LoggerT](appCreator, StartCmdOptions[T]{})
}

// StartCmdWithOptions runs the service passed in, either stand-alone or
// in-process with
// CometBFT.
func StartCmdWithOptions[T interface {
Start(context.Context) error
}](
appCreator types.AppCreator[T],
func StartCmdWithOptions[
T interface {
Start(context.Context) error
},
LoggerT log.AdvancedLogger[LoggerT],
](
appCreator types.AppCreator[T, LoggerT],
opts StartCmdOptions[T],
) *cobra.Command {
//nolint:lll // its okay.
Expand All @@ -96,9 +105,9 @@ custom: allow pruning options to be manually specified through 'pruning-keep-rec
`,
RunE: func(cmd *cobra.Command, _ []string) error {
logger := client.GetLoggerFromCmd(cmd)
cfg := client.GetConfigFromCmd(cmd)
v := client.GetViperFromCmd(cmd)
logger := clicontext.GetLoggerFromCmd[LoggerT](cmd)
cfg := clicontext.GetConfigFromCmd(cmd)
v := clicontext.GetViperFromCmd(cmd)
_, err := GetPruningOptionsFromFlags(v)
if err != nil {
return err
Expand All @@ -123,9 +132,11 @@ custom: allow pruning options to be manually specified through 'pruning-keep-rec
// addStartNodeFlags should be added to any CLI commands that start the network.
//
//nolint:lll // todo fix.
func addStartNodeFlags[T interface {
Start(context.Context) error
}](
func addStartNodeFlags[
T interface {
Start(context.Context) error
},
](
cmd *cobra.Command,
opts StartCmdOptions[T],
) {
Expand Down
17 changes: 11 additions & 6 deletions mod/cli/pkg/commands/server/types/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"context"
"io"

"cosmossdk.io/log"
"github.com/berachain/beacon-kit/mod/log"
cmtcfg "github.com/cometbft/cometbft/config"
dbm "github.com/cosmos/cosmos-db"
)
Expand All @@ -45,9 +45,14 @@ type (

// AppCreator is a function that allows us to lazily initialize an
// application using various configurations.
AppCreator[T interface {
Start(ctx context.Context) error
}] func(
log.Logger, dbm.DB, io.Writer, *cmtcfg.Config, AppOptions,
) T
AppCreator[
AppT interface {
Start(ctx context.Context) error
},
LoggerT interface {
log.AdvancedLogger[LoggerT]
},
] func(
LoggerT, dbm.DB, io.Writer, *cmtcfg.Config, AppOptions,
) AppT
)
6 changes: 4 additions & 2 deletions mod/cli/pkg/commands/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/berachain/beacon-kit/mod/cli/pkg/flags"
cmtcli "github.com/berachain/beacon-kit/mod/consensus/pkg/cometbft/cli"
cometbft "github.com/berachain/beacon-kit/mod/consensus/pkg/cometbft/service"
"github.com/berachain/beacon-kit/mod/log"
"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/primitives/pkg/constraints"
Expand All @@ -40,10 +41,11 @@ import (
func DefaultRootCommandSetup[
T types.Node,
ExecutionPayloadT constraints.EngineType[ExecutionPayloadT],
LoggerT log.AdvancedLogger[LoggerT],
](
root *Root,
mm *cometbft.Service,
appCreator servertypes.AppCreator[T],
mm *cometbft.Service[LoggerT],
appCreator servertypes.AppCreator[T, LoggerT],
chainSpec common.ChainSpec,
) {
// Add all the commands to the root command.
Expand Down
Loading

0 comments on commit 98dbc42

Please sign in to comment.