Skip to content

Commit

Permalink
fix: disable a bunch of features when verify is on
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesPiechota committed Nov 8, 2024
1 parent a2144ce commit 8b04ee2
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 32 deletions.
7 changes: 4 additions & 3 deletions apps/arweave/src/ar.erl
Original file line number Diff line number Diff line change
Expand Up @@ -678,10 +678,11 @@ start(Config) ->
timer:sleep(2000),
erlang:halt()
end,
ok = application:set_env(arweave, config, Config),
filelib:ensure_dir(Config#config.log_dir ++ "/"),
Config2 = ar_config:set_dependent_flags(Config),
ok = application:set_env(arweave, config, Config2),
filelib:ensure_dir(Config2#config.log_dir ++ "/"),
warn_if_single_scheduler(),
case Config#config.nonce_limiter_server_trusted_peers of
case Config2#config.nonce_limiter_server_trusted_peers of
[] ->
VDFSpeed = ar_bench_vdf:run_benchmark(),
?LOG_INFO([{event, vdf_benchmark}, {vdf_s, VDFSpeed / 1000000}]);
Expand Down
44 changes: 36 additions & 8 deletions apps/arweave/src/ar_config.erl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-module(ar_config).

-export([validate_config/1, auto_join/0, verify/0, use_remote_vdf_server/0,
-export([validate_config/1, set_dependent_flags/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]).

Expand All @@ -13,6 +13,7 @@
%%% Public interface.
%%%===================================================================

-spec validate_config(Config :: #config{}) -> boolean().
validate_config(Config) ->
validate_init(Config) andalso
validate_storage_modules(Config) andalso
Expand All @@ -21,13 +22,11 @@ validate_config(Config) ->
validate_packing_difficulty(Config) andalso
validate_verify(Config).

auto_join() ->
{ok, Config} = application:get_env(arweave, config),
Config#config.auto_join andalso not Config#config.verify.

verify() ->
{ok, Config} = application:get_env(arweave, config),
Config#config.verify.
-spec set_dependent_flags(Config :: #config{}) -> #config{}.
%% @doc Some flags force other flags to be set.
set_dependent_flags(Config) ->
Config2 = set_verify_flags(Config),
Config2.

use_remote_vdf_server() ->
{ok, Config} = application:get_env(arweave, config),
Expand Down Expand Up @@ -990,3 +989,32 @@ validate_verify(#config{ verify = true,
false;
validate_verify(_Config) ->
true.

disable_vdf(Config) ->
RemovePublicVDFServer =
lists:filter(fun(Item) -> Item =/= public_vdf_server end, Config#config.enable),
Config#config{
nonce_limiter_client_peers = [],
nonce_limiter_server_trusted_peers = [],
enable = RemovePublicVDFServer,
disable = [compute_own_vdf | Config#config.disable]
}.

set_verify_flags(#config{ verify = false } = Config) ->
Config;
set_verify_flags(Config) ->
io:format("~n~nWARNING: The verify flag is set. Forcing the following options:"),
io:format("~n - auto_join = false"),
io:format("~n - start_from_latest_state = true"),
io:format("~n - sync_jobs = 0"),
io:format("~n - block_pollers = 0"),
io:format("~n - header_sync_jobs = 0"),
io:format("~n - all VDF features disabled"),
Config2 = disable_vdf(Config),
Config2#config{
auto_join = false,
start_from_latest_state = true,
sync_jobs = 0,
block_pollers = 0,
header_sync_jobs = 0
}.
2 changes: 1 addition & 1 deletion apps/arweave/src/ar_node_worker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ init([]) ->
validate_trusted_peers(Config),
StartFromLocalState = Config#config.start_from_latest_state orelse
Config#config.start_from_block /= undefined,
case {StartFromLocalState, Config#config.init, ar_config:auto_join()} of
case {StartFromLocalState, Config#config.init, Config#config.auto_join} of
{false, false, true} ->
ar_join:start(ar_peers:get_trusted_peers());
{true, _, _} ->
Expand Down
33 changes: 14 additions & 19 deletions apps/arweave/src/ar_nonce_limiter.erl
Original file line number Diff line number Diff line change
Expand Up @@ -408,27 +408,22 @@ apply_external_update(Update, Peer) ->
%%%===================================================================

init([]) ->
case ar_config:verify() of
ok = ar_events:subscribe(node_state),
State =
case ar_node:is_joined() of
true ->
Blocks = get_blocks(),
handle_initialized(Blocks, #state{});
_ ->
#state{}
end,
case ar_config:use_remote_vdf_server() and not ar_config:compute_own_vdf() of
true ->
ignore;
gen_server:cast(?MODULE, check_external_vdf_server_input);
false ->
ok = ar_events:subscribe(node_state),
State =
case ar_node:is_joined() of
true ->
Blocks = get_blocks(),
handle_initialized(Blocks, #state{});
_ ->
#state{}
end,
case ar_config:use_remote_vdf_server() and not ar_config:compute_own_vdf() of
true ->
gen_server:cast(?MODULE, check_external_vdf_server_input);
false ->
ok
end,
{ok, start_worker(State#state{ autocompute = ar_config:compute_own_vdf() })}
end.
ok
end,
{ok, start_worker(State#state{ autocompute = ar_config:compute_own_vdf() })}.

get_blocks() ->
B = ar_node:get_current_block(),
Expand Down
2 changes: 1 addition & 1 deletion apps/arweave/src/ar_nonce_limiter_server_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ start_link() ->
%% ===================================================================

init([]) ->
case ar_config:is_vdf_server() andalso not ar_config:verify() of
case ar_config:is_vdf_server() of
false ->
ignore;
true ->
Expand Down

0 comments on commit 8b04ee2

Please sign in to comment.