Nodes should only be considered for slot selection if they've been newly added in the current epoch
pgebheim opened this issue · 0 comments
pgebheim commented
The existing algorithm has a known issue: If a user removes their stake, or if the service accounts sets a nodes weight to 0, or if the node is slashed by the system setting their weight to 0 — the above algorithm would include those nodes in the set of possible nodes to include randomly in future open slots.
Ideally, only newly nodes which hadn’t been previously considered would be addable via this process.
Solution
- When
addNodeRecord
is called, we add a key to an additional dictionary which tracks which nodes should be considered pending. - In removeUnapprovedNodes, before adding to pending nodes check if this nodeId is in the pending nodes list ([code would go here](https://gist.github.com/pgebheim/451bf2684c9ffc4b11fbc447c936de17#file-snippet-cdc-L50))
- At end of removeUnapprovedNodes clear the pending list.
Questions
- Does the pending node list need to be updated when a user unstakes their node or if the node is slashed?
- It is possible for completeness that this happen
- I think that by making
removedUnapprovedNodes
use the pending list as a filter condition, we can sidestep needing to bookkeep for removed nodes. Any nodes which don’t show up in the main node list at the end of the epoch would not be considered, and this epoch-global pending list would be cleared at the end of the epoch.