Skip to content

Commit 71a80eb

Browse files
committed
Fix lint errors, remove unused code and fix typos
1 parent 73bdddf commit 71a80eb

File tree

17 files changed

+121
-193
lines changed

17 files changed

+121
-193
lines changed

app/app.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737
sigtypes "github.com/cosmos/cosmos-sdk/types/tx/signing"
3838
txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
3939

40-
// "github.com/cosmos/cosmos-sdk/simapp"
4140
"github.com/cosmos/cosmos-sdk/runtime"
4241
sdk "github.com/cosmos/cosmos-sdk/types"
4342
"github.com/cosmos/cosmos-sdk/types/module"
@@ -60,14 +59,11 @@ import (
6059
v1_7 "github.com/scrtlabs/SecretNetwork/app/upgrades/v1.7"
6160
v1_8 "github.com/scrtlabs/SecretNetwork/app/upgrades/v1.8"
6261

63-
// v1_9 "github.com/scrtlabs/SecretNetwork/app/upgrades/v1.9"
64-
6562
icaauthtypes "github.com/scrtlabs/SecretNetwork/x/mauth/types"
6663

6764
"github.com/cosmos/cosmos-sdk/version"
6865
"github.com/cosmos/cosmos-sdk/x/auth/ante"
6966

70-
// authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
7167
evidencetypes "cosmossdk.io/x/evidence/types"
7268
"cosmossdk.io/x/feegrant"
7369
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
@@ -84,7 +80,6 @@ import (
8480
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
8581
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
8682

87-
// stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
8883
"cosmossdk.io/log"
8984
upgradetypes "cosmossdk.io/x/upgrade/types"
9085
abci "github.com/cometbft/cometbft/abci/types"
@@ -118,13 +113,11 @@ var (
118113
}
119114

120115
Upgrades = []upgrades.Upgrade{
121-
// v1_3.Upgrade,
122116
v1_4.Upgrade,
123117
v1_5.Upgrade,
124118
v1_6.Upgrade,
125119
v1_7.Upgrade,
126120
v1_8.Upgrade,
127-
// v1_9.Upgrade,
128121
v1_10.Upgrade,
129122
v1_11.Upgrade,
130123
v1_12.Upgrade,
@@ -134,7 +127,6 @@ var (
134127

135128
// Verify app interface at compile time
136129
var (
137-
// _ simapp.App = (*SecretNetworkApp)(nil)
138130
_ runtime.AppI = (*SecretNetworkApp)(nil)
139131
_ servertypes.Application = (*SecretNetworkApp)(nil)
140132
)
@@ -168,10 +160,6 @@ func (app *SecretNetworkApp) GetInterfaceRegistry() types.InterfaceRegistry {
168160
return app.interfaceRegistry
169161
}
170162

171-
func (app *SecretNetworkApp) GetCodec() codec.Codec {
172-
return app.appCodec
173-
}
174-
175163
func (app *SecretNetworkApp) GetBaseApp() *baseapp.BaseApp {
176164
return app.BaseApp
177165
}
@@ -291,7 +279,8 @@ func NewSecretNetworkApp(
291279

292280
app.AppKeepers.InitSdkKeepers(appCodec, legacyAmino, bApp, ModuleAccountPermissions, app.BlockedAddrs(), invCheckPeriod, skipUpgradeHeights, homePath, logger, &app.event)
293281

294-
enabledSignModes := append(authtx.DefaultSignModes, sigtypes.SignMode_SIGN_MODE_TEXTUAL)
282+
enabledSignModes := authtx.DefaultSignModes
283+
enabledSignModes = append(enabledSignModes, sigtypes.SignMode_SIGN_MODE_TEXTUAL)
295284

296285
signingOpts, err := authtx.NewDefaultSigningOptions()
297286
if err != nil {
@@ -445,7 +434,9 @@ func (app *SecretNetworkApp) InitChainer(ctx sdk.Context, req *abci.RequestInitC
445434
panic(err)
446435
}
447436

448-
app.AppKeepers.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())
437+
if err := app.AppKeepers.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap()); err != nil {
438+
panic(err)
439+
}
449440

450441
return app.mm.InitGenesis(ctx, app.appCodec, genesisState)
451442
}

app/config.go

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/cosmos/cosmos-sdk/client"
99
"github.com/cosmos/cosmos-sdk/codec"
1010
"github.com/cosmos/cosmos-sdk/codec/address"
11-
"github.com/cosmos/cosmos-sdk/codec/types"
1211
sdk "github.com/cosmos/cosmos-sdk/types"
1312
"github.com/cosmos/cosmos-sdk/types/module"
1413
"github.com/cosmos/cosmos-sdk/x/auth"
@@ -84,14 +83,6 @@ var mbasics = module.NewBasicManager(
8483
)...,
8584
)
8685

87-
func customKVStoreKeys() []string {
88-
return []string{
89-
compute.StoreKey,
90-
registration.StoreKey,
91-
icaauth.StoreKey,
92-
}
93-
}
94-
9586
func customModuleBasics() []module.AppModuleBasic {
9687
return []module.AppModuleBasic{
9788
compute.AppModuleBasic{},
@@ -109,42 +100,12 @@ func ModuleBasics() module.BasicManager {
109100
// EncodingConfig specifies the concrete encoding types to use for a given app.
110101
// This is provided for compatibility between protobuf and amino implementations.
111102
type EncodingConfig struct {
112-
InterfaceRegistry types.InterfaceRegistry
103+
InterfaceRegistry codectypes.InterfaceRegistry
113104
Codec codec.Codec
114105
TxConfig client.TxConfig
115106
Amino *codec.LegacyAmino
116107
}
117108

118-
// func MakeEncodingConfig() EncodingConfig {
119-
// amino := codec.NewLegacyAmino()
120-
// interfaceRegistry, _ := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{
121-
// ProtoFiles: proto.HybridResolver,
122-
// SigningOptions: signing.Options{
123-
// AddressCodec: address.Bech32Codec{
124-
// Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(),
125-
// },
126-
// ValidatorAddressCodec: address.Bech32Codec{
127-
// Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(),
128-
// },
129-
// },
130-
// })
131-
// appCodec := codec.NewProtoCodec(interfaceRegistry)
132-
// txCfg := tx.NewTxConfig(appCodec, tx.DefaultSignModes)
133-
134-
// std.RegisterInterfaces(interfaceRegistry)
135-
// std.RegisterLegacyAminoCodec(amino)
136-
137-
// ModuleBasics().RegisterLegacyAminoCodec(amino)
138-
// ModuleBasics().RegisterInterfaces(interfaceRegistry)
139-
140-
// return EncodingConfig{
141-
// InterfaceRegistry: interfaceRegistry,
142-
// Codec: appCodec,
143-
// TxConfig: txCfg,
144-
// Amino: amino,
145-
// }
146-
// }
147-
148109
type (
149110
CodecOptions struct {
150111
AccAddressPrefix string

app/encoding.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

app/export.go

Lines changed: 92 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package app
22

33
import (
44
"encoding/json"
5+
"fmt"
6+
7+
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
58

69
storetypes "cosmossdk.io/store/types"
710
servertypes "github.com/cosmos/cosmos-sdk/server/types"
@@ -14,7 +17,7 @@ import (
1417
func (app *SecretNetworkApp) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddrs []string, modulesToExport []string,
1518
) (servertypes.ExportedApp, error) {
1619
// as if they could withdraw from the start of the next block
17-
ctx := app.BaseApp.NewContext(true)
20+
ctx := app.NewContextLegacy(true, cmtproto.Header{Height: app.LastBlockHeight()})
1821

1922
// We export at last height + 1, because that's the height at which
2023
// Tendermint will start InitChain.
@@ -44,7 +47,7 @@ func (app *SecretNetworkApp) ExportAppStateAndValidators(forZeroHeight bool, jai
4447
Validators: validators,
4548
Height: height,
4649
ConsensusParams: app.BaseApp.GetConsensusParams(ctx),
47-
}, nil
50+
}, err
4851
}
4952

5053
// prepare for fresh start at zero height
@@ -75,24 +78,31 @@ func (app *SecretNetworkApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllow
7578
/* Handle fee distribution state. */
7679

7780
// withdraw all validator commission
78-
app.AppKeepers.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
79-
valAddr, _ := sdk.ValAddressFromBech32(val.GetOperator())
81+
err := app.AppKeepers.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
82+
valAddr, err := app.AppKeepers.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator())
83+
if err != nil {
84+
panic(err)
85+
}
8086
_, _ = app.AppKeepers.DistrKeeper.WithdrawValidatorCommission(ctx, valAddr)
8187
return false
8288
})
89+
if err != nil {
90+
panic(err)
91+
}
8392

8493
// withdraw all delegator rewards
85-
dels, _ := app.AppKeepers.StakingKeeper.GetAllDelegations(ctx)
94+
dels, err := app.AppKeepers.StakingKeeper.GetAllDelegations(ctx)
95+
if err != nil {
96+
panic(err)
97+
}
98+
8699
for _, delegation := range dels {
87100
valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress)
88101
if err != nil {
89102
panic(err)
90103
}
91104

92-
delAddr, err := sdk.AccAddressFromBech32(delegation.DelegatorAddress)
93-
if err != nil {
94-
panic(err)
95-
}
105+
delAddr := sdk.MustAccAddressFromBech32(delegation.DelegatorAddress)
96106

97107
_, _ = app.AppKeepers.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr)
98108
}
@@ -108,15 +118,28 @@ func (app *SecretNetworkApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllow
108118
ctx = ctx.WithBlockHeight(0)
109119

110120
// reinitialize all validators
111-
app.AppKeepers.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
112-
valAddr, _ := sdk.ValAddressFromBech32(val.GetOperator())
121+
err = app.AppKeepers.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
122+
valAddr, err := app.AppKeepers.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator())
123+
if err != nil {
124+
panic(err)
125+
}
113126
// donate any unwithdrawn outstanding reward fraction tokens to the community pool
114-
scraps, _ := app.AppKeepers.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, valAddr)
115-
feePool, _ := app.AppKeepers.DistrKeeper.FeePool.Get(ctx)
127+
scraps, err := app.AppKeepers.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, valAddr)
128+
if err != nil {
129+
panic(err)
130+
}
131+
feePool, err := app.AppKeepers.DistrKeeper.FeePool.Get(ctx)
132+
if err != nil {
133+
panic(err)
134+
}
116135
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
117-
app.AppKeepers.DistrKeeper.FeePool.Set(ctx, feePool)
136+
if err := app.AppKeepers.DistrKeeper.FeePool.Set(ctx, feePool); err != nil {
137+
panic(err)
138+
}
118139

119-
app.AppKeepers.DistrKeeper.Hooks().AfterValidatorCreated(ctx, valAddr)
140+
if err := app.AppKeepers.DistrKeeper.Hooks().AfterValidatorCreated(ctx, valAddr); err != nil {
141+
panic(err)
142+
}
120143
return false
121144
})
122145

