diff --git a/.gitlab/ci/jobs/packaging/opam_package.yml b/.gitlab/ci/jobs/packaging/opam_package.yml index d5e69c9f1915b348e46189b31932bbc7857b2751..c41066e99346f1aa113fe979d2a5d2e1c57248f5 100644 --- a/.gitlab/ci/jobs/packaging/opam_package.yml +++ b/.gitlab/ci/jobs/packaging/opam_package.yml @@ -330,7 +330,7 @@ opam:octez-node: opam:octez-node-config: extends: - .opam_template - - .rules_template__trigger_opam_batch_2 + - .rules_template__trigger_opam_batch_1 variables: package: octez-node-config @@ -372,7 +372,7 @@ opam:octez-proxy-server: opam:octez-signer: extends: - .opam_template - - .rules_template__trigger_opam_batch_2 + - .rules_template__trigger_opam_batch_1 variables: package: octez-signer @@ -1243,7 +1243,7 @@ opam:tezos-protocol-plugin-007-PsDELPH1: opam:tezos-protocol-plugin-007-PsDELPH1-registerer: extends: - .opam_template - - .rules_template__trigger_opam_batch_1 + - .rules_template__trigger_opam_batch_2 variables: package: tezos-protocol-plugin-007-PsDELPH1-registerer @@ -1257,7 +1257,7 @@ opam:tezos-protocol-plugin-008-PtEdo2Zk: opam:tezos-protocol-plugin-008-PtEdo2Zk-registerer: extends: - .opam_template - - .rules_template__trigger_opam_batch_1 + - .rules_template__trigger_opam_batch_2 variables: package: tezos-protocol-plugin-008-PtEdo2Zk-registerer diff --git a/manifest/main.ml b/manifest/main.ml index 6b6b8c6e8ea3b0c57390a6083b0cb30f8552fe5b..ed7399d711d48459ff426914ad42c65021796588 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -5462,7 +5462,7 @@ let hash = Protocol.hash |> open_ ~m:"TzPervasives.Error_monad.Legacy_monad_globals"; embedded |> open_; plugin |> open_; - octez_shell |> open_; + octez_validation |> open_; ] ~modules:["Plugin_registerer"] ~bisect_ppx:(if N.(number >= 008) then Yes else No) diff --git a/opam/tezos-protocol-plugin-007-PsDELPH1-registerer.opam b/opam/tezos-protocol-plugin-007-PsDELPH1-registerer.opam index bc9f4679581ea9cf1fee82daacb3953abf112b09..3db26c389b376841281ee3c54d51a263faea49c1 100644 --- a/opam/tezos-protocol-plugin-007-PsDELPH1-registerer.opam +++ b/opam/tezos-protocol-plugin-007-PsDELPH1-registerer.opam @@ -13,7 +13,7 @@ depends: [ "tezos-base" "tezos-embedded-protocol-007-PsDELPH1" "tezos-protocol-plugin-007-PsDELPH1" - "tezos-shell" + "tezos-validation" ] build: [ ["rm" "-r" "vendors"] diff --git a/opam/tezos-protocol-plugin-008-PtEdo2Zk-registerer.opam b/opam/tezos-protocol-plugin-008-PtEdo2Zk-registerer.opam index 7ee87971a122c8b9cfd26f7da6e3087fdf0b0b0a..56d6cc757e1f8fd32f3aa55f7124eedccf09d2ec 100644 --- a/opam/tezos-protocol-plugin-008-PtEdo2Zk-registerer.opam +++ b/opam/tezos-protocol-plugin-008-PtEdo2Zk-registerer.opam @@ -13,7 +13,7 @@ depends: [ "tezos-base" "tezos-embedded-protocol-008-PtEdo2Zk" "tezos-protocol-plugin-008-PtEdo2Zk" - "tezos-shell" + "tezos-validation" ] build: [ ["rm" "-r" "vendors"] diff --git a/opam/tezos-protocol-plugin-009-PsFLoren-registerer.opam b/opam/tezos-protocol-plugin-009-PsFLoren-registerer.opam index a1e464f3b37d305f763b0e5ad9d75d63fa698ff7..eb059b7dff693d49c11e0b526b2565069b6c4172 100644 --- a/opam/tezos-protocol-plugin-009-PsFLoren-registerer.opam +++ b/opam/tezos-protocol-plugin-009-PsFLoren-registerer.opam @@ -13,7 +13,7 @@ depends: [ "tezos-base" "tezos-embedded-protocol-009-PsFLoren" "tezos-protocol-plugin-009-PsFLoren" - "tezos-shell" + "tezos-validation" ] build: [ ["rm" "-r" "vendors"] diff --git a/opam/tezos-protocol-plugin-010-PtGRANAD-registerer.opam b/opam/tezos-protocol-plugin-010-PtGRANAD-registerer.opam index e645a364d57730debe4f2c5f9a1bf59f19e81404..448ee8d758b4c60b21a0bd5f870372aa8958b967 100644 --- a/opam/tezos-protocol-plugin-010-PtGRANAD-registerer.opam +++ b/opam/tezos-protocol-plugin-010-PtGRANAD-registerer.opam @@ -13,7 +13,7 @@ depends: [ "tezos-base" "tezos-embedded-protocol-010-PtGRANAD" "tezos-protocol-plugin-010-PtGRANAD" - "tezos-shell" + "tezos-validation" ] build: [ ["rm" "-r" "vendors"] diff --git a/opam/tezos-protocol-plugin-011-PtHangz2-registerer.opam b/opam/tezos-protocol-plugin-011-PtHangz2-registerer.opam index f85f268c8aa7c0f3838c640e2aac8f6712951c4b..a8896327ff3ddc69cee864cbd95acaf11fbb4374 100644 --- a/opam/tezos-protocol-plugin-011-PtHangz2-registerer.opam +++ b/opam/tezos-protocol-plugin-011-PtHangz2-registerer.opam @@ -13,7 +13,7 @@ depends: [ "tezos-base" "tezos-embedded-protocol-011-PtHangz2" "tezos-protocol-plugin-011-PtHangz2" - "tezos-shell" + "tezos-validation" ] build: [ ["rm" "-r" "vendors"] diff --git a/opam/tezos-protocol-plugin-012-Psithaca-registerer.opam b/opam/tezos-protocol-plugin-012-Psithaca-registerer.opam index 6ec7e8eeb7a6cdc841151137e590d95532c1097c..99b07167a8e8eea560bdc2459ac050118cd03808 100644 --- a/opam/tezos-protocol-plugin-012-Psithaca-registerer.opam +++ b/opam/tezos-protocol-plugin-012-Psithaca-registerer.opam @@ -13,7 +13,7 @@ depends: [ "tezos-base" "tezos-embedded-protocol-012-Psithaca" "tezos-protocol-plugin-012-Psithaca" - "tezos-shell" + "tezos-validation" ] build: [ ["rm" "-r" "vendors"] diff --git a/opam/tezos-protocol-plugin-013-PtJakart-registerer.opam b/opam/tezos-protocol-plugin-013-PtJakart-registerer.opam index 3f540cad2b628afba1c1827fa5eb9a0486ca261e..d6934156087185c5cc0003d65a6038b147d25271 100644 --- a/opam/tezos-protocol-plugin-013-PtJakart-registerer.opam +++ b/opam/tezos-protocol-plugin-013-PtJakart-registerer.opam @@ -13,7 +13,7 @@ depends: [ "tezos-base" "tezos-embedded-protocol-013-PtJakart" "tezos-protocol-plugin-013-PtJakart" - "tezos-shell" + "tezos-validation" ] build: [ ["rm" "-r" "vendors"] diff --git a/opam/tezos-protocol-plugin-014-PtKathma-registerer.opam b/opam/tezos-protocol-plugin-014-PtKathma-registerer.opam index 831c43727c934c3d0cafceb4ea8b7b7ad8005d3b..f50f6777c1e2d8b36f4b7c19eedc411318b83868 100644 --- a/opam/tezos-protocol-plugin-014-PtKathma-registerer.opam +++ b/opam/tezos-protocol-plugin-014-PtKathma-registerer.opam @@ -13,7 +13,7 @@ depends: [ "tezos-base" "tezos-embedded-protocol-014-PtKathma" "tezos-protocol-plugin-014-PtKathma" - "tezos-shell" + "tezos-validation" ] build: [ ["rm" "-r" "vendors"] diff --git a/opam/tezos-protocol-plugin-015-PtLimaPt-registerer.opam b/opam/tezos-protocol-plugin-015-PtLimaPt-registerer.opam index 69d259bf47d5edf4477768b4bd8bbb7905997867..76a740446982adef48ab06e65302a65360a38978 100644 --- a/opam/tezos-protocol-plugin-015-PtLimaPt-registerer.opam +++ b/opam/tezos-protocol-plugin-015-PtLimaPt-registerer.opam @@ -13,7 +13,7 @@ depends: [ "tezos-base" "tezos-embedded-protocol-015-PtLimaPt" "tezos-protocol-plugin-015-PtLimaPt" - "tezos-shell" + "tezos-validation" ] build: [ ["rm" "-r" "vendors"] diff --git a/opam/tezos-protocol-plugin-016-PtMumbai-registerer.opam b/opam/tezos-protocol-plugin-016-PtMumbai-registerer.opam index f283e4ac00cb73cf45a98976f7754ecc1a681803..153bc723130d2333a885243645fa4e7350fde57d 100644 --- a/opam/tezos-protocol-plugin-016-PtMumbai-registerer.opam +++ b/opam/tezos-protocol-plugin-016-PtMumbai-registerer.opam @@ -13,7 +13,7 @@ depends: [ "tezos-base" "tezos-embedded-protocol-016-PtMumbai" "tezos-protocol-plugin-016-PtMumbai" - "tezos-shell" + "tezos-validation" ] build: [ ["rm" "-r" "vendors"] diff --git a/opam/tezos-protocol-plugin-017-PtNairob-registerer.opam b/opam/tezos-protocol-plugin-017-PtNairob-registerer.opam index f11ab3a39974fbd2a2159eade6da2b3295daf246..9e53f2562cb4ebc0a909ff5a54343e90d59032fe 100644 --- a/opam/tezos-protocol-plugin-017-PtNairob-registerer.opam +++ b/opam/tezos-protocol-plugin-017-PtNairob-registerer.opam @@ -13,7 +13,7 @@ depends: [ "tezos-base" "tezos-embedded-protocol-017-PtNairob" "tezos-protocol-plugin-017-PtNairob" - "tezos-shell" + "tezos-validation" ] build: [ ["rm" "-r" "vendors"] diff --git a/opam/tezos-protocol-plugin-alpha-registerer.opam b/opam/tezos-protocol-plugin-alpha-registerer.opam index ec51b5b1d9c6ac52f7d2d8a684c4230a9bac97dd..a70e9508f966373a4c961dbaacbd9cc0411b7dd3 100644 --- a/opam/tezos-protocol-plugin-alpha-registerer.opam +++ b/opam/tezos-protocol-plugin-alpha-registerer.opam @@ -13,7 +13,7 @@ depends: [ "tezos-base" "tezos-embedded-protocol-alpha" "tezos-protocol-plugin-alpha" - "tezos-shell" + "tezos-validation" ] build: [ ["rm" "-r" "vendors"] diff --git a/src/lib_shell/chain_validator.ml b/src/lib_shell/chain_validator.ml index 0c179031bbb63cb841853a6e62b2d5a8262da2f4..588fe1ef44e2f6a190048743e7c7658b38edc5a8 100644 --- a/src/lib_shell/chain_validator.ml +++ b/src/lib_shell/chain_validator.ml @@ -364,24 +364,6 @@ let broadcast_head w ~previous block = Lwt.return_unit) else Distributed_db.Advertise.current_branch nv.chain_db -let safe_get_prevalidator_filter hash = - let open Lwt_syntax in - match Shell_plugin.find_filter hash with - | Some filter -> return_ok filter - | None -> ( - match Registered_protocol.get hash with - | None -> - (* FIXME. *) - (* This should not happen: it should be handled in the validator. *) - failwith - "chain_validator: missing protocol '%a' for the current block." - Protocol_hash.pp_short - hash - | Some (module Proto : Registered_protocol.T) -> - let* () = Events.(emit prevalidator_filter_not_found) hash in - return_ok - (module Shell_plugin.No_filter (Proto) : Shell_plugin.FILTER)) - let instantiate_prevalidator parameters set_prevalidator block chain_db = let open Lwt_syntax in let* r = @@ -389,7 +371,9 @@ let instantiate_prevalidator parameters set_prevalidator block chain_db = let* new_protocol = Store.Block.protocol_hash parameters.chain_store block in - let* filter = safe_get_prevalidator_filter new_protocol in + let* filter = + Shell_plugin.find_filter ~block_hash:(Store.Block.hash block) new_protocol + in Prevalidator.create parameters.prevalidator_limits filter chain_db in match r with diff --git a/src/lib_shell/prevalidation.ml b/src/lib_shell/prevalidation.ml index 3dd8940456e0c2081e51e8dcd5597a4109b1e7ba..2067a3bed8e1d4f00f9c7aa16420d145f18670cc 100644 --- a/src/lib_shell/prevalidation.ml +++ b/src/lib_shell/prevalidation.ml @@ -166,10 +166,17 @@ module MakeAbstract (Chain_store : CHAIN_STORE) (Filter : Shell_plugin.FILTER) : return {validation_info; mempool; filter_state} let pre_filter state filter_config op = - Filter.Mempool.pre_filter - ~filter_state:state.filter_state - filter_config - op.protocol + match Filter.Mempool.syntactic_check op.protocol with + | `Ill_formed -> + Lwt.return + (`Refused + (Error_monad.TzTrace.make + (Error_monad.error_of_fmt "Ill-formed operation filtered"))) + | `Well_formed -> + Filter.Mempool.pre_filter + ~filter_state:state.filter_state + filter_config + op.protocol type error_classification = Prevalidator_classification.error_classification diff --git a/src/lib_shell/test/test_prevalidation.ml b/src/lib_shell/test/test_prevalidation.ml index 954b210c28588863dea70b9f518bff401fd89b01..946d8fdf34e52784044ce98b269f2bf06eb81488 100644 --- a/src/lib_shell/test/test_prevalidation.ml +++ b/src/lib_shell/test/test_prevalidation.ml @@ -495,6 +495,8 @@ module Toy_filter = struct | F_crash -> assert false let conflict_handler _ ~existing_operation:_ ~new_operation:_ = assert false + + let syntactic_check _ = `Well_formed end end diff --git a/src/lib_validation/block_validation.ml b/src/lib_validation/block_validation.ml index a56a1f850497b365e392a8daf82d4387c5fc7699..212456eae3d9249800726ed41dc180a794e1d377 100644 --- a/src/lib_validation/block_validation.ml +++ b/src/lib_validation/block_validation.ml @@ -289,7 +289,9 @@ let may_patch_protocol ~user_activated_upgrades in return {validation_result with context} -module Make (Proto : Registered_protocol.T) = struct +module Make (Filter : Shell_plugin.FILTER) = struct + module Proto = Filter.Proto + type 'operation_data preapplied_operation = { hash : Operation_hash.t; raw : Operation.t; @@ -870,7 +872,10 @@ module Make (Proto : Registered_protocol.T) = struct in let open Lwt_result_syntax in let* validation_state = - Proto.validate_operation pv.validation_state op.hash operation + match Filter.Mempool.syntactic_check operation with + | `Ill_formed -> failwith "Ill-formed operation filtered" + | `Well_formed -> + Proto.validate_operation pv.validation_state op.hash operation in let* application_state, receipt = Proto.apply_operation pv.application_state op.hash operation @@ -1241,13 +1246,17 @@ module Make (Proto : Registered_protocol.T) = struct ~predecessor:predecessor_block_header.shell ~cache in + let* state = List.fold_left_es (fun state ops -> List.fold_left_es (fun state (oph, op) -> - let* state = Proto.validate_operation state oph op in - return state) + match Filter.Mempool.syntactic_check op with + | `Ill_formed -> failwith "Ill-formed operation filtered" + | `Well_formed -> + let* state = Proto.validate_operation state oph op in + return state) state ops) state @@ -1336,15 +1345,10 @@ let recompute_metadata chain_id ~predecessor_block_header ~predecessor_context block_hash block_header operations = let open Lwt_result_syntax in let*! pred_protocol_hash = Context_ops.get_protocol predecessor_context in - let* (module Proto) = - match Registered_protocol.get pred_protocol_hash with - | None -> - tzfail - (Unavailable_protocol - {block = block_hash; protocol = pred_protocol_hash}) - | Some p -> return p + let* (module Filter) = + Shell_plugin.find_filter ~block_hash pred_protocol_hash in - let module Block_validation = Make (Proto) in + let module Block_validation = Make (Filter) in Block_validation.recompute_metadata chain_id ~predecessor_block_header @@ -1383,15 +1387,10 @@ let precheck ~chain_id ~predecessor_block_header ~predecessor_block_hash let open Lwt_result_syntax in let block_hash = Block_header.hash block_header in let*! pred_protocol_hash = Context_ops.get_protocol predecessor_context in - let* (module Proto) = - match Registered_protocol.get pred_protocol_hash with - | None -> - tzfail - (Unavailable_protocol - {block = block_hash; protocol = pred_protocol_hash}) - | Some p -> return p + let* (module Filter) = + Shell_plugin.find_filter ~block_hash pred_protocol_hash in - let module Block_validation = Make (Proto) in + let module Block_validation = Make (Filter) in Block_validation.precheck chain_id ~predecessor_block_header @@ -1417,16 +1416,12 @@ let apply ?simulate ?cached_result ?(should_precheck = true) } ~cache block_hash block_header operations = let open Lwt_result_syntax in let*! pred_protocol_hash = Context_ops.get_protocol predecessor_context in - let* (module Proto) = - match Registered_protocol.get pred_protocol_hash with - | None -> - tzfail - (Unavailable_protocol - {block = block_hash; protocol = pred_protocol_hash}) - | Some p -> return p + let* (module Filter) = + Shell_plugin.find_filter ~block_hash pred_protocol_hash in let* () = - if should_precheck && Proto.(compare environment_version V7 >= 0) then + if should_precheck && Filter.Proto.(compare environment_version V7 >= 0) + then precheck ~chain_id ~predecessor_block_header @@ -1438,7 +1433,7 @@ let apply ?simulate ?cached_result ?(should_precheck = true) operations else return_unit in - let module Block_validation = Make (Proto) in + let module Block_validation = Make (Filter) in Block_validation.apply ?simulate ?cached_result @@ -1505,24 +1500,16 @@ let preapply ~chain_id ~user_activated_upgrades ~predecessor_block_metadata_hash ~predecessor_ops_metadata_hash operations = let open Lwt_result_syntax in let*! protocol = Context_ops.get_protocol predecessor_context in - let* (module Proto) = - match Registered_protocol.get protocol with - | None -> - (* FIXME: https://gitlab.com/tezos/tezos/-/issues/1718 *) - (* This should not happen: it should be handled in the validator. *) - failwith - "Prevalidation: missing protocol '%a' for the current block." - Protocol_hash.pp_short - protocol - | Some protocol -> return protocol + let* (module Filter) = + Shell_plugin.find_filter ~block_hash:predecessor_hash protocol in (* The cache might be inconsistent with the context. By forcing the reloading of the cache, we restore the consistency. *) - let module Block_validation = Make (Proto) in + let module Block_validation = Make (Filter) in let* protocol_data = match Data_encoding.Binary.of_bytes_opt - Proto.block_header_data_encoding + Filter.Proto.block_header_data_encoding protocol_data with | None -> failwith "Invalid block header" diff --git a/src/lib_shell/shell_plugin.ml b/src/lib_validation/shell_plugin.ml similarity index 75% rename from src/lib_shell/shell_plugin.ml rename to src/lib_validation/shell_plugin.ml index 6d1ca2a3d4f554f183538ead7a85692899cd4ccc..fd15fcc8318943500bea96b00c372bf470ab048e 100644 --- a/src/lib_shell/shell_plugin.ml +++ b/src/lib_validation/shell_plugin.ml @@ -46,12 +46,17 @@ module type FILTER = sig val remove : filter_state:state -> Operation_hash.t -> state + val syntactic_check : Proto.operation -> [`Well_formed | `Ill_formed] + val pre_filter : config -> filter_state:state -> Proto.operation -> - [ `Passed_prefilter of Prevalidator_pending_operations.priority - | Prevalidator_classification.error_classification ] + [ `Passed_prefilter of [`High | `Medium | `Low of Q.t list] + | `Branch_delayed of tztrace + | `Branch_refused of tztrace + | `Refused of tztrace + | `Outdated of tztrace ] Lwt.t val add_operation_and_enforce_mempool_bound : @@ -62,9 +67,15 @@ module type FILTER = sig ( state * [ `No_replace | `Replace of - Operation_hash.t * Prevalidator_classification.error_classification - ], - Prevalidator_classification.error_classification ) + Operation_hash.t + * [ `Branch_delayed of tztrace + | `Branch_refused of tztrace + | `Refused of tztrace + | `Outdated of tztrace ] ], + [ `Branch_delayed of tztrace + | `Branch_refused of tztrace + | `Refused of tztrace + | `Outdated of tztrace ] ) result Lwt.t @@ -98,6 +109,8 @@ module No_filter (Proto : Registered_protocol.T) : let flush _ ~head:_ = Lwt_result_syntax.return_unit + let syntactic_check _ = `Well_formed + let pre_filter _ ~filter_state:_ _ = Lwt.return @@ `Passed_prefilter (`Low []) @@ -166,4 +179,34 @@ let add_to_filter_table proto_hash filter = let register_filter (module Filter : FILTER) = add_to_filter_table Filter.Proto.hash (module Filter) -let find_filter = Protocol_hash.Table.find filter_table +let validator_filter_not_found = + Internal_event.Simple.declare_1 + ~section:["block"; "validation"] + ~name:"protocol_filter_not_found" + ~msg:"no protocol filter found for protocol {protocol_hash}" + ~level:Warning + ~pp1:Protocol_hash.pp + ("protocol_hash", Protocol_hash.encoding) + +let find_filter ~block_hash protocol_hash = + let open Lwt_result_syntax in + match Protocol_hash.Table.find filter_table protocol_hash with + | Some filter -> return filter + | None -> ( + match Registered_protocol.get protocol_hash with + | None -> + tzfail + (Block_validator_errors.Unavailable_protocol + {block = block_hash; protocol = protocol_hash}) + | Some (module Proto : Registered_protocol.T) -> + let*! () = + match Proto.environment_version with + | V0 -> + (* This is normal for protocols Genesis and 000 + because they don't have a plugin. *) + Lwt.return_unit + | _ -> + Internal_event.Simple.(emit validator_filter_not_found) + protocol_hash + in + return (module No_filter (Proto) : FILTER)) diff --git a/src/lib_shell/shell_plugin.mli b/src/lib_validation/shell_plugin.mli similarity index 86% rename from src/lib_shell/shell_plugin.mli rename to src/lib_validation/shell_plugin.mli index befd3f7faf35a5f9e08b55b7d5e763a0a58b670e..6ae50306d179d35f0748250a3ca7d38eab3d8887 100644 --- a/src/lib_shell/shell_plugin.mli +++ b/src/lib_validation/shell_plugin.mli @@ -58,6 +58,14 @@ module type FILTER = sig [oph] from the state of the filter *) val remove : filter_state:state -> Operation_hash.t -> state + (** Perform some syntactic checks on the operation. + + To be used mostly as an exceptional mechanism to prevent + ill-formed operations to block block application. + + Should be called before the {!pre_filter}, does not need a context. *) + val syntactic_check : Proto.operation -> [`Well_formed | `Ill_formed] + (** [pre_filter config ~filter_state operation_data] is called on arrival of an operation and after a flush of the prevalidator. This function calls the [pre_filter] in the protocol @@ -73,8 +81,11 @@ module type FILTER = sig config -> filter_state:state -> Proto.operation -> - [ `Passed_prefilter of Prevalidator_pending_operations.priority - | Prevalidator_classification.error_classification ] + [ `Passed_prefilter of [`High | `Medium | `Low of Q.t list] + | `Branch_delayed of tztrace + | `Branch_refused of tztrace + | `Refused of tztrace + | `Outdated of tztrace ] Lwt.t (** Add an operation to the filter {!state}. @@ -104,9 +115,15 @@ module type FILTER = sig ( state * [ `No_replace | `Replace of - Operation_hash.t * Prevalidator_classification.error_classification - ], - Prevalidator_classification.error_classification ) + Operation_hash.t + * [ `Branch_delayed of tztrace + | `Branch_refused of tztrace + | `Refused of tztrace + | `Outdated of tztrace ] ], + [ `Branch_delayed of tztrace + | `Branch_refused of tztrace + | `Refused of tztrace + | `Outdated of tztrace ] ) result Lwt.t @@ -159,8 +176,10 @@ val register_rpc : (module RPC) -> unit (** Register a metrics plugin module *) val register_metrics : (module METRICS) -> unit -(** Looks for a mempool filter plug-in for a specific protocol. *) -val find_filter : Protocol_hash.t -> (module FILTER) option +(** Looks for a protocol filter plug-in for a specific protocol. The + [block_hash] argument is used for the error message. *) +val find_filter : + block_hash:Block_hash.t -> Protocol_hash.t -> (module FILTER) tzresult Lwt.t (** Looks for an rpc plug-in for a specific protocol. *) val find_rpc : Protocol_hash.t -> (module RPC) option diff --git a/src/proto_007_PsDELPH1/lib_plugin/dune b/src/proto_007_PsDELPH1/lib_plugin/dune index b4f3fcd6ed5e7dc848a7b83cddc1f7e51eca9081..72b937ff6e697111b26047af068c3ccc6d59587e 100644 --- a/src/proto_007_PsDELPH1/lib_plugin/dune +++ b/src/proto_007_PsDELPH1/lib_plugin/dune @@ -21,12 +21,12 @@ tezos-base tezos-embedded-protocol-007-PsDELPH1 tezos-protocol-plugin-007-PsDELPH1 - tezos-shell) + tezos-validation) (flags (:standard) -open Tezos_base.TzPervasives -open Tezos_base.TzPervasives.Error_monad.Legacy_monad_globals -open Tezos_embedded_protocol_007_PsDELPH1 -open Tezos_protocol_plugin_007_PsDELPH1 - -open Tezos_shell) + -open Tezos_validation) (modules Plugin_registerer)) diff --git a/src/proto_008_PtEdo2Zk/lib_plugin/dune b/src/proto_008_PtEdo2Zk/lib_plugin/dune index 624c38de08ff500beaeab3a970dd3aca5d6cfd3e..fe0905f1f400411d075ea7f07d0ddb7ef36df4ff 100644 --- a/src/proto_008_PtEdo2Zk/lib_plugin/dune +++ b/src/proto_008_PtEdo2Zk/lib_plugin/dune @@ -23,12 +23,12 @@ tezos-base tezos-embedded-protocol-008-PtEdo2Zk tezos-protocol-plugin-008-PtEdo2Zk - tezos-shell) + tezos-validation) (flags (:standard) -open Tezos_base.TzPervasives -open Tezos_base.TzPervasives.Error_monad.Legacy_monad_globals -open Tezos_embedded_protocol_008_PtEdo2Zk -open Tezos_protocol_plugin_008_PtEdo2Zk - -open Tezos_shell) + -open Tezos_validation) (modules Plugin_registerer)) diff --git a/src/proto_009_PsFLoren/lib_plugin/dune b/src/proto_009_PsFLoren/lib_plugin/dune index 2e834249870384b437f9e939a57098ee3f024cdf..88c97a269bbd70d0dba8227ee6fec09ef54eb886 100644 --- a/src/proto_009_PsFLoren/lib_plugin/dune +++ b/src/proto_009_PsFLoren/lib_plugin/dune @@ -23,12 +23,12 @@ tezos-base tezos-embedded-protocol-009-PsFLoren tezos-protocol-plugin-009-PsFLoren - tezos-shell) + tezos-validation) (flags (:standard) -open Tezos_base.TzPervasives -open Tezos_base.TzPervasives.Error_monad.Legacy_monad_globals -open Tezos_embedded_protocol_009_PsFLoren -open Tezos_protocol_plugin_009_PsFLoren - -open Tezos_shell) + -open Tezos_validation) (modules Plugin_registerer)) diff --git a/src/proto_010_PtGRANAD/lib_plugin/dune b/src/proto_010_PtGRANAD/lib_plugin/dune index a249bc0db86f45356a56af0938aa6eb739c76cfb..0c21a73736e0e3806cf8a3869248189e35aa8747 100644 --- a/src/proto_010_PtGRANAD/lib_plugin/dune +++ b/src/proto_010_PtGRANAD/lib_plugin/dune @@ -23,12 +23,12 @@ tezos-base tezos-embedded-protocol-010-PtGRANAD tezos-protocol-plugin-010-PtGRANAD - tezos-shell) + tezos-validation) (flags (:standard) -open Tezos_base.TzPervasives -open Tezos_base.TzPervasives.Error_monad.Legacy_monad_globals -open Tezos_embedded_protocol_010_PtGRANAD -open Tezos_protocol_plugin_010_PtGRANAD - -open Tezos_shell) + -open Tezos_validation) (modules Plugin_registerer)) diff --git a/src/proto_011_PtHangz2/lib_plugin/dune b/src/proto_011_PtHangz2/lib_plugin/dune index f5838c36abc3df305b3e6fc96c687a2ea3256b25..be7b099664655ec45077442e20e37a36f9750b1d 100644 --- a/src/proto_011_PtHangz2/lib_plugin/dune +++ b/src/proto_011_PtHangz2/lib_plugin/dune @@ -23,12 +23,12 @@ tezos-base tezos-embedded-protocol-011-PtHangz2 tezos-protocol-plugin-011-PtHangz2 - tezos-shell) + tezos-validation) (flags (:standard) -open Tezos_base.TzPervasives -open Tezos_base.TzPervasives.Error_monad.Legacy_monad_globals -open Tezos_embedded_protocol_011_PtHangz2 -open Tezos_protocol_plugin_011_PtHangz2 - -open Tezos_shell) + -open Tezos_validation) (modules Plugin_registerer)) diff --git a/src/proto_012_Psithaca/lib_plugin/dune b/src/proto_012_Psithaca/lib_plugin/dune index edb66c2d20a2a8a0c2a5fc83237ebd427df34e38..4e11c0bb314347e9c5e37e0532cfc76e2c9b7724 100644 --- a/src/proto_012_Psithaca/lib_plugin/dune +++ b/src/proto_012_Psithaca/lib_plugin/dune @@ -23,12 +23,12 @@ tezos-base tezos-embedded-protocol-012-Psithaca tezos-protocol-plugin-012-Psithaca - tezos-shell) + tezos-validation) (flags (:standard) -open Tezos_base.TzPervasives -open Tezos_base.TzPervasives.Error_monad.Legacy_monad_globals -open Tezos_embedded_protocol_012_Psithaca -open Tezos_protocol_plugin_012_Psithaca - -open Tezos_shell) + -open Tezos_validation) (modules Plugin_registerer)) diff --git a/src/proto_013_PtJakart/lib_plugin/dune b/src/proto_013_PtJakart/lib_plugin/dune index 8afa4d74c043ed7285be0d101ef67b2d0a4bc532..0a306d1209466a738e424335964bb81cd5abf071 100644 --- a/src/proto_013_PtJakart/lib_plugin/dune +++ b/src/proto_013_PtJakart/lib_plugin/dune @@ -23,12 +23,12 @@ tezos-base tezos-embedded-protocol-013-PtJakart tezos-protocol-plugin-013-PtJakart - tezos-shell) + tezos-validation) (flags (:standard) -open Tezos_base.TzPervasives -open Tezos_base.TzPervasives.Error_monad.Legacy_monad_globals -open Tezos_embedded_protocol_013_PtJakart -open Tezos_protocol_plugin_013_PtJakart - -open Tezos_shell) + -open Tezos_validation) (modules Plugin_registerer)) diff --git a/src/proto_014_PtKathma/lib_plugin/dune b/src/proto_014_PtKathma/lib_plugin/dune index ad8aba89065067b7aa65260dc778fb31d84560fe..ff1a881658a474a5ba11d295875add0b4388223d 100644 --- a/src/proto_014_PtKathma/lib_plugin/dune +++ b/src/proto_014_PtKathma/lib_plugin/dune @@ -23,12 +23,12 @@ tezos-base tezos-embedded-protocol-014-PtKathma tezos-protocol-plugin-014-PtKathma - tezos-shell) + tezos-validation) (flags (:standard) -open Tezos_base.TzPervasives -open Tezos_base.TzPervasives.Error_monad.Legacy_monad_globals -open Tezos_embedded_protocol_014_PtKathma -open Tezos_protocol_plugin_014_PtKathma - -open Tezos_shell) + -open Tezos_validation) (modules Plugin_registerer)) diff --git a/src/proto_015_PtLimaPt/lib_plugin/dune b/src/proto_015_PtLimaPt/lib_plugin/dune index 6d1fe04877654098347f619fc0aa7696aac4c0d4..baa723a3b681dfd253bada2f02d1bd111356e976 100644 --- a/src/proto_015_PtLimaPt/lib_plugin/dune +++ b/src/proto_015_PtLimaPt/lib_plugin/dune @@ -23,12 +23,12 @@ tezos-base tezos-embedded-protocol-015-PtLimaPt tezos-protocol-plugin-015-PtLimaPt - tezos-shell) + tezos-validation) (flags (:standard) -open Tezos_base.TzPervasives -open Tezos_base.TzPervasives.Error_monad.Legacy_monad_globals -open Tezos_embedded_protocol_015_PtLimaPt -open Tezos_protocol_plugin_015_PtLimaPt - -open Tezos_shell) + -open Tezos_validation) (modules Plugin_registerer)) diff --git a/src/proto_016_PtMumbai/lib_plugin/dune b/src/proto_016_PtMumbai/lib_plugin/dune index 4b63789b72b73579e16bd4d06c17a323ca19437e..7021bb912e5096b48a157e6d1cdf4d8df7399d8d 100644 --- a/src/proto_016_PtMumbai/lib_plugin/dune +++ b/src/proto_016_PtMumbai/lib_plugin/dune @@ -25,12 +25,12 @@ tezos-base tezos-embedded-protocol-016-PtMumbai tezos-protocol-plugin-016-PtMumbai - tezos-shell) + tezos-validation) (flags (:standard) -open Tezos_base.TzPervasives -open Tezos_base.TzPervasives.Error_monad.Legacy_monad_globals -open Tezos_embedded_protocol_016_PtMumbai -open Tezos_protocol_plugin_016_PtMumbai - -open Tezos_shell) + -open Tezos_validation) (modules Plugin_registerer)) diff --git a/src/proto_016_PtMumbai/lib_plugin/mempool.ml b/src/proto_016_PtMumbai/lib_plugin/mempool.ml index bdec72bfb9389890b39273f9046c351029107f38..a641e48b105222ac119b387657876bad22d1664a 100644 --- a/src/proto_016_PtMumbai/lib_plugin/mempool.ml +++ b/src/proto_016_PtMumbai/lib_plugin/mempool.ml @@ -774,6 +774,8 @@ let pre_filter_far_future_consensus_ops config ~filter_state in match res with Ok b -> Lwt.return b | Error _ -> Lwt.return_false +let syntactic_check _ = `Well_formed + (** A quasi infinite amount of "valid" (pre)endorsements could be sent by a committee member, one for each possible round number. diff --git a/src/proto_017_PtNairob/lib_plugin/dune b/src/proto_017_PtNairob/lib_plugin/dune index 2c59eac8e4ed9a6966579ea08a7239a8a14483a1..250c70cf1842f229dc2274d51e2479c6ac5f665b 100644 --- a/src/proto_017_PtNairob/lib_plugin/dune +++ b/src/proto_017_PtNairob/lib_plugin/dune @@ -25,12 +25,12 @@ tezos-base tezos-embedded-protocol-017-PtNairob tezos-protocol-plugin-017-PtNairob - tezos-shell) + tezos-validation) (flags (:standard) -open Tezos_base.TzPervasives -open Tezos_base.TzPervasives.Error_monad.Legacy_monad_globals -open Tezos_embedded_protocol_017_PtNairob -open Tezos_protocol_plugin_017_PtNairob - -open Tezos_shell) + -open Tezos_validation) (modules Plugin_registerer)) diff --git a/src/proto_017_PtNairob/lib_plugin/mempool.ml b/src/proto_017_PtNairob/lib_plugin/mempool.ml index bdec72bfb9389890b39273f9046c351029107f38..41e1c01924d5c28b9a555b99bbf9037fe5a62b9f 100644 --- a/src/proto_017_PtNairob/lib_plugin/mempool.ml +++ b/src/proto_017_PtNairob/lib_plugin/mempool.ml @@ -535,6 +535,63 @@ let check_minimal_weight config state ~fee ~gas_limit op = (`Branch_delayed [Environment.wrap_tzerror (Fees_too_low_for_mempool required_fee)]) +let output_proof_encoding = + let open Data_encoding in + obj3 + (req + "output_proof" + Sc_rollup_wasm.V2_0_0.Protocol_implementation.proof_encoding) + (req "output_proof_state" Sc_rollup.State_hash.encoding) + (req "output_proof_output" Variable.bytes) + +let kinded_hash_to_state_hash = function + | `Value hash | `Node hash -> + Sc_rollup.State_hash.context_hash_to_state_hash hash + +let is_invalid_op : type t. t manager_operation -> bool = function + | Sc_rollup_execute_outbox_message + {rollup = _; cemented_commitment = _; output_proof} -> ( + match + Data_encoding.Binary.of_string_opt output_proof_encoding output_proof + with + | None -> true + | Some (output_proof, output_proof_state, _) -> + not + (Sc_rollup.State_hash.equal + output_proof_state + (kinded_hash_to_state_hash + output_proof.Environment.Context.Proof.before))) + | _ -> false + +let rec contains_invalid_op : type t. t Kind.manager contents_list -> bool = + function + | Single (Manager_operation {operation; _}) -> is_invalid_op operation + | Cons (Manager_operation {operation; _}, rest) -> + is_invalid_op operation || contains_invalid_op rest + +let syntactic_check + ({shell = _; protocol_data = Operation_data {contents; _}} : Main.operation) + = + match contents with + | Single (Failing_noop _) + | Single (Preendorsement _) + | Single (Endorsement _) + | Single (Dal_attestation _) + | Single (Seed_nonce_revelation _) + | Single (Double_preendorsement_evidence _) + | Single (Double_endorsement_evidence _) + | Single (Double_baking_evidence _) + | Single (Activate_account _) + | Single (Proposals _) + | Single (Vdf_revelation _) + | Single (Drain_delegate _) + | Single (Ballot _) -> + `Well_formed + | Single (Manager_operation _) as op -> + if contains_invalid_op op then `Ill_formed else `Well_formed + | Cons (Manager_operation _, _) as op -> + if contains_invalid_op op then `Ill_formed else `Well_formed + let pre_filter_manager : type t. config -> diff --git a/src/proto_alpha/lib_plugin/dune b/src/proto_alpha/lib_plugin/dune index d68db6e047471cf25517c61fe7b66cd7f03587a3..c0ae384ad9c5fd2d0ea68ca9086a4ae999bf26d7 100644 --- a/src/proto_alpha/lib_plugin/dune +++ b/src/proto_alpha/lib_plugin/dune @@ -25,12 +25,12 @@ tezos-base tezos-embedded-protocol-alpha tezos-protocol-plugin-alpha - tezos-shell) + tezos-validation) (flags (:standard) -open Tezos_base.TzPervasives -open Tezos_base.TzPervasives.Error_monad.Legacy_monad_globals -open Tezos_embedded_protocol_alpha -open Tezos_protocol_plugin_alpha - -open Tezos_shell) + -open Tezos_validation) (modules Plugin_registerer)) diff --git a/src/proto_alpha/lib_plugin/mempool.ml b/src/proto_alpha/lib_plugin/mempool.ml index 7347f2b19750986215f75b5fedc80eae09c80fcb..1199fb4161137f2f5c6638bdff4ed110f8f82929 100644 --- a/src/proto_alpha/lib_plugin/mempool.ml +++ b/src/proto_alpha/lib_plugin/mempool.ml @@ -1028,3 +1028,5 @@ let conflict_handler config : Mempool.conflict_handler = | Ok _ | Error _ -> `Keep else if Operation.compare existing_operation new_operation < 0 then `Replace else `Keep + +let syntactic_check _ = `Well_formed