-
Notifications
You must be signed in to change notification settings - Fork 132
tapdb: add implementation of supplycommit.SupplyTreeView #1507
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
base: asset-commitment-creator
Are you sure you want to change the base?
tapdb: add implementation of supplycommit.SupplyTreeView #1507
Conversation
7c88480
to
522c3ee
Compare
8d5041c
to
648cb72
Compare
d786104
to
af5f8f5
Compare
In this commit, we add new namespace routines for the supply tree. We'll use these to modify exactly which namespace we use for the ignore and burn trees. Rather than store using the old universe namespace, we choose to roll a new set of namespaces, as these trees are specific to a given group key.
…space directly In this commit, as a prep for the new universe supply tree routines, we refactor the InsertBurns method to rely on a new internal helper function. We also change the namespace we store things under to use the new supply tree namespaces. Finally, we fix a bug that would use different roots for the merkle tree proofs after insertion. We'll now ensure that the merkle tree proofs all use the same merkle root.
…pace Similar to the last commit, in this commit, we refactor the AddTuples method to use a new helper function. We then start to use the new supply tree namespace just like we did for the burn tree.
…ce directly In this commit, we update the helper functions that the ignore and burn tree use to take the namespace directly instead of the universe.Identifier. This makes the functions more flexible, as they don't assume a namespace derivation.
In this commit, we break up the singular universeUpsertProofLeaf function into two: one for inserting into the universe tree, and one for taking the updated universe root to insert into the multi-verse tree.
In this commit, we add a new migration for the universe supply trees. Rather than use the multi-verse pointers (which are namespaced by proof type), we instead move to use a new set of smt tree pointers, that are scoped by the group key instead. We'll use these later to keep track of the new supply sub-trees, and also root supply tree. We also add a new proof type of mint_supply, to distinguish from the normal issuance type.
In this commit, we add a concrete implementation of SupplyTreeStore in tapdb. This is similar to the structs we used to manage the multiverse tree, which is scoped by proof type. Instead, the supply trees are scoped by group key. We can use this to stage a series of updates for a group key (mint, ignore, burn), and insert into a supply tree in a single atomic transaction. We also expose methods to fetch each sub supply tree as well.
af5f8f5
to
64516c9
Compare
In this commit, we add tests for the supply tree store. We use rapid to ensure that we can handle any combiniation of events when we go to update them in the tree.
64516c9
to
6e0b6a4
Compare
6e0b6a4
to
aa782c8
Compare
@ffranr: review reminder |
id, err := specifierToIdentifier(spec, universe.ProofTypeBurn) | ||
if err != nil { | ||
return lfn.Err[lfn.Option[uint64]](err) | ||
groupKey := spec.UnwrapGroupKeyToPtr() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another possibility: spec.UnwrapGroupKeyOrErr
txErr := bt.db.ExecTx(ctx, &writeTx, func(db BaseUniverseStore) error { | ||
finalResults, err = insertBurnsInternal( | ||
ctx, db, spec, burnLeaves..., | ||
) | ||
|
||
// TODO(roasbeef): also update the root supply tree? | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect it probably would be best to update the supply tree root here also as the TODO suggests. Within the same db transaction. If not here then where?
// To insert the universe leaf below, we'll need both the db the | ||
// outpoint to be ignored. primary key for the asset genesis, | ||
// and also the raw bytes of | ||
assetGenID, err := db.FetchGenesisIDByAssetID( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfinished comment
scriptKey := ignoreTup.ScriptKey | ||
err = db.UpsertUniverseLeaf(ctx, UpsertUniverseLeaf{ | ||
AssetGenesisID: assetGenID, | ||
ScriptKeyBytes: scriptKey.SchnorrSerialized(), //nolint:lll |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//nolint:lll
unnecessary here
// addTuplesInternal performs the insertion of ignore tuples within a database | ||
// transaction. It also updates the main supply tree with the new ignore | ||
// sub-tree root. | ||
// | ||
// NOTE: This function must be called within a database transaction. | ||
func addTuplesInternal(ctx context.Context, db BaseUniverseStore, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this in the doc comment is not currently true for this function:
It also updates the main supply tree with the new ignore
// sub-tree root.
txErr := it.db.ExecTx(ctx, &writeTx, func(db BaseUniverseStore) error { | ||
finalResults, err = addTuplesInternal(ctx, db, spec, tuples...) | ||
return err | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider updating supply tree root here, similar to burn tree insertion
|
||
namespace := id.String() | ||
namespace string, proofTypeStr string, groupKey *btcec.PublicKey, | ||
key universe.LeafKey, leaf *universe.Leaf, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this commit doesn't compile, perhaps we should squash into another commit?
-- Reference to the root supply tree this leaf belongs to. | ||
supply_root_id BIGINT NOT NULL REFERENCES universe_supply_roots(id) ON DELETE CASCADE, | ||
|
||
-- The type of sub-tree this leaf represents (issuance, burn, ignore). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issuence
should be mint_supply
in this comment?
LeafNodeNamespace: subNs, | ||
}) | ||
if err != nil { | ||
fmt.Println("sub tree: ", subTreeType.String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fmt.Println
left over from debugging?
INSERT INTO proof_types (proof_type) VALUES ('burn'), ('ignore'), ('mint_supply') | ||
ON CONFLICT (proof_type) DO NOTHING; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also add a new proof type of mint_supply, to distinguish from the normal issuance type.
Is the new proof type (mint_supply
) necessary here? I thought we already added supply commit specific prefixes to the relevant namespaces? If true, then I think we could just reuse the issuance
proof type.
In this commit, we add an implementation of the
supplycommitment.SupplyTreeView
interface to tapdb. This provides us with a concrete interface to be used along side #1464.The structure is similar to the existing multi-verse trees, but we instead of scoping by proof type (issuance or transfer), we instead scope by the group key of a given asset.
Along the way we do some refactors to allow us to do atomic inserts across all the sub-trees, and also the root tree.