Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement/longer pricing window #616

Merged
merged 10 commits into from
Oct 6, 2024
8 changes: 6 additions & 2 deletions apps/arweave/include/ar.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,12 @@
%% The updated estimation of the number of Winstons it costs the network to store
%% one gibibyte for one minute.
scheduled_price_per_gib_minute = 0,
%% The recursive hash of the network hash rates, block rewards, and mining addresses of
%% the latest ?REWARD_HISTORY_BLOCKS blocks.
%% The recursive hash of the network hash rates, block rewards, mining addresses,
%% and denominations.
%% Note that the length of the reward history has increased from
%% ?LEGACY_REWARD_HISTORY_BLOCKS to ?REWARD_HISTORY_BLOCKS in 2.8.
%% Before 2.8 every new hash was computed over the latest ?REWARD_HISTORY_BLOCKS.
%% After 2.8 the new hash is computed from the new history element and the previous hash.
reward_history_hash,
%% The network hash rates, block rewards, and mining addresses from the latest
%% ?REWARD_HISTORY_BLOCKS + ?STORE_BLOCKS_BEHIND_CURRENT blocks. Used internally, not gossiped.
Expand Down
4 changes: 3 additions & 1 deletion apps/arweave/include/ar_config.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
-define(MAX_PARALLEL_WALLET_LIST_REQUESTS, 1).
-define(MAX_PARALLEL_POST_CHUNK_REQUESTS, 100).
-define(MAX_PARALLEL_GET_SYNC_RECORD_REQUESTS, 10).
-define(MAX_PARALLEL_REWARD_HISTORY_REQUESTS, 1).

%% The number of parallel tx validation processes.
-define(MAX_PARALLEL_POST_TX_REQUESTS, 20).
Expand Down Expand Up @@ -172,7 +173,8 @@
get_block_index => ?MAX_PARALLEL_BLOCK_INDEX_REQUESTS,
get_wallet_list => ?MAX_PARALLEL_WALLET_LIST_REQUESTS,
get_sync_record => ?MAX_PARALLEL_GET_SYNC_RECORD_REQUESTS,
post_tx => ?MAX_PARALLEL_POST_TX_REQUESTS
post_tx => ?MAX_PARALLEL_POST_TX_REQUESTS,
get_reward_history => ?MAX_PARALLEL_REWARD_HISTORY_REQUESTS
},
disk_cache_size = ?DISK_CACHE_SIZE,
packing_rate,
Expand Down
2 changes: 1 addition & 1 deletion apps/arweave/include/ar_consensus.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
%% The size of a recall range. The first range is randomly chosen from the given
%% mining partition. The second range is chosen from the entire weave.
-ifdef(DEBUG).
-define(RECALL_RANGE_SIZE, (256 * 1024)).
-define(RECALL_RANGE_SIZE, (128 * 1024)).
-else.
-define(RECALL_RANGE_SIZE, 26214400). % == 25 * 1024 * 1024
-endif.
Expand Down
26 changes: 22 additions & 4 deletions apps/arweave/include/ar_pricing.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,34 @@ end).
%% fluctuate a lot around the fork.
-define(FORK_2_6_PRE_TRANSITION_USD_TO_AR_RATE, {1, 10}).

%% The number of recent blocks contributing data points to the continuous estimation
%% of the average price of storing a gibibyte for a minute. Also, the reward history
%% is used to tracking the reserved mining rewards.
%% The number of recent blocks with the reserved (temporarily locked) mining rewards.
-ifdef(DEBUG).
% testnet value should have same ratio 30:1 to VDF_DIFFICULTY_RETARGET
% BUT. For tests we are using old value
-define(LOCKED_REWARDS_BLOCKS, 3).
-else.
-ifndef(LOCKED_REWARDS_BLOCKS).
-define(LOCKED_REWARDS_BLOCKS, (30 * 24 * 30)).
-endif.
-endif.

%% The number of recent blocks contributing data points to the continuous estimation
%% of the average price of storing a gibibyte for a minute. A recent subset of the
%% reward history is used for tracking the reserved mining rewards.
-ifdef(DEBUG).
-define(REWARD_HISTORY_BLOCKS, 3).
-else.
-ifndef(REWARD_HISTORY_BLOCKS).
-define(REWARD_HISTORY_BLOCKS, (30 * 24 * 30)).
-define(REWARD_HISTORY_BLOCKS, (3 * 30 * 24 * 30)).
-endif.
-endif.

%% The REWARD_HISTORY_BLOCKS before 2.8.
-ifdef(DEBUG).
-define(LEGACY_REWARD_HISTORY_BLOCKS, 3).
-else.
-ifndef(LEGACY_REWARD_HISTORY_BLOCKS).
-define(LEGACY_REWARD_HISTORY_BLOCKS, (30 * 24 * 30)).
-endif.
-endif.

