Skip to content

Commit

Permalink
[TODO] Blockers @okdas (#674)
Browse files Browse the repository at this point in the history
Co-authored-by: Bryan White <[email protected]>
  • Loading branch information
okdas and bryanchriswhite authored Jul 15, 2024
1 parent d4398f7 commit c6d987c
Show file tree
Hide file tree
Showing 69 changed files with 335 additions and 323 deletions.
21 changes: 9 additions & 12 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
linters-settings:
govet:
check-shadowing: true
enable:
- shadow

# TODO_TECHDEBT: Enable each linter listed, 1 by 1, fixing issues as they appear.
# Don't forget to delete the `disable-all: true` line as well.
linters:
disable-all: true
enable:
# - govet
# - revive
# - errcheck
# - unused
- errcheck
- gosimple
- goimports
- govet
- ineffassign
- staticcheck
- unused

issues:
exclude-use-default: true
max-issues-per-linter: 0
max-same-issues: 0
# TODO_CONSIDERATION/TODO_TECHDEBT: Perhaps we should prefer enforcing the best
# practices suggested by the linters over convention or the default in generated
# code (where possible). The more exceptions we have, the bigger the gaps will be
# in our linting coverage. We could eliminate or reduce these exceptions step-
# by-step.
exclude-rules:
# Exclude cosmos-sdk module genesis.go files as they are generated with an
# empty import block containing a comment used by ignite CLI.
Expand All @@ -48,6 +44,7 @@ issues:
- path: ^x/.+/codec.go$
linters:
- revive
# Exclude test files from errcheck linter
- path: _test\.go$
linters:
- errcheck
Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ endif
####################

# TODO_IMPROVE(@okdas): Add other dependencies (ignite, docker, k8s, etc) here
# TODO_BLOCKER(@okdas): bump `golangci-lint` when we upgrade golang to 1.21+
.PHONY: install_ci_deps
install_ci_deps: ## Installs `mockgen` and other go tools
go install "github.com/golang/mock/[email protected]" && mockgen --version
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.3 && golangci-lint --version
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1 && golangci-lint --version
go install golang.org/x/tools/cmd/goimports@latest
go install github.com/mikefarah/yq/v4@latest

Expand Down
20 changes: 10 additions & 10 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,20 @@ configmap_create(
secret_create_generic(
"poktrolld-keys", from_file=listdir("localnet/poktrolld/keyring-test/")
)

# Import validator keys for the poktrolld helm chart to consume
secret_create_generic(
"poktrolld-validator-keys",
from_file=[
"localnet/poktrolld/config/node_key.json",
"localnet/poktrolld/config/priv_validator_key.json",
],
)

# Import configuration files into Kubernetes ConfigMap
configmap_create(
"poktrolld-configs", from_file=listdir("localnet/poktrolld/config/"), watch=True
)
# TODO_BLOCKER(@okdas): Import validator keys when we switch to `poktrolld` helm chart
# by uncommenting the following lines:
# load("ext://secret", "secret_create_generic")
# secret_create_generic(
# "poktrolld-validator-keys",
# from_file=[
# "localnet/poktrolld/config/node_key.json",
# "localnet/poktrolld/config/priv_validator_key.json",
# ],
# )

# Hot reload protobuf changes
local_resource(
Expand Down
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func New(
appBuilder *runtime.AppBuilder

// merge the AppConfig and other configuration in one config
appConfig = depinject.Configs(
deps = depinject.Configs(
AppConfig(),
depinject.Supply(
// Supply the application options
Expand Down Expand Up @@ -246,7 +246,7 @@ func New(
)
)

if err := depinject.Inject(appConfig,
if err := depinject.Inject(deps,
&appBuilder,
&app.appCodec,
&app.legacyAmino,
Expand Down
68 changes: 40 additions & 28 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
}

for _, delegation := range dels {
valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress)
if err != nil {
panic(err)
valAddr, bech32Err := sdk.ValAddressFromBech32(delegation.ValidatorAddress)
if bech32Err != nil {
panic(bech32Err)
}

delAddr := sdk.MustAccAddressFromBech32(delegation.DelegatorAddress)
Expand All @@ -116,44 +116,44 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str

// reinitialize all validators
err = app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
valBz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator())
if err != nil {
panic(err)
valBz, addrErr := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator())
if addrErr != nil {
panic(addrErr)
}
// donate any unwithdrawn outstanding reward fraction tokens to the community pool
scraps, err := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, valBz)
if err != nil {
panic(err)
scraps, rewardsErr := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, valBz)
if rewardsErr != nil {
panic(rewardsErr)
}
feePool, err := app.DistrKeeper.FeePool.Get(ctx)
if err != nil {
panic(err)
feePool, feeErr := app.DistrKeeper.FeePool.Get(ctx)
if feeErr != nil {
panic(feeErr)
}
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
if err := app.DistrKeeper.FeePool.Set(ctx, feePool); err != nil {
if err = app.DistrKeeper.FeePool.Set(ctx, feePool); err != nil {
panic(err)
}

if err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, valBz); err != nil {
if err = app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, valBz); err != nil {
panic(err)
}
return false
})

// reinitialize all delegations
for _, del := range dels {
valAddr, err := sdk.ValAddressFromBech32(del.ValidatorAddress)
if err != nil {
panic(err)
valAddr, bech32Err := sdk.ValAddressFromBech32(del.ValidatorAddress)
if bech32Err != nil {
panic(bech32Err)
}
delAddr := sdk.MustAccAddressFromBech32(del.DelegatorAddress)

if err := app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr); err != nil {
if err = app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr); err != nil {
// never called as BeforeDelegationCreated always returns nil
panic(fmt.Errorf("error while incrementing period: %w", err))
}

if err := app.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr); err != nil {
if err = app.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr); err != nil {
// never called as AfterDelegationModified always returns nil
panic(fmt.Errorf("error while creating a new delegation period record: %w", err))
}
Expand All @@ -165,7 +165,7 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
/* Handle staking state. */

// iterate through redelegations, reset creation height
app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) {
err = app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) {
for i := range red.Entries {
red.Entries[i].CreationHeight = 0
}
Expand All @@ -175,9 +175,12 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
}
return false
})
if err != nil {
panic(fmt.Errorf("unable to iterate reldelegations: %w", err))
}

// iterate through unbonding delegations, reset creation height
app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) {
err = app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) {
for i := range ubd.Entries {
ubd.Entries[i].CreationHeight = 0
}
Expand All @@ -187,6 +190,9 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
}
return false
})
if err != nil {
panic(fmt.Errorf("unable to iterate unbonding delegations: %w", err))
}

