diff --git a/app/fork_test.go b/app/fork_test.go index a510f84a..7ea76277 100644 --- a/app/fork_test.go +++ b/app/fork_test.go @@ -1,7 +1,6 @@ package app import ( - "fmt" "testing" "time" @@ -13,12 +12,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -var oneEnternityLater = time.Date(9999, 9, 9, 9, 9, 9, 9, time.UTC) - func TestFork(t *testing.T) { realio := Setup(false, nil) - ctx := realio.BaseApp.NewContext(false, tmproto.Header{Height: int64(ForkHeight)}) + ctx := realio.BaseApp.NewContext(false, tmproto.Header{Height: ForkHeight}) stakingKeeper := realio.StakingKeeper timeKey := time.Date(2024, 4, 1, 1, 1, 1, 1, time.UTC) @@ -27,7 +24,7 @@ func TestFork(t *testing.T) { DelegatorAddress: "test_del_1", ValidatorAddress: "test_val_1", Entries: []stakingtypes.UnbondingDelegationEntry{ - stakingtypes.NewUnbondingDelegationEntry(int64(ForkHeight), timeKey, math.OneInt()), + stakingtypes.NewUnbondingDelegationEntry(ForkHeight, timeKey, math.OneInt()), }, } @@ -39,7 +36,7 @@ func TestFork(t *testing.T) { ValidatorSrcAddress: "test_val_1", ValidatorDstAddress: "test_val_2", Entries: []stakingtypes.RedelegationEntry{ - stakingtypes.NewRedelegationEntry(int64(ForkHeight), timeKey, math.OneInt(), sdk.OneDec()), + stakingtypes.NewRedelegationEntry(ForkHeight, timeKey, math.OneInt(), sdk.OneDec()), }, } stakingKeeper.InsertRedelegationQueue(ctx, duplicativeRedelegation, timeKey) @@ -48,7 +45,7 @@ func TestFork(t *testing.T) { duplicativeVal := stakingtypes.Validator{ OperatorAddress: "test_op", - UnbondingHeight: int64(ForkHeight), + UnbondingHeight: ForkHeight, UnbondingTime: timeKey, } @@ -74,9 +71,8 @@ func TestFork(t *testing.T) { require.Equal(t, triplets[0].ValidatorDstAddress, duplicativeRedelegation.ValidatorDstAddress) require.Equal(t, triplets[0].ValidatorSrcAddress, duplicativeRedelegation.ValidatorSrcAddress) - vals := stakingKeeper.GetUnbondingValidators(ctx, timeKey, int64(ForkHeight)) + vals := stakingKeeper.GetUnbondingValidators(ctx, timeKey, ForkHeight) require.Equal(t, vals[0], duplicativeVal.OperatorAddress) - } func checkDuplicateUBDQueue(ctx sdk.Context, realio RealioNetwork) bool { @@ -94,14 +90,13 @@ func checkDuplicateUBDQueue(ctx sdk.Context, realio RealioNetwork) bool { return false } -func checkDuplicateUBD(eles []stakingtypes.DVPair) bool { - unique_eles := map[string]bool{} - for _, ele := range eles { - unique_eles[ele.String()] = true +func checkDuplicateUBD(eels []stakingtypes.DVPair) bool { + uniqueEles := map[string]bool{} + for _, ele := range eels { + uniqueEles[ele.String()] = true } - fmt.Println(eles, "eles") - return len(unique_eles) != len(eles) + return len(uniqueEles) != len(eels) } func checkDuplicateRelegationQueue(ctx sdk.Context, realio RealioNetwork) bool { @@ -119,13 +114,13 @@ func checkDuplicateRelegationQueue(ctx sdk.Context, realio RealioNetwork) bool { return false } -func checkDuplicateRedelegation(eles []stakingtypes.DVVTriplet) bool { - unique_eles := map[string]bool{} - for _, ele := range eles { - unique_eles[ele.String()] = true +func checkDuplicateRedelegation(eels []stakingtypes.DVVTriplet) bool { + uniqueEles := map[string]bool{} + for _, ele := range eels { + uniqueEles[ele.String()] = true } - return len(unique_eles) != len(eles) + return len(uniqueEles) != len(eels) } func checkDuplicateValQueue(ctx sdk.Context, realio RealioNetwork) bool { @@ -142,11 +137,12 @@ func checkDuplicateValQueue(ctx sdk.Context, realio RealioNetwork) bool { } return false } -func checkDuplicateValAddr(eles []string) bool { - unique_eles := map[string]bool{} - for _, ele := range eles { - unique_eles[ele] = true + +func checkDuplicateValAddr(eels []string) bool { + uniqueEles := map[string]bool{} + for _, ele := range eels { + uniqueEles[ele] = true } - return len(unique_eles) != len(eles) + return len(uniqueEles) != len(eels) } diff --git a/app/forks.go b/app/forks.go index 865c5f48..ef855dd0 100644 --- a/app/forks.go +++ b/app/forks.go @@ -8,7 +8,10 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) -var ForkHeight = 5989487 +var ( + ForkHeight = int64(5989487) + oneEnternityLater = time.Date(9999, 9, 9, 9, 9, 9, 9, time.UTC) +) // ScheduleForkUpgrade executes any necessary fork logic for based upon the current // block height and chain ID (mainnet or testnet). It sets an upgrade plan once @@ -19,7 +22,7 @@ var ForkHeight = 5989487 // 1. Release a non-breaking patch version so that the chain can set the scheduled upgrade plan at upgrade-height. // 2. Release the software defined in the upgrade-info func (app *RealioNetwork) ScheduleForkUpgrade(ctx sdk.Context) { - if ctx.BlockHeight() == 5989487 { + if ctx.BlockHeight() == ForkHeight { // remove duplicate UnbondingQueueKey removeDuplicateValueUnbondingQueueKey(app, ctx) @@ -63,11 +66,7 @@ func removeDuplicateValueRedelegationQueueKey(app *RealioNetwork, ctx sdk.Contex cdc := app.AppCodec() store := ctx.KVStore(app.keys[stakingtypes.ModuleName]) - // remove duplicate UnbondingQueueKey - ubdTime := sk.UnbondingTime(ctx) - currTime := ctx.BlockTime() - - redelegationTimesliceIterator := sk.RedelegationQueueIterator(ctx, currTime.Add(ubdTime)) // make sure to iterate all queue + redelegationTimesliceIterator := sk.RedelegationQueueIterator(ctx, oneEnternityLater) // make sure to iterate all queue defer redelegationTimesliceIterator.Close() for ; redelegationTimesliceIterator.Valid(); redelegationTimesliceIterator.Next() { @@ -80,7 +79,6 @@ func removeDuplicateValueRedelegationQueueKey(app *RealioNetwork, ctx sdk.Contex store.Set(redelegationTimesliceIterator.Key(), bz) } - } func removeDuplicateDVVTriplets(triplets []stakingtypes.DVVTriplet) []stakingtypes.DVVTriplet { @@ -105,7 +103,7 @@ func containsDVVTriplets(s []stakingtypes.DVVTriplet, e stakingtypes.DVVTriplet) } func removeDuplicateUnbondingValidator(app *RealioNetwork, ctx sdk.Context) { - valIter := app.StakingKeeper.ValidatorQueueIterator(ctx, time.Date(9999, 9, 9, 9, 9, 9, 9, time.UTC), 99999999999999) + valIter := app.StakingKeeper.ValidatorQueueIterator(ctx, oneEnternityLater, 99999999999999) defer valIter.Close() for ; valIter.Valid(); valIter.Next() { @@ -117,13 +115,13 @@ func removeDuplicateUnbondingValidator(app *RealioNetwork, ctx sdk.Context) { vals[valAddr] = true } - unique_addrs := []string{} - for valAddr, _ := range vals { - unique_addrs = append(unique_addrs, valAddr) + uniqueAddrs := []string{} + for valAddr := range vals { + uniqueAddrs = append(uniqueAddrs, valAddr) } - sort.Strings(unique_addrs) + sort.Strings(uniqueAddrs) - ctx.KVStore(app.GetKey(stakingtypes.StoreKey)).Set(valIter.Key(), app.appCodec.MustMarshal(&stakingtypes.ValAddresses{Addresses: unique_addrs})) + ctx.KVStore(app.GetKey(stakingtypes.StoreKey)).Set(valIter.Key(), app.appCodec.MustMarshal(&stakingtypes.ValAddresses{Addresses: uniqueAddrs})) } } @@ -133,11 +131,7 @@ func removeDuplicateValueUnbondingQueueKey(app *RealioNetwork, ctx sdk.Context) cdc := app.AppCodec() store := ctx.KVStore(app.keys[stakingtypes.ModuleName]) - // remove duplicate UnbondingQueueKey - ubdTime := sk.UnbondingTime(ctx) - currTime := ctx.BlockTime() - - unbondingTimesliceIterator := sk.UBDQueueIterator(ctx, currTime.Add(ubdTime)) // make sure to iterate all queue + unbondingTimesliceIterator := sk.UBDQueueIterator(ctx, oneEnternityLater) // make sure to iterate all queue defer unbondingTimesliceIterator.Close() for ; unbondingTimesliceIterator.Valid(); unbondingTimesliceIterator.Next() { diff --git a/x/asset/keeper/msg_server_create_token.go b/x/asset/keeper/msg_server_create_token.go index ae24c8d1..90f2290e 100644 --- a/x/asset/keeper/msg_server_create_token.go +++ b/x/asset/keeper/msg_server_create_token.go @@ -59,7 +59,6 @@ func (k msgServer) CreateToken(goCtx context.Context, msg *types.MsgCreateToken) coin := sdk.Coins{{Denom: baseDenom, Amount: canonicalAmount}} err = k.bankKeeper.MintCoins(ctx, types.ModuleName, coin) - if err != nil { panic(err) }