github.com/filecoin-project/specs-actors/v4@v4.0.2/actors/builtin/reward/reward_calc.py (about)

     1  #!/usr/bin/python3
     2  
     3  # This file can be used to recalculate the reward constants in the code when
     4  # changing the reward factor and/or the epoch duration in seconds.
     5  
     6  from decimal import Decimal
     7  import decimal
     8  
     9  # Number of seconds per epoch.
    10  EPOCH_DURATION_SECONDS = 30
    11  
    12  # Total Filecoin supply
    13  SIMPLE_SUPPLY_TOTAL=330000000
    14  
    15  # Growth factor per year. Currently 100%.
    16  GROWTH_FACTOR = 1.0
    17  
    18  # Seconds in a year, according to filecoin. This is actually slightly shorter
    19  # than a year, but it's close enough.
    20  SECONDS_PER_YEAR=60*60*365*24
    21  
    22  # Precision factor.
    23  Q128 = 2**128
    24  
    25  
    26  # Set the precision to enough digits to store (Q128 * Q128).
    27  #
    28  # This gives us wolfram-alpha level precision.
    29  decimal.getcontext().prec=int(Decimal(Q128**2).log10().to_integral_value(decimal.ROUND_CEILING))
    30  
    31  def epochs_in_year() -> Decimal:
    32      return Decimal(SECONDS_PER_YEAR)/Decimal(EPOCH_DURATION_SECONDS)
    33  
    34  def q128(val) -> str:
    35      return str((Q128 * val).to_integral_value(decimal.ROUND_DOWN))
    36  
    37  def atto(val) -> str:
    38      return str((10**18 * val).to_integral_value(decimal.ROUND_DOWN))
    39  
    40  # exp(ln[1 + 200%] / epochsInYear)
    41  def baseline_exponent() -> Decimal: 
    42      return (Decimal(1 + GROWTH_FACTOR).ln() / epochs_in_year()).exp()
    43  
    44  # ln(2) / (6 * epochsInYear)
    45  def reward_lambda() -> Decimal: 
    46      # 2 is a constant such that the half life is 6 years.
    47      return Decimal(2).ln() / (6 * epochs_in_year())
    48  
    49  # exp(lambda) - 1
    50  def reward_lambda_prime() -> Decimal: 
    51      return reward_lambda().exp() - 1
    52  
    53  # exp(-lambda) - 1
    54  def initial_reward_veolocity_estimate() -> Decimal: 
    55      return reward_lambda().copy_negate().exp() - 1
    56  
    57  def initial_reward_position_estimate() -> Decimal: 
    58      return (1 - reward_lambda().copy_negate().exp())*SIMPLE_SUPPLY_TOTAL
    59  
    60  def main():
    61      print("BaselineExponent: ", q128(baseline_exponent()))
    62      print("lambda: ", q128(reward_lambda()))
    63      print("expLamSubOne: ", q128(reward_lambda_prime()))
    64      print("InitialRewardVelocityEstimate: ", atto(initial_reward_veolocity_estimate()))
    65      print("InitialRewardPositionEstimate: ", atto(initial_reward_position_estimate()))
    66  
    67  if __name__ == "__main__":
    68      main()