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

multiverse: add overlay points for universe trees #624

Merged
merged 16 commits into from
Dec 13, 2023
Merged

Conversation

guggero
Copy link
Member

@guggero guggero commented Oct 25, 2023

Fixes #574.
Fixes #621.

Depends on the caching PR (not up yet).

@guggero guggero changed the title universe: add overlay points multiverse: add overlay points for universe trees Oct 25, 2023
@dstadulis dstadulis added this to the v0.3.1 milestone Oct 25, 2023
tapdb/sqlc/migrations/000010_multiverse_tree.up.sql Outdated Show resolved Hide resolved
tapdb/sqlc/queries/universe.sql Outdated Show resolved Hide resolved
tapdb/sqlc/migrations/000010_multiverse_tree.up.sql Outdated Show resolved Hide resolved
tapdb/universe.go Outdated Show resolved Hide resolved
@guggero
Copy link
Member Author

guggero commented Oct 26, 2023

Addressed all comments so far and added unit tests.
Main thing missing now are just the RPC methods.

@guggero guggero marked this pull request as ready for review October 27, 2023 16:04
@guggero
Copy link
Member Author

guggero commented Oct 27, 2023

Added RPCs and integration tests.
This now also fixes #621 I believe. Or did you have more specific functionality in mind for that, @Roasbeef?

universe/base.go Outdated
log.Debugf("Fetching multiverse root for proof type: %v", proofType)

leaveIDs, err := a.cfg.Multiverse.FetchMultiverseLeaves(
ctx, nil, nil, proofType,
Copy link
Member

Choose a reason for hiding this comment

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

Rather than fetch everything all the time, we can instead pass the identifier in (if they exist) and use db filtering for it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is resolved in the latest commits. I think what Roas says still makes sense here. I'll unresolve this conversation.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is now addressed with @Roasbeef's additional commits.

universe/base.go Outdated Show resolved Hide resolved
@Roasbeef
Copy link
Member

Roasbeef commented Nov 2, 2023

Will re-open this against my main branch. I think the only thing that needs to change is that: the leaf value for the multiverse tree is the root of a universe tree itself. So when we go to try and make the in memory version of the tree, we can just use the value directly (hash+sum).

@ffranr
Copy link
Contributor

ffranr commented Nov 3, 2023

I'm going to update the milestone for this PR to 0.3.2 because the issue it fixes has been moved to the 0.3.2 milestone.

@ffranr ffranr modified the milestones: v0.3.1, v0.3.2 Nov 3, 2023
@ffranr ffranr removed the v0.3.1 label Nov 3, 2023
@Roasbeef Roasbeef modified the milestones: v0.3.2, v0.4 Nov 6, 2023
@Roasbeef Roasbeef force-pushed the multiverse-trees branch 2 times, most recently from 0ac6a37 to acac981 Compare November 14, 2023 00:17
@Roasbeef Roasbeef requested review from ffranr and jharveyb and removed request for jharveyb November 14, 2023 03:09
@Roasbeef
Copy link
Member

@ffranr @jharveyb PTAL

@dstadulis
Copy link
Collaborator

Need to add another unit test that @jharveyb highlighted

@guggero
Copy link
Member Author

guggero commented Dec 5, 2023

Okay, updated unit test is in, this would now catch the issue with the unique index. Ready for final review.

@guggero guggero requested a review from jharveyb December 5, 2023 16:52
@dstadulis dstadulis assigned guggero and unassigned Roasbeef Dec 5, 2023
guggero and others added 15 commits December 12, 2023 17:19
This commit adds two new tables for the two multiverse trees we
currently have: multiverse_roots (will currently only contain two
entries, one for the issuance and one for the transfer multiverse roots)
and multiverse_leaves (which will contain an entry for each issuance and
proof universe we currently have).

We already have all information needed to fill these tables for existing
universes, so we can use conditional INSERT statements to create the
entries for all existing universes.
Any new universes will be added through the new upsert methods added.
Otherwise it conflicts with the new Option[T] type
By modifying this query we can simplify other logic as now we get the
full context which includes the value+sum of the SMT leaf. In this case,
the value is the universe root hash, and the sum the root sum.
This query will be used to fetch the multiverse leaf directly, without
first needing to make a temp SMT tree.
In this commit, we rename RootNode to MultiverseRootNode as we can
return multiple root types. We also modify the query to use the new
`FetchMultiverseRoot` method as well.
These will be used in the database to modify the existing
FetchMultiverseLeaves call to use a single DB query.
In this commit, we modify the FetchMultiverseLeaves method to allow it
to return either all the leaves, or a subset of leaves filtered by the
`MultiverseLeafDesc` type. In the future, we can further extend this to
use postgres batch queries so we can get the resp in a single round
trip.
In this commit, we modify the `MultiverseRoot` method to use a single DB
query. If we don't have anything to filter, then we'll fetch the global
root for that proof type.

Otherwise, we'll query the DB for the leaves that match the set of IDs,
then insert those into our in-memory tree.

This saves us N DB queries where N is the size of the set of Identifier.
@lightninglabs-deploy
Copy link

@Roasbeef: review reminder
@jharveyb: review reminder

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 🔧

@Roasbeef Roasbeef merged commit 7c0688e into main Dec 13, 2023
14 checks passed
@guggero guggero deleted the multiverse-trees branch December 13, 2023 08:06
@jharveyb
Copy link
Contributor

Post-merge approval 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: ✅ Done
6 participants