From 512b048ce0f86624897e9b61e3c76290db2717e2 Mon Sep 17 00:00:00 2001 From: Thomas Letan Date: Mon, 22 Apr 2024 10:51:26 +0200 Subject: [PATCH] WASM PVM: Restore Nairobi protocol Removing a variant in the type [Pvm_input_kind.protocol] is forbidden, because it alters how the WASM PVM behaves to the protocol migration message. Although this breaking change has no consequence in the real world, we should strive to keep the WASM PVM backward compatible in any circumstances. --- src/lib_scoru_wasm/constants.ml | 2 ++ src/lib_scoru_wasm/pvm_input_kind.ml | 13 +++++++++---- src/lib_scoru_wasm/pvm_input_kind.mli | 2 +- src/lib_scoru_wasm/test/test_protocol_migration.ml | 7 +++++-- src/lib_scoru_wasm/wasm_vm.ml | 1 + 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/lib_scoru_wasm/constants.ml b/src/lib_scoru_wasm/constants.ml index 6a4a197c3db1..d2edf65dd840 100644 --- a/src/lib_scoru_wasm/constants.ml +++ b/src/lib_scoru_wasm/constants.ml @@ -69,6 +69,8 @@ let version_key = Durable.key_of_string_exn "/readonly/wasm_version" let stack_size_limit = 300 +let nairobi_name = "nairobi_017" + let oxford_name = "oxford_018" let paris_name = "paris_019" diff --git a/src/lib_scoru_wasm/pvm_input_kind.ml b/src/lib_scoru_wasm/pvm_input_kind.ml index 96768f50bbde..d9ef5d81b58d 100644 --- a/src/lib_scoru_wasm/pvm_input_kind.ml +++ b/src/lib_scoru_wasm/pvm_input_kind.ml @@ -23,7 +23,8 @@ (* *) (*****************************************************************************) -type protocol = Paris | Oxford | Proto_alpha +(* You can only add variants to this type. You cannot remove them. *) +type protocol = Nairobi | Oxford | Paris | Proto_alpha (* This type mimics [Sc_rollup_inbox_repr.internal_inbox_messages], without fully deserializing the `Transfer`, and is produced by reading the first bytes @@ -56,12 +57,14 @@ let protocol_from_raw payload = else let payload = String.sub payload 2 (String.length payload - 2) in match Data_encoding.(Binary.of_string_exn string payload) with - | payload when String.equal payload Constants.proto_alpha_name -> - Some (Protocol_migration Proto_alpha) + | payload when String.equal payload Constants.nairobi_name -> + Some (Protocol_migration Nairobi) | payload when String.equal payload Constants.oxford_name -> Some (Protocol_migration Oxford) | payload when String.equal payload Constants.paris_name -> Some (Protocol_migration Paris) + | payload when String.equal payload Constants.proto_alpha_name -> + Some (Protocol_migration Proto_alpha) | _ -> None let internal_from_raw payload = @@ -89,9 +92,11 @@ let from_raw_input payload = module Internal_for_tests = struct let proto_to_binary = function - | Paris -> Data_encoding.(Binary.to_string_exn string Constants.paris_name) + | Nairobi -> + Data_encoding.(Binary.to_string_exn string Constants.nairobi_name) | Oxford -> Data_encoding.(Binary.to_string_exn string Constants.oxford_name) + | Paris -> Data_encoding.(Binary.to_string_exn string Constants.paris_name) | Proto_alpha -> Data_encoding.(Binary.to_string_exn string Constants.proto_alpha_name) diff --git a/src/lib_scoru_wasm/pvm_input_kind.mli b/src/lib_scoru_wasm/pvm_input_kind.mli index c9a79308fc7e..fcb4ce0aede7 100644 --- a/src/lib_scoru_wasm/pvm_input_kind.mli +++ b/src/lib_scoru_wasm/pvm_input_kind.mli @@ -23,7 +23,7 @@ (* *) (*****************************************************************************) -type protocol = Paris | Oxford | Proto_alpha +type protocol = Nairobi | Oxford | Paris | Proto_alpha (** [internal_message_kind] represent an internal message in a inbox. *) type internal_message_kind = diff --git a/src/lib_scoru_wasm/test/test_protocol_migration.ml b/src/lib_scoru_wasm/test/test_protocol_migration.ml index 629536995cb1..7e75f04c7626 100644 --- a/src/lib_scoru_wasm/test/test_protocol_migration.ml +++ b/src/lib_scoru_wasm/test/test_protocol_migration.ml @@ -60,8 +60,9 @@ let test_protocol_migration_message ~from_version ~to_version Lwt_result_syntax.return_unit let proto_name : Tezos_scoru_wasm.Pvm_input_kind.protocol -> string = function - | Paris -> "Paris" + | Nairobi -> "Nairobi" | Oxford -> "Oxford" + | Paris -> "Paris" | Proto_alpha -> "Proto_alpha" let tests = @@ -82,7 +83,9 @@ let tests = ~from_version ~to_version ~after_protocol_activation:protocol)) - [(V3, V4, Paris); (V1, V2, Oxford); (V3, V4, Proto_alpha)] + [ + (V2, V4, Proto_alpha); (V2, V4, Paris); (V1, V2, Oxford); (V0, V1, Nairobi); + ] let () = Alcotest_lwt.run diff --git a/src/lib_scoru_wasm/wasm_vm.ml b/src/lib_scoru_wasm/wasm_vm.ml index 5736a478903e..af93bfb48079 100644 --- a/src/lib_scoru_wasm/wasm_vm.ml +++ b/src/lib_scoru_wasm/wasm_vm.ml @@ -28,6 +28,7 @@ open Wasm_pvm_state.Internal_state let version_for_protocol : Pvm_input_kind.protocol -> Wasm_pvm_state.version = function + | Nairobi -> V1 | Oxford -> V2 | Paris -> V4 | Proto_alpha -> V4 -- GitLab