Expand Down
66 changes: 5 additions & 61 deletions apps/arweave/src/ar.erl
Original file line number Diff line number Diff line change
Expand Up @@ -654,24 +654,14 @@ start(Config) ->
logger:add_handler(console, logger_std_h, #{level => all});
_->
ok
end,
case Config#config.init of
end,
case ar_config:validate_config(Config) of
true ->
case ?NETWORK_NAME of
"arweave.N.1" ->
io:format("~nCannot start a new network with the mainnet name! "
"Use ./bin/start-localnet ... when running from sources "
"or compile via ./rebar3 as localnet tar and use "
"./bin/start ... as usual.~n~n"),
erlang:halt();
_ ->
ok
end;
ok;
false ->
ok
timer:sleep(2000),
erlang:halt()
end,
validate_repack_in_place_config(Config),
validate_cm_pool_config(Config),
ok = application:set_env(arweave, config, Config),
filelib:ensure_dir(Config#config.log_dir ++ "/"),
warn_if_single_scheduler(),
Expand All @@ -684,52 +674,6 @@ start(Config) ->
end,
start_dependencies().

validate_repack_in_place_config(Config) ->
Modules = [ar_storage_module:id(M) || M <- Config#config.storage_modules],
validate_repack_in_place_config(Config#config.repack_in_place_storage_modules, Modules).

validate_repack_in_place_config([], _Modules) ->
ok;
validate_repack_in_place_config([{Module, _ToPacking} | L], Modules) ->
ID = ar_storage_module:id(Module),
case lists:member(ID, Modules) of
true ->
io:format("~nCannot use the storage module ~s "
"while it is being repacked in place.~n~n", [ID]),
timer:sleep(2000),
erlang:halt();
false ->
validate_repack_in_place_config(L, Modules)
end.

validate_cm_pool_config(Config) ->
case {Config#config.coordinated_mining, Config#config.is_pool_server} of
{true, true} ->
io:format("~nThe pool server node cannot participate "
"in the coordinated mining.~n~n"),
timer:sleep(1000),
erlang:halt();
_ ->
ok
end,
case {Config#config.is_pool_server, Config#config.is_pool_client} of
{true, true} ->
io:format("~nThe node cannot be a pool server and a pool client "
"at the same time.~n~n"),
timer:sleep(1000),
erlang:halt();
_ ->
ok
end,
case {Config#config.is_pool_client, Config#config.mine} of
{true, false} ->
io:format("~nThe mine flag must be set along with the is_pool_client flag.~n~n"),
timer:sleep(1000),
erlang:halt();
_ ->
ok
end.

start(normal, _Args) ->
{ok, Config} = application:get_env(arweave, config),
%% Configure logging for console output.
Expand Down
21 changes: 6 additions & 15 deletions apps/arweave/src/ar_chunk_storage.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

-behaviour(gen_server).

-export([start_link/2, encode_packing/1, put/2, put/3,
-export([start_link/2, put/2, put/3,
open_files/1, get/1, get/2, get/5, read_chunk2/5, get_range/2, get_range/3,
close_file/2, close_files/1, cut/2, delete/1, delete/2,
list_files/2, run_defragmentation/0]).
Expand Down Expand Up @@ -32,16 +32,6 @@
%%% Public interface.
%%%===================================================================

encode_packing({spora_2_6, Addr}) ->
"spora_2_6_" ++ binary_to_list(ar_util:encode(Addr));
encode_packing({composite, Addr, PackingDifficulty}) ->
"composite_" ++ binary_to_list(ar_util:encode(Addr)) ++ "."
++ integer_to_list(PackingDifficulty);
encode_packing(spora_2_5) ->
"spora_2_5";
encode_packing(unpacked) ->
"unpacked".

%% @doc Start the server.
start_link(Name, StoreID) ->
gen_server:start_link({local, Name}, ?MODULE, StoreID, []).
Expand Down Expand Up @@ -370,15 +360,15 @@ handle_info({chunk, {packed, Ref, ChunkArgs}},
?LOG_ERROR([{event, failed_to_store_repacked_chunk},
{storage_module, StoreID},
{offset, Offset},
{packing, encode_packing(Packing)},
{packing, ar_serialize:encode_packing(Packing, true)},
{error, io_lib:format("~p", [Error2])}]),
{noreply, State2}
end;
Error3 ->
?LOG_ERROR([{event, failed_to_remove_repacked_chunk_from_sync_record},
{storage_module, StoreID},
{offset, Offset},
{packing, encode_packing(Packing)},
{packing, ar_serialize:encode_packing(Packing, true)},
{error, io_lib:format("~p", [Error3])}]),
{noreply, State2}
end
Expand Down Expand Up @@ -774,7 +764,7 @@ repack(Cursor, RightBound, Packing, StoreID) ->
"node with the new storage module.~n", []),
?LOG_INFO([{event, repacking_complete},
{storage_module, StoreID},
{target_packing, encode_packing(Packing)}]),
{target_packing, ar_serialize:encode_packing(Packing, true)}]),
Server = list_to_atom("ar_chunk_storage_"
++ ar_storage_module:label_by_id(StoreID)),
gen_server:cast(Server, repacking_complete),
Expand Down Expand Up @@ -872,7 +862,8 @@ repack(Start, End, NextCursor, RightBound, RequiredPacking, StoreID) ->
?LOG_WARNING([{event,
repacking_process_chunk_already_repacked},
{storage_module, StoreID},
{packing, encode_packing(RequiredPacking)},
{packing,
ar_serialize:encode_packing(RequiredPacking,true)},
{offset, AbsoluteOffset}]),
ok;
{true, Packing} ->
Expand Down
100 changes: 98 additions & 2 deletions apps/arweave/src/ar_config.erl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-module(ar_config).

-export([use_remote_vdf_server/0, pull_from_remote_vdf_server/0, compute_own_vdf/0,
is_vdf_server/0, is_public_vdf_server/0,
-export([validate_config/1, use_remote_vdf_server/0, pull_from_remote_vdf_server/0,
compute_own_vdf/0, is_vdf_server/0, is_public_vdf_server/0,
parse/1, parse_storage_module/1, log_config/1]).

-include_lib("arweave/include/ar.hrl").
Expand All @@ -13,6 +13,12 @@
%%% Public interface.
%%%===================================================================

validate_config(Config) ->
validate_init(Config) andalso
validate_repack_in_place(Config) andalso
validate_cm_pool(Config) andalso
validate_storage_modules(Config).

use_remote_vdf_server() ->
{ok, Config} = application:get_env(arweave, config),
case Config#config.nonce_limiter_server_trusted_peers of
Expand Down Expand Up @@ -85,6 +91,10 @@ parse_storage_module(IOList) ->
%%% Private functions.
%%%===================================================================


%% -------------------------------------------------------------------
%% @doc Parse the configuration options.
%% -------------------------------------------------------------------
parse_options({KVPairs}) when is_list(KVPairs) ->
parse_options(KVPairs, #config{});
parse_options(JsonValue) ->
Expand Down Expand Up @@ -842,3 +852,89 @@ format_storage_module({RangeSize, RangeNumber, {composite, MiningAddress, Packin
{RangeSize, RangeNumber, {composite, format_binary(MiningAddress), PackingDiff}};
format_storage_module(StorageModule) ->
StorageModule.

%% -------------------------------------------------------------------
%% @doc Validate the configuration options.
%% -------------------------------------------------------------------
validate_init(Config) ->
case Config#config.init of
true ->
case ?NETWORK_NAME of
"arweave.N.1" ->
io:format("~nCannot start a new network with the mainnet name! "
"Use ./bin/start-localnet ... when running from sources "
"or compile via ./rebar3 as localnet tar and use "
"./bin/start ... as usual.~n~n"),
false;
_ ->
true
end;
false ->
true
end.
validate_repack_in_place(Config) ->
Modules = [ar_storage_module:id(M) || M <- Config#config.storage_modules],
validate_repack_in_place(Config#config.repack_in_place_storage_modules, Modules).

validate_repack_in_place([], _Modules) ->
true;
validate_repack_in_place([{Module, _ToPacking} | L], Modules) ->
ID = ar_storage_module:id(Module),
case lists:member(ID, Modules) of
true ->
io:format("~nCannot use the storage module ~s "
"while it is being repacked in place.~n~n", [ID]),
false;
false ->
validate_repack_in_place(L, Modules)
end.

validate_cm_pool(Config) ->
A = case {Config#config.coordinated_mining, Config#config.is_pool_server} of
{true, true} ->
io:format("~nThe pool server node cannot participate "
"in the coordinated mining.~n~n"),
false;
_ ->
true
end,
B = case {Config#config.is_pool_server, Config#config.is_pool_client} of
{true, true} ->
io:format("~nThe node cannot be a pool server and a pool client "
"at the same time.~n~n"),
false;
_ ->
true
end,
C = case {Config#config.is_pool_client, Config#config.mine} of
{true, false} ->
io:format("~nThe mine flag must be set along with the is_pool_client flag.~n~n"),
false;
_ ->
true
end,
A andalso B andalso C.

validate_storage_modules(#config{ mine = false }) ->
true;
validate_storage_modules(Config) ->
MiningAddr = Config#config.mining_addr,
UniquePackingDifficulties = lists:foldl(
fun({_, _, {composite, Addr, Difficulty}}, Acc) when Addr =:= MiningAddr ->
sets:add_element(Difficulty, Acc);
({_, _, {spora_2_6, Addr}}, Acc) when Addr =:= MiningAddr ->
sets:add_element(0, Acc);
(_, Acc) ->
Acc
end,
sets:new(),
Config#config.storage_modules
),
case sets:size(UniquePackingDifficulties) =< 1 of
true ->
true;
false ->
io:format("~nThe node cannot mine multiple packing difficulties "
"for the same mining address.~n~n"),
false
end.
Loading
Loading