From d964c544955bbbe476319c09da0e335fd8c478b3 Mon Sep 17 00:00:00 2001 From: Benjamin Canou Date: Thu, 13 Jul 2023 11:12:19 +0200 Subject: [PATCH 1/4] Move shell plugins in the dependency graph --- .gitlab/ci/jobs/packaging/opam_package.yml | 8 ++++---- manifest/main.ml | 2 +- ...otocol-plugin-007-PsDELPH1-registerer.opam | 2 +- ...otocol-plugin-008-PtEdo2Zk-registerer.opam | 2 +- ...otocol-plugin-009-PsFLoren-registerer.opam | 2 +- ...otocol-plugin-010-PtGRANAD-registerer.opam | 2 +- ...otocol-plugin-011-PtHangz2-registerer.opam | 2 +- ...otocol-plugin-012-Psithaca-registerer.opam | 2 +- ...otocol-plugin-013-PtJakart-registerer.opam | 2 +- ...otocol-plugin-014-PtKathma-registerer.opam | 2 +- ...otocol-plugin-015-PtLimaPt-registerer.opam | 2 +- ...otocol-plugin-016-PtMumbai-registerer.opam | 2 +- ...otocol-plugin-017-PtNairob-registerer.opam | 2 +- ...ezos-protocol-plugin-alpha-registerer.opam | 2 +- .../shell_plugin.ml | 19 ++++++++++++++----- .../shell_plugin.mli | 19 ++++++++++++++----- src/proto_007_PsDELPH1/lib_plugin/dune | 4 ++-- src/proto_008_PtEdo2Zk/lib_plugin/dune | 4 ++-- src/proto_009_PsFLoren/lib_plugin/dune | 4 ++-- src/proto_010_PtGRANAD/lib_plugin/dune | 4 ++-- src/proto_011_PtHangz2/lib_plugin/dune | 4 ++-- src/proto_012_Psithaca/lib_plugin/dune | 4 ++-- src/proto_013_PtJakart/lib_plugin/dune | 4 ++-- src/proto_014_PtKathma/lib_plugin/dune | 4 ++-- src/proto_015_PtLimaPt/lib_plugin/dune | 4 ++-- src/proto_016_PtMumbai/lib_plugin/dune | 4 ++-- src/proto_017_PtNairob/lib_plugin/dune | 4 ++-- src/proto_alpha/lib_plugin/dune | 4 ++-- 28 files changed, 69 insertions(+), 51 deletions(-) rename src/{lib_shell => lib_validation}/shell_plugin.ml (91%) rename src/{lib_shell => lib_validation}/shell_plugin.mli (93%) diff --git a/.gitlab/ci/jobs/packaging/opam_package.yml b/.gitlab/ci/jobs/packaging/opam_package.yml index d5e69c9f1915..c41066e99346 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 6b6b8c6e8ea3..ed7399d711d4 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 bc9f4679581e..3db26c389b37 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 7ee87971a122..56d6cc757e1f 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 a1e464f3b37d..eb059b7dff69 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 e645a364d577..448ee8d758b4 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 f85f268c8aa7..a8896327ff3d 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 6ec7e8eeb7a6..99b07167a8e8 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 3f540cad2b62..d69341560871 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 831c43727c93..f50f6777c1e2 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 69d259bf47d5..76a740446982 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 f283e4ac00cb..153bc723130d 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 f11ab3a39974..9e53f2562cb4 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 ec51b5b1d9c6..a70e9508f966 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/shell_plugin.ml b/src/lib_validation/shell_plugin.ml similarity index 91% rename from src/lib_shell/shell_plugin.ml rename to src/lib_validation/shell_plugin.ml index 6d1ca2a3d4f5..b9a1c0d60b72 100644 --- a/src/lib_shell/shell_plugin.ml +++ b/src/lib_validation/shell_plugin.ml @@ -50,8 +50,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 val add_operation_and_enforce_mempool_bound : @@ -62,9 +65,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 diff --git a/src/lib_shell/shell_plugin.mli b/src/lib_validation/shell_plugin.mli similarity index 93% rename from src/lib_shell/shell_plugin.mli rename to src/lib_validation/shell_plugin.mli index befd3f7faf35..443839014a1b 100644 --- a/src/lib_shell/shell_plugin.mli +++ b/src/lib_validation/shell_plugin.mli @@ -73,8 +73,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 +107,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 diff --git a/src/proto_007_PsDELPH1/lib_plugin/dune b/src/proto_007_PsDELPH1/lib_plugin/dune index b4f3fcd6ed5e..72b937ff6e69 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 624c38de08ff..fe0905f1f400 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 2e8342498703..88c97a269bbd 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 a249bc0db86f..0c21a73736e0 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 f5838c36abc3..be7b09966465 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 edb66c2d20a2..4e11c0bb3143 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 8afa4d74c043..0a306d120946 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 ad8aba890650..ff1a881658a4 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 6d1fe0487765..baa723a3b681 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 4b63789b72b7..7021bb912e50 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_017_PtNairob/lib_plugin/dune b/src/proto_017_PtNairob/lib_plugin/dune index 2c59eac8e4ed..250c70cf1842 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_alpha/lib_plugin/dune b/src/proto_alpha/lib_plugin/dune index d68db6e04747..c0ae384ad9c5 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)) -- GitLab From 254ad254a38851dc4d4b9dde9ac9ec1556e8ac3e Mon Sep 17 00:00:00 2001 From: Pierre Boutillier Date: Mon, 17 Jul 2023 15:20:39 +0200 Subject: [PATCH 2/4] Plugins: add a [syntactic_check] function and plug it --- src/lib_shell/prevalidation.ml | 15 +++++-- src/lib_shell/test/test_prevalidation.ml | 2 + src/lib_validation/block_validation.ml | 46 ++++++++++++-------- src/lib_validation/shell_plugin.ml | 4 ++ src/lib_validation/shell_plugin.mli | 8 ++++ src/proto_016_PtMumbai/lib_plugin/mempool.ml | 2 + src/proto_017_PtNairob/lib_plugin/mempool.ml | 2 + src/proto_alpha/lib_plugin/mempool.ml | 2 + 8 files changed, 59 insertions(+), 22 deletions(-) diff --git a/src/lib_shell/prevalidation.ml b/src/lib_shell/prevalidation.ml index 3dd8940456e0..2067a3bed8e1 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 954b210c2858..946d8fdf34e5 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 a56a1f850497..f814c83d4ac5 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,15 @@ 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 + let* (module Filter) = + match Shell_plugin.find_filter pred_protocol_hash with | None -> tzfail (Unavailable_protocol {block = block_hash; protocol = pred_protocol_hash}) | Some p -> return p 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 +1392,15 @@ 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 + let* (module Filter) = + match Shell_plugin.find_filter pred_protocol_hash with | None -> tzfail (Unavailable_protocol {block = block_hash; protocol = pred_protocol_hash}) | Some p -> return p in - let module Block_validation = Make (Proto) in + let module Block_validation = Make (Filter) in Block_validation.precheck chain_id ~predecessor_block_header @@ -1417,8 +1426,8 @@ 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 + let* (module Filter) = + match Shell_plugin.find_filter pred_protocol_hash with | None -> tzfail (Unavailable_protocol @@ -1426,7 +1435,8 @@ let apply ?simulate ?cached_result ?(should_precheck = true) | Some p -> return p 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 +1448,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,8 +1515,8 @@ 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 + let* (module Filter) = + match Shell_plugin.find_filter protocol with | None -> (* FIXME: https://gitlab.com/tezos/tezos/-/issues/1718 *) (* This should not happen: it should be handled in the validator. *) @@ -1518,11 +1528,11 @@ let preapply ~chain_id ~user_activated_upgrades 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_validation/shell_plugin.ml b/src/lib_validation/shell_plugin.ml index b9a1c0d60b72..512c28cab49c 100644 --- a/src/lib_validation/shell_plugin.ml +++ b/src/lib_validation/shell_plugin.ml @@ -46,6 +46,8 @@ 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 -> @@ -107,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 []) diff --git a/src/lib_validation/shell_plugin.mli b/src/lib_validation/shell_plugin.mli index 443839014a1b..3d789804d8d3 100644 --- a/src/lib_validation/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 diff --git a/src/proto_016_PtMumbai/lib_plugin/mempool.ml b/src/proto_016_PtMumbai/lib_plugin/mempool.ml index bdec72bfb938..a641e48b1052 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/mempool.ml b/src/proto_017_PtNairob/lib_plugin/mempool.ml index bdec72bfb938..d3f7b5bdfc7a 100644 --- a/src/proto_017_PtNairob/lib_plugin/mempool.ml +++ b/src/proto_017_PtNairob/lib_plugin/mempool.ml @@ -535,6 +535,8 @@ let check_minimal_weight config state ~fee ~gas_limit op = (`Branch_delayed [Environment.wrap_tzerror (Fees_too_low_for_mempool required_fee)]) +let syntactic_check _ = `Well_formed + let pre_filter_manager : type t. config -> diff --git a/src/proto_alpha/lib_plugin/mempool.ml b/src/proto_alpha/lib_plugin/mempool.ml index 7347f2b19750..1199fb416113 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 -- GitLab From 9ed5a77cd1dacb3e5c9d63ea9f6fd0e8e99da542 Mon Sep 17 00:00:00 2001 From: Benjamin Canou Date: Thu, 13 Jul 2023 11:59:31 +0200 Subject: [PATCH 3/4] Plugin/Nairobi: early rejection of ill formed ops --- src/proto_017_PtNairob/lib_plugin/mempool.ml | 57 +++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/src/proto_017_PtNairob/lib_plugin/mempool.ml b/src/proto_017_PtNairob/lib_plugin/mempool.ml index d3f7b5bdfc7a..41e1c01924d5 100644 --- a/src/proto_017_PtNairob/lib_plugin/mempool.ml +++ b/src/proto_017_PtNairob/lib_plugin/mempool.ml @@ -535,7 +535,62 @@ let check_minimal_weight config state ~fee ~gas_limit op = (`Branch_delayed [Environment.wrap_tzerror (Fees_too_low_for_mempool required_fee)]) -let syntactic_check _ = `Well_formed +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. -- GitLab From c1b2032d75c6681a146033916786339c58c25080 Mon Sep 17 00:00:00 2001 From: vbot Date: Thu, 13 Jul 2023 17:11:00 +0200 Subject: [PATCH 4/4] Plugin: refactor shell plugin's find_filter Co-authored-by: Diane Gallois-Wong --- src/lib_shell/chain_validator.ml | 22 +++--------------- src/lib_validation/block_validation.ml | 31 ++++--------------------- src/lib_validation/shell_plugin.ml | 32 +++++++++++++++++++++++++- src/lib_validation/shell_plugin.mli | 6 +++-- 4 files changed, 42 insertions(+), 49 deletions(-) diff --git a/src/lib_shell/chain_validator.ml b/src/lib_shell/chain_validator.ml index 0c179031bbb6..588fe1ef44e2 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_validation/block_validation.ml b/src/lib_validation/block_validation.ml index f814c83d4ac5..212456eae3d9 100644 --- a/src/lib_validation/block_validation.ml +++ b/src/lib_validation/block_validation.ml @@ -1346,12 +1346,7 @@ let recompute_metadata chain_id ~predecessor_block_header ~predecessor_context let open Lwt_result_syntax in let*! pred_protocol_hash = Context_ops.get_protocol predecessor_context in let* (module Filter) = - match Shell_plugin.find_filter pred_protocol_hash with - | None -> - tzfail - (Unavailable_protocol - {block = block_hash; protocol = pred_protocol_hash}) - | Some p -> return p + Shell_plugin.find_filter ~block_hash pred_protocol_hash in let module Block_validation = Make (Filter) in Block_validation.recompute_metadata @@ -1393,12 +1388,7 @@ let precheck ~chain_id ~predecessor_block_header ~predecessor_block_hash let block_hash = Block_header.hash block_header in let*! pred_protocol_hash = Context_ops.get_protocol predecessor_context in let* (module Filter) = - match Shell_plugin.find_filter pred_protocol_hash with - | None -> - tzfail - (Unavailable_protocol - {block = block_hash; protocol = pred_protocol_hash}) - | Some p -> return p + Shell_plugin.find_filter ~block_hash pred_protocol_hash in let module Block_validation = Make (Filter) in Block_validation.precheck @@ -1427,12 +1417,7 @@ let apply ?simulate ?cached_result ?(should_precheck = true) let open Lwt_result_syntax in let*! pred_protocol_hash = Context_ops.get_protocol predecessor_context in let* (module Filter) = - match Shell_plugin.find_filter pred_protocol_hash with - | None -> - tzfail - (Unavailable_protocol - {block = block_hash; protocol = pred_protocol_hash}) - | Some p -> return p + Shell_plugin.find_filter ~block_hash pred_protocol_hash in let* () = if should_precheck && Filter.Proto.(compare environment_version V7 >= 0) @@ -1516,15 +1501,7 @@ let preapply ~chain_id ~user_activated_upgrades let open Lwt_result_syntax in let*! protocol = Context_ops.get_protocol predecessor_context in let* (module Filter) = - match Shell_plugin.find_filter 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 + 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. *) diff --git a/src/lib_validation/shell_plugin.ml b/src/lib_validation/shell_plugin.ml index 512c28cab49c..fd15fcc83189 100644 --- a/src/lib_validation/shell_plugin.ml +++ b/src/lib_validation/shell_plugin.ml @@ -179,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_validation/shell_plugin.mli b/src/lib_validation/shell_plugin.mli index 3d789804d8d3..6ae50306d179 100644 --- a/src/lib_validation/shell_plugin.mli +++ b/src/lib_validation/shell_plugin.mli @@ -176,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 -- GitLab