vegaprotocol / vega

A Go implementation of the Vega Protocol, a protocol for creating and trading derivatives on a fully decentralised network.
https://vega.xyz
GNU Affero General Public License v3.0
37 stars 22 forks source link

Validator voting power value not according to formula in ACs #6114

Closed claudiumilea closed 2 years ago

claudiumilea commented 2 years ago

ACs: On Vega the voting power is calcualted as follows: stakeScore x performanceScore normalised by the sum of those scores.

0066-VALW-002 and 0066-VALW-004 and 0066-VALW-006 ACs are here: 0066-VALW-additional-acs

Tests are here: https://github.com/vegaprotocol/system-tests/pull/1137

In the tests I assert the value of voting power only based on the values returned by get_node_details() -> api.grpc_stub_trd_data_v2.ListNodes(Empty()) so normally since I check the value based on other values that I also get from the API it should work.

Either this is a bug or the specs need to be updated with what should happen differently in the situation depicted in the test case.

ze97286 commented 2 years ago

@claudiumilea can you please include a failing run.

ze97286 commented 2 years ago

this is a misunderstanding of the spec and the data.

ranking_score_for_voting_power = anti-whaled-stake-score * performance-score
voting power = 10000 * ranking_score_for_voting_power_i / sum(ranking_score_for_voting_power)

vs what you're doing: ranking_score_for_voting_power = stake-score * performance-score

the anti-whaled stake score is not reported in the event so you need to work out the maths yourself if you want to do it this way.

to put this into numbers as an example: you have 2 validators, one with 2/3 of the stake and one with 1/3 (which is already not nearly what the AC is stating but anyways). With the network parameters you're running with a validator is penalised if they have more than a 1/3 of the stake, meaning their anti-whaled stake score becomes 1/3. So applying the above calculation the right way leads to:

ranking_score_for_voting_power_1 = 1/3 * 1
ranking_score_for_voting_power_2 = 1/3 * 0.05

voting_power for_1 = 10000 * 1/3 / (1/3 * 1.05) = 9523
voting_power_for_2 = 10000 * 1/3 * 0.05 / (1/3 * 1.05) = 476

which is what you're getting from the API and tendermint: [2022-09-08T23:04:40.667Z] 2022-09-08 23:04:40.559:[INFO] [MainProcess] [MainThread] [test_validator_voting_power.py]:[check_validator_tendermint_voting_power]:[ 445] Voting power of Tendermint Key TwksGVz262LknP9tebJYz25NiE6mrFIJL0KtFoQ4Poc= in Tendermint - {'TwksGVz262LknP9tebJYz25NiE6mrFIJL0KtFoQ4Poc=': '9523'} API - 9523, performance_score - 1.0, stake_score - 0.3334246110201377

[2022-09-08T23:04:40.668Z] 2022-09-08 23:04:40.562:[INFO] [MainProcess] [MainThread] [test_validator_voting_power.py]:[check_validator_tendermint_voting_power]:[ 445] Voting power of Tendermint Key V3WY9WELi7hknJ8hAEpLMhOZc6w5/4uE5js23VsLjfU= in Tendermint - {'V3WY9WELi7hknJ8hAEpLMhOZc6w5/4uE5js23VsLjfU=': '476'} API - 476, performance_score - 0.05, stake_score - 0.6665753889798623

all correct. But if you do it the way you do in the test you're getting the wrong results and thinking the first validator should get 9091 (= 10000 1/3 / (2/3 0.05 + 1/3)) and the second one should get 908 (= 10000 2/3 0.05 / (2/3 * 0.05 + 1/3))

the run for this numbers is here https://jenkins.ops.vega.xyz/blue/organizations/jenkins/common%2Fsystem-tests-wrapper/detail/system-tests-wrapper/6076/pipeline/269.

to do the anti-whaling maths yourself (I wonder if you don't already have this code in system tests) you can look here: https://github.com/vegaprotocol/specs/blob/a9f2168e7e32b80ab128f9847215277330e19d1c/protocol/0061-REWP-pos_rewards.md#validatorscore-functions

gordsport commented 2 years ago

Not a bug on core - work on ST side to resolve