@@ -126,14 +149,17 @@ func (app *SecretNetworkApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllow
126149
if err != nil {
127150
panic(err)
128151
}
152+
delAddr := sdk.MustAccAddressFromBech32(del.DelegatorAddress)
129153

130-
delAddr, err := sdk.AccAddressFromBech32(del.DelegatorAddress)
131-
if err != nil {
132-
panic(err)
154+
if err := app.AppKeepers.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr); err != nil {
155+
// never called as BeforeDelegationCreated always returns nil
156+
panic(fmt.Errorf("error while incrementing period: %w", err))
133157
}
134158

135-
app.AppKeepers.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr)
136-
app.AppKeepers.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr)
159+
if err := app.AppKeepers.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr); err != nil {
160+
// never called as AfterDelegationModified always returns nil
161+
panic(fmt.Errorf("error while creating a new delegation period record: %w", err))
162+
}
137163
}
138164

139165
// reset context height
@@ -142,22 +168,34 @@ func (app *SecretNetworkApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllow
142168
/* Handle staking state. */
143169

144170
// iterate through redelegations, reset creation height
145-
app.AppKeepers.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) {
171+
err = app.AppKeepers.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) {
146172
for i := range red.Entries {
147173
red.Entries[i].CreationHeight = 0
148174
}
149-
app.AppKeepers.StakingKeeper.SetRedelegation(ctx, red)
175+
err = app.AppKeepers.StakingKeeper.SetRedelegation(ctx, red)
176+
if err != nil {
177+
panic(err)
178+
}
150179
return false
151180
})
181+
if err != nil {
182+
panic(err)
183+
}
152184

