Skip to content

Commit

Permalink
update fork func
Browse files Browse the repository at this point in the history
  • Loading branch information
expertdicer committed Apr 2, 2024
1 parent bcf1ea5 commit 93661c3
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions app/forks.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,7 @@ func (app *RealioNetwork) ScheduleForkUpgrade(ctx sdk.Context) {
// remove duplicate UnbondingQueueKey
removeDuplicateValueUnbondingQueueKey(app, ctx)
removeDuplicateValueRedelegationQueueKey(app, ctx)

valIter := app.StakingKeeper.ValidatorQueueIterator(ctx, time.Date(9999, 9, 9, 9, 9, 9, 9, time.UTC), 99999999999999)
defer valIter.Close()

for ; valIter.Valid(); valIter.Next() {
addrs := stakingtypes.ValAddresses{}
app.appCodec.MustUnmarshal(valIter.Value(), &addrs)

vals := map[string]bool{}
for _, valAddr := range addrs.Addresses {
vals[valAddr] = true
}

unique_addrs := []string{}
for valAddr, _ := range vals {
unique_addrs = append(unique_addrs, valAddr)
}
sort.Strings(unique_addrs)

ctx.KVStore(app.GetKey(stakingtypes.StoreKey)).Set(valIter.Key(), app.appCodec.MustMarshal(&stakingtypes.ValAddresses{Addresses: unique_addrs}))
}

removeDuplicateUnbondingValidator(app, ctx)
}
// NOTE: there are no testnet forks for the existing versions
// if !types.IsMainnet(ctx.ChainID()) {
Expand Down Expand Up @@ -123,6 +102,29 @@ func containsDVVTriplets(s []stakingtypes.DVVTriplet, e stakingtypes.DVVTriplet)
return false
}

func removeDuplicateUnbondingValidator(app *RealioNetwork, ctx sdk.Context) {
valIter := app.StakingKeeper.ValidatorQueueIterator(ctx, time.Date(9999, 9, 9, 9, 9, 9, 9, time.UTC), 99999999999999)
defer valIter.Close()

for ; valIter.Valid(); valIter.Next() {
addrs := stakingtypes.ValAddresses{}
app.appCodec.MustUnmarshal(valIter.Value(), &addrs)

vals := map[string]bool{}
for _, valAddr := range addrs.Addresses {
vals[valAddr] = true
}

unique_addrs := []string{}

Check warning on line 118 in app/forks.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: don't use underscores in Go names; var unique_addrs should be uniqueAddrs (revive)
for valAddr, _ := range vals {

Check failure on line 119 in app/forks.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
unique_addrs = append(unique_addrs, valAddr)
}
sort.Strings(unique_addrs)

ctx.KVStore(app.GetKey(stakingtypes.StoreKey)).Set(valIter.Key(), app.appCodec.MustMarshal(&stakingtypes.ValAddresses{Addresses: unique_addrs}))
}
}

func removeDuplicateValueUnbondingQueueKey(app *RealioNetwork, ctx sdk.Context) {
// Get Staking keeper, codec and staking store
sk := app.StakingKeeper
Expand Down

0 comments on commit 93661c3

Please sign in to comment.