Skip to content

Commit

Permalink
Merge pull request #120 from zack-bitcoin/partial_hash_fix
Browse files Browse the repository at this point in the history
Partial hash fix
  • Loading branch information
zack-bitcoin committed Mar 13, 2018
2 parents 9856efe + b547518 commit 46f20bf
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
8 changes: 7 additions & 1 deletion apps/amoveo_core/src/consensus/chain/block.erl
Expand Up @@ -300,7 +300,13 @@ mine2(Block, Times) ->
ParentPlus = get_by_hash(PH),
Trees = ParentPlus#block.trees,
MineDiff = Block#block.difficulty,
case pow:pow(hash(Block), MineDiff, Times, constants:hash_size()) of
F2 = forks:get(2),
Height = Block#block.height,
Fork = if
F2 > Height -> 0;
true -> 1
end,
case pow:pow(hash(Block), MineDiff, Times, Fork) of
false -> false;
Pow -> Block#block{nonce = pow:nonce(Pow)}
end.
Expand Down
8 changes: 7 additions & 1 deletion apps/amoveo_core/src/consensus/chain/headers.erl
Expand Up @@ -114,7 +114,13 @@ check_pow(Header) ->
MineDiff = Header#header.difficulty,
Data = block:hash(Header#header{nonce = <<0:256>>}),
<<Nonce:256>> = Header#header.nonce,
pow:check_pow({pow, Data, MineDiff, Nonce}, constants:hash_size()).
F2 = forks:get(2),
Height = Header#header.height,
Fork = if
F2 > Height -> 0;
true -> 1
end,
pow:check_pow({pow, Data, MineDiff, Nonce}, constants:hash_size(), Fork).

check_difficulty(A) ->
B = case A#header.height < 2 of
Expand Down
6 changes: 6 additions & 0 deletions apps/amoveo_core/src/consensus/forks.erl
Expand Up @@ -5,4 +5,10 @@ get(1) ->
case application:get_env(amoveo_core, kind) of
{ok, "production"} -> 4200;
_ -> 0
end;
get(2) ->
case application:get_env(amoveo_core, kind) of
{ok, "production"} -> 9000;
_ -> 3
end.

19 changes: 17 additions & 2 deletions apps/amoveo_http/src/api.erl
Expand Up @@ -455,8 +455,17 @@ txs(IP, Port) ->
0.
-define(mining, "data/mining_block.db").
work(Nonce, _) ->
<<N:256>> = Nonce,
Block = potential_block:check(),
Height = Block#block.height,
F2 = forks:get(2),
N = if
F2 > Height ->
<<X:256>> = Nonce,
X;
true ->
<<X:184>> = Nonce,
X
end,
Block2 = Block#block{nonce = N},
%io:fwrite("work block hash is "),
%io:fwrite(packer:pack(hash:doit(block:hash(Block)))),
Expand All @@ -480,8 +489,14 @@ mining_data() ->
%io:fwrite("mining data block hash is "),
%io:fwrite(packer:pack(hash:doit(block:hash(Block)))),
%io:fwrite("\n"),
F2 = forks:get(2),
Height = Block#block.height,
Entropy = if
F2 > Height -> 32;
true -> 23
end,
[hash:doit(block:hash(Block)),
crypto:strong_rand_bytes(32),
crypto:strong_rand_bytes(Entropy),
%headers:difficulty_should_be(Top)].
Block#block.difficulty].

Expand Down
4 changes: 2 additions & 2 deletions rebar.config
@@ -1,7 +1,7 @@
{erl_opts, [debug_info, {parse_transform, lager_transform}]}.
{deps, [
{trie, "1", {git, "https://github.com/BumblebeeBat/MerkleTrie", {tag, "master"}}},
{chalang, "1", {git, "https://github.com/zack-bitcoin/chalang", {tag, "master"}}},
{trie, "1", {git, "https://github.com/BumblebeeBat/MerkleTrie", {tag, "partial-hash-fix"}}},
{chalang, "1", {git, "https://github.com/zack-bitcoin/chalang", {tag, "partial-hash-fix"}}},
{cowboy, "1.0.4", {git, "https://github.com/ninenines/cowboy.git", {tag, "1.0.4"}}},
{lager, ".*", {git, "https://github.com/erlang-lager/lager.git", {tag, "3.5.1"}}}
]}.
Expand Down

0 comments on commit 46f20bf

Please sign in to comment.