Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions hathor/consensus/block_consensus.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,6 @@ def update_voided_info(self, block: Block) -> None:
meta = block.get_metadata()
if not meta.voided_by:
storage.indexes.height.add_new(block.get_height(), block.hash, block.timestamp)
storage.update_best_block_tips_cache([block.hash])
# The following assert must be true, but it is commented out for performance reasons.
if self._settings.SLOW_ASSERTS:
assert len(storage.get_best_block_tips(skip_cache=True)) == 1
else:
# Resolve all other cases, but (i).
log = self.log.new(block=block.hash_hex)
Expand Down Expand Up @@ -529,7 +525,6 @@ def update_voided_info(self, block: Block) -> None:
self.log.debug('index new winner block', height=height, block=block.hash_hex)
# We update the height cache index with the new winner chain
storage.indexes.height.update_new_chain(height, block)
storage.update_best_block_tips_cache([block.hash])

def mark_as_reorg_if_needed(self, common_block: Block, new_best_block: Block) -> None:
"""Mark as reorg only if reorg size > 0."""
Expand Down
1 change: 0 additions & 1 deletion hathor/consensus/transaction_consensus.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,6 @@ def add_voided_by(self, tx: Transaction, voided_hash: bytes, *, is_dag_verificat
if tx2.is_block:
assert isinstance(tx2, Block)
self.context.block_algorithm.mark_as_voided(tx2)
tx2.storage.update_best_block_tips_cache(None)

assert not meta2.voided_by or voided_hash not in meta2.voided_by
if tx2.hash != tx.hash and meta2.conflict_with and not meta2.voided_by:
Expand Down
36 changes: 7 additions & 29 deletions hathor/indexes/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from hathor.indexes.nc_creation_index import NCCreationIndex
from hathor.indexes.nc_history_index import NCHistoryIndex
from hathor.indexes.timestamp_index import ScopeType as TimestampScopeType, TimestampIndex
from hathor.indexes.tips_index import ScopeType as TipsScopeType, TipsIndex
from hathor.indexes.tokens_index import TokensIndex
from hathor.indexes.utxo_index import UtxoIndex
from hathor.transaction import BaseTransaction
Expand Down Expand Up @@ -60,9 +59,6 @@ class IndexesManager(ABC):
log = get_logger()

info: InfoIndex
all_tips: TipsIndex
block_tips: TipsIndex
tx_tips: TipsIndex

sorted_all: TimestampIndex
sorted_blocks: TimestampIndex
Expand Down Expand Up @@ -94,9 +90,6 @@ def iter_all_indexes(self) -> Iterator[BaseIndex]:
""" Iterate over all of the indexes abstracted by this manager, hiding their specific implementation details"""
return filter(None, [
self.info,
self.all_tips,
self.block_tips,
self.tx_tips,
self.sorted_all,
self.sorted_blocks,
self.sorted_txs,
Expand Down Expand Up @@ -356,20 +349,12 @@ def add_tx(self, tx: BaseTransaction) -> bool:
"""
self.info.update_timestamps(tx)

# These two calls return False when a transaction changes from
# voided to executed and vice-versa.
r1 = self.all_tips.add_tx(tx)
r2 = self.sorted_all.add_tx(tx)
assert r1 == r2
r1 = self.sorted_all.add_tx(tx)

if tx.is_block:
r3 = self.block_tips.add_tx(tx)
r4 = self.sorted_blocks.add_tx(tx)
assert r3 == r4
r2 = self.sorted_blocks.add_tx(tx)
else:
r3 = self.tx_tips.add_tx(tx)
r4 = self.sorted_txs.add_tx(tx)
assert r3 == r4
r2 = self.sorted_txs.add_tx(tx)

if self.addresses:
self.addresses.add_tx(tx)
Expand All @@ -390,10 +375,10 @@ def add_tx(self, tx: BaseTransaction) -> bool:

# We need to check r1 as well to make sure we don't count twice the transactions/blocks that are
# just changing from voided to executed or vice-versa
if r1 and r3:
if r1 and r2:
self.info.update_counts(tx)

return r3
return r2

def del_tx(self, tx: BaseTransaction, *, remove_all: bool = False, relax_assert: bool = False) -> None:
""" Delete a transaction from the indexes
Expand All @@ -404,9 +389,8 @@ def del_tx(self, tx: BaseTransaction, *, remove_all: bool = False, relax_assert:

if remove_all:
# We delete from indexes in two cases: (i) mark tx as voided, and (ii) remove tx.
# We only remove tx from all_tips and sorted_all when it is removed from the storage.
# For clarity, when a tx is marked as voided, it is not removed from all_tips and sorted_all.
self.all_tips.del_tx(tx, relax_assert=relax_assert)
# We only remove tx from sorted_all when it is removed from the storage.
# For clarity, when a tx is marked as voided, it is not removed from sorted_all.
self.sorted_all.del_tx(tx)
if self.addresses:
self.addresses.remove_tx(tx)
Expand All @@ -428,10 +412,8 @@ def del_tx(self, tx: BaseTransaction, *, remove_all: bool = False, relax_assert:
self.mempool_tips.update(tx, force_remove=True)

if tx.is_block:
self.block_tips.del_tx(tx, relax_assert=relax_assert)
self.sorted_blocks.del_tx(tx)
else:
self.tx_tips.del_tx(tx, relax_assert=relax_assert)
self.sorted_txs.del_tx(tx)

if self.tokens:
Expand All @@ -440,7 +422,6 @@ def del_tx(self, tx: BaseTransaction, *, remove_all: bool = False, relax_assert:

class RocksDBIndexesManager(IndexesManager):
def __init__(self, rocksdb_storage: 'RocksDBStorage', *, settings: HathorSettings) -> None:
from hathor.indexes.partial_rocksdb_tips_index import PartialRocksDBTipsIndex
from hathor.indexes.rocksdb_height_index import RocksDBHeightIndex
from hathor.indexes.rocksdb_info_index import RocksDBInfoIndex
from hathor.indexes.rocksdb_timestamp_index import RocksDBTimestampIndex
Expand All @@ -450,9 +431,6 @@ def __init__(self, rocksdb_storage: 'RocksDBStorage', *, settings: HathorSetting

self.info = RocksDBInfoIndex(self._db, settings=settings)
self.height = RocksDBHeightIndex(self._db, settings=settings)
self.all_tips = PartialRocksDBTipsIndex(self._db, scope_type=TipsScopeType.ALL, settings=settings)
self.block_tips = PartialRocksDBTipsIndex(self._db, scope_type=TipsScopeType.BLOCKS, settings=settings)
self.tx_tips = PartialRocksDBTipsIndex(self._db, scope_type=TipsScopeType.TXS, settings=settings)

self.sorted_all = RocksDBTimestampIndex(self._db, scope_type=TimestampScopeType.ALL, settings=settings)
self.sorted_blocks = RocksDBTimestampIndex(self._db, scope_type=TimestampScopeType.BLOCKS, settings=settings)
Expand Down
156 changes: 0 additions & 156 deletions hathor/indexes/memory_tips_index.py

This file was deleted.

5 changes: 3 additions & 2 deletions hathor/indexes/mempool_tips_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ def iter_all(self, tx_storage: 'TransactionStorage') -> Iterator[Transaction]:
def get(self) -> set[bytes]:
"""
Get the set of mempool tips indexed.

What to do with `get_tx_tips()`? They kind of do the same thing and it might be really confusing in the future.
"""
raise NotImplementedError

Expand All @@ -98,6 +96,9 @@ def init_loop_step(self, tx: BaseTransaction) -> None:
assert tx.hash is not None
assert tx.storage is not None
tx_meta = tx.get_metadata()
# do not include voided transactions
if tx_meta.voided_by:
return
# do not include transactions that have been confirmed
if tx_meta.first_block:
return
Expand Down
Loading
Loading