Proto: use integer comparison while checking proof-of-work.
This commit is contained in:
parent
c842140f74
commit
b9c3d95406
@ -29,7 +29,7 @@ module Constants : sig
|
||||
val first_free_mining_slot: block -> int32 tzresult Lwt.t
|
||||
val max_signing_slot: block -> int tzresult Lwt.t
|
||||
val instructions_per_transaction: block -> int tzresult Lwt.t
|
||||
val stamp_threshold: block -> int tzresult Lwt.t
|
||||
val stamp_threshold: block -> int64 tzresult Lwt.t
|
||||
end
|
||||
|
||||
module Context : sig
|
||||
|
@ -39,7 +39,7 @@ type constants = {
|
||||
first_free_mining_slot: int32 ;
|
||||
max_signing_slot: int ;
|
||||
instructions_per_transaction: int ;
|
||||
proof_of_work_threshold: int ;
|
||||
proof_of_work_threshold: int64 ;
|
||||
}
|
||||
|
||||
let default = {
|
||||
@ -56,7 +56,8 @@ let default = {
|
||||
first_free_mining_slot = 16l ;
|
||||
max_signing_slot = 15 ;
|
||||
instructions_per_transaction = 16 * 1024 ;
|
||||
proof_of_work_threshold = 8 ;
|
||||
proof_of_work_threshold =
|
||||
Int64.(lognot (sub (shift_left 1L 56) 1L)) ;
|
||||
}
|
||||
|
||||
let opt (=) def v = if def = v then None else Some v
|
||||
@ -95,7 +96,7 @@ let constants_encoding =
|
||||
opt Int.(=)
|
||||
default.instructions_per_transaction c.instructions_per_transaction
|
||||
and proof_of_work_threshold =
|
||||
opt Int.(=)
|
||||
opt Int64.(=)
|
||||
default.proof_of_work_threshold c.proof_of_work_threshold
|
||||
in
|
||||
( cycle_length,
|
||||
@ -144,7 +145,7 @@ let constants_encoding =
|
||||
(opt "first_free_mining_slot" int32)
|
||||
(opt "max_signing_slot" int31)
|
||||
(opt "instructions_per_transaction" int31)
|
||||
(opt "proof_of_work_threshold" int31)
|
||||
(opt "proof_of_work_threshold" int64)
|
||||
)
|
||||
|
||||
type error += Constant_read of exn
|
||||
|
@ -132,16 +132,10 @@ let first_endorsement_slots
|
||||
endorsement_priorities ctxt level >>=? fun delegate_list ->
|
||||
select_delegate delegate delegate_list max_priority
|
||||
|
||||
|
||||
let check_hash hash stamp_threshold =
|
||||
let bytes = Block_hash.to_bytes hash in
|
||||
let len = MBytes.length bytes * 8 in
|
||||
try
|
||||
for i = len - 1 downto (len - stamp_threshold) do
|
||||
if MBytes.get_bool bytes i then raise Exit
|
||||
done;
|
||||
true
|
||||
with Exit -> false
|
||||
let bytes = Block_hash.to_raw hash in
|
||||
let word = String.get_int64 bytes 0 in
|
||||
Compare.Uint64.(word < stamp_threshold)
|
||||
|
||||
let check_header_hash {Block.shell;proto;signature} stamp_threshold =
|
||||
let hash =
|
||||
|
@ -70,7 +70,7 @@ val first_endorsement_slots:
|
||||
val check_signature:
|
||||
context -> Block.header -> public_key_hash -> unit tzresult Lwt.t
|
||||
|
||||
val check_hash: Block_hash.t -> int -> bool
|
||||
val check_hash: Block_hash.t -> int64 -> bool
|
||||
val check_proof_of_work_stamp:
|
||||
context -> Block.header -> unit tzresult Lwt.t
|
||||
|
||||
|
@ -97,7 +97,7 @@ module Constants = struct
|
||||
~description: "Stamp threshold"
|
||||
~input: empty
|
||||
~output: (wrap_tzerror @@
|
||||
describe ~title: "proof_of_work threshold" int31)
|
||||
describe ~title: "proof_of_work threshold" int64)
|
||||
RPC.Path.(custom_root / "constants" / "proof_of_work_threshold")
|
||||
|
||||
let errors custom_root =
|
||||
|
@ -79,7 +79,8 @@ let () =
|
||||
let proof_of_work_threshold ctxt =
|
||||
return @@ Constants.proof_of_work_threshold ctxt
|
||||
|
||||
let () = register0 Services.Constants.proof_of_work_threshold proof_of_work_threshold
|
||||
let () =
|
||||
register0 Services.Constants.proof_of_work_threshold proof_of_work_threshold
|
||||
|
||||
let () =
|
||||
register1_noctxt Services.Constants.errors
|
||||
|
@ -185,7 +185,7 @@ module Constants : sig
|
||||
val first_free_mining_slot: context -> int32
|
||||
val max_signing_slot: context -> int
|
||||
val instructions_per_transaction: context -> int
|
||||
val proof_of_work_threshold: context -> int
|
||||
val proof_of_work_threshold: context -> int64
|
||||
|
||||
end
|
||||
|
||||
|
@ -41,9 +41,6 @@ val substring: t -> int -> int -> string
|
||||
val get_char: t -> int -> char
|
||||
(** [get_char buff i] reads 1 byte at offset i as a char *)
|
||||
|
||||
val get_bool: t -> int -> bool
|
||||
(** [get_bool buff i] reads 1 bit at offset i as an unsigned int bit. *)
|
||||
|
||||
val get_uint8: t -> int -> int
|
||||
(** [get_uint8 buff i] reads 1 byte at offset i as an unsigned int of 8
|
||||
bits. i.e. It returns a value between 0 and 2^8-1 *)
|
||||
|
@ -73,9 +73,6 @@ let substring src srcoff len =
|
||||
|
||||
include EndianBigstring.BigEndian
|
||||
|
||||
let get_bool s off =
|
||||
((get_uint8 s (off / 8)) lsr (off mod 8)) land 1 = 1
|
||||
|
||||
let of_float f =
|
||||
let buf = create 8 in
|
||||
set_float buf 0 f;
|
||||
|
@ -49,9 +49,6 @@ val substring: t -> int -> int -> string
|
||||
val get_char: t -> int -> char
|
||||
(** [get_char buff i] reads 1 byte at offset i as a char *)
|
||||
|
||||
val get_bool: t -> int -> bool
|
||||
(** [get_bool buff i] reads 1 bit at offset i as an unsigned int bit. *)
|
||||
|
||||
val get_uint8: t -> int -> int
|
||||
(** [get_uint8 buff i] reads 1 byte at offset i as an unsigned int of 8
|
||||
bits. i.e. It returns a value between 0 and 2^8-1 *)
|
||||
|
Loading…
Reference in New Issue
Block a user