diff --git a/test/hbbft_worker.erl b/test/hbbft_worker.erl index caaf473..dac7543 100644 --- a/test/hbbft_worker.erl +++ b/test/hbbft_worker.erl @@ -48,23 +48,12 @@ verify_chain([G], PubKey) -> io:format("no genesis block~n"), false end; -verify_chain([A, B|_]=Chain, PubKey) -> +verify_chain(Chain, PubKey) -> io:format("Chain verification depth ~p~n", [length(Chain)]), - %% A should have the the prev_hash of B - case A#block.prev_hash == hash_block(B) of - true -> - %% A should have a valid signature - HM = tpke_pubkey:hash_message(PubKey, term_to_binary(A#block{signature= <<>>})), - Signature = tpke_pubkey:deserialize_element(PubKey, A#block.signature), - case tpke_pubkey:verify_signature(PubKey, Signature, HM) of - true -> - verify_chain(tl(Chain), PubKey); - false -> - io:format("bad signature~n"), - false - end; + case verify_block_fit(Chain, PubKey) of + true -> verify_chain(tl(Chain), PubKey); false -> - io:format("parent hash mismatch ~p ~p~n", [A#block.prev_hash, hash_block(B)]), + io:format("bad signature~n"), false end.