Skip to content

Commit

Permalink
update mining pool to work after the fork.
Browse files Browse the repository at this point in the history
  • Loading branch information
zack-bitcoin committed Mar 11, 2018
1 parent 27c2d8d commit 315108c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
16 changes: 8 additions & 8 deletions apps/amoveo_mining_pool/src/mining_pool_server.erl
Expand Up @@ -2,7 +2,7 @@
-behaviour(gen_server).
-export([start_link/0,code_change/3,handle_call/3,handle_cast/2,handle_info/2,init/1,terminate/2,
start_cron/0, problem_api_mimic/0, receive_work/2]).
-define(FullNode, "http://localhost:8081/").
-define(FullNode, "http://localhost:3011/").
-record(data, {hash, nonce, diff, time}).
-define(RefreshPeriod, 2).%in seonds. How often we get a new problem from the node to work on.
%init(ok) -> {ok, new_problem_internal()}.
Expand Down Expand Up @@ -58,26 +58,26 @@ start_cron() ->
gen_server:cast(?MODULE, new_problem_cron),
timer:sleep(500),
start_cron().
receive_work(<<Nonce:256>>, Pubkey) ->
receive_work(<<Nonce:184>>, Pubkey) ->
%Pubkey = base64:decode(Pubkey0),
D = problem(),
H = D#data.hash,
Diff = D#data.diff,
%io:fwrite(packer:pack({recent_work, H, Diff, Nonce})),
%io:fwrite("\n"),
Y = <<H/binary, Diff:16, Nonce:256>>,
I = pow:hash2integer(hash:doit(Y)),
Y = <<H/binary, Nonce:184>>,
I = pow:hash2integer(hash:doit(Y), 1),
%if the work is good enough, give some money to pubkey.
if
I > Diff -> found_block(<<Nonce:256>>),
I > Diff -> found_block(<<Nonce:184>>),
Msg = {spend, Pubkey, 95216213},
talk_helper(Msg, ?FullNode, 10),
"found work";
true -> "invalid work"
end.
found_block(<<Nonce:256>>) ->
BinNonce = base64:encode(<<Nonce:256>>),
Data = {work, <<Nonce:256>>, 0},
found_block(<<Nonce:184>>) ->
BinNonce = base64:encode(<<Nonce:184>>),
Data = {work, <<Nonce:184>>, 0},
talk_helper(Data, ?FullNode, 10),%spend 8 seconds checking 5 times per second if we can start mining again.
spawn(fun() ->
timer:sleep(1000),
Expand Down
3 changes: 2 additions & 1 deletion rebar.config
@@ -1,6 +1,7 @@
{erl_opts, [debug_info]}.
{deps, [
{trie, "1", {git, "https://github.com/BumblebeeBat/MerkleTrie", {tag, "master"}}},
{pink_hash, "1", {git, "https://github.com/BumblebeeBat/pink_crypto", {branch, "partial_hash_problem"}}},
{trie, "1", {git, "https://github.com/BumblebeeBat/MerkleTrie", {branch, "partial-hash-fix"}}},
{cowboy, "1.0.4", {git, "https://github.com/ninenines/cowboy.git", {tag, "1.0.4"}}}
]}.

Expand Down
10 changes: 5 additions & 5 deletions rebar.lock
Expand Up @@ -12,16 +12,16 @@
1},
{<<"encrypter">>,
{git,"https://github.com/zack-bitcoin/encrypter",
{ref,"05c7352698de4fb7288dd4b3a83b717cd90cdabd"}},
2},
{ref,"dd702465a7d88fd12ce4a4e26786b872ad5d0530"}},
1},
{<<"jiffy">>,
{git,"https://github.com/davisp/jiffy",
{ref,"1febce3ca86c5ca5d5a3618ed3d5f125bb99e4c5"}},
3},
2},
{<<"pink_hash">>,
{git,"https://github.com/BumblebeeBat/pink_crypto",
{ref,"15922aa08dc026ccf05a278466843ebced6cbfe7"}},
1},
{ref,"7cfcf35068f7545ae8067c6d6c076a647c88d9b8"}},
0},
{<<"ranch">>,
{git,"https://github.com/ninenines/ranch.git",
{ref,"adf1822defc2b7cfdc7aca112adabfa1d614043c"}},
Expand Down

0 comments on commit 315108c

Please sign in to comment.