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

Interchain security rebase #13722

Merged
merged 49 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
c50ebe9
feat: store ABCI validator updates in transient store
fedekunze Sep 16, 2021
9b8d920
fix test build
fedekunze Sep 16, 2021
57f5633
change transient key name
AdityaSripal Nov 10, 2021
30985a0
add UnbondingDelegationEntryCreated hook
jtremback Oct 14, 2021
83f2868
add id to UnbondingDelegationEntry
jtremback Oct 14, 2021
6e78767
changes to add simple version of staking ccv hooks
jtremback Oct 15, 2021
fe36b17
ubde id to string
jtremback Oct 15, 2021
4e5e193
rough draft of more efficient technique
jtremback Oct 16, 2021
c13716b
change hook api and do some clean ups
jtremback Oct 29, 2021
890c47e
use ByEntry index and keep stopped entries in Entries array
jtremback Nov 5, 2021
71e928a
correct error convention
jtremback Nov 5, 2021
53f2184
add comment
jtremback Nov 5, 2021
9e468ac
some cleanups
jtremback Nov 5, 2021
1433612
comment cleanup
jtremback Nov 5, 2021
82e1f0f
finish hooking up hooks
jtremback Nov 5, 2021
b7b5da6
get the tests to pass
jtremback Nov 5, 2021
7ebe44f
proof of concept with embedded mock hooks
jtremback Nov 8, 2021
7ff872b
first unit test of CCV hooks
jtremback Nov 9, 2021
a84c23f
fix forgotten pointer bug
jtremback Nov 9, 2021
d5b64ea
move hook mocks into own file
jtremback Nov 10, 2021
48d1cf7
added test for completing stopped unbonding early
jtremback Nov 10, 2021
fb8108a
added staking hooks template
jtremback Nov 10, 2021
9b365d3
correct file and module names
jtremback Nov 10, 2021
2c0437a
clean up and fix import error
jtremback Nov 11, 2021
1b776a3
move staking hooks template to types
jtremback Nov 11, 2021
b293d64
fix hooks after merge
jtremback Nov 16, 2021
2413b86
fix silly proto bug
jtremback Jan 6, 2022
58c103c
feat: Add AfterValidatorDowntime hook in slashing module (#10938)
sainoe Jan 12, 2022
29c717a
update: Remove slashing module hooks (#11425)
sainoe Mar 23, 2022
e75e83f
Finish staking hooks merge (#11677)
jtremback May 10, 2022
4cc2851
feat: enable double-signing evidence in Interchain-Security (#11921)
sainoe May 23, 2022
c783aea
chore: remove direct reliance on staking from slashing (backport #121…
mergify[bot] Jun 7, 2022
67c8163
fix: make ModuleAccountInvariants pass for IS SDK changes (#12554)
mpoke Jul 19, 2022
df7683a
Revert "fix: make ModuleAccountInvariants pass for IS SDK changes (#1…
mpoke Aug 1, 2022
9ebbd57
fix: make ModuleAccountInvariants pass for IS SDK changes (#12783)
mpoke Aug 1, 2022
bbb8d86
fix: [Interchain Security] `validatorUnbondingCanComplete` must take …
mpoke Aug 5, 2022
63a1efc
fix: [Interchain Security] Fix leak in unbonding hooks (#12849)
mpoke Aug 9, 2022
a63f1f7
docs: [Interchain Security] update spec (#12848)
mpoke Aug 9, 2022
e2a7cd3
store ValidatorUpdates in normal store (#12845)
mpoke Aug 9, 2022
402f4c0
Update x/slashing/keeper/signing_info.go
mpoke Aug 11, 2022
7f34d09
Update x/staking/keeper/val_state_change.go
mpoke Aug 11, 2022
53d139e
Update x/staking/keeper/val_state_change.go
mpoke Aug 11, 2022
5df5b1c
Update x/slashing/keeper/infractions.go
mpoke Aug 11, 2022
0b5c039
Update x/staking/keeper/val_state_change.go
mpoke Aug 11, 2022
7cfdd65
Update x/staking/keeper/val_state_change.go
mpoke Aug 11, 2022
8ba98c8
fix compile errors
mpoke Aug 11, 2022
846d015
remove stakingtypes.TStoreKey
mpoke Aug 11, 2022
06d4a64
fix: decrease minimums for genesis parameters (#13106)
shaspitz Sep 1, 2022
4ce26e1
Merge branch 'ics-45.6' into interchain-security-rebase
jtremback Nov 1, 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
Prev Previous commit
Next Next commit
change hook api and do some clean ups
  • Loading branch information
jtremback committed Feb 10, 2022
commit c13716b99dd519ea29a96dc738e54706f6fe9f7c
40 changes: 21 additions & 19 deletions x/staking/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,11 +824,20 @@ func (k Keeper) CompleteUnbonding(ctx sdk.Context, delAddr sdk.AccAddress, valAd
for i := 0; i < len(ubd.Entries); i++ {
entry := ubd.Entries[i]
if entry.IsMature(ctxTime) {
// call hook, if error is returned, stop unbonding
err := k.BeforeUnbondingDelegationEntryComplete(ctx, entry.Id)
if err == nil {
// This hook allows external modules to stop an unbonding delegation entry from fully unbonding
// when the completionTime has passed. This allows them to prolong the unbonding period.
stop := k.BeforeUnbondingDelegationEntryComplete(ctx, entry.Id)
if stop {
// Move entry to stopped UBDE bucket to be completed later
ubd.RemoveEntry(int64(i))
i--

k.SetStoppedUnbondingDelegationEntry(ctx, entry)
} else {
// Proceed with unbonding
ubd.RemoveEntry(int64(i))
i--

// track undelegation only when remaining or truncated shares are non-zero
if !entry.Balance.IsZero() {
amt := sdk.NewCoin(bondDenom, entry.Balance)
Expand All @@ -840,12 +849,6 @@ func (k Keeper) CompleteUnbonding(ctx sdk.Context, delAddr sdk.AccAddress, valAd

balances = balances.Add(amt)
}
} else {
// Move entry to stopped UBDE bucket to be completed later
ubd.RemoveEntry(int64(i))
i--

k.SetStoppedUnbondingDelegationEntry(ctx, entry)
}
}
}
Expand All @@ -860,30 +863,29 @@ func (k Keeper) CompleteUnbonding(ctx sdk.Context, delAddr sdk.AccAddress, valAd
return balances, nil
}

func (k Keeper) CompleteStoppedUnbonding(ctx sdk.Context, id uint64) error {
entry, found := k.GetStoppedUnbondingDelegationEntry(ctx, id)
func (k Keeper) CompleteStoppedUnbonding(ctx sdk.Context, id uint64) (err error, found bool) {
ubde, found := k.GetStoppedUnbondingDelegationEntry(ctx, id)
if !found {
// ERROR
return nil, false
}

delegatorAddress, err := sdk.AccAddressFromBech32(entry.DelegatorAddress)
delegatorAddress, err := sdk.AccAddressFromBech32(ubde.DelegatorAddress)
if err != nil {
return err
return err, true
}

bondDenom := k.GetParams(ctx).BondDenom

// track undelegation only when remaining or truncated shares are non-zero
if !entry.Balance.IsZero() {
amt := sdk.NewCoin(bondDenom, entry.Balance)
if !ubde.Balance.IsZero() {
amt := sdk.NewCoin(bondDenom, ubde.Balance)
if err := k.bankKeeper.UndelegateCoinsFromModuleToAccount(
ctx, types.NotBondedPoolName, delegatorAddress, sdk.NewCoins(amt),
); err != nil {
return err
return err, true
}
}

return nil
return nil, true
}

// begin unbonding / redelegation; create a redelegation record
Expand Down
13 changes: 5 additions & 8 deletions x/staking/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,17 @@ func (k Keeper) BeforeValidatorSlashed(ctx sdk.Context, valAddr sdk.ValAddress,
// TODO JEHAN: I'm using this for a proof of concept for CCV. It's possible that this functionality can
// instead be provided with RemoveDelegation and AfterDelegationModified but it will be more complicated
func (k Keeper) UnbondingDelegationEntryCreated(ctx sdk.Context, delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress,
creationHeight int64, completionTime time.Time, balance sdk.Int, id uint64) error {
creationHeight int64, completionTime time.Time, balance sdk.Int, id uint64) {
if k.hooks != nil {
return k.hooks.UnbondingDelegationEntryCreated(ctx, delegatorAddr, validatorAddr, creationHeight, completionTime, balance, id)
k.hooks.UnbondingDelegationEntryCreated(ctx, delegatorAddr, validatorAddr, creationHeight, completionTime, balance, id)
}
return nil
}

// This is called before completing unbonding of a UnbondingDelegationEntry. returning an error
// This is called before completing unbonding of a UnbondingDelegationEntry. returning true
// will stop the unbonding.
// TODO JEHAN: Using an error this way feels wrong because it's not really an error. I would use
// a return value but i'm not sure if that's ok to do with hooks
func (k Keeper) BeforeUnbondingDelegationEntryComplete(ctx sdk.Context, id uint64) error {
func (k Keeper) BeforeUnbondingDelegationEntryComplete(ctx sdk.Context, id uint64) bool {
if k.hooks != nil {
return k.hooks.BeforeUnbondingDelegationEntryComplete(ctx, id)
}
return nil
return false
}