From 196847af157ed271ee10530a92afea7b7e44c865 Mon Sep 17 00:00:00 2001 From: Chiwon Cho Date: Wed, 11 Nov 2020 20:12:40 +0900 Subject: [PATCH] Apply dummy last key to VarDB * Add DUMMY to KeyType class --- iconservice/iconscore/db.py | 4 +++- iconservice/iconscore/icon_container_db.py | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/iconservice/iconscore/db.py b/iconservice/iconscore/db.py index 0f7d308b0..b0e67b66c 100644 --- a/iconservice/iconscore/db.py +++ b/iconservice/iconscore/db.py @@ -46,6 +46,7 @@ class KeyType(Enum): SUB = auto() ARRAY_SIZE = auto() + DUMMY = auto() LAST = auto() @@ -170,7 +171,8 @@ def _get_container_final_key_with_pipe(self, last_key: Key) -> List[bytes]: keys.append(self._tag.value) keys.append(key.value) - keys.append(last_key.value) + if last_key.type != KeyType.DUMMY: + keys.append(last_key.value) return keys diff --git a/iconservice/iconscore/icon_container_db.py b/iconservice/iconscore/icon_container_db.py index 0156095b6..7d6c3819c 100644 --- a/iconservice/iconscore/icon_container_db.py +++ b/iconservice/iconscore/icon_container_db.py @@ -284,6 +284,7 @@ class VarDB(object): :K: [int, str, Address, bytes] :V: [int, str, Address, bytes, bool] """ + _DUMMY_LAST_KEY = Key(b"", KeyType.DUMMY) def __init__(self, var_key: K, db: 'IconScoreDatabase', value_type: type) -> None: # Use var_key as a db prefix in the case of VarDB @@ -297,7 +298,7 @@ def set(self, value: V) -> None: :param value: a value to be set """ byte_value = ContainerUtil.encode_value(value) - self._db.put(b"", byte_value) + self._db.put(self._DUMMY_LAST_KEY, byte_value) def get(self) -> Optional[V]: """ @@ -305,13 +306,16 @@ def get(self) -> Optional[V]: :return: value of the var db """ - return ContainerUtil.decode_object(self._db.get(b""), self.__value_type) + return ContainerUtil.decode_object( + self._db.get(self._DUMMY_LAST_KEY), + self.__value_type + ) def remove(self) -> None: """ Deletes the value """ - self._db.delete(b"") + self._db.delete(self._DUMMY_LAST_KEY) def get_default_value(value_type: type) -> Any: