tangle-network / dkg-substrate

Multy-party threshold ECDSA (GG20) Substrate node
https://tangle.webb.tools/
GNU General Public License v3.0
60 stars 15 forks source link

[TASK] Include sorting by stake in best authorities calculation #629

Closed drewstone closed 1 year ago

drewstone commented 1 year ago

Issue summary

We currently select best authorities by reputation. Everyone starts with full reputation. This might lead to low stake validators getting selected for the authority selection mechanism and not rotating out unless they lose rep. We should consider sorting by stake first, then modifying the sort by reputation to at least to ensure we are selecting with stake in mind.

1xstj commented 1 year ago

This how the authority selection flow works right now,

  1. Session pallet notifies that a session is ending, this session change notification is send to staking pallet (https://github.com/webb-tools/dkg-substrate/blob/8da00187a9eec81808bf7310b4c096925c3b8ee2/standalone/runtime/src/lib.rs#L311)
  2. The SessionManager of Stake pallet proceeds to select new validators, to do this it calls the ElectionProvider (https://github.com/paritytech/substrate/blob/5a7003b5bafb1343adaa47fc1d25ab1097b92836/frame/staking/src/pallet/impls.rs#L511)
  3. The ElectionProvider pallet selects the validators list using a combination of highest staked + most delegated (https://github.com/paritytech/substrate/blob/5a7003b5bafb1343adaa47fc1d25ab1097b92836/frame/elections-phragmen/src/lib.rs#L999)
  4. The result from the Election provider is set as the new validator set.
  5. The new validator set is passed to the dkg-metadata pallet via the SessionHandler trait (https://github.com/webb-tools/dkg-substrate/blob/8da00187a9eec81808bf7310b4c096925c3b8ee2/pallets/dkg-metadata/src/lib.rs#L2251)
  6. Using the new validators as base, we sort by reputation and select the new dkg-best-authorities (https://github.com/webb-tools/dkg-substrate/blob/8da00187a9eec81808bf7310b4c096925c3b8ee2/pallets/dkg-metadata/src/lib.rs#L2150)

aka at step6, we already have the sorted-by-stake validators as input, resorting them again is redundant. Wdyt? @drewstone