livepeer / protocol

Livepeer protocol
MIT License
152 stars 45 forks source link

Keep track of the total stake of the activeSet for a round #302

Closed kyriediculous closed 5 years ago

kyriediculous commented 5 years ago

In the current version of the BondingManager we keep track of the total stake by the active set for a round in the activeTranscoderSet round=>ActiveTranscoderSet map's totalStake field. The aggregation of this stake is made when we call setActiveTranscoders() and write the current active set for a round to storage.

We aim to delete this function in #299 so we need a different way to keep track of the totalStake for a round so that we can calculate the correct reward distribution when a transcoder calls BondingManager.Reward().

We can use two new state variables to track this. currentRoundTotalActiveStake and nextRoundTotalActiveStake

We can update nextRoundTotalActiveStake when the active set for the next round changes based on transcoderPool insertions/evictions and then "lock in" that amount by setting currentRoundTotalActiveStake equal to nextRoundTotalActiveStake upon initializing a new round.

There is a good reason for not choosing a map of round=>totalStake here, because that would require setting zeroed storage slots to non-zero, which incurs a higher gas cost (20 000 extra) compared to setting a non-zeroed storage slot to another non-zeroed value.

yondonfu commented 5 years ago

Closed by #323