From dc74acba5699a44620036c6a85674d8cd6c69a92 Mon Sep 17 00:00:00 2001 From: Milo Davis Date: Tue, 10 Oct 2017 14:03:44 +0200 Subject: [PATCH] Validator: better error message for operations that exceed max size --- src/proto/alpha/operation_repr.ml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/proto/alpha/operation_repr.ml b/src/proto/alpha/operation_repr.ml index b7df5f4f5..6f58072da 100644 --- a/src/proto/alpha/operation_repr.ml +++ b/src/proto/alpha/operation_repr.ml @@ -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