Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove unnecessary parts of app.go in consumer and provider #98

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
139bc40
pass tests after renaming 'UnbondingOp' in sdk
sainoe May 9, 2022
913a455
Double-sign slashing
sainoe May 10, 2022
612b7a5
use rigel hack to progress in IntTest debugging
sainoe May 11, 2022
7f024b9
small fix
sainoe May 11, 2022
fde338e
Merge branch 'main' into cis-merge-main
sainoe May 12, 2022
21409b5
change sdk import
sainoe May 12, 2022
6dc0d1e
merge main
sainoe May 12, 2022
ea1c6d5
clean before merge
sainoe May 12, 2022
f0730f6
clean tests
sainoe May 12, 2022
f298c83
fix nits
sainoe May 12, 2022
60dc6b9
remove unecessary parts of app.go in consumer and provider
okwme May 12, 2022
78eb2bd
fix conflicts from rebase
okwme May 19, 2022
7161749
begin adding GetHistoricalInfo
okwme May 19, 2022
65a70da
add back historic height
okwme May 19, 2022
9140d53
remove disables from testing framework
okwme May 19, 2022
a1ac1f0
Merge branch 'okwme/app-specific' of github.com:cosmos/interchain-sec…
okwme May 19, 2022
d34581b
add historic height to beginblock
okwme May 19, 2022
95543f5
add stub for ApplyAndReturnValidatorSetUpdates
okwme May 20, 2022
0e0a5f0
add back ApplyAndReturnValidatorSetUpdates to provider
okwme May 20, 2022
11ef039
added UnbondingTime, stubbed GetLastTotalPower and SetLastTotalPower,…
okwme May 20, 2022
1d0b532
Merge branch 'main' into okwme/app-specific
okwme May 20, 2022
e576185
add forked slashing module to allow for staking interface
okwme May 20, 2022
4d156e9
merged in sainoe/consumer-initiated-slashing
okwme May 20, 2022
174bb09
fixed IBC app interface with forks
okwme May 20, 2022
9d4d457
satisfies IBCKeeper
okwme May 20, 2022
c072e5b
compiles, no thanks to meticulously adding every keeper method
okwme May 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
382 changes: 176 additions & 206 deletions app/consumer/app.go

Large diffs are not rendered by default.

176 changes: 92 additions & 84 deletions app/consumer/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import (
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ibcconsumer "github.com/cosmos/interchain-security/x/ccv/consumer"
)

// ExportAppStateAndValidators exports the state of the application for a genesis
Expand All @@ -36,7 +35,7 @@ func (app *App) ExportAppStateAndValidators(
return servertypes.ExportedApp{}, err
}

validators, err := staking.WriteValidators(ctx, app.StakingKeeper)
validators, err := ibcconsumer.WriteValidators(ctx, app.ConsumerKeeper)
if err != nil {
return servertypes.ExportedApp{}, err
}
Expand All @@ -52,12 +51,13 @@ func (app *App) ExportAppStateAndValidators(
// NOTE zero height genesis is a temporary feature which will be deprecated
// in favour of export at a block height
func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) {
applyAllowedAddrs := false
// TODO: decide whether this can be removed permanentely
// applyAllowedAddrs := false

// check if there is a allowed address list
if len(jailAllowedAddrs) > 0 {
applyAllowedAddrs = true
}
// // check if there is a allowed address list
// if len(jailAllowedAddrs) > 0 {
// applyAllowedAddrs = true
// }

allowedAddrsMap := make(map[string]bool)

Expand All @@ -75,101 +75,109 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
/* Handle fee distribution state. */

// withdraw all validator commission
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
_, err := app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
if err != nil {
panic(err)
}
return false
})
// TODO: add back with gov-staking
// app.ConsumerKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
// _, err := app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
// if err != nil {
// panic(err)
// }
// return false
// })

// withdraw all delegator rewards
dels := app.StakingKeeper.GetAllDelegations(ctx)
for _, delegation := range dels {
_, err := app.DistrKeeper.WithdrawDelegationRewards(ctx, delegation.GetDelegatorAddr(), delegation.GetValidatorAddr())
if err != nil {
panic(err)
}
}

// TODO: add back with gov-staking
// dels := app.ConsumerKeeper.GetAllDelegations(ctx)
// for _, delegation := range dels {
// _, err := app.DistrKeeper.WithdrawDelegationRewards(ctx, delegation.GetDelegatorAddr(), delegation.GetValidatorAddr())
// if err != nil {
// panic(err)
// }
// }

