Skip to content

Commit

Permalink
Merge branch 'main' into feat/remove-module-placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani authored Dec 12, 2024
2 parents 75e5836 + 236f8a0 commit 241edaa
Showing 1 changed file with 35 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,27 +158,37 @@ func initAppForTestnet(app *app.App, args valArgs) *app.App {
iterator.Close()

// Add our validator to power and last validators store
app.StakingKeeper.SetValidator(ctx, newVal)
err = app.StakingKeeper.SetValidatorByConsAddr(ctx, newVal)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
app.StakingKeeper.SetValidatorByPowerIndex(ctx, newVal)
app.StakingKeeper.SetLastValidatorPower(ctx, validator, 0)
if err := app.StakingKeeper.Hooks().AfterValidatorCreated(ctx, validator); err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}

handleErr(app.StakingKeeper.SetValidator(ctx, newVal))
handleErr(app.StakingKeeper.SetValidatorByConsAddr(ctx, newVal))
handleErr(app.StakingKeeper.SetValidatorByPowerIndex(ctx, newVal))
handleErr(app.StakingKeeper.SetLastValidatorPower(ctx, validator, 0))
handleErr(app.StakingKeeper.Hooks().AfterValidatorCreated(ctx, validator))

// DISTRIBUTION
//

// Initialize records for this validator across all distribution stores
app.DistrKeeper.ValidatorHistoricalRewards.Set(ctx, collections.Join(sdk.ValAddress(validator), uint64(0)), distrtypes.NewValidatorHistoricalRewards(sdk.DecCoins{}, 1))
app.DistrKeeper.ValidatorCurrentRewards.Set(ctx, validator, distrtypes.NewValidatorCurrentRewards(sdk.DecCoins{}, 1))
app.DistrKeeper.ValidatorsAccumulatedCommission.Set(ctx, validator, distrtypes.InitialValidatorAccumulatedCommission())
app.DistrKeeper.ValidatorOutstandingRewards.Set(ctx, validator, distrtypes.ValidatorOutstandingRewards{Rewards: sdk.DecCoins{}})
handleErr(app.DistrKeeper.ValidatorHistoricalRewards.Set(
ctx,
collections.Join(sdk.ValAddress(validator), uint64(0)),
distrtypes.NewValidatorHistoricalRewards(sdk.DecCoins{}, 1),
))

handleErr(app.DistrKeeper.ValidatorCurrentRewards.Set(
ctx,
validator,
distrtypes.NewValidatorCurrentRewards(sdk.DecCoins{}, 1),
))

handleErr(app.DistrKeeper.ValidatorsAccumulatedCommission.Set(
ctx, validator, distrtypes.InitialValidatorAccumulatedCommission(),
))

handleErr(app.DistrKeeper.ValidatorOutstandingRewards.Set(
ctx,
validator,
distrtypes.ValidatorOutstandingRewards{Rewards: sdk.DecCoins{}},
))

<%= if (!IsChainMinimal) { %>
// SLASHING
Expand All @@ -204,7 +214,6 @@ func initAppForTestnet(app *app.App, args valArgs) *app.App {

defaultCoins := sdk.NewCoins(sdk.NewInt64Coin(bondDenom, 1000000000))

// Fund local accounts
// Fund local accounts
for _, accountStr := range args.accountsToFund {
err := app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, defaultCoins)
Expand Down Expand Up @@ -267,3 +276,11 @@ func getCommandArgs(appOpts servertypes.AppOptions) (valArgs, error) {

return args, nil
}

// handleErr prints the error and exits the program if the error is not nil
func handleErr(err error) {
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
}

0 comments on commit 241edaa

Please sign in to comment.