12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)openProtocolletdefault_constant="\x00\x00\x00\x05"letis_updated_constant=letcommit_hash=matchHex.to_string(`HexTezos_version.Current_git_info.commit_hash)with|None->Tezos_version.Current_git_info.commit_hash|Somes->sinifString.lengthcommit_hash>=4thenString.subcommit_hash04elsedefault_constantletis_updated_constant_len=String.lengthis_updated_constant(* add a version to the pow *)letinit_proof_of_work_nonce()=letbuf=Bytes.makeAlpha_context.Constants.proof_of_work_nonce_size'\000'inBytes.blit_stringis_updated_constant0buf0is_updated_constant_len;letmax_z_len=Alpha_context.Constants.proof_of_work_nonce_size-is_updated_constant_leninletrecauxz=letz_len=(Z.numbitsz+7)/8inifz_len>max_z_lenthenSeq.Nilelse(Bytes.blit_string(Z.to_bitsz)0bufis_updated_constant_lenz_len;Seq.Cons(buf,fun()->aux(Z.succz)))inauxZ.zero(* This was used before November 2018 *)(* (\* Random proof of work *\)
* let generate_proof_of_work_nonce () =
* Tezos_crypto.Rand.generate Alpha_context.Constants.proof_of_work_nonce_size *)letempty_proof_of_work_nonce=Bytes.makeConstants_repr.proof_of_work_nonce_size'\000'letmine~proof_of_work_thresholdshellbuilder=letrecloopnonce_seq=matchnonce_seqwith|Seq.Nil->failwith"Client_baking_pow.mine: couldn't find nonce for required proof of \
work"|Seq.Cons(nonce,seq)->letblock=buildernonceinifAlpha_context.Block_header.Proof_of_work.check_header_proof_of_work_stampshellblockproof_of_work_thresholdthenreturnblockelseloop(seq())inloop(init_proof_of_work_nonce())