153185
// iterate through unbonding delegations, reset creation height
154-
app.AppKeepers.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) {
186+
err = app.AppKeepers.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) {
155187
for i := range ubd.Entries {
156188
ubd.Entries[i].CreationHeight = 0
157189
}
158-
app.AppKeepers.StakingKeeper.SetUnbondingDelegation(ctx, ubd)
190+
err = app.AppKeepers.StakingKeeper.SetUnbondingDelegation(ctx, ubd)
191+
if err != nil {
192+
panic(err)
193+
}
159194
return false
160195
})
196+
if err != nil {
197+
panic(err)
198+
}
161199

162200
// Iterate through validators by power descending, reset bond heights, and
163201
// update bond intra-tx counters.
@@ -166,7 +204,7 @@ func (app *SecretNetworkApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllow
166204
counter := int16(0)
167205

168206
for ; iter.Valid(); iter.Next() {
169-
addr := sdk.ValAddress(iter.Key()[1:])
207+
addr := sdk.ValAddress(stakingtypes.AddressFromValidatorsKey(iter.Key()))
170208
validator, err := app.AppKeepers.StakingKeeper.GetValidator(ctx, addr)
171209
if err != nil {
172210
panic("expected validator, not found")
@@ -175,27 +213,49 @@ func (app *SecretNetworkApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllow
175213
validator.UnbondingHeight = 0
176214
if applyAllowedAddrs && !allowedAddrsMap[addr.String()] {
177215
validator.Jailed = true
178-
app.AppKeepers.StakingKeeper.SetValidator(ctx, validator)
179-
app.AppKeepers.StakingKeeper.DeleteValidatorByPowerIndex(ctx, validator)
216+
err = app.AppKeepers.StakingKeeper.SetValidator(ctx, validator)
217+
if err != nil {
218+
panic(err)
219+
}
220+
err = app.AppKeepers.StakingKeeper.DeleteValidatorByPowerIndex(ctx, validator)
221+
if err != nil {
222+
panic(err)
223+
}
180224
} else {
181-
app.AppKeepers.StakingKeeper.SetValidator(ctx, validator)
225+
err = app.AppKeepers.StakingKeeper.SetValidator(ctx, validator)
226+
if err != nil {
227+
panic(err)
228+
}
182229
}
183230

184231
counter++
185232
}
186233

187-
iter.Close()
234+
if err := iter.Close(); err != nil {
235+
app.Logger().Error("error while closing the key-value store reverse prefix iterator: ", err)
236+
return
237+
}
238+
239+
_, err = app.AppKeepers.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
240+
if err != nil {
241+
panic(err)
242+
}
188243

189-
_, _ = app.AppKeepers.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
190244
/* Handle slashing state. */
191245

192246
// reset start height on signing infos
193-
app.AppKeepers.SlashingKeeper.IterateValidatorSigningInfos(
247+
err = app.AppKeepers.SlashingKeeper.IterateValidatorSigningInfos(
194248
ctx,
195249
func(addr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) (stop bool) {
196250
info.StartHeight = 0
197-
app.AppKeepers.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info)
251+
err = app.AppKeepers.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info)
252+
if err != nil {
253+
panic(err)
254+
}
198255
return false
199256
},
200257
)
258+
if err != nil {
259+
panic(err)
260+
}
201261
}

0 commit comments

Comments
 (0)