// Iterate through validators by power descending, reset bond heights, and
// update bond intra-tx counters.
Expand All @@ -196,8 +202,8 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str

for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(stakingtypes.AddressFromValidatorsKey(iter.Key()))
validator, err := app.StakingKeeper.GetValidator(ctx, addr)
if err != nil {
validator, valErr := app.StakingKeeper.GetValidator(ctx, addr)
if valErr != nil {
panic("expected validator, not found")
}

Expand All @@ -206,11 +212,13 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
validator.Jailed = true
}

app.StakingKeeper.SetValidator(ctx, validator)
if err = app.StakingKeeper.SetValidator(ctx, validator); err != nil {
panic(fmt.Errorf("unable to set validator: %v: %w", validator, err))
}
counter++
}

if err := iter.Close(); err != nil {
if err = iter.Close(); err != nil {
app.Logger().Error("error while closing the key-value store reverse prefix iterator: ", err)
return
}
Expand All @@ -223,12 +231,16 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
/* Handle slashing state. */

// reset start height on signing infos
app.SlashingKeeper.IterateValidatorSigningInfos(
if err = app.SlashingKeeper.IterateValidatorSigningInfos(
ctx,
func(addr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) (stop bool) {
info.StartHeight = 0
app.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info)
if err = app.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info); err != nil {
panic(fmt.Errorf("unable to set validator signing info: %w", err))
}
return false
},
)
); err != nil {
panic(fmt.Errorf("unable to iterate validator signing infos: %w", err))
}
}
2 changes: 1 addition & 1 deletion app/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v8/modules/core"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck // SA1019
ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
Expand Down
2 changes: 1 addition & 1 deletion cmd/poktrolld/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func appExport(
return servertypes.ExportedApp{}, err
}

