Skip to content

Commit

Permalink
Difficulty_2_7_0_factor
Browse files Browse the repository at this point in the history
  • Loading branch information
chives-network committed Jan 9, 2024
1 parent 79e2dcb commit afbf91e
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 19 deletions.
34 changes: 21 additions & 13 deletions apps/chivesweave/src/ar_fork.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-module(ar_fork).

-export([height_1_6/0, height_1_7/0, height_1_8/0, height_1_9/0, height_2_0/0, height_2_2/0,
height_2_3/0, height_2_4/0, height_2_5/0, height_2_6/0, height_2_6_8/0,
height_2_3/0, height_2_4/0, height_2_5/0, height_2_6/0, height_2_6_8/0, height_2_7_0/0,
height_2_7/0]).

-include_lib("chivesweave/include/ar.hrl").
Expand Down Expand Up @@ -109,20 +109,28 @@ height_2_6_8() ->
-endif.
-endif.

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

-ifdef(FORKS_RESET).
height_2_7() ->
?FORK_2_7_HEIGHT.
26280000.
-else.
-ifdef(FORKS_RESET).
height_2_7() ->
262800.
-ifdef(TESTNET).
height_2_7() ->
26280000.
-else.
-ifdef(TESTNET).
height_2_7() ->
262800.
-else.
height_2_7() ->
262800. % Targeting 2023-10-04 14:00 UTC
-endif.
height_2_7() ->
26280000. % Targeting 2023-10-04 14:00 UTC
-endif.
-endif.
27 changes: 21 additions & 6 deletions apps/chivesweave/src/ar_inflation.erl
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@ calculate(Height) ->
calculate2(Height).
-endif.

calculate2(Height) when Height =< ?FORK_15_HEIGHT ->
pre_15_calculate(Height);
calculate2(Height) when Height =< ?BLOCKS_PER_YEAR ->
calculate_base(Height);
calculate2(Height) ->
case Height >= ar_fork:height_2_5() of
case Height >= ar_fork:height_2_7_0() of
true ->
calculate_base(Height);
calculate_base_fork_2_7_0(Height);
false ->
calculate_base(Height)
end.
Expand Down Expand Up @@ -75,6 +71,25 @@ calculate_base(Height) ->
* EXDividend
).

calculate_base_fork_2_7_0(Height) ->
{Ln2Dividend, Ln2Divisor} = ?LN2,
Dividend = Height * Ln2Dividend,
Divisor = ?BLOCKS_PER_YEAR * 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
div (
10
* 0.9
* ?BLOCKS_PER_YEAR
* Ln2Divisor
* EXDividend
).

calculate_base_pre_fork_2_5(Height) ->
?WINSTON_PER_AR
* (
Expand Down
28 changes: 28 additions & 0 deletions apps/chivesweave/src/ar_retarget.erl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ calculate_difficulty(OldDiff, TS, Last, Height, PrevTS) ->
Fork_1_9 = ar_fork:height_1_9(),
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(),
case Height of
_ when Height >= Fork_2_7_0 ->
calculate_difficulty_2_7_0(OldDiff, TS, Last, Height);
_ when Height >= 1010 ->
calculate_difficulty(OldDiff, TS, Last, Height);
_ when Height > Fork_2_5 ->
Expand Down Expand Up @@ -143,6 +146,31 @@ calculate_difficulty(OldDiff, TS, Last, Height) ->
)
end.

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

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),
case ActualTime < ?RETARGET_TOLERANCE_UPPER_BOUND
andalso ActualTime > ?RETARGET_TOLERANCE_LOWER_BOUND of
true ->
OldDiff;
false ->
MaxDiff = ?MAX_DIFF,
MinDiff = min_difficulty(Height),
DiffInverse = (MaxDiff - OldDiff) * ActualTime div TargetTime * Difficulty_2_7_0_factor,
between(
MaxDiff - DiffInverse,
MinDiff,
MaxDiff - 1
)
end.

calculate_difficulty_at_2_5(OldDiff, TS, Last, Height, PrevTS) ->
calculate_difficulty_with_drop(OldDiff, TS, Last, Height, PrevTS, ?DIFF_DROP_2_5,
?DIFF_DROP_2_5).
Expand Down

0 comments on commit afbf91e

Please sign in to comment.