Skip to content

Commit

Permalink
BLOCKS_PER_YEAR
Browse files Browse the repository at this point in the history
  • Loading branch information
HiveProject2021 committed Jan 11, 2024
1 parent 36a92ae commit e81ed98
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
6 changes: 3 additions & 3 deletions apps/chivesweave/src/ar_fork.erl
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ height_2_6_8() ->

-ifdef(FORKS_RESET).
height_2_7_0() ->
1100.
15.
-else.
-ifdef(TESTNET).
height_2_7_0() ->
1100.
15.
-else.
height_2_7_0() ->
1100. % Targeting 2023-05-30 16:00 UTC
15. % Targeting 2023-05-30 16:00 UTC
-endif.
-endif.

Expand Down
14 changes: 7 additions & 7 deletions apps/chivesweave/src/ar_inflation.erl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ calculate_post_15_y1_extra() ->
Pre15 = erlang:trunc(sum_rewards(fun calculate/1, 0, ?FORK_15_HEIGHT)),
Base = erlang:trunc(sum_rewards(fun calculate_base/1, 0, ?FORK_15_HEIGHT)),
Post15Diff = Base - Pre15,
erlang:trunc(Post15Diff / (?BLOCKS_PER_YEAR - ?FORK_15_HEIGHT)).
erlang:trunc(Post15Diff / (30 * 24 * 365 - ?FORK_15_HEIGHT)).

%%%===================================================================
%%% Private functions.
Expand All @@ -45,7 +45,7 @@ calculate_post_15_y1_extra() ->
calculate_base(Height) ->
{Ln2Dividend, Ln2Divisor} = ?LN2,
Dividend = Height * Ln2Dividend,
Divisor = ?BLOCKS_PER_YEAR * Ln2Divisor,
Divisor = 30 * 24 * 365 * Ln2Divisor,
Precision = ?INFLATION_NATURAL_EXPONENT_DECIMAL_FRACTION_PRECISION,
{EXDividend, EXDivisor} = ar_fraction:natural_exponent({Dividend, Divisor}, Precision),
?GENESIS_TOKENS
Expand All @@ -55,26 +55,26 @@ calculate_base(Height) ->
* Ln2Dividend
div (
10
* ?BLOCKS_PER_YEAR
* 30 * 24 * 365
* Ln2Divisor
* EXDividend
).

calculate_base_fork_2_7_0(Height) ->
{Ln2Dividend, Ln2Divisor} = ?LN2,
Dividend = Height * Ln2Dividend,
Divisor = ?BLOCKS_PER_YEAR * Ln2Divisor,
Divisor = 120 * 24 * 365 * Ln2Divisor,
Precision = ?INFLATION_NATURAL_EXPONENT_DECIMAL_FRACTION_PRECISION,
{EXDividend, EXDivisor} = ar_fraction:natural_exponent({Dividend, Divisor}, Precision),
?GENESIS_TOKENS
* ?WINSTON_PER_AR
* EXDivisor
* 1
* Ln2Dividend
* 12
div (
10
* 0.9
* ?BLOCKS_PER_YEAR
* 10
* 120 * 24 * 365
* Ln2Divisor
* EXDividend
).
Expand Down
4 changes: 2 additions & 2 deletions apps/chivesweave/src/ar_pricing.erl
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,9 @@ get_gb_cost_per_block_at_datetime(DT, Height) ->
case Height >= ar_fork:height_2_5() of
true ->
{Dividend, Divisor} = get_gb_cost_per_year_at_datetime(DT, Height),
{Dividend, Divisor * ?BLOCKS_PER_YEAR};
{Dividend, Divisor * 120 * 24 * 365};
false ->
get_gb_cost_per_year_at_datetime(DT, Height) / ?BLOCKS_PER_YEAR
get_gb_cost_per_year_at_datetime(DT, Height) / 120 * 24 * 365
end.

%% @doc Return the cost in USD of storing 1 GB per year. Estmimated from empirical data.
Expand Down
15 changes: 12 additions & 3 deletions apps/chivesweave/src/ar_retarget.erl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ is_retarget_block(Block) ->
?IS_RETARGET_BLOCK(Block).

maybe_retarget(Height, CurDiff, TS, LastRetargetTS, PrevTS) ->
?LOG_INFO([{calculate_difficulty_2_7_0_Height_________________________________, Height}]),
?LOG_INFO([{calculate_difficulty_2_7_0_maybe_retarget_________________________, ar_retarget:is_retarget_height(Height)}]),
case ar_retarget:is_retarget_height(Height) of
true ->
calculate_difficulty(CurDiff, TS, LastRetargetTS, Height, PrevTS);
Expand All @@ -78,6 +80,7 @@ calculate_difficulty(OldDiff, TS, Last, Height, PrevTS) ->
Fork_2_4 = ar_fork:height_2_4(),
Fork_2_5 = ar_fork:height_2_5(),
Fork_2_7_0 = ar_fork:height_2_7_0(),
?LOG_INFO([{calculate_difficulty_now, calculate_difficulty_2_7_0(OldDiff, TS, Last, Height)}]),
case Height of
_ when Height >= Fork_2_7_0 ->
calculate_difficulty_2_7_0(OldDiff, TS, Last, Height);
Expand Down Expand Up @@ -149,8 +152,8 @@ calculate_difficulty(OldDiff, TS, Last, Height) ->

calculate_difficulty_2_7_0_factor(ActualTime, TargetTime) ->
case ActualTime > TargetTime of
true -> 0.8;
false -> 1.2
true -> 8;
false -> 12
end.

calculate_target_time(Height) ->
Expand All @@ -165,14 +168,20 @@ calculate_difficulty_2_7_0(OldDiff, TS, Last, Height) ->
TargetTime = ?RETARGET_BLOCKS * Target_Time,
ActualTime = max(TS - Last, ar_block:get_max_timestamp_deviation()),
Difficulty_2_7_0_factor = calculate_difficulty_2_7_0_factor(ActualTime, TargetTime),
?LOG_INFO([{calculate_difficulty_2_7_0_TargetTime, TargetTime}]),
?LOG_INFO([{calculate_difficulty_2_7_0_ActualTime, ActualTime}]),
?LOG_INFO([{calculate_difficulty_2_7_0_Difficulty_2_7_0_factor, Difficulty_2_7_0_factor}]),
case ActualTime < (?RETARGET_BLOCKS * Target_Time + Target_Time)
andalso ActualTime > (?RETARGET_BLOCKS * Target_Time - Target_Time) of
true ->
OldDiff;
false ->
MaxDiff = ?MAX_DIFF,
MinDiff = min_difficulty(Height),
DiffInverse = (MaxDiff - OldDiff) * ActualTime div TargetTime * Difficulty_2_7_0_factor,
DiffInverse = (MaxDiff - OldDiff) * ActualTime * Difficulty_2_7_0_factor div (TargetTime * 10),
?LOG_INFO([{calculate_difficulty_2_7_0_MaxDiff, MaxDiff}]),
?LOG_INFO([{calculate_difficulty_2_7_0_MinDiff, MinDiff}]),
?LOG_INFO([{calculate_difficulty_2_7_0_DiffInverse, DiffInverse}]),
between(
MaxDiff - DiffInverse,
MinDiff,
Expand Down

0 comments on commit e81ed98

Please sign in to comment.