Validator: better error message for operations that exceed max size
This commit is contained in:
parent
b5e53191e2
commit
dc74acba56
@ -327,6 +327,7 @@ module Encoding = struct
|
||||
end
|
||||
|
||||
type error += Cannot_parse_operation
|
||||
type error += Operation_exceeds_max_length of int
|
||||
|
||||
let encoding =
|
||||
let open Data_encoding in
|
||||
@ -352,11 +353,23 @@ let () =
|
||||
Format.fprintf ppf "The operation cannot be parsed")
|
||||
Data_encoding.unit
|
||||
(function Cannot_parse_operation -> Some () | _ -> None)
|
||||
(fun () -> Cannot_parse_operation)
|
||||
(fun () -> Cannot_parse_operation) ;
|
||||
register_error_kind
|
||||
`Branch
|
||||
~id:"operationExceedsMaxLength"
|
||||
~title:"Operation exceeded maximum allowed operation length"
|
||||
~description:"The operation exceeded the maximum allowed length of an operation."
|
||||
~pp:(fun ppf len ->
|
||||
Format.fprintf ppf
|
||||
"The operation was %d bytes, but operations must be less than %d bytes."
|
||||
len Constants_repr.max_operation_data_length)
|
||||
Data_encoding.(obj1 (req "length" int31))
|
||||
(function Operation_exceeds_max_length len -> Some len | _ -> None)
|
||||
(fun len -> Operation_exceeds_max_length len)
|
||||
|
||||
let parse hash (op: Operation.t) =
|
||||
if not (Compare.Int.(MBytes.length op.proto <= Constants_repr.max_operation_data_length)) then
|
||||
error Cannot_parse_operation
|
||||
error (Operation_exceeds_max_length (MBytes.length op.proto))
|
||||
else
|
||||
match Data_encoding.Binary.of_bytes
|
||||
Encoding.signed_proto_operation_encoding
|
||||
|
Loading…
Reference in New Issue
Block a user