Open djrtwo opened 6 years ago
One source of confusion comes from the fact that last_voter_rescale
and last_nonvoter_rescale
are variables that are used to debug instead of really required to be there. So a proposed change is to make these variables become constant functions.
diff --git a/casper/contracts/simple_casper.v.py b/casper/contracts/simple_casper.v.py
index 3b94cc9..6b02682 100644
--- a/casper/contracts/simple_casper.v.py
+++ b/casper/contracts/simple_casper.v.py
@@ -72,9 +72,6 @@ main_hash_justified: public(bool)
# Value used to calculate the per-epoch fee that validators should be charged
deposit_scale_factor: public(decimal(m)[int128])
-last_nonvoter_rescale: public(decimal)
-last_voter_rescale: public(decimal)
-
current_epoch: public(int128)
last_finalized_epoch: public(int128)
last_justified_epoch: public(int128)
@@ -244,6 +241,7 @@ def insta_finalize():
# Returns the current collective reward factor, which rewards the dynasty for high-voting levels.
@private
+@constant
def collective_reward() -> decimal:
epoch: int128 = self.current_epoch
live: bool = self.esf() <= 2
@@ -323,6 +321,15 @@ def total_curdyn_deposits_in_wei() -> wei_value:
def total_prevdyn_deposits_in_wei() -> wei_value:
return floor(self.total_prevdyn_deposits * self.deposit_scale_factor[self.current_epoch])
+@public
+@constant
+def last_voter_rescale() -> decimal:
+ return 1 + self.collective_reward()
+
+@public
+@constant
+def last_nonvoter_rescale() -> decimal:
+ return (1 + self.collective_reward()) / (1 + self.reward_factor)
@public
# cannot be labeled @constant because of external call
@@ -505,9 +512,8 @@ def initialize_epoch(epoch: int128):
self.current_epoch = epoch
- self.last_voter_rescale = 1 + self.collective_reward()
- self.last_nonvoter_rescale = self.last_voter_rescale / (1 + self.reward_factor)
- self.deposit_scale_factor[epoch] = self.deposit_scale_factor[epoch - 1] * self.last_nonvoter_rescale
+ self.deposit_scale_factor[epoch] = self.deposit_scale_factor[epoch - 1] * \
+ (1 + self.collective_reward()) / (1 + self.reward_factor)
self.total_slashed[epoch] = self.total_slashed[epoch - 1]
if self.deposit_exists():
Issue
I frequently have to explain what is actually happening with the scale factor and collective rewards. I also have to frequently re-figure out what's going on. It's very opaque.
Need to reward the names of things and also probably write a post.