@@ -36,15 +36,15 @@ carry-over, which is stored in (2) `rewardRoundingDust`.
3636Finally, the (3) ` operatorRewards ` keep track of each operator's individual
3737state indexed by their ` id ` . An operator's ` accumulated ` value represents a
3838snapshot of the ` globalRewardAccumulator ` at the time they were last updated.
39- Their ` available ` value represents how much reward is available for withdraw.
40- Their ` weight ` is their weight in the pool.
39+ Their ` available ` value represents how much reward is available for withdraw,
40+ as of their most recent update. Their ` weight ` is their weight in the pool.
4141
4242To see how all of these pieces of state interact, we can go through some
4343event logs.
4444
4545#### Join -> Reward -> Withdraw
4646```
47- event 1) Alice (id 0 ) joins the pool with weight 10
47+ event 1) Alice (id 1 ) joins the pool with weight 10
4848event 2) 123 rewards are granted to the pool
4949event 3) Alice withdraws their rewards
5050```
@@ -56,7 +56,7 @@ rewardRoundingDust: 0
5656operatorRewards: {}
5757```
5858
59- Joining the pool is handled with ` updateOperatorRewards(0 , 10) ` (some
59+ Joining the pool is handled with ` updateOperatorRewards(1 , 10) ` (some
6060complexity abridged to be introduced later)
6161```
6262function updateOperatorRewards(uint32 operator, uint32 newWeight) internal {
@@ -78,12 +78,12 @@ accruedRewards = (0 - 0) * 0 = 0
7878o.available = 0 + 0 = 0
7979o.accumulated = 0
8080o.weight = 10
81- operatorRewards: {0 : {accumulated: 0, available: 0, weight: 10}}
81+ operatorRewards: {1 : {accumulated: 0, available: 0, weight: 10}}
8282
8383// new state
8484globalRewardAccumulator: 0
8585rewardRoundingDust: 0
86- operatorRewards: {0 : {accumulated: 0, available: 0, weight: 10}}
86+ operatorRewards: {1 : {accumulated: 0, available: 0, weight: 10}}
8787```
8888
8989Ever time an operator is updated, they accrue rewards equal to however much the
@@ -118,7 +118,7 @@ rewardRoundingDust = 3
118118// new state
119119globalRewardAccumulator: 12
120120rewardRoundingDust: 3
121- operatorRewards: {0 : {accumulated: 0, available: 0, weight: 10}}
121+ operatorRewards: {1 : {accumulated: 0, available: 0, weight: 10}}
122122```
123123
124124Whenever rewards are distributed, we * only* update ` globalRewardAccumulator `
@@ -127,7 +127,7 @@ lazily via `updateOperatorRewards`. Note that at this point, alice's
127127accumulator is 12 rewards behind the global accumulator!
128128
129129In order to Alice to withdraw her rewards, she shoud * update* herself first,
130- since her ` available ` state is ` 0 ` . So, first we call ` updateOperatorRewards(0 , 10) `
130+ since her ` available ` state is ` 0 ` . So, first we call ` updateOperatorRewards(1 , 10) `
131131
132132```
133133acc = 12
@@ -136,12 +136,12 @@ accruedRewards = (12 - 0) * 10 = 120
136136o.available = 0 + 120 = 120
137137o.accumulated = 12
138138o.weight = 10
139- operatorRewards: {0 : {accumulated: 12, available: 120, weight: 10}}
139+ operatorRewards: {1 : {accumulated: 12, available: 120, weight: 10}}
140140
141141// new state
142142globalRewardAccumulator: 12
143143rewardRoundingDust: 3
144- operatorRewards: {0 : {accumulated: 12, available: 120, weight: 10}}
144+ operatorRewards: {1 : {accumulated: 12, available: 120, weight: 10}}
145145```
146146
147147Some amount of reward (an amount between 0 and the total operator weight) will
@@ -150,7 +150,7 @@ threshold, the weight precision is 1 weight = 1 T, (1e18 divisor), but rewards
150150are represented with full precision (1e18), so numerically, even small rewards
151151should greatly exceed the total pool weight.
152152
153- Alice is now ready to withdraw! We call ` withdrawOperatorRewards(0 ) `
153+ Alice is now ready to withdraw! We call ` withdrawOperatorRewards(1 ) `
154154
155155```
156156function withdrawOperatorRewards(uint32 operator)
@@ -165,7 +165,7 @@ function withdrawOperatorRewards(uint32 operator)
165165// new state
166166globalRewardAccumulator: 12
167167rewardRoundingDust: 3
168- operatorRewards: {0 : {accumulated: 12, available: 0, weight: 10}}
168+ operatorRewards: {1 : {accumulated: 12, available: 0, weight: 10}}
169169```
170170
171171This returns ` 120 ` to the caller, and sets Alice's available rewards to 0. The
@@ -180,25 +180,25 @@ globalRewardAccumulator: 0
180180rewardRoundingDust: 0
181181operatorRewards: {}
182182
183- event 2) Alice (id 0 ) joins the pool with weight 10
183+ event 2) Alice (id 1 ) joins the pool with weight 10
184184globalRewardAccumulator: 0
185185rewardRoundingDust: 0
186- operatorRewards: {0 : {accumulated: 0, available: 0, weight: 10}}
186+ operatorRewards: {1 : {accumulated: 0, available: 0, weight: 10}}
187187
188188event 3) 123 rewards are granted to the pool
189189globalRewardAccumulator: 12
190190rewardRoundingDust: 3
191- operatorRewards: {0 : {accumulated: 0, available: 0, weight: 10}}
191+ operatorRewards: {1 : {accumulated: 0, available: 0, weight: 10}}
192192
193193event 4) Update Alice
194194globalRewardAccumulator: 12
195195rewardRoundingDust: 3
196- operatorRewards: {0 : {accumulated: 12, available: 120, weight: 10}}
196+ operatorRewards: {1 : {accumulated: 12, available: 120, weight: 10}}
197197
198198event 5) Withdraw Alice's Rewards
199199globalRewardAccumulator: 12
200200rewardRoundingDust: 3
201- operatorRewards: {0 : {accumulated: 12, available: 0, weight: 10}}
201+ operatorRewards: {1 : {accumulated: 12, available: 0, weight: 10}}
202202return: 120
203203```
204204
@@ -210,63 +210,63 @@ globalRewardAccumulator: 0
210210rewardRoundingDust: 0
211211operatorRewards: {}
212212
213- event 2) Alice (id 0 ) joins the pool with weight 10
213+ event 2) Alice (id 1 ) joins the pool with weight 10
214214globalRewardAccumulator: 0
215215rewardRoundingDust: 0
216- operatorRewards: {0 : {accumulated: 0, available: 0, weight: 10}}
216+ operatorRewards: {1 : {accumulated: 0, available: 0, weight: 10}}
217217
218218event 3) 123 rewards are granted to the pool
219219globalRewardAccumulator: 12
220220rewardRoundingDust: 3
221- operatorRewards: {0 : {accumulated: 0, available: 0, weight: 10}}
221+ operatorRewards: {1 : {accumulated: 0, available: 0, weight: 10}}
222222
223- event 4) Bob (id 1 ) joins the pool with weight 20
223+ event 4) Bob (id 2 ) joins the pool with weight 20
224224globalRewardAccumulator: 12
225225rewardRoundingDust: 3
226226operatorRewards: {
227- 0 : {accumulated: 0, available: 0, weight: 10}
228- 1 : {accumulated: 12, available: 0, weight: 20}
227+ 1 : {accumulated: 0, available: 0, weight: 10}
228+ 2 : {accumulated: 12, available: 0, weight: 20}
229229}
230230
231231event 5) 321 rewards are granted to the pool
232232globalRewardAccumulator: 22
233233rewardRoundingDust: 24
234234operatorRewards: {
235- 0 : {accumulated: 0, available: 0, weight: 10}
236- 1 : {accumulated: 12, available: 0, weight: 20}
235+ 1 : {accumulated: 0, available: 0, weight: 10}
236+ 2 : {accumulated: 12, available: 0, weight: 20}
237237}
238238
239239event 6) Update Alice
240240globalRewardAccumulator: 22
241241rewardRoundingDust: 24
242242operatorRewards: {
243- 0 : {accumulated: 22, available: 220, weight: 10}
244- 1 : {accumulated: 12, available: 0, weight: 20}
243+ 1 : {accumulated: 22, available: 220, weight: 10}
244+ 2 : {accumulated: 12, available: 0, weight: 20}
245245}
246246
247247event 7) Withdraw Alice's rewards
248248globalRewardAccumulator: 22
249249rewardRoundingDust: 24
250250operatorRewards: {
251- 0 : {accumulated: 22, available: 0, weight: 10}
252- 1 : {accumulated: 12, available: 0, weight: 20}
251+ 1 : {accumulated: 22, available: 0, weight: 10}
252+ 2 : {accumulated: 12, available: 0, weight: 20}
253253}
254254return: 220
255255
256256event 8) Update Bob
257257globalRewardAccumulator: 22
258258rewardRoundingDust: 24
259259operatorRewards: {
260- 0 : {accumulated: 22, available: 0, weight: 10}
261- 1 : {accumulated: 22, available: 200, weight: 20}
260+ 1 : {accumulated: 22, available: 0, weight: 10}
261+ 2 : {accumulated: 22, available: 200, weight: 20}
262262}
263263
264264event 9) Withdraw Bob's Rewards
265265globalRewardAccumulator: 22
266266rewardRoundingDust: 24
267267operatorRewards: {
268- 0 : {accumulated: 22, available: 0, weight: 10}
269- 1 : {accumulated: 22, available: 0, weight: 20}
268+ 1 : {accumulated: 22, available: 0, weight: 10}
269+ 2 : {accumulated: 22, available: 0, weight: 20}
270270}
271271return 200
272272```
@@ -350,61 +350,61 @@ rewardRoundingDust: 0
350350ineligibleEarnedRewards: 0
351351operatorRewards: {}
352352
353- event 2) Alice (id 0 ) joins the pool with weight 10
353+ event 2) Alice (id 1 ) joins the pool with weight 10
354354globalRewardAccumulator: 0
355355rewardRoundingDust: 0
356356ineligibleEarnedRewards: 0
357- operatorRewards: {0 : {accumulated: 0, available: 0, weight: 10, ineligibleUntil: 0}}
357+ operatorRewards: {1 : {accumulated: 0, available: 0, weight: 10, ineligibleUntil: 0}}
358358
359359event 3) 123 rewards are granted to the pool
360360globalRewardAccumulator: 12
361361rewardRoundingDust: 3
362362ineligibleEarnedRewards: 0
363- operatorRewards: {0 : {accumulated: 0, available: 0, weight: 10, ineligibleUntil: 0}}
363+ operatorRewards: {1 : {accumulated: 0, available: 0, weight: 10, ineligibleUntil: 0}}
364364
365- event 4) Bob (id 1 ) joins the pool with weight 20
365+ event 4) Bob (id 2 ) joins the pool with weight 20
366366globalRewardAccumulator: 12
367367rewardRoundingDust: 3
368368ineligibleEarnedRewards: 0
369369operatorRewards: {
370- 0 : {accumulated: 0, available: 0, weight: 10, ineligibleUntil: 0}
371- 1 : {accumulated: 12, available: 0, weight: 20, ineligibleUntil: 0}
370+ 1 : {accumulated: 0, available: 0, weight: 10, ineligibleUntil: 0}
371+ 2 : {accumulated: 12, available: 0, weight: 20, ineligibleUntil: 0}
372372}
373373
374374event 5) Bob is set as ineligable until 100000 seconds from now
375375globalRewardAccumulator: 12
376376rewardRoundingDust: 3
377377ineligibleEarnedRewards: 0
378378operatorRewards: {
379- 0 : {accumulated: 0, available: 0, weight: 10, ineligibleUntil: 0}
380- 1 : {accumulated: 12, available: 0, weight: 20, ineligibleUntil: event5-time + 10000}
379+ 1 : {accumulated: 0, available: 0, weight: 10, ineligibleUntil: 0}
380+ 2 : {accumulated: 12, available: 0, weight: 20, ineligibleUntil: event5-time + 10000}
381381}
382382
383383event 6) 321 rewards are granted to the pool
384384globalRewardAccumulator: 22
385385rewardRoundingDust: 24
386386ineligibleEarnedRewards: 0
387387operatorRewards: {
388- 0 : {accumulated: 0, available: 0, weight: 10, ineligibleUntil: 0}
389- 1 : {accumulated: 12, available: 0, weight: 20, ineligibleUntil: event5-time + 10000}
388+ 1 : {accumulated: 0, available: 0, weight: 10, ineligibleUntil: 0}
389+ 2 : {accumulated: 12, available: 0, weight: 20, ineligibleUntil: event5-time + 10000}
390390}
391391
392392event 7) Update Alice
393393globalRewardAccumulator: 22
394394rewardRoundingDust: 24
395395ineligibleEarnedRewards: 0
396396operatorRewards: {
397- 0 : {accumulated: 22, available: 220, weight: 10, ineligibleUntil: 0}
398- 1 : {accumulated: 12, available: 0, weight: 20, ineligibleUntil: event5-time + 10000}
397+ 1 : {accumulated: 22, available: 220, weight: 10, ineligibleUntil: 0}
398+ 2 : {accumulated: 12, available: 0, weight: 20, ineligibleUntil: event5-time + 10000}
399399}
400400
401401event 8) Withdraw Alice's rewards
402402globalRewardAccumulator: 22
403403rewardRoundingDust: 24
404404ineligibleEarnedRewards: 0
405405operatorRewards: {
406- 0 : {accumulated: 22, available: 0, weight: 10, ineligibleUntil: 0}
407- 1 : {accumulated: 12, available: 0, weight: 20, ineligibleUntil: event5-time + 10000}
406+ 1 : {accumulated: 22, available: 0, weight: 10, ineligibleUntil: 0}
407+ 2 : {accumulated: 12, available: 0, weight: 20, ineligibleUntil: event5-time + 10000}
408408}
409409return: 220
410410
@@ -413,17 +413,17 @@ globalRewardAccumulator: 22
413413rewardRoundingDust: 24
414414ineligibleEarnedRewards: 200
415415operatorRewards: {
416- 0 : {accumulated: 22, available: 0, weight: 10, ineligibleUntil: 0}
417- 1 : {accumulated: 22, available: 0, weight: 20, ineligibleUntil: event5-time + 10000}
416+ 1 : {accumulated: 22, available: 0, weight: 10, ineligibleUntil: 0}
417+ 2 : {accumulated: 22, available: 0, weight: 20, ineligibleUntil: event5-time + 10000}
418418}
419419
420420event 10) Withdraw Ineligable Rewards
421421globalRewardAccumulator: 22
422422rewardRoundingDust: 24
423423ineligibleEarnedRewards: 0
424424operatorRewards: {
425- 0 : {accumulated: 22, available: 0, weight: 10, ineligibleUntil: 0}
426- 1 : {accumulated: 22, available: 0, weight: 20, ineligibleUntil: event5-time + 10000}
425+ 1 : {accumulated: 22, available: 0, weight: 10, ineligibleUntil: 0}
426+ 2 : {accumulated: 22, available: 0, weight: 20, ineligibleUntil: event5-time + 10000}
427427}
428428return: 200
429429```
0 commit comments