Skip to content

fix: Fix rare conditions captured by random simulations #283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

msbrogli
Copy link
Member

No description provided.

@msbrogli msbrogli added the bug Something isn't working label Jul 30, 2021
@msbrogli msbrogli self-assigned this Jul 30, 2021
@msbrogli msbrogli force-pushed the fix/tests-simulator branch 3 times, most recently from 20fb9a8 to 568a6ea Compare July 30, 2021 11:19
@msbrogli msbrogli force-pushed the fix/tests-simulator branch from 568a6ea to e5dddc4 Compare July 30, 2021 11:25
@codecov
Copy link

codecov bot commented Jul 30, 2021

Codecov Report

Merging #283 (e5dddc4) into dev (eac9d82) will increase coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #283      +/-   ##
==========================================
+ Coverage   82.16%   82.21%   +0.05%     
==========================================
  Files         152      152              
  Lines       14408    14423      +15     
  Branches     2056     2061       +5     
==========================================
+ Hits        11838    11858      +20     
  Misses       2132     2132              
+ Partials      438      433       -5     
Impacted Files Coverage Δ
hathor/consensus.py 93.89% <100.00%> (+0.40%) ⬆️
hathor/indexes.py 93.20% <100.00%> (-0.88%) ⬇️
hathor/p2p/node_sync.py 84.42% <100.00%> (+1.25%) ⬆️
hathor/transaction/storage/transaction_storage.py 87.72% <100.00%> (+0.31%) ⬆️
hathor/p2p/manager.py 69.16% <0.00%> (-1.25%) ⬇️
hathor/simulator/simulator.py 93.89% <0.00%> (+2.29%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cee7191...e5dddc4. Read the comment docs.

pedroferreira1
pedroferreira1 previously approved these changes Aug 2, 2021
if not self.with_index:
raise NotImplementedError
assert self.block_index is not None
assert self.tx_index is not None
if self.tokens_index:
self.tokens_index.del_tx(tx)
if tx.is_block:
self._cache_block_count -= 1
self.block_index.del_tx(tx, relax_assert=relax_assert)
# This is the code to remove the block from the indexes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might get confusing here when we should set del_blocks=True. If I understood correctly, only when you want to completely remove the block from the storage is when you should set it, right? Or is there any other situation? Maybe we could have this as a comment just to prevent mistakes

I am saying that because on the consensus file we are not using del_blocks=True and on remove_transaction we are. Instead of re-reading all places to understand the reasoning behind, we could just write here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this information adds anything: as far as I know there is only one case in practice where a fullnode will remove a transaction by itself (that is without you opening a shell and doing it manually), it is when there is a re-org that changes the reward-lock validity of a transaction. In all other cases the uses of remove_transaction are artificial which are basically used in tests.

@luislhl luislhl changed the base branch from dev to master April 24, 2023 11:50
@luislhl luislhl dismissed pedroferreira1’s stale review April 24, 2023 11:50

The base branch was changed.

@@ -59,14 +59,16 @@ def add_tx(self, tx: BaseTransaction) -> bool:
assert r1 == r2
return r1

def del_tx(self, tx: BaseTransaction, *, relax_assert: bool = False) -> None:
def del_tx(self, tx: BaseTransaction, *, relax_assert: bool = False) -> bool:
""" Delete a transaction from the indexes

:param tx: Transaction to be deleted
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update docstring with meaning the return value.

@@ -161,15 +163,15 @@ def add_tx(self, tx: BaseTransaction) -> bool:
self.tx_last_interval[tx.hash] = interval
return True

def del_tx(self, tx: BaseTransaction, *, relax_assert: bool = False) -> None:
def del_tx(self, tx: BaseTransaction, *, relax_assert: bool = False) -> bool:
""" Remove a transaction from the index.
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update docstring with meaning the return value.

@@ -293,14 +297,16 @@ def add_tx(self, tx: BaseTransaction) -> bool:
self.transactions.add(element)
return True

def del_tx(self, tx: BaseTransaction) -> None:
def del_tx(self, tx: BaseTransaction) -> bool:
""" Delete a transaction from the index

:param tx: Transaction to be deleted
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update docstring with meaning the return value.

# without going through the whole download.
for deferred in pending:
yield deferred
pending = WeakSet()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it slightly better to do pending.clear() to avoid an allocation and having to wait for the GC to collect the previous set?

# block rewards.
if del_blocks:
if self.block_index.del_tx(tx, relax_assert=relax_assert):
self._cache_block_count -= 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we still using tx_storage.tx_index, tx_storage.block_index or tx_storage.all_index? I just checked and apparently there's only some leftover references from before the last refactor, and they use hasattr, so the code wouldn't even be running currently. Is this really the case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants