From 0848f05c4db5b904eb107732c71f196b77a49d14 Mon Sep 17 00:00:00 2001 From: Brendan Schell Date: Thu, 27 Jun 2024 17:18:40 -0400 Subject: [PATCH 1/2] add missing migrations --- packages/syft/src/syft/service/code/user_code.py | 12 ++++++++++++ .../syft/service/code_history/code_history.py | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/packages/syft/src/syft/service/code/user_code.py b/packages/syft/src/syft/service/code/user_code.py index b8df87fc619..d2a27abc861 100644 --- a/packages/syft/src/syft/service/code/user_code.py +++ b/packages/syft/src/syft/service/code/user_code.py @@ -1933,3 +1933,15 @@ def migrate_usercode_v5_to_v4() -> list[Callable]: drop("origin_node_side_type"), drop("l0_deny_reason"), ] + + +@migrate(UserCodeV5, UserCode) +def migrate_usercode_v5_to_v6() -> list[Callable]: + return [ + drop("enclave_metadata"), + ] + + +@migrate(UserCode, UserCodeV5) +def migrate_usercode_v6_to_v5() -> list[Callable]: + return [make_set_default("enclave_metadata", None)] diff --git a/packages/syft/src/syft/service/code_history/code_history.py b/packages/syft/src/syft/service/code_history/code_history.py index e013ef22c34..d1dde068581 100644 --- a/packages/syft/src/syft/service/code_history/code_history.py +++ b/packages/syft/src/syft/service/code_history/code_history.py @@ -1,4 +1,5 @@ # stdlib +from collections.abc import Callable import json from typing import Any @@ -7,10 +8,13 @@ from ...client.enclave_client import EnclaveMetadata from ...serde.serializable import serializable from ...service.user.user_roles import ServiceRole +from ...types.syft_migration import migrate from ...types.syft_object import SYFT_OBJECT_VERSION_2 from ...types.syft_object import SYFT_OBJECT_VERSION_3 from ...types.syft_object import SyftObject from ...types.syft_object import SyftVerifyKey +from ...types.transforms import drop +from ...types.transforms import make_set_default from ...types.uid import UID from ...util.notebook_ui.components.tabulator_template import ( build_tabulator_table_with_data, @@ -171,3 +175,15 @@ def _repr_html_(self) -> str | None: "icon": None, } return build_tabulator_table_with_data(rows, metadata) + + +@migrate(CodeHistoryV2, CodeHistory) +def code_history_v2_to_v3() -> list[Callable]: + return [drop("enclave_metadata")] + + +@migrate(CodeHistory, CodeHistoryV2) +def code_history_v3_to_v2() -> list[Callable]: + return [ + make_set_default("enclave_metadata", None), + ] From 6565444ac04f920f54b8907867962bcbb7d6b041 Mon Sep 17 00:00:00 2001 From: Shubham Gupta Date: Tue, 2 Jul 2024 14:07:26 +0530 Subject: [PATCH 2/2] remove user code version 6 and merge its changes to user code version 5 - restage protocol --- .../src/syft/protocol/protocol_version.json | 12 +--- .../syft/src/syft/service/code/user_code.py | 56 ++++--------------- 2 files changed, 13 insertions(+), 55 deletions(-) diff --git a/packages/syft/src/syft/protocol/protocol_version.json b/packages/syft/src/syft/protocol/protocol_version.json index 5054b847ee4..1a1a53bffd9 100644 --- a/packages/syft/src/syft/protocol/protocol_version.json +++ b/packages/syft/src/syft/protocol/protocol_version.json @@ -281,19 +281,9 @@ } }, "UserCode": { - "4": { - "version": 4, - "hash": "0a7181cd5f76800b6566175ffa7276d0cf38c4ddc5110114430147dfc8bfdb2a", - "action": "remove" - }, "5": { "version": 5, - "hash": "128705a5fdf308055ef857b25c80966c928938a05ec03459dae9b36bd6122aa2", - "action": "add" - }, - "6": { - "version": 6, - "hash": "c48ec3160bb34adf937e6306523c7ebc52861ff84a576a30a28cd45c224ded0f", + "hash": "c2409f51bf920cce557d288c40b6964ec4df3d8c23e33c5d5668addc30368632", "action": "add" } }, diff --git a/packages/syft/src/syft/service/code/user_code.py b/packages/syft/src/syft/service/code/user_code.py index d2a27abc861..0f8d303da2a 100644 --- a/packages/syft/src/syft/service/code/user_code.py +++ b/packages/syft/src/syft/service/code/user_code.py @@ -57,7 +57,6 @@ from ...types.syft_object import SYFT_OBJECT_VERSION_2 from ...types.syft_object import SYFT_OBJECT_VERSION_4 from ...types.syft_object import SYFT_OBJECT_VERSION_5 -from ...types.syft_object import SYFT_OBJECT_VERSION_6 from ...types.syft_object import SyftObject from ...types.syncable_object import SyncableSyftObject from ...types.transforms import TransformContext @@ -271,6 +270,7 @@ def get_sync_dependencies(self, context: AuthedServiceContext) -> list[UID]: return [self.user_code_link.object_uid] +@serializable() class UserCodeV4(SyncableSyftObject): # version __canonical_name__ = "UserCode" @@ -302,46 +302,11 @@ class UserCodeV4(SyncableSyftObject): worker_pool_name: str | None = None -@serializable() -class UserCodeV5(SyncableSyftObject): - # version - __canonical_name__ = "UserCode" - __version__ = SYFT_OBJECT_VERSION_5 - - id: UID - node_uid: UID | None = None - user_verify_key: SyftVerifyKey - raw_code: str - input_policy_type: type[InputPolicy] | UserPolicy - input_policy_init_kwargs: dict[Any, Any] | None = None - input_policy_state: bytes = b"" - output_policy_type: type[OutputPolicy] | UserPolicy - output_policy_init_kwargs: dict[Any, Any] | None = None - output_policy_state: bytes = b"" - parsed_code: str - service_func_name: str - unique_func_name: str - user_unique_func_name: str - code_hash: str - signature: inspect.Signature - status_link: LinkedObject | None = None - input_kwargs: list[str] - enclave_metadata: EnclaveMetadata | None = None - submit_time: DateTime | None = None - # tracks if the code calls domain.something, variable is set during parsing - uses_domain: bool = False - - nested_codes: dict[str, tuple[LinkedObject, dict]] | None = {} - worker_pool_name: str | None = None - origin_node_side_type: NodeSideType - l0_deny_reason: str | None = None - - @serializable() class UserCode(SyncableSyftObject): # version __canonical_name__ = "UserCode" - __version__ = SYFT_OBJECT_VERSION_6 + __version__ = SYFT_OBJECT_VERSION_5 id: UID node_uid: UID | None = None @@ -1924,24 +1889,27 @@ def migrate_usercode_v4_to_v5() -> list[Callable]: return [ make_set_default("origin_node_side_type", NodeSideType.HIGH_SIDE), make_set_default("l0_deny_reason", None), + drop("enclave_metadata"), ] @migrate(UserCode, UserCodeV4) def migrate_usercode_v5_to_v4() -> list[Callable]: return [ - drop("origin_node_side_type"), - drop("l0_deny_reason"), + drop(["origin_node_side_type", "l0_deny_reason"]), + make_set_default("enclave_metadata", None), ] -@migrate(UserCodeV5, UserCode) -def migrate_usercode_v5_to_v6() -> list[Callable]: +@migrate(SubmitUserCodeV4, SubmitUserCode) +def upgrade_submitusercode() -> list[Callable]: return [ drop("enclave_metadata"), ] -@migrate(UserCode, UserCodeV5) -def migrate_usercode_v6_to_v5() -> list[Callable]: - return [make_set_default("enclave_metadata", None)] +@migrate(SubmitUserCode, SubmitUserCodeV4) +def downgrade_submitusercode() -> list[Callable]: + return [ + make_set_default("enclave_metadata", None), + ]