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!: simplify penalty handling logic #9

Merged
merged 9 commits into from
Jul 21, 2023

Conversation

zsystm
Copy link

@zsystm zsystm commented Jul 21, 2023

Description

  • logic updated
  • spec updated
  • when handle paired chunk, check whether paired insurance's balance >= 5.75% (double_sign_fraction + down_time_fraction) or not.

    • If not, then start un-pair & un-delegate. As now we can make sure that there will be no case where un-pairing ins at previous epoch cannot cover its penalty during un-bonding(or re-delegation) period.
    • By doing this, we don't need ReDelegationInfo's Deletable and penaltyAmt fields anymore.
  • when calc penaltyAmt, must check shares value is decimal or integer. if it is decimal, then we must use ceiled value as penaltyAmt to fully cover pantly.

  • refactored some common code


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • included the necessary unit and integration tests
  • reviewed "Files changed" and left comments if necessary

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

when insurance is under 5.75% of chunk size, then un-delegate it.
now we can make sure that during unbonding or re-delegation period, there must be no case where un-pairing insurance cannot cover penalty.

remainings:
* fix broken tests
* remove re-delegation info's deletable and amt field
* add tcs for new logics.
when calc penaltyAmt, must check shares value based on amt.
Those fields are introduced to cover the situation where unpairing ins at previous epoch cannot cover the penalty during re-delegation period.
But now we check paired ins with IsEnoughToCoverSlash so we don't need PenaltyAmt and Deletable anymore. Because that scenario will not happen.
@zsystm zsystm self-assigned this Jul 21, 2023
@codecov
Copy link

codecov bot commented Jul 21, 2023

Codecov Report

Merging #9 (88d24ad) into liquidstaking-module (8c3ba3c) will decrease coverage by 0.02%.
The diff coverage is 78.88%.

@@                   Coverage Diff                    @@
##           liquidstaking-module       #9      +/-   ##
========================================================
- Coverage                 71.62%   71.61%   -0.02%     
========================================================
  Files                       158      158              
  Lines                     11123    11083      -40     
========================================================
- Hits                       7967     7937      -30     
+ Misses                     2871     2868       -3     
+ Partials                    285      278       -7     
Impacted Files Coverage Δ
x/liquidstaking/types/redelegation_info.go 100.00% <ø> (ø)
x/liquidstaking/keeper/liquidstaking.go 80.39% <78.88%> (+2.25%) ⬆️

... and 6 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@dongsam dongsam requested review from dongsam and poorphd July 21, 2023 01:12
@dongsam dongsam mentioned this pull request Jul 21, 2023
19 tasks
x/liquidstaking/keeper/liquidstaking.go Show resolved Hide resolved
x/liquidstaking/keeper/liquidstaking.go Outdated Show resolved Hide resolved
x/liquidstaking/keeper/liquidstaking.go Show resolved Hide resolved
x/liquidstaking/keeper/liquidstaking.go Outdated Show resolved Hide resolved
@dongsam dongsam changed the title BREAKING CHANGE: simplify penalty handling logic feat!: simplify penalty handling logic Jul 21, 2023
@dongsam
Copy link
Member

dongsam commented Jul 21, 2023

Could you merge or rebase from upstream(liquidstaking-module) branch? to track simulation result on this PR (simulation PR just merged on upstream) Looks it's already triggering well, never mind

* panic when validator is invalid (this must not happen)
* remove empty branch
* fix wrong calc in IsEnoughToCoverSlash

feedbacks:
* #9 (comment)
* #9 (comment)
@zsystm
Copy link
Author

zsystm commented Jul 21, 2023

Could you merge or rebase from upstream(liquidstaking-module) branch? to track simulation result on this PR (simulation PR just merged on upstream)

Of course. I'll rebase it after all comments are resolved.

by adding IsEnoughToCoverSlash function, the edge cases we were previously worried about are gone.
(unpairing ins at previous epoch cannot cover the penalty during re-delegation period).

so comments and checking logics for that edge should be deleted as now.
@zsystm zsystm requested a review from dongsam July 21, 2023 06:25
Copy link
Member

@dongsam dongsam left a comment

Choose a reason for hiding this comment

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

LGTM fixed logics, please update spec and PR description ( downtime fraction part )

Comment on lines 3527 to 3533
func (suite *KeeperTestSuite) TestQuoInt() {
fmt.Println(sdk.NewDec(7).QuoInt(sdk.NewInt(9)).String())
fmt.Println(sdk.NewDec(7).Quo(sdk.NewDec(9)).String())
fmt.Println(sdk.NewDec(7).QuoTruncate(sdk.NewDec(9)).String())
fmt.Println(sdk.NewDec(7).QuoRoundUp(sdk.NewDec(9)).String())
fmt.Println(sdk.NewDec(7).Quo(sdk.NewDec(9)).String())
}
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a temporary code added to the development process, so I think you can delete it

Copy link
Author

Choose a reason for hiding this comment

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

Ooops. You are right. I'll delete it and update SPEC docs.

updated spec related with this pr

remove tc created during test locally

change function name of mustDelegate
mustDelegatePenaltyAmt is more readable and meaningful
Copy link
Member

@dongsam dongsam left a comment

Choose a reason for hiding this comment

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

LGTM except for broken links, please merge when workflow passed after applied the suggestions

x/liquidstaking/spec/02_state.md Outdated Show resolved Hide resolved
x/liquidstaking/spec/02_state.md Outdated Show resolved Hide resolved
zsystm and others added 2 commits July 21, 2023 17:31
Co-authored-by: dongsam <dongsamb@gmail.com>
Co-authored-by: dongsam <dongsamb@gmail.com>
@zsystm zsystm merged commit 75bc01b into liquidstaking-module Jul 21, 2023
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

2 participants