Alpha: minor change to the PoW check
This commit is contained in:
parent
e3bfe0d651
commit
a873930a09
@ -29,9 +29,7 @@ let forge_block_header
|
||||
let proof_of_work_nonce = generate_proof_of_work_nonce () in
|
||||
let protocol_data : Block_header.protocol_data =
|
||||
{ priority ; seed_nonce_hash ; proof_of_work_nonce } in
|
||||
let faked_header : Block_header.t =
|
||||
{ shell ; protocol_data ; signature = Signature.zero } in
|
||||
if Baking.check_header_hash faked_header stamp_threshold then
|
||||
if Baking.check_header_proof_of_work_stamp shell protocol_data stamp_threshold then
|
||||
let unsigned_header =
|
||||
Alpha_context.Block_header.forge_unsigned shell protocol_data in
|
||||
Client_keys.append cctxt delegate_sk unsigned_header >>=? fun signed_header ->
|
||||
|
@ -251,19 +251,18 @@ let check_hash hash stamp_threshold =
|
||||
let word = MBytes.get_int64 bytes 0 in
|
||||
Compare.Uint64.(word <= stamp_threshold)
|
||||
|
||||
let check_header_hash header stamp_threshold =
|
||||
let check_header_proof_of_work_stamp shell protocol_data stamp_threshold =
|
||||
let hash =
|
||||
Block_header.hash_raw
|
||||
{ shell = header.Block_header.shell ;
|
||||
protocol_data =
|
||||
Data_encoding.Binary.to_bytes
|
||||
Block_header.protocol_data_encoding
|
||||
header.protocol_data } in
|
||||
Block_header.hash
|
||||
{ shell ; protocol_data ; signature = Signature.zero } in
|
||||
check_hash hash stamp_threshold
|
||||
|
||||
let check_proof_of_work_stamp ctxt block =
|
||||
let proof_of_work_threshold = Constants.proof_of_work_threshold ctxt in
|
||||
if check_header_hash block proof_of_work_threshold then
|
||||
if check_header_proof_of_work_stamp
|
||||
block.Block_header.shell
|
||||
block.protocol_data
|
||||
proof_of_work_threshold then
|
||||
return ()
|
||||
else
|
||||
fail Invalid_stamp
|
||||
|
@ -103,7 +103,12 @@ val first_endorsement_slots:
|
||||
the given key *)
|
||||
val check_signature: Block_header.t -> public_key -> unit tzresult Lwt.t
|
||||
|
||||
val check_header_hash: Block_header.t -> int64 -> bool
|
||||
(** Checks if the header that would be built from the given components
|
||||
is valid for the given diffculty. The signature is not passed as it
|
||||
is does not impact the proof-of-work stamp. The stamp is checked on
|
||||
the hash of a block header whose signature has been zeroed-out. *)
|
||||
val check_header_proof_of_work_stamp:
|
||||
Block_header.shell_header -> Block_header.protocol_data -> int64 -> bool
|
||||
|
||||
(** verify if the proof of work stamp is valid *)
|
||||
val check_proof_of_work_stamp:
|
||||
|
Loading…
Reference in New Issue
Block a user