diff --git a/apps/arweave/src/ar.erl b/apps/arweave/src/ar.erl index 473cadf59..360dea491 100644 --- a/apps/arweave/src/ar.erl +++ b/apps/arweave/src/ar.erl @@ -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}]); diff --git a/apps/arweave/src/ar_config.erl b/apps/arweave/src/ar_config.erl index ad2479f90..116ef35a2 100644 --- a/apps/arweave/src/ar_config.erl +++ b/apps/arweave/src/ar_config.erl @@ -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]). @@ -13,6 +13,7 @@ %%% Public interface. %%%=================================================================== +-spec validate_config(Config :: #config{}) -> boolean(). validate_config(Config) -> validate_init(Config) andalso validate_storage_modules(Config) andalso @@ -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), @@ -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 + }. diff --git a/apps/arweave/src/ar_node_worker.erl b/apps/arweave/src/ar_node_worker.erl index 6ba61fba7..ebedf43c0 100644 --- a/apps/arweave/src/ar_node_worker.erl +++ b/apps/arweave/src/ar_node_worker.erl @@ -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, _, _} -> diff --git a/apps/arweave/src/ar_nonce_limiter.erl b/apps/arweave/src/ar_nonce_limiter.erl index 90d9441e5..afbcd2bf2 100644 --- a/apps/arweave/src/ar_nonce_limiter.erl +++ b/apps/arweave/src/ar_nonce_limiter.erl @@ -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(), diff --git a/apps/arweave/src/ar_nonce_limiter_server_sup.erl b/apps/arweave/src/ar_nonce_limiter_server_sup.erl index eab8540a4..fb3898e2a 100644 --- a/apps/arweave/src/ar_nonce_limiter_server_sup.erl +++ b/apps/arweave/src/ar_nonce_limiter_server_sup.erl @@ -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 ->