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

feat: implement slashing functionality on the provider chain (ADR-013) #1275

Merged
merged 31 commits into from
Sep 27, 2023
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
93a0db5
first version
insumity Sep 7, 2023
ea87bdc
fix mocks
insumity Sep 8, 2023
177e1db
move slashing to other file and check tombstoning
insumity Sep 8, 2023
e1bdfff
add tests that checks that Slash is called
insumity Sep 11, 2023
bbff2ee
add FIXME msg
insumity Sep 11, 2023
dfef410
small changes
insumity Sep 11, 2023
8b49af1
add fixme
insumity Sep 11, 2023
bf89509
fix test
insumity Sep 11, 2023
868e0d2
modified E2E tests and general cleaning up
insumity Sep 12, 2023
9ba3a3d
clean up
insumity Sep 12, 2023
b1a6f31
feat!: Cryptographic verification of equivocation (#1287)
mpoke Sep 14, 2023
d92a4c8
undelegations are getting slashed integraiton test
insumity Sep 14, 2023
72abcf4
Merge branch 'release/v2.1.x-lsm' into insumity/adr-013-impl-on-feat
insumity Sep 14, 2023
b46ace4
fix merge issues
insumity Sep 14, 2023
59d8192
fix mocks
insumity Sep 14, 2023
31c090d
fix lint issue
insumity Sep 14, 2023
79f8f18
Merge branch 'feat/ics-misbehaviour-handling' into insumity/adr-013-i…
insumity Sep 22, 2023
ed35638
took into account Simon's comments
insumity Sep 22, 2023
62212c7
go.sum changes
insumity Sep 22, 2023
e5b46dd
gosec fix
insumity Sep 22, 2023
4cb6283
fix linter issue
insumity Sep 22, 2023
6f15a61
cherry-picked ADR-05 so markdown link checker does not complain
insumity Sep 22, 2023
93c2cdb
lint
sainoe Sep 22, 2023
1d3ee78
Use cached context to get tokens in undelegations and redelegations.
insumity Sep 25, 2023
5c053bb
return the error
insumity Sep 26, 2023
f8633b5
lint issue
insumity Sep 26, 2023
f96f1bc
take into account Philip's comments
insumity Sep 26, 2023
d3dc0bc
clean up
insumity Sep 26, 2023
39bbcf5
fix flakey test
insumity Sep 27, 2023
694dce7
lint issue
insumity Sep 27, 2023
366e3b1
fix error returns and fix flaky test in a better way
insumity Sep 27, 2023
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
take into account Philip's comments
  • Loading branch information
insumity committed Sep 26, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit f96f1bce5d5f1a31e3f5d90795b44669e8a10c0b
6 changes: 3 additions & 3 deletions tests/integration/double_vote.go
Original file line number Diff line number Diff line change
@@ -127,7 +127,7 @@ func (s *CCVTestSuite) TestHandleConsumerDoubleVoting() {
// we create two votes that only differ by their Block IDs and
// signed them using the same validator private key and chain ID
// of the consumer chain
"valid double voting evidence 1 - should pass",
"valid double voting evidence - should pass",
&tmtypes.DuplicateVoteEvidence{
VoteA: consuVote,
VoteB: consuBadVote,
@@ -141,7 +141,7 @@ func (s *CCVTestSuite) TestHandleConsumerDoubleVoting() {
},
{
// create a double voting evidence using the provider validator key
"valid double voting evidence 2 - should pass",
"valid double voting evidence - should not pass because validator tombstoned in the previous test case",
&tmtypes.DuplicateVoteEvidence{
VoteA: provVote,
VoteB: provBadVote,
@@ -151,7 +151,7 @@ func (s *CCVTestSuite) TestHandleConsumerDoubleVoting() {
},
s.consumerChain.ChainID,
provVal.PubKey,
true,
false,
},
}

4 changes: 3 additions & 1 deletion x/ccv/provider/keeper/punish_validator.go
Original file line number Diff line number Diff line change
@@ -47,13 +47,15 @@ func (k Keeper) JailAndTombstoneValidator(ctx sdk.Context, providerAddr types.Pr
}

// ComputePowerToSlash computes the power to be slashed based on the tokens in non-matured `undelegations` and
// `redelegations`, as well as the current `power` of the validator
// `redelegations`, as well as the current `power` of the validator.
// Note that this method does not perform any slashing.
func (k Keeper) ComputePowerToSlash(ctx sdk.Context, validator stakingtypes.Validator, undelegations []stakingtypes.UnbondingDelegation,
redelegations []stakingtypes.Redelegation, power int64, powerReduction sdk.Int,
) int64 {
// compute the total numbers of tokens currently being undelegated
undelegationsInTokens := sdk.NewInt(0)

// Note that we use a **cached** context to avoid any actual slashing of undelegations or redelegations.
cachedCtx, _ := ctx.CacheContext()
insumity marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of using this cached context here (or in addition to this), we could have wraps for SlashUnbondingDelegation and SlashRedelegation that just call those on cached contexts and call the wraps e.g. ComputeUnbondingDelegationPower - it's very subtle with the cached context and the slash factor of 1 here

for _, u := range undelegations {
amountSlashed := k.stakingKeeper.SlashUnbondingDelegation(cachedCtx, u, 0, sdk.NewDec(1))
mpoke marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 8 additions & 0 deletions x/ccv/provider/keeper/punish_validator_test.go
Original file line number Diff line number Diff line change
@@ -329,9 +329,17 @@ func TestComputePowerToSlash(t *testing.T) {
}).AnyTimes(),
)

tokensBeforeCall := validator.GetTokens()
delegatorSharesBeforeCall := validator.GetDelegatorShares()

actualPower := providerKeeper.ComputePowerToSlash(ctx, validator,
tc.undelegations, tc.redelegations, tc.power, tc.powerReduction)
insumity marked this conversation as resolved.
Show resolved Hide resolved

// safeguard check that validator remains unmodified after a call to `ComputePowerToSlash`
// `ComputePowerToSlash` only computes the power and does not modify the state of the system in any way
require.Equal(t, tokensBeforeCall, validator.GetTokens())
require.Equal(t, delegatorSharesBeforeCall, validator.GetDelegatorShares())

if tc.expectedPower != actualPower {
require.Fail(t, fmt.Sprintf("\"%s\" failed", tc.name),
"expected is %d but actual is %d", tc.expectedPower, actualPower)