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!: port LSM module to SDK v0.47.x #18694

Merged

Conversation

sainoe
Copy link
Contributor

@sainoe sainoe commented Dec 11, 2023

Description

Port the LSM module changes from feature/v0.45.x-ics-lsm to feature/v0.47.x-ics-lsm, which is pointing at release/v0.47.x@044ff4d8c015.

Closes: #18200

cc: @riley-stride, @sampocs


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...

  • included the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

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 the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

mpoke and others added 6 commits November 27, 2023 21:50
* Format protos

* Fix Proto lints

* update protos

* make proto-gen

* implement necessary interfaces

* remove minSelfDelegation (partially)

---------

Co-authored-by: Zaki Manian <[email protected]>
* set min_self_delegation to 0 in TestAminoCodecFullDecodeAndEncode

* add WithdrawTokenizeShareRecordReward and WithdrawAllTokenizeShareRecordReward

* add methods to distribution/keeper

* register distribution msgs

* add SimulateMsgWithdrawTokenizeShareRecordReward

* LSM distribution queries

* LSM distr cli

* add BeforeTokenizeShareRecordRemoved hook

* add signers to proto distribution

* set signers correctly
* set min_self_delegation to 0 in TestAminoCodecFullDecodeAndEncode

* add WithdrawTokenizeShareRecordReward and WithdrawAllTokenizeShareRecordReward

* add methods to distribution/keeper

* register distribution msgs

* add SimulateMsgWithdrawTokenizeShareRecordReward

* LSM distribution queries

* LSM distr cli

* add BeforeTokenizeShareRecordRemoved hook

* add signers to proto distribution

* set signers correctly

* minimum refactor to build

* tag LSM test to be refactored

* Merge with feat/lsm/v0.47.x

tag LSM tests to be refactored

Fix nits

* nit

* comments more failing tests

* make protos

* Update x/staking/keeper/msg_server.go

Co-authored-by: Marius Poke <[email protected]>

* Update x/staking/keeper/msg_server.go

Co-authored-by: Marius Poke <[email protected]>

* add go.work and fix silent errors

* address comments

* tests: add lsm distribution tests (#6)

---------

Co-authored-by: mpoke <[email protected]>
Co-authored-by: MSalopek <[email protected]>
* set min_self_delegation to 0 in TestAminoCodecFullDecodeAndEncode

* add WithdrawTokenizeShareRecordReward and WithdrawAllTokenizeShareRecordReward

* add methods to distribution/keeper

* register distribution msgs

* add SimulateMsgWithdrawTokenizeShareRecordReward

* LSM distribution queries

* LSM distr cli

* add BeforeTokenizeShareRecordRemoved hook

* add signers to proto distribution

* set signers correctly

* minimum refactor to build

* tag LSM test to be refactored

* Merge with feat/lsm/v0.47.x

tag LSM tests to be refactored

Fix nits

* nit

* comments more failing tests

* make protos

* Update x/staking/keeper/msg_server.go

Co-authored-by: Marius Poke <[email protected]>

* Update x/staking/keeper/msg_server.go

Co-authored-by: Marius Poke <[email protected]>

* add go.work and fix silent errors

* address comments

* refactor staking msg_server_tests.go - distrib hooks cause them to fail

* make integration tests pass

* clean up

* clean up

* refactor last integration

* nits

* revert deterministic tests change

* tests: update simulation randfees calc (#9)

* address min self delegation depreciation in tests

* refactor e2e tests and other nits

* tests: appease linter in randfees

---------

Co-authored-by: mpoke <[email protected]>
Co-authored-by: MSalopek <[email protected]>
@sainoe sainoe marked this pull request as ready for review December 11, 2023 14:53
@sainoe sainoe requested a review from a team as a code owner December 11, 2023 14:53
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

gosec found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

x/distribution/types/msg.go Dismissed Show dismissed Hide dismissed
func (msg MsgWithdrawAllTokenizeShareRecordReward) GetSigners() []sdk.AccAddress {
owner, err := sdk.AccAddressFromBech32(msg.OwnerAddress)
if err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt

tokensBz, err := tokens.Marshal()
if err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt

var tokens math.Int
if err := tokens.Unmarshal(tokensBz); err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
// This only error's if the total liquid staked tokens underflows
// which would indicate there's a corrupted state where the validator has
// liquid tokens that are not accounted for in the global total
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
func (msg MsgTransferTokenizeShareRecord) GetSigners() []sdk.AccAddress {
sender, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
func (msg MsgDisableTokenizeShares) GetSigners() []sdk.AccAddress {
sender, err := sdk.AccAddressFromBech32(msg.DelegatorAddress)
if err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
func (msg MsgEnableTokenizeShares) GetSigners() []sdk.AccAddress {
sender, err := sdk.AccAddressFromBech32(msg.DelegatorAddress)
if err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
func (msg MsgValidatorBond) GetSigners() []sdk.AccAddress {
delegator, err := sdk.AccAddressFromBech32(msg.DelegatorAddress)
if err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
@@ -17,6 +17,7 @@
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)

k.TrackHistoricalInfo(ctx)
k.RemoveExpiredTokenizeShareLocks(ctx, ctx.BlockTime())

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
@mpoke mpoke requested review from zmanian and mpoke December 11, 2023 20:21
@MSalopek
Copy link
Contributor

Migration code was done in this commit:

The same commit is visible in the PR using:

MinCommissionRate: sdk.NewDecWithPrec(rapid.Int64Range(0, 100).Draw(t, "commission"), 2),
ValidatorBondFactor: sdk.NewDecWithPrec(rapid.Int64Range(0, 100).Draw(t, "bond-factor"), 2),
GlobalLiquidStakingCap: sdk.NewDecWithPrec(rapid.Int64Range(0, 100).Draw(t, "global-liquid-staking-cap"), 2),
ValidatorLiquidStakingCap: sdk.NewDecWithPrec(rapid.Int64Range(0, 100).Draw(t, "validator-liquid-staking-cap"), 2),
Copy link
Member

Choose a reason for hiding this comment

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

We set the validator liquid staking cap to 100% on the cosmos hub. I am not sure this value is necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree in the context of the hub. However, I believe we still gain some confidence in the overall logic by varying the ValidatorLiquidStakingCap value in the tests.

runtime/app.go Outdated Show resolved Hide resolved
snapshots/store.go Outdated Show resolved Hide resolved
Copy link

@mpoke mpoke left a comment

Choose a reason for hiding this comment

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

In general it looks good to me. I left some comments. I'll approve once the comments are addressed and the tests are passing.

x/staking/migrations/v3/Readme.md Outdated Show resolved Hide resolved
x/staking/migrations/v3/Readme.md Outdated Show resolved Hide resolved
@mpoke
Copy link

mpoke commented Dec 22, 2023

Seems the TestIntegrationTestSuite/TestQueryABCIHeight test is failing

Copy link
Contributor

@sampocs sampocs left a comment

Choose a reason for hiding this comment

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

Looks great!

Let me know if there are any sensitive areas that warrant a more thorough review (i.e. any place where the changes were more than just a copy+paste). I did a slower/more focused review for the staking msg_server, liquid_stake.go, and the migration.

x/staking/keeper/liquid_stake_test.go Show resolved Hide resolved
x/staking/keeper/liquid_stake.go Outdated Show resolved Hide resolved
x/staking/keeper/msg_server.go Show resolved Hide resolved
x/staking/migrations/v3/Readme.md Outdated Show resolved Hide resolved
x/staking/migrations/v4/migrations_test.go Show resolved Hide resolved
Comment on lines +41 to +54
// Checks if an account associated with a given delegation is related to liquid staking
//
// This is determined by checking if the account has a 32-length address
// which will identify the following scenarios:
// - An account has tokenized their shares, and thus the delegation is
// owned by the tokenize share record module account
// - A liquid staking provider is delegating through an ICA account
//
// Both ICA accounts and tokenize share record module accounts have 32-length addresses
// NOTE: This will have to be refactored before adapting it to chains beyond gaia
// as other chains may have 32-length addresses that are not related to the above scenarios
func (k Keeper) DelegatorIsLiquidStaker(delegatorAddress sdk.AccAddress) bool {
return len(delegatorAddress) == 32
}
Copy link
Contributor

Choose a reason for hiding this comment

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

(this comment shouldn't block the upgrade to 47) but might be worth revisiting what the long term plan is here, wrt to upstreaming this into 51.

Iirc, legacy CW addresses are less than 32 bytes so I don't think this covers all cases on a chain with CW enabled. That said, maybe that doesn't matter if LSPs would have to move off the legacy contract in order to upgrade?

func (msg MsgUnbondValidator) GetSigners() []sdk.AccAddress {
valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress)
if err != nil {
panic(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure it really matters, but I think for the other messages in 47, there's no longer panics here after the address validation

x/staking/README.md Show resolved Hide resolved
OpWeightMsgEditValidator = "op_weight_msg_edit_validator"
OpWeightMsgDelegate = "op_weight_msg_delegate"
OpWeightMsgUndelegate = "op_weight_msg_undelegate"
OpWeightMsgBeginRedelegate = "op_weight_msg_begin_redelegate"

Check failure

Code scanning / Golang security checks by gosec

Potential hardcoded credentials Error

Potential hardcoded credentials
OpWeightMsgCreateValidator = "op_weight_msg_create_validator"
OpWeightMsgEditValidator = "op_weight_msg_edit_validator"
OpWeightMsgDelegate = "op_weight_msg_delegate"
OpWeightMsgUndelegate = "op_weight_msg_undelegate"

Check failure

Code scanning / Golang security checks by gosec

Potential hardcoded credentials Error

Potential hardcoded credentials

OpWeightMsgCreateValidator = "op_weight_msg_create_validator"
OpWeightMsgEditValidator = "op_weight_msg_edit_validator"
OpWeightMsgDelegate = "op_weight_msg_delegate"

Check failure

Code scanning / Golang security checks by gosec

Potential hardcoded credentials Error

Potential hardcoded credentials
DefaultWeightMsgDisableTokenizeShares int = 1

OpWeightMsgCreateValidator = "op_weight_msg_create_validator"
OpWeightMsgEditValidator = "op_weight_msg_edit_validator"

Check failure

Code scanning / Golang security checks by gosec

Potential hardcoded credentials Error

Potential hardcoded credentials
DefaultWeightMsgFundCommunityPool int = 50
OpWeightMsgSetWithdrawAddress = "op_weight_msg_set_withdraw_address" //nolint:gosec
OpWeightMsgWithdrawDelegationReward = "op_weight_msg_withdraw_delegation_reward" //nolint:gosec
OpWeightMsgWithdrawValidatorCommission = "op_weight_msg_withdraw_validator_commission" //nolint:gosec

Check failure

Code scanning / Golang security checks by gosec

Potential hardcoded credentials Error

Potential hardcoded credentials
OpWeightMsgBeginRedelegate = "op_weight_msg_begin_redelegate"
OpWeightMsgCancelUnbondingDelegation = "op_weight_msg_cancel_unbonding_delegation"
OpWeightMsgValidatorBond = "op_weight_msg_validator_bond" //nolint:gosec
OpWeightMsgTokenizeShares = "op_weight_msg_tokenize_shares" //nolint:gosec

Check failure

Code scanning / Golang security checks by gosec

Potential hardcoded credentials Error

Potential hardcoded credentials
OpWeightMsgUndelegate = "op_weight_msg_undelegate"
OpWeightMsgBeginRedelegate = "op_weight_msg_begin_redelegate"
OpWeightMsgCancelUnbondingDelegation = "op_weight_msg_cancel_unbonding_delegation"
OpWeightMsgValidatorBond = "op_weight_msg_validator_bond" //nolint:gosec

Check failure

Code scanning / Golang security checks by gosec

Potential hardcoded credentials Error

Potential hardcoded credentials
OpWeightMsgDelegate = "op_weight_msg_delegate"
OpWeightMsgUndelegate = "op_weight_msg_undelegate"
OpWeightMsgBeginRedelegate = "op_weight_msg_begin_redelegate"
OpWeightMsgCancelUnbondingDelegation = "op_weight_msg_cancel_unbonding_delegation"

Check failure

Code scanning / Golang security checks by gosec

Potential hardcoded credentials Error

Potential hardcoded credentials
OpWeightMsgWithdrawDelegationReward = "op_weight_msg_withdraw_delegation_reward" //nolint:gosec
OpWeightMsgWithdrawValidatorCommission = "op_weight_msg_withdraw_validator_commission" //nolint:gosec
OpWeightMsgFundCommunityPool = "op_weight_msg_fund_community_pool" //nolint:gosec
OpWeightMsgWithdrawAllTokenizeShareRecordReward = "op_weight_msg_withdraw_all_tokenize_share_record_reward" //nolint:gosec

Check failure

Code scanning / Golang security checks by gosec

Potential hardcoded credentials Error

Potential hardcoded credentials
OpWeightMsgSetWithdrawAddress = "op_weight_msg_set_withdraw_address" //nolint:gosec
OpWeightMsgWithdrawDelegationReward = "op_weight_msg_withdraw_delegation_reward" //nolint:gosec
OpWeightMsgWithdrawValidatorCommission = "op_weight_msg_withdraw_validator_commission" //nolint:gosec
OpWeightMsgFundCommunityPool = "op_weight_msg_fund_community_pool" //nolint:gosec

Check failure

Code scanning / Golang security checks by gosec

Potential hardcoded credentials Error

Potential hardcoded credentials
sainoe and others added 3 commits January 5, 2024 09:50
* Fix bug in `CheckExceedsValidatorLiquidStakingCap` formula

* Update x/staking/keeper/liquid_stake.go

Co-authored-by: Marius Poke <[email protected]>

* fix unit test bug

---------

Co-authored-by: Marius Poke <[email protected]>
Copy link
Contributor

@sampocs sampocs left a comment

Choose a reason for hiding this comment

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

lgtm, great work here!

Copy link

@mpoke mpoke left a comment

Choose a reason for hiding this comment

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

LGTM. Great work @sainoe and @MSalopek

@sainoe sainoe merged commit 173f2ea into cosmos:feature/v0.47.x-ics-lsm Jan 12, 2024
23 of 27 checks passed
JayT106 pushed a commit to JayT106/cosmos-sdk that referenced this pull request Feb 15, 2024
Co-authored-by: Marius Poke <[email protected]>
Co-authored-by: Zaki Manian <[email protected]>
Co-authored-by: MSalopek <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants