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

Commit 684c189

Browse files
committed
More verbose ledger_poc_v3:verify error
1 parent de79b08 commit 684c189

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/ledger/v1/blockchain_ledger_poc_v3.erl

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,25 @@ start_height(PoC) ->
8282
start_height(Height, PoC) ->
8383
PoC#poc_v3{start_height=Height}.
8484

85-
-spec verify(poc(), libp2p_crypto:pubkey_bin(), binary()) -> boolean().
85+
-spec verify(poc(), libp2p_crypto:pubkey_bin(), binary()) -> ok | {error, any()}.
8686
verify(PoC, Challenger, BlockHash) ->
87-
?MODULE:challenger(PoC) =:= Challenger andalso ?MODULE:block_hash(PoC) =:= BlockHash.
87+
POCChallenger = ?MODULE:challenger(PoC),
88+
POCBlockHash = ?MODULE:block_hash(PoC),
89+
C1 = POCChallenger =:= Challenger,
90+
C2 = POCBlockHash =:= BlockHash,
91+
case (C1 andalso C2) of
92+
true -> ok;
93+
false ->
94+
ErrorRes = [{onion_key_hash, ?MODULE:onion_key_hash(PoC)},
95+
{txn_challenger, libp2p_crypto:bin_to_b58(Challenger)},
96+
{ledger_challenger, libp2p_crypto:bin_to_b58(POCChallenger)},
97+
{txn_blockhash, libp2p_crypto:bin_to_b58(BlockHash)},
98+
{ledger_blockhash, libp2p_crypto:bin_to_b58(POCBlockHash)},
99+
{equal_challenger, C1},
100+
{equal_blockhash, C2}],
101+
102+
{error, ErrorRes}
103+
end.
88104

89105
-spec serialize(poc()) -> binary().
90106
serialize(PoC) ->

src/transactions/v2/blockchain_txn_poc_receipts_v2.erl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,9 @@ absorb(_POCVersion, Txn, Chain) ->
448448
throw(replay)
449449
end,
450450
case blockchain_ledger_poc_v3:verify(PoC, Challenger, BlockHash) of
451-
false ->
452-
{error, invalid_poc};
453-
true ->
451+
{error, R} ->
452+
{error, {invalid_poc, R}};
453+
ok ->
454454
%% maybe update the last activity field for all challengees and GWs
455455
%% participating in the POC
456456
case blockchain:config(?poc_activity_filter_enabled, Ledger) of
@@ -1202,8 +1202,8 @@ verify_poc_details(Txn, PoC, Keys) ->
12021202
SigFun = libp2p_crypto:mk_sig_fun(PrivKey),
12031203
SignedPayload = SigFun(OnionHash),
12041204
case blockchain_ledger_poc_v3:verify(PoC, Challenger, BlockHash) of
1205-
false -> {error, mismatched_poc};
1206-
true ->
1205+
{error, R} -> {error, {mismatched_poc, R}};
1206+
ok ->
12071207
case POCOnionKeyHash == OnionHash of
12081208
false -> {error, mismatched_onion_key_hash};
12091209
true ->

0 commit comments

Comments
 (0)