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

imp(staking): implement the EditValidator function for staking precompiled contract #2051

Merged
merged 43 commits into from
May 23, 2024

Conversation

luchenqun
Copy link
Contributor

@luchenqun luchenqun commented Nov 17, 2023

Description

I have implemented the editValidator function in the #2030, and along with you the previously implemented delegate, undelegate, redelegate and related functions, the staking precompiled contract is only missing the final editValidator. With previous experience, I spent about three hours complete the editValidator.

Some Design Details

For the function editValidator defined in the StakingI.sol file, when the related values in the description parameter are "[do-not-modify]" string, the system will not changing the original values, the design comes from cosmos sdk, see https://github.com/evmos/cosmos-sdk/blob/v0.47.5-evmos/x/staking/client/cli/flags.go#L87-L91 and https://github.com/evmos/cosmos-sdk/blob/v0.47.5-evmos/x/staking/types/validator.go#L213-L241 . Since ths Solidity language does not have like the nil value in the Go language. Therefore, when the commissionRate and minSelfDelegation values are -1, the system keeps the original values unchanged.
Why commissionRate and minSelfDelegation not use the uint256 type and default to 0 without modifying the original value? Because the minimum value of commissionRate can be 0. If you think using -1 without modifying the original value is a reasonable design, I suggest that all subsequent related designs follow this principle.

Testing

Step 1

Set up at least one validator node and check the original information of the validator.
image

Step 2

Connect to the validator node by Remix and call the editValidator method of the Staking precompiled contract with the following parameters:

  • description: [ "[do-not-modify]", "[do-not-modify]", "[do-not-modify]", "[do-not-modify]", "i want update my details" ]
  • validatorAddress: 0xbf657D0ef7b48167657A703Ed8Fd063F075246D7
  • commissionRate: -1
  • minSelfDelegation: 1000000

Note: If you want to test modifying the commissionRate, you need to remove the restriction that it can only be changed once a day in cosmos sdk. For details see the code: https://github.com/evmos/cosmos-sdk/blob/v0.47.5-evmos/x/staking/types/commission.go#L86-L88

Step 3

Verify if the modifications have taken effect

  • The details value in the description has changed, while the others remain unchanged.
  • Since -1 was passed, the commissionRate value remains unchanged.
  • The minSelfDelegation value has changed from 1 to 1000000.
image

Query EVM transactions.

image

Query Cosmos transactions.

image

@luchenqun luchenqun requested a review from a team as a code owner November 17, 2023 06:03
@luchenqun luchenqun requested review from Vvaradinov and GAtom22 and removed request for a team November 17, 2023 06:03
Copy link

codecov bot commented Nov 17, 2023

Codecov Report

Attention: Patch coverage is 93.87755% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 59.66%. Comparing base (f097735) to head (4844766).
Report is 153 commits behind head on main.

Current head 4844766 differs from pull request most recent head d25a4ec

Please upload reports for the commit d25a4ec to get more accurate results.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #2051       +/-   ##
===========================================
- Coverage   70.45%   59.66%   -10.79%     
===========================================
  Files         293      341       +48     
  Lines       22559    21676      -883     
===========================================
- Hits        15893    12934     -2959     
- Misses       5800     7693     +1893     
- Partials      866     1049      +183     
Files Coverage Δ
precompiles/staking/types.go 90.02% <100.00%> (+2.69%) ⬆️
precompiles/staking/events.go 76.96% <91.30%> (+4.59%) ⬆️
precompiles/staking/staking.go 85.00% <0.00%> (+2.04%) ⬆️
precompiles/staking/tx.go 88.65% <89.47%> (+0.28%) ⬆️

... and 342 files with indirect coverage changes

@luchenqun luchenqun marked this pull request as draft November 17, 2023 06:20
@luchenqun luchenqun marked this pull request as ready for review November 17, 2023 06:25
@luchenqun luchenqun changed the title imp(staking): implement the EditValidator function for staking precom… imp(staking): implement the EditValidator function for staking precompiled contract Nov 20, 2023
precompiles/staking/tx.go Outdated Show resolved Hide resolved
precompiles/staking/tx.go Outdated Show resolved Hide resolved
precompiles/staking/tx.go Outdated Show resolved Hide resolved
precompiles/staking/types.go Outdated Show resolved Hide resolved
precompiles/staking/types.go Outdated Show resolved Hide resolved
precompiles/staking/types.go Outdated Show resolved Hide resolved
precompiles/staking/StakingI.sol Outdated Show resolved Hide resolved
Copy link
Contributor

@Vvaradinov Vvaradinov left a comment

Choose a reason for hiding this comment

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

Great work on this @luchenqun . Left some comments

precompiles/staking/tx.go Outdated Show resolved Hide resolved
precompiles/staking/types.go Outdated Show resolved Hide resolved
precompiles/staking/types.go Outdated Show resolved Hide resolved
precompiles/staking/types.go Outdated Show resolved Hide resolved
precompiles/staking/types.go Outdated Show resolved Hide resolved
Copy link
Contributor

@Vvaradinov Vvaradinov left a comment

Choose a reason for hiding this comment

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

Hey @luchenqun lefts some additional comments. Please also address the changes @fedekunze requested on the string coversion

precompiles/staking/tx.go Outdated Show resolved Hide resolved
precompiles/staking/tx.go Outdated Show resolved Hide resolved
precompiles/staking/types.go Show resolved Hide resolved
precompiles/staking/types.go Show resolved Hide resolved
precompiles/staking/types.go Show resolved Hide resolved
precompiles/staking/types.go Outdated Show resolved Hide resolved
@GAtom22 GAtom22 marked this pull request as ready for review May 13, 2024 21:37
Copy link
Contributor

@GAtom22 GAtom22 left a comment

Choose a reason for hiding this comment

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

thanks for the contribution @luchenqun!

precompiles/staking/events_test.go Show resolved Hide resolved
precompiles/staking/tx_test.go Show resolved Hide resolved
precompiles/staking/StakingI.sol Outdated Show resolved Hide resolved
@luchenqun luchenqun requested a review from 0xstepit May 14, 2024 14:57
@GAtom22 GAtom22 merged commit 28be1e5 into evmos:main May 23, 2024
41 of 44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants