Skip to content
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

refactor(verification): externalize verification dependencies [part 1/2] #859

Conversation

glevco
Copy link
Contributor

@glevco glevco commented Nov 9, 2023

Depends on #896

Motivation

This PR introduces the concept of verification dependencies. Before, to perform verifications, it was necessary to retrieve data from the vertex itself and also from multiple other sources, for example from the TransactionStorage.

Now, instead of doing this dependency retrieval one by one, interspersed in the whole verification process, a single point retrieves all necessary dependencies and everything is verified from the vertex data plus those pre-calculated dependencies. This prevents unnecessary duplicate calculations, and will be necessary for the Multiprocess Verification project.

There are also some other side-benefits:

  • This is one step forward in completely removing the TransactionStorage from inside vertices.
  • Sync-v2 may verify vertices using dependencies from its memory instead of the TransactionStorage (as discussed here).
  • Improved typing and ergonomics of VerificationService methods.

Note: in this PR, not all ad-hoc dependencies have been moved yet. This will be completed in the next PR.

Acceptance Criteria

  • Create new verification dependency models that are pre-calculated before verification.
  • Update verifiers to use dependency models instead of directly accessing storage.
  • Add new auxiliary methods to SimpleMemoryStorage.

Checklist

  • If you are requesting a merge into master, confirm this code is production-ready and can be included in future releases as soon as it gets merged

@glevco glevco added the refactor label Nov 9, 2023
@glevco glevco self-assigned this Nov 9, 2023
Copy link

codecov bot commented Nov 9, 2023

Codecov Report

Attention: Patch coverage is 97.68786% with 4 lines in your changes are missing coverage. Please review.

❗ No coverage uploaded for pull request base (refactor/feature-activation/enable-usage@96c6ab0). Click here to learn what that means.

❗ Current head 2a6d4d0 differs from pull request most recent head 6578961. Consider uploading reports for the commit 6578961 to get more accurate results

Files Patch % Lines
...athor/transaction/storage/simple_memory_storage.py 94.00% 3 Missing ⚠️
hathor/verification/block_verifier.py 90.90% 1 Missing ⚠️
Additional details and impacted files
@@                             Coverage Diff                             @@
##             refactor/feature-activation/enable-usage     #859   +/-   ##
===========================================================================
  Coverage                                            ?   85.43%           
===========================================================================
  Files                                               ?      290           
  Lines                                               ?    22500           
  Branches                                            ?     3384           
===========================================================================
  Hits                                                ?    19222           
  Misses                                              ?     2609           
  Partials                                            ?      669           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@glevco glevco force-pushed the refactor/move-token-info branch from 8cff879 to a7635d4 Compare November 9, 2023 19:22
@glevco glevco force-pushed the refactor/verification-dependencies branch from 8c08e8c to 581399b Compare November 9, 2023 19:25
@glevco glevco force-pushed the refactor/move-token-info branch from a7635d4 to 1bef803 Compare November 9, 2023 19:28
@glevco glevco force-pushed the refactor/verification-dependencies branch from 581399b to a89dde8 Compare November 9, 2023 19:28
@glevco glevco force-pushed the refactor/verification-dependencies branch 2 times, most recently from 2da64c0 to 492f364 Compare November 9, 2023 20:12
@glevco glevco marked this pull request as ready for review November 9, 2023 20:34


@dataclass(frozen=True, slots=True, kw_only=True)
class VertexDependencies:
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 we can simplify it a lot by just implementing a simple memory database.

class SimpleMemoryDB:
    def __init__(self):
        self._db: Dict[VertexId, BaseTransaction] = {}

    def add_vertex(self, vertex: BaseTransaction) -> None:
        self._db[vertex.hash] = vertex

    def get_vertex(self, _id: VertexId) -> BaseTransaction:
        return self._db[_id]

It might have support for metadata too if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR was completely changed, so I recommend re-reviewing it. Indeed the SimpleMemoryDB was a good solution for tx parents and spent txs, and I implemented it. But I needed to keep the verification model abstractions for some other dependencies.

@glevco glevco marked this pull request as draft November 10, 2023 15:15
@glevco glevco force-pushed the refactor/move-token-info branch 3 times, most recently from 50171eb to 5693c13 Compare November 16, 2023 20:03
Base automatically changed from refactor/move-token-info to master November 16, 2023 21:21
@glevco glevco force-pushed the refactor/verification-dependencies branch 6 times, most recently from 2473e1b to b5266b2 Compare December 22, 2023 17:29
@glevco glevco changed the base branch from master to refactor/feature-activation/enable-usage December 22, 2023 17:30
@glevco glevco changed the title refactor(verification): implement verification dependencies refactor(verification): externalize verification dependencies Dec 22, 2023
@glevco glevco force-pushed the refactor/verification-dependencies branch from b5266b2 to 774ccf4 Compare December 22, 2023 20:22
@glevco glevco force-pushed the refactor/verification-dependencies branch from c8261f4 to 021a595 Compare January 11, 2024 23:54
@glevco glevco force-pushed the refactor/feature-activation/enable-usage branch from d0f339c to a73d566 Compare January 23, 2024 03:00
@glevco glevco force-pushed the refactor/verification-dependencies branch 2 times, most recently from 1618015 to 2a6d4d0 Compare January 23, 2024 03:04
@glevco glevco force-pushed the refactor/feature-activation/enable-usage branch 4 times, most recently from 4540afe to d82a5db Compare March 25, 2024 21:38
@glevco glevco force-pushed the refactor/verification-dependencies branch from 2a6d4d0 to 02efe61 Compare April 1, 2024 16:35
@glevco glevco requested review from jansegre and msbrogli April 1, 2024 16:36
@glevco
Copy link
Contributor Author

glevco commented Apr 1, 2024

@jansegre @msbrogli requested re-review after rebase with conflicts.

EDIT: I also added a new commit fixing a performance regression that I found.

@glevco glevco force-pushed the refactor/feature-activation/enable-usage branch from d82a5db to a12297b Compare April 3, 2024 23:39
@glevco glevco force-pushed the refactor/verification-dependencies branch from 02efe61 to 6397eb3 Compare April 3, 2024 23:39
@glevco glevco force-pushed the refactor/feature-activation/enable-usage branch from a12297b to eb0f05d Compare April 9, 2024 15:55
@glevco glevco force-pushed the refactor/verification-dependencies branch 2 times, most recently from 91f19c2 to 9e7caf3 Compare April 9, 2024 16:01
@glevco glevco force-pushed the refactor/feature-activation/enable-usage branch from eb0f05d to 43d2174 Compare April 17, 2024 00:33
@glevco glevco force-pushed the refactor/verification-dependencies branch from f156d96 to 6b0c206 Compare April 17, 2024 00:37
@glevco glevco force-pushed the refactor/feature-activation/enable-usage branch from 43d2174 to 3911dbf Compare May 2, 2024 22:47
@glevco glevco deleted the branch refactor/feature-activation/enable-usage May 3, 2024 20:43
@glevco glevco closed this May 3, 2024
@glevco glevco reopened this May 6, 2024
@glevco glevco force-pushed the refactor/feature-activation/enable-usage branch from 3911dbf to 96c6ab0 Compare May 6, 2024 00:15
@glevco glevco force-pushed the refactor/verification-dependencies branch from 6b0c206 to 6578961 Compare May 6, 2024 00:20
@glevco glevco deleted the branch refactor/feature-activation/enable-usage May 6, 2024 00:21
@glevco glevco closed this May 6, 2024
@glevco
Copy link
Contributor Author

glevco commented May 7, 2024

Moved to PRs #1022 and #1023.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants