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 CreateValidator
function for staking precompiled contract
#2030
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #2030 +/- ##
==========================================
- Coverage 70.39% 69.99% -0.40%
==========================================
Files 338 335 -3
Lines 25223 25228 +5
==========================================
- Hits 17756 17659 -97
- Misses 6558 6663 +105
+ Partials 909 906 -3
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work @luchenqun thank you for this PR. Left some comments on ways you can refactor to improve readability and consistency.
…'s address which is 0x0000000000000000000000000000000000000800 to create a new validator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some final comments
…datorAddress to address indexed validatorAddress
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @luchenqun great work and thank you for updating this. Left some additional comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for all the work @luchenqun
Description
I noticed that evmos have already implemented functions like
delegate
,undelegate
, andredelegate
and so on in the precompiled contract. However, I think the importantcreateValidator
function is missing. Additionally, thecreateValidator
function is not currently implemented in evmosjs either, so the only way to create a validator is through the CLI commandevmosd tx staking create-validator
. Due to these reasons, I have implemented thecreateValidator
function in the precompiled contract.Prerequisites
Start two nodes, named node0 and node1. Node0 is a validator node and node1 is a non-validator node. Node0 and node1 have already been linked via p2p.
Currently, there is only one validator node produces and signs the block
Check the list of validators, which currently has only one validator.
Objective
Call the
createValidator
method in the Staking precompiled contract make node1 become a validator node.Steps
Step 1
Use the command
evmosd tendermint show-validator --home=./nodes/node1/evmosd
to obtain the node public key for node1. Let's assume the obtained content is as follows:The key is the node1 public key.
Step 2
Use Remix to connect to node1. Note: Be sure to connect to node1 using Remix's External HTTP Provider method, as calling the contract requires online signing.
Then, call the
createValidator
method in the Staking precompiled contract with the following parameters:description
: ["node1","I'm identity","http://cosmos.lucq.fun","0x0000000000000000000000000000000000000800","I'm details"]commissionRates
: ["100000000000000000","100000000000000000","100000000000000000"]minSelfDelegation
: 1delegatorAddress
: 0xC79b690bA90B8e04625b8a11C20e8b356f5996d2validatorAddress
: evmosvaloper1c7dkjzafpw8qgcjm3gguyr5tx4h4n9kjuquq78pubkey
: OD/HHcEPGg9z+sGO1OCFItC1oup2pHUVbyXZKxOtI/o=value
: 100000000000000000000Note that the input parameters in the
commissionRates
field should be decimal numbers with a precision of 18. So, the decimal values shown above are all 0.1. ReplacedelegatorAddress
,validatorAddress
, andpubkey
with your actual values. Then send the transaction using Remix.Note: During the test, I found that the estimated gas was not very accurate, and the transaction failed due to insufficient gas. After repeated testing, gas consumption is approximately 158870, so it is recommended to set gasLimit to 200000 for testing. Therefore, transactions sent using remix may fail due to insufficient gas, so it is recommended to assemble the transaction yourself and set the gaslimit to 20,000.
For example, the following is a test case I sent using eth_sendTransaction. 0x30d40 = 200000
Step 3
Verify that node1 has become a validator.
The list of validators should now display an additional validator called node1.
There are currently two validators node produces and signs the block
Query evm type transactions.
Query cosmos type transactions.
The tool website used in some of the above screenshots is http://cosmos.lucq.fun/
TODO
CreateValidator
event, there are currently some hardcoded.