Hook: UpdateExchangeRates
The UpdateExchangeRates
hook is called every VotePeriod
blocks and is responsible for updating the exchange rates based on all the votes that have been cast from the validators. The basic flow is
Reset the current exchange rates by removing them all from the store.
Split the votes into ballots by pair, removing any votes from nonbonded or jailed validators, any non-whitelisted pairs, pairs with less than the minimum number of votes, or pairs that have less than the voting power threshold.
For each valid pair, tally up the votes and find the weighted median exchange rate and record the validators that voted for an exchange rate that was within the reward band, and then update the exchange rate.
Count up the validators who missed the vote and increase the appropriate miss counters.
Distribute rewards to the validators that voted for an exchange rate that was within the reward band.
Clear previous prevotes and all votes from the store.