Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Commit

Permalink
More verbose ledger_poc_v3:verify error
Browse files Browse the repository at this point in the history
  • Loading branch information
vihu committed May 13, 2022
1 parent 89cc129 commit 0d43362
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 8 additions & 2 deletions src/ledger/v1/blockchain_ledger_poc_v3.erl
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,15 @@ start_height(PoC) ->
start_height(Height, PoC) ->
PoC#poc_v3{start_height=Height}.

-spec verify(poc(), libp2p_crypto:pubkey_bin(), binary()) -> boolean().
-spec verify(poc(), libp2p_crypto:pubkey_bin(), binary()) -> ok | {error, {boolean(), boolean()}}.
verify(PoC, Challenger, BlockHash) ->
?MODULE:challenger(PoC) =:= Challenger andalso ?MODULE:block_hash(PoC) =:= BlockHash.
C1 = ?MODULE:challenger(PoC) =:= Challenger,
C2 = ?MODULE:block_hash(PoC) =:= BlockHash,
case (C1 andalso C2) of
true -> ok;
false ->
{error, {C1, C2}}
end.

-spec serialize(poc()) -> binary().
serialize(PoC) ->
Expand Down
10 changes: 5 additions & 5 deletions src/transactions/v2/blockchain_txn_poc_receipts_v2.erl
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,9 @@ absorb(_POCVersion, Txn, Chain) ->
throw(replay)
end,
case blockchain_ledger_poc_v3:verify(PoC, Challenger, BlockHash) of
false ->
{error, invalid_poc};
true ->
{error, R} ->
{error, {invalid_poc, R}};
ok ->
%% maybe update the last activity field for all challengees and GWs
%% participating in the POC
case blockchain:config(?poc_activity_filter_enabled, Ledger) of
Expand Down Expand Up @@ -1202,8 +1202,8 @@ verify_poc_details(Txn, PoC, Keys) ->
SigFun = libp2p_crypto:mk_sig_fun(PrivKey),
SignedPayload = SigFun(OnionHash),
case blockchain_ledger_poc_v3:verify(PoC, Challenger, BlockHash) of
false -> {error, mismatched_poc};
true ->
{error, R} -> {error, {mismatched_poc, R}};
ok ->
case POCOnionKeyHash == OnionHash of
false -> {error, mismatched_onion_key_hash};
true ->
Expand Down

0 comments on commit 0d43362

Please sign in to comment.