Skip to content

fix(sync-v2): Fix dependencies update for the first block #897

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

Merged
merged 1 commit into from
Dec 20, 2023
Merged
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
13 changes: 5 additions & 8 deletions hathor/p2p/sync_v2/transaction_streaming_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,18 @@ def _process_transaction(self, tx: BaseTransaction) -> Generator[Any, Any, None]
if tx.hash in self._db:
# This case might happen during a resume, so we just log and keep syncing.
self.log.debug('duplicated vertex received', tx_id=tx.hash.hex())
self.update_dependencies(tx)
self._update_dependencies(tx)
elif tx.hash in self._existing_deps:
# This case might happen if we already have the transaction from another sync.
self.log.debug('existing vertex received', tx_id=tx.hash.hex())
self.update_dependencies(tx)
self._update_dependencies(tx)
else:
self.log.info('unexpected vertex received', tx_id=tx.hash.hex())
self.fails(UnexpectedVertex(tx.hash.hex()))
return
self._waiting_for.remove(tx.hash)

self.update_dependencies(tx)
self._update_dependencies(tx)

self._db[tx.hash] = tx

Expand All @@ -194,7 +194,7 @@ def _process_transaction(self, tx: BaseTransaction) -> Generator[Any, Any, None]
if self._tx_received % 100 == 0:
self.log.debug('tx streaming in progress', txs_received=self._tx_received)

def update_dependencies(self, tx: BaseTransaction) -> None:
def _update_dependencies(self, tx: BaseTransaction) -> None:
"""Update _existing_deps and _waiting_for with the dependencies."""
for dep in tx.get_all_dependencies():
if self.tx_storage.transaction_exists(dep) or dep in self._db:
Expand Down Expand Up @@ -249,7 +249,4 @@ def _prepare_block(self, blk: 'Block') -> None:
self._db.clear()
self._existing_deps.clear()

# Add pending dependencies from block.
for dep in blk.get_all_dependencies():
if not self.tx_storage.transaction_exists(dep):
self._waiting_for.add(dep)
self._update_dependencies(blk)