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.
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'stotalStake
field. The aggregation of this stake is made when we callsetActiveTranscoders()
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
andnextRoundTotalActiveStake
We can update
nextRoundTotalActiveStake
when the active set for the next round changes based ontranscoderPool
insertions/evictions and then "lock in" that amount by settingcurrentRoundTotalActiveStake
equal tonextRoundTotalActiveStake
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.