-
Notifications
You must be signed in to change notification settings - Fork 50
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
FEATURE: Efficiency Refactoring and Slot Selection for Staking Contracts #321
Conversation
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.
Approach is looking good - nice improvements.
- Added a few naming/documentation suggestions
- Added a suggestion to disallow approving an un-registered node ID (fixes an outstanding potential security issue, and would simplify some code added in this PR)
…328) * merge from pending moves * add preconditions and transactions * add new staking changes * add tests for slot selection * get tests passing with merged changes * add slot over limit test * more comments and clearer conditionals
I just merged the other two branches into this feature branch, but the CI is failing because the integration with flow-go is still broken. I'll talk with Jordan today about getting that resolved. I've also written a transaction that we can use for the upgrade. I'll start putting it in a PR in the service account repo and a forum post so we can have a formal plan and announcement for it, but I'm leaving it here so people can start reviewing it. I think the only values we'll need to change for the different networks are the staking slot limits.
|
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.
Reviewed new commit 81cfbf1
3837: Update `core-contracts` dependency (slot selection) r=jordanschalm a=jordanschalm This PR updates the version of `flow-core-contracts` to include onflow/flow-core-contracts#321. - Updates Staking Table contract deployment and scripts to match new version - Fixes issue where transaction errors in state bootstrapping were swallowed - This revealed some FVM tests which were configured in a way which failed state bootstrapping (see [comment](https://github.com/onflow/flow-go/pull/3837/files#r1083076101)) ### Outstanding Issues - [x] Update FVM tests which fail state bootstrapping https://github.com/onflow/flow-go/pull/3837/files#r1083076101 - [x] Fix `core-contracts` bug onflow/flow-core-contracts#339 Co-authored-by: Jordan Schalm <[email protected]> Co-authored-by: Janez Podhostnik <[email protected]>
Feature branch for big changes to the staking contracts to improve efficiency for epoch phase transition transactions and algorithm for random slot selection for new nodes.
Current Changes:
Changes approved node ID arguments to dictionaries instead of arrays
Cleans up some unnecessary code and should help with performance of certain transactions
Stores stakedNodeIDs as a dictionary in account storage and uses it to iterate over instead of all IDs
Should improve the performance of the calculateRewards function because the function will only iterate through staked node IDs instead of all node IDs
Also significantly helps the performance of getter functions like getProposedNodes and getStakedNodes because they just return the list of node IDs instead of having to iterate through the list to construct the nodes that are staked
Adds Pending Token Movements Dictionary
Adds a stored dictionary that represents nodes and delegators who have submitted a transaction to move tokens between buckets in some way. They are added to this record when they submit their transaction, not when the system chunk checks.
At the end of the epoch, when the moveTokens function is called, the function will only iterate through nodes and delegators who have submitted requests to move tokens, instead of checking all of the nodes and delegators.
This dictionary is cleared when the moveTokens function is called. Nodes who's unstaked tokens are moved to unstaking are automatically added to the dictionary for the next epoch.
This should significantly improve performance for the end epoch transactions.
This did not require any new tests because the existing tests were sufficient.
Adds a Candidate Node List
A candidate node is defined as a node who is not participating/staked in the current epoch, but has committed enough tokens to participate in the next epoch.
The candidate node list is a dictionary that maps roles to an array of node IDs:
This is added to make the random slot selection process easier. This process will be much more efficient with the candidate node list because it can select nodes for each role separately instead of having to do them all in one loop.
Some tests were added to test this list as well as some testing utility functions
Adds Events for Unstaking Requests
Events were added to mark when a node or delegator requests to unstake, indicating how much they requested
Additional
TokensUnstaked
event emissions were added on unstaking requests when tokens in the commited bucket are moved to the tokensUnstaked bucket. it isn't a full unstaking per se, but it matches the rest of the patterns thatTokensUnstaked
is emitted when tokens are moved into the tokens unstaked bucket.Adds new storage fields to the contract to track staking slots for node roles:
Role Slot Limits
{UInt8: UInt16}
Indicates how many of each node role can participate in each epoch
Participant Node Role Counts
Indicates how many of each node role are currently staked and participating in the epoch
Separates
removeAndRefundNodeRecord
into its own functionThis process is now done multiple times for checking for approval, staking minimum, and random slot selection, so it is now its own method
Adds
fillNodeRoleSlots
method to Admin resourceThis method randomly select candidate nodes for each slot until there are no candidate nodes left or all the slots for a given role have been filled. Leftover nodes are refunded.
As part of this addition, the need for Access nodes (role=5) to be approved by the admin has been removed. Other node roles will receive this update in the future
Adds
setNodeWeight
method to Admin resourceAllows the admin to set a node's weight to any number less than 100
NOTES FOR REVIEWERS: Ignore the
FlowIDTableStaking_new.cdc
file. I'm currently using this for testing because the flow-go dependencies don't like it when I make changes to the main contract file and some of the transactions.