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
2 changes: 0 additions & 2 deletions hathor/cli/run_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ def register_resources(self, args: Namespace) -> None:
GraphvizNeighboursResource,
PushTxResource,
SubmitBlockResource,
TipsHistogramResource,
TransactionAccWeightResource,
TransactionResource,
TxParentsResource,
Expand Down Expand Up @@ -374,7 +373,6 @@ def register_resources(self, args: Namespace) -> None:
PushTxResource(self.manager, args.max_output_script_size, args.allow_non_standard_script),
root),
(b'graphviz', graphviz, root),
(b'tips-histogram', TipsHistogramResource(self.manager), root),
(b'transaction', TransactionResource(self.manager), root),
(b'transaction_acc_weight', TransactionAccWeightResource(self.manager), root),
(b'dashboard_tx', DashboardTransactionResource(self.manager), root),
Expand Down
18 changes: 14 additions & 4 deletions hathor/consensus.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def update_voided_info(self, block: Block) -> None:
meta = block.get_metadata()
if not meta.voided_by:
storage._best_block_tips = [block.hash]
storage.add_new_to_block_height_index(meta.height, block.hash)
# The following assert must be true, but it is commented out for performance reasons.
# assert len(storage.get_best_block_tips(skip_cache=True)) == 1
else:
Expand Down Expand Up @@ -242,8 +243,17 @@ def update_voided_info(self, block: Block) -> None:
meta = block.get_metadata()
if not meta.voided_by:
storage._best_block_tips = [block.hash]
self.log.debug('index new winner block', height=meta.height, block=block.hash_hex)
# We update the height cache index with the new winner chain
storage.update_block_height_cache_new_chain(meta.height, block)
else:
storage._best_block_tips = [blk.hash for blk in heads]
# XXX Is it safe to select one of the heads?
best_block = heads[0]
assert best_block.hash is not None
best_meta = best_block.get_metadata()
self.log.debug('index previous best block', height=best_meta.height, block=best_block.hash_hex)
storage.add_new_to_block_height_index(best_meta.height, best_block.hash)

# Uncomment the following lines to check that the cache update is working properly.
# You shouldn't run this test in production because it dampens performance.
Expand Down Expand Up @@ -286,7 +296,7 @@ def update_voided_by_from_parents(self, block: Block) -> bool:
else:
meta.voided_by = voided_by.copy()
block.storage.save_transaction(block, only_metadata=True)
block.storage._del_from_cache(block, relax_assert=True) # XXX: accessing private method
block.storage.del_from_indexes(block, relax_assert=True)
return True
return False

Expand Down Expand Up @@ -735,7 +745,7 @@ def update_voided_info(self, tx: Transaction) -> None:
if voided_by:
meta.voided_by = voided_by.copy()
tx.storage.save_transaction(tx, only_metadata=True)
tx.storage._del_from_cache(tx) # XXX: accessing private method
tx.storage.del_from_indexes(tx)

# Check conflicts of the transactions voiding us.
for h in voided_by:
Expand Down Expand Up @@ -853,7 +863,7 @@ def remove_voided_by(self, tx: Transaction, voided_hash: bytes) -> bool:
tx2.storage.save_transaction(tx2, only_metadata=True)
if not meta.voided_by:
meta.voided_by = None
tx.storage._add_to_cache(tx2) # XXX: accessing private method
tx.storage.add_to_indexes(tx2)

from hathor.transaction import Transaction
for tx2 in check_list:
Expand Down Expand Up @@ -912,7 +922,7 @@ def add_voided_by(self, tx: Transaction, voided_hash: bytes) -> bool:
# All voided transactions with conflicts must have their accumulated weight calculated.
tx2.update_accumulated_weight(save_file=False)
tx2.storage.save_transaction(tx2, only_metadata=True)
tx2.storage._del_from_cache(tx2, relax_assert=True) # XXX: accessing private method
tx2.storage.del_from_indexes(tx2, relax_assert=True)

for tx2 in check_list:
self.check_conflicts(tx2)
Expand Down
4 changes: 4 additions & 0 deletions hathor/daa.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@
from math import log
from typing import TYPE_CHECKING, List

from structlog import get_logger

from hathor.conf import HathorSettings
from hathor.profiler import get_cpu_profiler
from hathor.util import iwindows

if TYPE_CHECKING:
from hathor.transaction import Block, Transaction

logger = get_logger()
settings = HathorSettings()
cpu = get_cpu_profiler()

Expand All @@ -49,6 +52,7 @@ class TestMode(IntFlag):

def _set_test_mode(mode: TestMode) -> None:
global TEST_MODE
logger.debug('change DAA test mode', from_mode=TEST_MODE.name, to_mode=mode.name)
TEST_MODE = mode


Expand Down
Loading