Skip to content

Commit 452fd4a

Browse files
committed
review changes
1 parent 62895df commit 452fd4a

File tree

6 files changed

+18
-39
lines changed

6 files changed

+18
-39
lines changed

hathor/consensus/block_consensus.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,9 +568,9 @@ def update_voided_by_from_parents(self, block: Block) -> bool:
568568
else:
569569
meta.voided_by = voided_by.copy()
570570
self.context.save(block)
571-
block.storage.del_from_critical_indexes(block)
571+
block.storage.indexes.del_from_critical_indexes(block)
572572
with non_critical_code(self.log):
573-
block.storage.del_from_non_critical_indexes(block)
573+
block.storage.indexes.del_from_non_critical_indexes(block)
574574
return True
575575
return False
576576

hathor/consensus/transaction_consensus.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ def update_voided_info(self, tx: Transaction) -> None:
229229
if voided_by:
230230
meta.voided_by = voided_by.copy()
231231
self.context.save(tx)
232-
tx.storage.del_from_critical_indexes(tx)
232+
tx.storage.indexes.del_from_critical_indexes(tx)
233233
with non_critical_code(self.log):
234-
tx.storage.del_from_non_critical_indexes(tx)
234+
tx.storage.indexes.del_from_non_critical_indexes(tx)
235235

236236
# Check conflicts of the transactions voiding us.
237237
for h in voided_by:
@@ -403,7 +403,7 @@ def remove_voided_by(self, tx: Transaction, voided_hash: bytes) -> bool:
403403
if not meta2.voided_by:
404404
meta2.voided_by = None
405405
with non_critical_code(self.log):
406-
tx.storage.add_to_non_critical_indexes(tx2)
406+
tx.storage.indexes.add_to_non_critical_indexes(tx2)
407407
self.context.save(tx2)
408408
self.assert_valid_consensus(tx2)
409409
bfs.add_neighbors()
@@ -507,9 +507,9 @@ def add_voided_by(self, tx: Transaction, voided_hash: bytes, *, is_dag_verificat
507507
# All voided transactions with conflicts must have their accumulated weight calculated.
508508
tx2.update_accumulated_weight(save_file=False)
509509
self.context.save(tx2)
510-
tx2.storage.del_from_critical_indexes(tx2)
510+
tx2.storage.indexes.del_from_critical_indexes(tx2)
511511
with non_critical_code(self.log):
512-
tx2.storage.del_from_non_critical_indexes(tx2)
512+
tx2.storage.indexes.del_from_non_critical_indexes(tx2)
513513
self.assert_valid_consensus(tx2)
514514
bfs.add_neighbors()
515515

hathor/indexes/manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def non_critical_handle_contract_unexecution(self, tx: BaseTransaction) -> None:
338338
case _:
339339
assert_never(record)
340340

341-
def add_tx_to_non_critical_indexes(self, tx: BaseTransaction) -> bool:
341+
def add_to_non_critical_indexes(self, tx: BaseTransaction) -> bool:
342342
""" Add a transaction to the indexes
343343
344344
:param tx: Transaction to be added
@@ -376,14 +376,14 @@ def add_tx_to_non_critical_indexes(self, tx: BaseTransaction) -> bool:
376376

377377
return r2
378378

379-
def del_tx_from_critical_indexes(self, tx: BaseTransaction) -> None:
379+
def del_from_critical_indexes(self, tx: BaseTransaction) -> None:
380380
assert tx.storage is not None
381381
# mempool will pick-up if the transaction is voided/invalid and remove it
382382
if tx.storage.transaction_exists(tx.hash):
383383
logger.debug('remove from mempool tips', tx=tx.hash_hex)
384384
self.mempool_tips.update(tx, force_remove=True)
385385

386-
def del_tx_from_non_critical_indexes(self, tx: BaseTransaction, *, remove_all: bool = False) -> None:
386+
def del_from_non_critical_indexes(self, tx: BaseTransaction, *, remove_all: bool = False) -> None:
387387
""" Delete a transaction from the indexes
388388
389389
:param tx: Transaction to be deleted

hathor/transaction/storage/transaction_storage.py

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ def _save_or_verify_genesis(self) -> None:
345345
assert tx == tx2
346346
except TransactionDoesNotExist:
347347
self.save_transaction(tx)
348-
self.add_to_non_critical_indexes(tx)
348+
self.indexes.add_to_non_critical_indexes(tx)
349349
tx2 = tx
350350
self._genesis_cache[tx2.hash] = tx2
351351

@@ -482,9 +482,9 @@ def remove_transaction(self, tx: BaseTransaction) -> None:
482482
483483
:param tx: Transaction to be removed
484484
"""
485-
self.del_from_critical_indexes(tx)
485+
self.indexes.del_from_critical_indexes(tx)
486486
with non_critical_code(self.log):
487-
self.del_from_non_critical_indexes(tx, remove_all=True)
487+
self.indexes.del_from_non_critical_indexes(tx, remove_all=True)
488488

489489
@abstractmethod
490490
def transaction_exists(self, hash_bytes: bytes) -> bool:
@@ -782,18 +782,6 @@ def _topological_sort_metadata(self) -> Iterator[BaseTransaction]:
782782
"""
783783
raise NotImplementedError
784784

785-
@abstractmethod
786-
def add_to_non_critical_indexes(self, tx: BaseTransaction) -> None:
787-
raise NotImplementedError
788-
789-
@abstractmethod
790-
def del_from_critical_indexes(self, tx: BaseTransaction) -> None:
791-
raise NotImplementedError
792-
793-
@abstractmethod
794-
def del_from_non_critical_indexes(self, tx: BaseTransaction, *, remove_all: bool = False) -> None:
795-
raise NotImplementedError
796-
797785
@abstractmethod
798786
def get_block_count(self) -> int:
799787
raise NotImplementedError
@@ -1290,15 +1278,6 @@ def _run_topological_sort_dfs(self, root: BaseTransaction, visited: dict[bytes,
12901278
else:
12911279
stack.append(txinput)
12921280

1293-
def add_to_non_critical_indexes(self, tx: BaseTransaction) -> None:
1294-
self.indexes.add_tx_to_non_critical_indexes(tx)
1295-
1296-
def del_from_critical_indexes(self, tx: BaseTransaction) -> None:
1297-
self.indexes.del_tx_from_critical_indexes(tx)
1298-
1299-
def del_from_non_critical_indexes(self, tx: BaseTransaction, *, remove_all: bool = False) -> None:
1300-
self.indexes.del_tx_from_non_critical_indexes(tx, remove_all=remove_all)
1301-
13021281
def get_block_count(self) -> int:
13031282
return self.indexes.info.get_block_count()
13041283

hathor/vertex_handler/vertex_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def _unsafe_save_and_run_consensus(self, vertex: BaseTransaction) -> None:
238238
vertex.update_initial_metadata(save=False)
239239
self._tx_storage.save_transaction(vertex)
240240
with non_critical_code(self._log):
241-
self._tx_storage.add_to_non_critical_indexes(vertex)
241+
self._tx_storage.indexes.add_to_non_critical_indexes(vertex)
242242
self._consensus.unsafe_update(vertex)
243243

244244
def _post_consensus(

hathor_tests/tx/test_tx_storage.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def test_vertices_count(self):
154154

155155
def validate_save(self, obj):
156156
self.tx_storage.save_transaction(obj)
157-
self.tx_storage.add_to_non_critical_indexes(obj)
157+
self.tx_storage.indexes.add_to_non_critical_indexes(obj)
158158

159159
loaded_obj1 = self.tx_storage.get_transaction(obj.hash)
160160

@@ -177,14 +177,14 @@ def validate_save(self, obj):
177177
self.assertIn(idx_elem, self.tx_storage.indexes.sorted_txs)
178178
self.assertNotIn(idx_elem, self.tx_storage.indexes.sorted_blocks)
179179

180-
self.tx_storage.del_from_critical_indexes(obj)
181-
self.tx_storage.del_from_non_critical_indexes(obj, remove_all=True)
180+
self.tx_storage.indexes.del_from_critical_indexes(obj)
181+
self.tx_storage.indexes.del_from_non_critical_indexes(obj, remove_all=True)
182182

183183
self.assertNotIn(idx_elem, self.tx_storage.indexes.sorted_all)
184184
self.assertNotIn(idx_elem, self.tx_storage.indexes.sorted_txs)
185185
self.assertNotIn(idx_elem, self.tx_storage.indexes.sorted_blocks)
186186

187-
self.tx_storage.add_to_non_critical_indexes(obj)
187+
self.tx_storage.indexes.add_to_non_critical_indexes(obj)
188188
self.assertIn(idx_elem, self.tx_storage.indexes.sorted_all)
189189
if obj.is_block:
190190
self.assertIn(idx_elem, self.tx_storage.indexes.sorted_blocks)

0 commit comments

Comments
 (0)