-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Track solutions found and rejected for a solo miner
Also introduce ar_mining_router to route requests based on the node configuration, e.g.: solo miner vs. cm miner vs. cm exit node vs. pool miner vs. pool cm
- Loading branch information
1 parent
e39b4cc
commit 2ebe7cc
Showing
12 changed files
with
324 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
-module(ar_mining_router). | ||
|
||
-behaviour(gen_server). | ||
|
||
-export([start_link/0, prepare_solution/1, post_solution/1]). | ||
|
||
-export([init/1, handle_cast/2, handle_call/3, handle_info/2, terminate/2]). | ||
|
||
-include_lib("arweave/include/ar.hrl"). | ||
-include_lib("arweave/include/ar_config.hrl"). | ||
-include_lib("arweave/include/ar_mining.hrl"). | ||
-include_lib("eunit/include/eunit.hrl"). | ||
-include_lib("stdlib/include/ms_transform.hrl"). | ||
|
||
-record(state, { | ||
}). | ||
|
||
%%%=================================================================== | ||
%%% Public interface. | ||
%%%=================================================================== | ||
|
||
%% @doc Start the gen_server. | ||
start_link() -> | ||
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). | ||
|
||
prepare_solution(Candidate) -> | ||
%% A pool client does not validate VDF before sharing a solution. | ||
{ok, Config} = application:get_env(arweave, config), | ||
ar_mining_server:prepare_solution(Candidate, Config#config.is_pool_client). | ||
|
||
post_solution(Solution) -> | ||
{ok, Config} = application:get_env(arweave, config), | ||
post_solution(Config#config.cm_exit_peer, Config#config.is_pool_client, Solution). | ||
|
||
%%%=================================================================== | ||
%%% Generic server callbacks. | ||
%%%=================================================================== | ||
|
||
init([]) -> | ||
{ok, #state{}}. | ||
|
||
handle_call(Request, _From, State) -> | ||
?LOG_WARNING([{event, unhandled_call}, {module, ?MODULE}, {request, Request}]), | ||
{reply, ok, State}. | ||
|
||
handle_cast(Cast, State) -> | ||
?LOG_WARNING([{event, unhandled_cast}, {module, ?MODULE}, {cast, Cast}]), | ||
{noreply, State}. | ||
|
||
handle_info(Message, State) -> | ||
?LOG_WARNING([{event, unhandled_info}, {module, ?MODULE}, {message, Message}]), | ||
{noreply, State}. | ||
|
||
terminate(_Reason, _State) -> | ||
ok. | ||
|
||
%%%=================================================================== | ||
%%% Private functions. | ||
%%%=================================================================== | ||
|
||
post_solution(not_set, true, Solution) -> | ||
%% When posting a partial solution the pool client will skip many of the validation steps | ||
%% that are normally performed before sharing a solution. | ||
ar_pool:post_partial_solution(Solution); | ||
post_solution(not_set, _IsPoolClient, Solution) -> | ||
ar_mining_server:validate_solution(Solution); | ||
post_solution(ExitPeer, true, Solution) -> | ||
case ar_http_iface_client:post_partial_solution(ExitPeer, Solution) of | ||
{ok, _} -> | ||
ok; | ||
{error, Reason} -> | ||
?LOG_WARNING([{event, found_partial_solution_but_failed_to_reach_exit_node}, | ||
{reason, io_lib:format("~p", [Reason])}]), | ||
ar:console("We found a partial solution but failed to reach the exit node, " | ||
"error: ~p.", [io_lib:format("~p", [Reason])]) | ||
end; | ||
post_solution(ExitPeer, _IsPoolClient, Solution) -> | ||
case ar_http_iface_client:cm_publish_send(ExitPeer, Solution) of | ||
{ok, _} -> | ||
ok; | ||
{error, Reason} -> | ||
?LOG_WARNING([{event, solution_rejected}, | ||
{reason, failed_to_reach_exit_node}, | ||
{message, io_lib:format("~p", [Reason])}]), | ||
ar:console("We found a solution but failed to reach the exit node, " | ||
"error: ~p.", [io_lib:format("~p", [Reason])]), | ||
ar_mining_stats:solution(rejected) | ||
end. |
Oops, something went wrong.