Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
duelingbenjos committed Oct 8, 2024
1 parent c52a330 commit 1d64902
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/contracting/execution/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def execute(self, sender, contract_name, function_name, kwargs,
metering=None) -> dict:

current_driver_pending_writes = deepcopy(self.driver.pending_writes)
self.driver.clear_transaction_writes()

if not self.bypass_privates:
assert not function_name.startswith(constants.PRIVATE_METHOD_PREFIX), 'Private method not callable.'
Expand Down Expand Up @@ -175,6 +176,7 @@ def execute(self, sender, contract_name, function_name, kwargs,
balance = max(balance - to_deduct, 0)

driver.set(balances_key, balance)
transaction_writes[balances_key] = balance

if auto_commit:
driver.commit()
Expand Down
8 changes: 5 additions & 3 deletions src/contracting/storage/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ def __init__(self, bypass_cache=False, storage_home=constants.STORAGE_HOME):
self.pending_deltas = {}
self.pending_writes = {}
self.pending_reads = {}
self.transaction_writes = {}
self.cache = TTLCache(maxsize=1000, ttl=6*3600)
self.bypass_cache = bypass_cache
self.contract_state = storage_home.joinpath("contract_state")
self.run_state = storage_home.joinpath("run_state")
self.__build_directories()
self.transaction_writes = {} # New dictionary for transaction-specific writes

def __build_directories(self):
self.contract_state.mkdir(exist_ok=True, parents=True)
Expand Down Expand Up @@ -87,14 +87,15 @@ def get(self, key: str, save: bool = True):
return value


def set(self, key, value):
def set(self, key, value, is_txn_write=False):
rt.deduct_write(*encode_kv(key, value))
if self.pending_reads.get(key) is None:
self.get(key)
if type(value) in [decimal.Decimal, float]:
value = ContractingDecimal(str(value))
self.pending_writes[key] = value
self.transaction_writes[key] = value
if is_txn_write:
self.transaction_writes[key] = value


def find(self, key: str):
Expand Down Expand Up @@ -291,6 +292,7 @@ def flush_cache(self):
self.pending_writes.clear()
self.pending_reads.clear()
self.pending_deltas.clear()
self.transaction_writes.clear()
self.cache.clear()

def flush_disk(self):
Expand Down
4 changes: 2 additions & 2 deletions src/contracting/storage/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def set(self, value):
assert isinstance(value, self._type), (f'Wrong type passed to variable! '
f'Expected {self._type}, got {type(value)}.')

self._driver.set(self._key, value)
self._driver.set(self._key, value, True)

def get(self):
return self._driver.get(self._key)
Expand All @@ -39,7 +39,7 @@ def __init__(self, contract, name, driver: Driver = driver, default_value=None):
self._default_value = default_value

def _set(self, key, value):
self._driver.set(f'{self._key}{self._delimiter}{key}', value)
self._driver.set(f'{self._key}{self._delimiter}{key}', value, True)

def _get(self, item):
value = self._driver.get(f'{self._key}{self._delimiter}{item}')
Expand Down

0 comments on commit 1d64902

Please sign in to comment.