Skip to content

Commit

Permalink
Squashed Commits
Browse files Browse the repository at this point in the history
  • Loading branch information
rezbera committed Feb 3, 2025
1 parent 1aff871 commit f81e675
Show file tree
Hide file tree
Showing 6 changed files with 755 additions and 53 deletions.
108 changes: 56 additions & 52 deletions cli/commands/genesis/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/berachain/beacon-kit/consensus-types/types"
"github.com/berachain/beacon-kit/errors"
"github.com/berachain/beacon-kit/primitives/encoding/json"
cmtcfg "github.com/cometbft/cometbft/config"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/spf13/afero"
Expand All @@ -43,64 +44,67 @@ func CollectGenesisDepositsCmd() *cobra.Command {
Short: "adds a validator to the genesis file",
RunE: func(cmd *cobra.Command, _ []string) error {
config := context.GetConfigFromCmd(cmd)

appGenesis, err := genutiltypes.AppGenesisFromFile(
config.GenesisFile(),
)
if err != nil {
return errors.Wrap(err, "failed to read genesis doc from file")
}

// create the app state
appGenesisState, err := genutiltypes.GenesisStateFromAppGenesis(
appGenesis,
)
if err != nil {
return err
}

var deposits []*types.Deposit
if deposits, err = CollectValidatorJSONFiles(
filepath.Join(config.RootDir, "config", "premined-deposits"),
appGenesis,
); err != nil {
return errors.Wrap(
err,
"failed to collect validator json files",
)
}

genesisInfo := &types.Genesis{}

if err = json.Unmarshal(
appGenesisState["beacon"], genesisInfo,
); err != nil {
return errors.Wrap(err, "failed to unmarshal beacon genesis")
}

for i, deposit := range deposits {
deposit.Index = uint64(i) // #nosec G115 -- won't realistically overflow.
genesisInfo.Deposits = append(genesisInfo.Deposits, deposit)
}

appGenesisState["beacon"], err = json.Marshal(genesisInfo)
if err != nil {
return errors.Wrap(err, "failed to marshal beacon genesis")
}

if appGenesis.AppState, err = json.MarshalIndent(
appGenesisState, "", " ",
); err != nil {
return err
}

return genutil.ExportGenesisFile(appGenesis, config.GenesisFile())
return CollectGenesisValidators(config)
},
}

return cmd
}

func CollectGenesisValidators(config *cmtcfg.Config) error {
appGenesis, err := genutiltypes.AppGenesisFromFile(
config.GenesisFile(),
)
if err != nil {
return errors.Wrap(err, "failed to read genesis doc from file")
}

// create the app state
appGenesisState, err := genutiltypes.GenesisStateFromAppGenesis(
appGenesis,
)
if err != nil {
return err
}

var deposits []*types.Deposit
if deposits, err = CollectValidatorJSONFiles(
filepath.Join(config.RootDir, "config", "premined-deposits"),
appGenesis,
); err != nil {
return errors.Wrap(
err,
"failed to collect validator json files",
)
}

genesisInfo := &types.Genesis{}

if err = json.Unmarshal(
appGenesisState["beacon"], genesisInfo,
); err != nil {
return errors.Wrap(err, "failed to unmarshal beacon genesis")
}

for i, deposit := range deposits {
deposit.Index = uint64(i) // #nosec G115 -- won't realistically overflow.
genesisInfo.Deposits = append(genesisInfo.Deposits, deposit)
}

appGenesisState["beacon"], err = json.Marshal(genesisInfo)
if err != nil {
return errors.Wrap(err, "failed to marshal beacon genesis")
}

if appGenesis.AppState, err = json.MarshalIndent(
appGenesisState, "", " ",
); err != nil {
return err
}

return genutil.ExportGenesisFile(appGenesis, config.GenesisFile())
}

// CollectValidatorJSONFiles collects JSON files from the specified directory
// and unmarshals them into a list of Deposit objects.
func CollectValidatorJSONFiles(
Expand Down
10 changes: 10 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ func (c Config) GetEngine() *engineclient.Config {
return &c.Engine
}

// GetPayloadBuilder returns the block store configuration.
func (c Config) GetPayloadBuilder() *builder.Config {
return &c.PayloadBuilder
}

// GetBlockStoreService returns the block store configuration.
func (c Config) GetBlockStoreService() *blockstore.Config {
return &c.BlockStoreService
}

// GetLogger returns the logger configuration.
func (c Config) GetLogger() *log.Config {
return &c.Logger
Expand Down
1 change: 0 additions & 1 deletion consensus/cometbft/service/init_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func (s *Service) initChain(

s.finalizeBlockState = s.resetState(ctx)

//nolint:contextcheck // ctx already passed via resetState
resValidators, err := s.initChainer(

Check failure on line 88 in consensus/cometbft/service/init_chain.go

View workflow job for this annotation

GitHub Actions / lint

Function `initChainer` should pass the context parameter (contextcheck)
s.finalizeBlockState.Context(),
req.AppStateBytes,
Expand Down
Loading

0 comments on commit f81e675

Please sign in to comment.