if err := bApp.LoadHeight(height); err != nil {
if err = bApp.LoadHeight(height); err != nil {
return servertypes.ExportedApp{}, err
}
} else {
Expand Down
36 changes: 22 additions & 14 deletions cmd/poktrolld/cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package cmd

import (
"errors"
"log"
"os"
"strings"

"cosmossdk.io/client/v2/autocli"
clientv2keyring "cosmossdk.io/client/v2/autocli/keyring"
"cosmossdk.io/core/address"
"cosmossdk.io/depinject"
"cosmossdk.io/log"
cosmoslog "cosmossdk.io/log"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand Down Expand Up @@ -43,7 +45,7 @@ func NewRootCmd() *cobra.Command {
if err := depinject.Inject(
depinject.Configs(app.AppConfig(),
depinject.Supply(
log.NewNopLogger(),
cosmoslog.NewNopLogger(),
),
depinject.Provide(
ProvideClientContext,
Expand All @@ -62,13 +64,13 @@ func NewRootCmd() *cobra.Command {
Use: app.Name + "d",
Short: "Start poktroll node",
SilenceErrors: true,
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
PersistentPreRunE: func(cmd *cobra.Command, _ []string) (err error) {
// set the default command outputs
cmd.SetOut(cmd.OutOrStdout())
cmd.SetErr(cmd.ErrOrStderr())

clientCtx = clientCtx.WithCmdContext(cmd.Context())
clientCtx, err := client.ReadPersistentCommandFlags(clientCtx, cmd.Flags())
clientCtx, err = client.ReadPersistentCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
Expand All @@ -91,11 +93,11 @@ func NewRootCmd() *cobra.Command {
}

clientCtx = clientCtx.WithTxConfig(txConfigWithTextual)
if err := client.SetCmdClientContextHandler(clientCtx, cmd); err != nil {
if err = client.SetCmdClientContextHandler(clientCtx, cmd); err != nil {
return err
}

if err := client.SetCmdClientContextHandler(clientCtx, cmd); err != nil {
if err = client.SetCmdClientContextHandler(clientCtx, cmd); err != nil {
return err
}

Expand All @@ -115,10 +117,12 @@ func NewRootCmd() *cobra.Command {
}
initRootCmd(rootCmd, clientCtx.TxConfig, clientCtx.InterfaceRegistry, clientCtx.Codec, moduleBasicManager)

overwriteFlagDefaults(rootCmd, map[string]string{
if err := overwriteFlagDefaults(rootCmd, map[string]string{
flags.FlagChainID: strings.ReplaceAll(app.Name, "-", ""),
flags.FlagKeyringBackend: "test",
})
}); err != nil {
log.Fatal(err)
}

if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil {
panic(err)
Expand All @@ -137,20 +141,24 @@ func NewRootCmd() *cobra.Command {
return rootCmd
}

func overwriteFlagDefaults(c *cobra.Command, defaults map[string]string) {
set := func(s *pflag.FlagSet, key, val string) {
func overwriteFlagDefaults(c *cobra.Command, defaults map[string]string) (err error) {
set := func(s *pflag.FlagSet, key, val string) error {
if f := s.Lookup(key); f != nil {
f.DefValue = val
f.Value.Set(val)
if err = f.Value.Set(val); err != nil {
return err
}
}
return nil
}
for key, val := range defaults {
set(c.Flags(), key, val)
set(c.PersistentFlags(), key, val)
err = errors.Join(err, set(c.Flags(), key, val))
err = errors.Join(err, set(c.PersistentFlags(), key, val))
}
for _, c := range c.Commands() {
overwriteFlagDefaults(c, defaults)
err = errors.Join(err, overwriteFlagDefaults(c, defaults))
}
return err
}

func ProvideClientContext(
Expand Down
2 changes: 1 addition & 1 deletion docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func handler(title string) http.HandlerFunc {
t, _ := httptemplate.ParseFS(template, indexFile)

return func(w http.ResponseWriter, req *http.Request) {
t.Execute(w, struct {
_ = t.Execute(w, struct {
Title string
URL string
}{
Expand Down
Loading

0 comments on commit c6d987c

Please sign in to comment.