// TODO: add back with gov-staking
// clear validator slash events
app.DistrKeeper.DeleteAllValidatorSlashEvents(ctx)
// app.DistrKeeper.DeleteAllValidatorSlashEvents(ctx)

// TODO: add back with gov-staking
// clear validator historical rewards
app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx)
// app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx)

// set context height to zero
height := ctx.BlockHeight()
ctx = ctx.WithBlockHeight(0)

// reinitialize all validators
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
// donate any unwithdrawn outstanding reward fraction tokens to the community pool
scraps := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator())
feePool := app.DistrKeeper.GetFeePool(ctx)
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
app.DistrKeeper.SetFeePool(ctx, feePool)

app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())
return false
})
// TODO: add back with gov-staking
// app.ConsumerKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
// // donate any unwithdrawn outstanding reward fraction tokens to the community pool
// scraps := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator())
// feePool := app.DistrKeeper.GetFeePool(ctx)
// feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
// app.DistrKeeper.SetFeePool(ctx, feePool)

// app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator())
// return false
// })

// reinitialize all delegations
for _, del := range dels {
app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
app.DistrKeeper.Hooks().AfterDelegationModified(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
}
// for _, del := range dels {
// app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
// app.DistrKeeper.Hooks().AfterDelegationModified(ctx, del.GetDelegatorAddr(), del.GetValidatorAddr())
// }

// reset context height
ctx = ctx.WithBlockHeight(height)

/* Handle staking state. */

// iterate through redelegations, reset creation height
app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) {
for i := range red.Entries {
red.Entries[i].CreationHeight = 0
}
app.StakingKeeper.SetRedelegation(ctx, red)
return false
})

// iterate through unbonding delegations, reset creation height
app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) {
for i := range ubd.Entries {
ubd.Entries[i].CreationHeight = 0
}
app.StakingKeeper.SetUnbondingDelegation(ctx, ubd)
return false
})

// Iterate through validators by power descending, reset bond heights, and
// update bond intra-tx counters.
store := ctx.KVStore(app.keys[stakingtypes.StoreKey])
iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey)
counter := int16(0)

for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(iter.Key()[1:])
validator, found := app.StakingKeeper.GetValidator(ctx, addr)
if !found {
panic("expected validator, not found")
}

validator.UnbondingHeight = 0
if applyAllowedAddrs && !allowedAddrsMap[addr.String()] {
validator.Jailed = true
}

app.StakingKeeper.SetValidator(ctx, validator)
counter++
}

iter.Close()

if _, err := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx); err != nil {
panic(err)
}
// TODO: decide whether this can be removed permanentely
// // iterate through redelegations, reset creation height
// app.ConsumerKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) {
// for i := range red.Entries {
// red.Entries[i].CreationHeight = 0
// }
// app.ConsumerKeeper.SetRedelegation(ctx, red)
// return false
// })

// TODO: decide whether this can be removed permanentely
// // iterate through unbonding delegations, reset creation height
// app.ConsumerKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) {
// for i := range ubd.Entries {
// ubd.Entries[i].CreationHeight = 0
// }
// app.ConsumerKeeper.SetUnbondingDelegation(ctx, ubd)
// return false
// })

// TODO: decide whether this can be removed permanentely
// // Iterate through validators by power descending, reset bond heights, and
// // update bond intra-tx counters.
// store := ctx.KVStore(app.keys[stakingtypes.StoreKey])
// iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey)
// counter := int16(0)

// for ; iter.Valid(); iter.Next() {
// addr := sdk.ValAddress(iter.Key()[1:])
// validator, found := app.ConsumerKeeper.GetValidator(ctx, addr)
// if !found {
// panic("expected validator, not found")
// }

// validator.UnbondingHeight = 0
// if applyAllowedAddrs && !allowedAddrsMap[addr.String()] {
// validator.Jailed = true
// }

// app.ConsumerKeeper.SetValidator(ctx, validator)
// counter++
// }

// iter.Close()

// if _, err := app.ConsumerKeeper.ApplyAndReturnValidatorSetUpdates(ctx); err != nil {
// panic(err)
// }

/* Handle slashing state. */

Expand Down
Loading