Verified Commit 13067b95 authored by vbot's avatar vbot Committed by Romain

Validation: dismiss operations with unserializable metadata

parent 16facd87
Pipeline #158129738 passed with stages
in 20 minutes and 35 seconds
......@@ -183,7 +183,7 @@ struct
pv.state
{shell = op.raw.shell; protocol_data = op.protocol_data})
>|= function
| Ok (state, receipt) ->
| Ok (state, receipt) -> (
let pv =
{
state;
......@@ -193,7 +193,18 @@ struct
Operation_hash.Set.add op.hash pv.live_operations;
}
in
Applied (pv, receipt)
try
let receipt =
Data_encoding.Binary.(
of_bytes_exn
Proto.operation_receipt_encoding
(to_bytes_exn Proto.operation_receipt_encoding receipt))
in
Applied (pv, receipt)
with exn ->
Refused
[Validation_errors.Cannot_serialize_operation_metadata; Exn exn]
)
| Error errors -> (
match classify_errors errors with
| `Branch ->
......
......@@ -38,6 +38,8 @@ type error +=
time : Time.System.t;
}
type error += Cannot_serialize_operation_metadata
let () =
(* Parse error *)
register_error_kind
......@@ -102,7 +104,17 @@ let () =
| _ ->
None)
(fun (block, block_time, time) ->
Future_block_header {block; block_time; time})
Future_block_header {block; block_time; time}) ;
Error_monad.register_error_kind
`Permanent
~id:"block_validation.cannot_serialize_metadata"
~title:"Cannot serialize metadata"
~description:"Unable to serialize metadata"
~pp:(fun ppf () ->
Format.fprintf ppf "Unable to serialize the metadata for an operation.")
Data_encoding.empty
(function Cannot_serialize_operation_metadata -> Some () | _ -> None)
(fun () -> Cannot_serialize_operation_metadata)
(************************* State errors ***********************************)
......
......@@ -38,6 +38,8 @@ type error +=
time : Time.System.t;
}
type error += Cannot_serialize_operation_metadata
(************************* State errors ***********************************)
type error += Unknown_chain of Chain_id.t
......
......@@ -348,12 +348,29 @@ module Make (Proto : Registered_protocol.T) = struct
Proto.block_header_metadata_encoding
block_data
in
let ops_metadata =
List.map
(List.map
(Data_encoding.Binary.to_bytes_exn Proto.operation_receipt_encoding))
ops_metadata
in
( try
return
(List.map
(List.map (fun receipt ->
(* Check that the metadata are
serializable/deserializable *)
let bytes =
Data_encoding.Binary.to_bytes_exn
Proto.operation_receipt_encoding
receipt
in
let _ =
Data_encoding.Binary.of_bytes_exn
Proto.operation_receipt_encoding
bytes
in
bytes))
ops_metadata)
with exn ->
trace
Validation_errors.Cannot_serialize_operation_metadata
(fail (Exn exn)) )
>>=? fun ops_metadata ->
let context =
Shell_context.unwrap_disk_context validation_result.context
in
......
......@@ -614,14 +614,33 @@ let filter_and_apply_operations cctxt state ~chain ~block block_info ~priority
Tag.DSL.(
fun f ->
f
"@[<v 4>Client-side validation: invalid operation filtered %[email protected]\n\
"@[<v 4>Client-side validation: filtered invalid operation %[email protected]\n\
%[email protected]]"
-% t event "baking_rejected_invalid_operation"
-% a Operation_hash.Logging.tag (Operation.hash_packed op)
-% a errs_tag errs)
>>= fun () -> Lwt.return_none
| Ok (resulting_state, _receipt) ->
| Ok (resulting_state, receipt) -> (
try
(* Check that the metadata are serializable/deserializable *)
let _ =
Data_encoding.Binary.(
of_bytes_exn
Protocol.operation_receipt_encoding
(to_bytes_exn Protocol.operation_receipt_encoding receipt))
in
Lwt.return_some resulting_state
with exn ->
lwt_debug
Tag.DSL.(
fun f ->
f "Client-side validation: filtered invalid operation %a"
-% t event "baking_rejected_invalid_operation"
-% a
errs_tag
[ Validation_errors.Cannot_serialize_operation_metadata;
Exn exn ])
>>= fun () -> Lwt.return_none )
in
let filter_valid_operations inc ops =
Lwt_list.fold_left_s
......
......@@ -614,14 +614,33 @@ let filter_and_apply_operations cctxt state ~chain ~block block_info ~priority
Tag.DSL.(
fun f ->
f
"@[<v 4>Client-side validation: invalid operation filtered %[email protected]\n\
"@[<v 4>Client-side validation: filtered invalid operation %[email protected]\n\
%[email protected]]"
-% t event "baking_rejected_invalid_operation"
-% a Operation_hash.Logging.tag (Operation.hash_packed op)
-% a errs_tag errs)
>>= fun () -> Lwt.return_none
| Ok (resulting_state, _receipt) ->
| Ok (resulting_state, receipt) -> (
try
(* Check that the metadata are serializable/deserializable *)
let _ =
Data_encoding.Binary.(
of_bytes_exn
Protocol.operation_receipt_encoding
(to_bytes_exn Protocol.operation_receipt_encoding receipt))
in
Lwt.return_some resulting_state
with exn ->
lwt_debug
Tag.DSL.(
fun f ->
f "Client-side validation: filtered invalid operation %a"
-% t event "baking_rejected_invalid_operation"
-% a
errs_tag
[ Validation_errors.Cannot_serialize_operation_metadata;
Exn exn ])
>>= fun () -> Lwt.return_none )
in
let filter_valid_operations inc ops =
Lwt_list.fold_left_s
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment