-
Notifications
You must be signed in to change notification settings - Fork 532
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
[RFC-201/205] Staking and validator storage rework #1442
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Deploy root contracts * New child contracts deployment * Lint fix * nil reference exception fix * Comments fix
* Change whitelist and register commands * Build fix * Lint fix * Include submodule fix * Remove leftover const * Minor change * Minor updates * Check error before checking doesMatch flag * Add private key flag to whitelist command * two new GetXYZFromSecret methods * Change whitelist command for secrets * Lint fix --------- Co-authored-by: Stefan Negovanović <[email protected]> Co-authored-by: Igor Crevar <[email protected]>
* Register child chain to StakeManager * Lint fix * Small fix * Comments fix
* Change stake command * Build fix * Bring commands back to polybft command * Validate jsonRPC address * Comments fix * Build fix * Lint fix
* Supernet command * Use GetECDSAKey in whitelist command * Validate jsonRPC address * Comments fix * Comments fix * Rebase fix
* Change validator info command * Lint fix
* Validate validator set delta * Lint fix * Remove comment * Add test
* Initial changes * Lint fix * Comments fix * Comments fix * Remove comment * Comments fix * Improve sorted map * Comments fix * Lint fix * Add comments in code * Comments fix * New UT * Lint fix * Call stakeManager in consensus runtime * Testing deterministic behavior of sort by stake * simple changes * even simplier things * different stakeMap and some refactoring * lower number of execution times for test * fix --------- Co-authored-by: Igor Crevar <[email protected]>
* Initial changes * Change withdraw command * Unstake command change * Remove ChildValidatorSet * Deploy MockRewardContract * Deploy contract fix * Lint fix * Fix sc_integration_test * Separate unstake and withdraw * Comments fix
* Save full validator set in db * Lint fix * Fix * Test fix * validatorStakeMap refactor * lint fix --------- Co-authored-by: Igor Crevar <[email protected]>
* Add whitelist and register validator steps to e2e tests * Initial staking on genesis * Finalize genesis set on supernet manager * Parallelize register and stake commands * Lint fix * Small optimization * Comments fix * Return negative case MakeKOSKSignature test * Lint fix
* New init of contracts * Reward token configuration * Rebase fix * Lint fix * Validate wallet amount in genesis * Comments fix * Comments fix * Comments fix
* WithoutBridge * fix fund command test * Remove WithBridge invocation * Rename error message * Rename to initializeNew (unblock whitelist) * kosk refactor * Kosk key fix * Lint fix * Kosk signature print * Remove chainID from register command * Remove leftovers and lint fixes * Remove chain-id flag from register validator command * Remove feat-polybft-release for core-contracts submodule * Remove delegation e2e test * GetValidatorInfo refactor * Remove comments * Latest SC spec * Leftover and comment * Fix Test_MakeKOSKSignature * Fix GetValidatorInfo, partially fix stake function * RewardPool updates * Withdraw child and withdraw root functions, obsolete e2e test with delegate * Increase timeout to 1.5h * Lint fix * Register and white list validators * Fix typo * ChangeVotingPower test fix * Lint fix * Fund per validator * Unstake test fix * amount should be big.Int * Update SCs and lint fix * Fix TestE2E_Consensus_MintableERC20NativeToken * Fix TestE2E_Consensus_Validator_Unstake * Unstake test fix * Fix RegisterValidator test * Lint fix * ChangeVotingPower test modification * TestIntegration_CommitEpoch fix * Fix TestE2E_Bridge_ChangeVotingPower * Minor fixes * Fix TestE2E_Bridge_ChangeVotingPower (part 2) * Update smart contracts * Remove commented code * RFC-201-205 Stake manager db fix (#1457) * stake manager db fix * bls key * Fix with Data field error on logs * Fix timeout * Fix test timeout * Copy data array * Remove log copying from bindings generator * Wait for epoch ending block in ChangeVotingPower e2e test * Persist initial validator set as epoch id 0 --------- Co-authored-by: Goran Rojovic <[email protected]> Co-authored-by: Stefan Negovanović <[email protected]> * Update README --------- Co-authored-by: Stefan Negovanović <[email protected]> Co-authored-by: Goran Rojovic <[email protected]>
…idator-storage-rework
goran-ethernal
added
the
breaking change
Functionality that contains breaking changes
label
May 2, 2023
Stefan-Ethernal
approved these changes
May 3, 2023
Stefan-Ethernal
force-pushed
the
feat/validator-storage-rework
branch
from
May 3, 2023 07:12
52087ed
to
414221a
Compare
igorcrevar
approved these changes
May 3, 2023
Nemanja0x
approved these changes
May 3, 2023
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR refactors the workflow of validators staking and validator set storage in accordance to RFCs 201 and 205.
Edge is now used as
L2
, meaning it can operate only in bridge mode, and from now on called aSupernet
. Its validators are registered on, and stake on therootchain
. A stake is transferred tochildchain
through the bridge mechanism, and the validator set is updated on the client itself. It is worth noting that staking is done in the native root token on therootchain
.Two new contracts are deployed to
rootchain
:StakeManager
- a single instance contract onrootchain
that has references to eachsupernet
and handles staking for each of them onrootchain
.CustomSupernetManager
- a contract that will be deployed for each supernet, which stores the validator info for a given supernet, whitelists, registers, and bridges stake to its supernet (childchain
).After
StakeManager
is deployed, andSupernetManager
is deployed for the given supernet, deployer needs to register theSupernetManager
toStakeManager
by calling theregisterChildChain
function. This function will emit an event that contains an id of theSupernetManager
(or given supernet). That id will be our newchainID
of thechildChain
and needs to be added togenesis
file generated by thegenesis
command (this can be done manually, but thedeploy
command provided by Edge, does this automatically).After the contracts are deployed on the
rootchain
,SupernetManager
deployer can whitelist validators in thegenesis
file to it, by calling thewhitelist
function (note, only the deployer can do this).After the validators are whitelisted on the
rootchain
, each of them can proceed to register itself on theSupernetManager
, by calling theregister
function. They need to provide their publicbls
key and signature when registering.After validators register themselves on the
SupernetManager
, they can do the initial staking on therootchain
, by calling thestakeFor
function onStakeManager
, and providing thechainID
theStakeManager
emitted when registeringSupernetManager
, and the amount of tokens they want to stake. By using thechainID
,StakeManager
knows on which supernet the given validator wants to stake. It is worth noting that validators can change stakes as they wish before starting the child chain. Once the genesis staking is finalized by theSupernetManager
deployer, validators stake at that moment will be considered final, andchildchain
can be started.Genesis staking is finalized by the
SupernetManager
deployer by calling thefinalizeGenesis
function on the contract.After genesis staking is finalized on the
rootchain
, supernet (childchain
) can be started.Once the supernet is started, each stake change on the
rootchain
is bridged to theValidatorSet
contract on the child chain which acts as anERC20
implementation, where balances of accounts are their stake on the rootchain.Unstaking is done on the supernet first, by calling the
unstake
function on theValidatorSet
contract. The user needs to wait for one epoch so that he can withdraw his stake from the supernet to therootchain
. Withdraw on theValidatorSet
contract, bridges the unstaked amount to therootchain
StakeManager
contract. This releases the given stake on therootchain
and the user can withdraw it from theStakeManager
by calling thewithdrawStake
function.On the supernet (
childchain
) we have two new contracts:ValidatorSet
- as mentioned earlier is just aERC20
implementation that wraps the stake change onrootchain
to thechildchain
, where balance of an account onValidatorSet
is the stake of the given account on therootchain
. It also has bridge functionality to bridge the stake/unstake changes from one chain to the other.ValidatorSet
has the oldcommitFunction
to commit the ending of an epoch, but does not handle rewards distribution.RewardPool
- is a new contract that handles the reward distribution. It is called by the edge client in a state transaction to distribute rewards to block signers at the epoch-ending block. It uses a reward token (anERC20
implementation, which can be either a nativeERC20
token onchildchain
or a customERC20
token provided by the client.A graphical look of the new flow can be seen on the picture below:
Deployment steps are now changed to support this:
genesis
command. It is important to note that we added two new flags ingenesis
command:--reward-token
- hex encoded byte code of a custom rewardERC20
token if clients want to use a customERC20
token for rewards. If not provided, nativeERC20
token on child chain will be used for rewards.--reward-wallet
- a mandatory flag where users define a reward wallet address and the amount of tokens that need to be premined to it on genesis (address:amount).StakeManager
andCustomSupernetManager
contracts, initialize them and register supernet toStakeManager
, or use the provideddeploy
command by Edge that simplifies this workflow. Keep in mind that if you opt to do the manual deployment ofrootchain
contracts, you will need to extract thechainID
of you supernet that is emitted byStakeManager
when registering the supernet to it, by reading the transaction logs, and updating thegenesis
file manually. That is why we recommend using thedeploy
command, which does all this automatically.CustomSupernetManager
. You can use thewhitelist-validators
command provided by Edge.CustomSupernetManager
.StakeManager
. Keep in mind they need to provide thechainID
from genesis.SupernetManager
deployer needs to finalize genesis staking on it as a final step before starting the supernet. We recommend using thesupernet
command provided by Edge.Changes include
Breaking changes
L2
(operating only in bridge mode, therefore it is not possible to run it as L1, sovereign chain anymore).rootchain
.Checklist
Testing