-
Notifications
You must be signed in to change notification settings - Fork 132
universe+tapdb: add new block_height
field to universe_leaves
use that to implement block height based supply tree queries
#1596
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: main
Are you sure you want to change the base?
Conversation
tapdb/supply_tree.go
Outdated
// SupplyUpdate is a struct that holds a supply update event and its block | ||
// height. | ||
type SupplyUpdate struct { | ||
supplycommit.SupplyUpdateEvent | ||
BlockHeight uint32 | ||
} | ||
|
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.
supplycommit.SupplyUpdateEvent
already includes
// BlockHeight returns the block height of the update.
BlockHeight() uint32
so I don't think we need the separate BlockHeight uint32
field in SupplyUpdate
.
3e7ed65
to
c57d19d
Compare
c2c394f
to
b1173b9
Compare
c57d19d
to
bd5d0b4
Compare
b1173b9
to
c6f9962
Compare
bd5d0b4
to
37f23fa
Compare
c6f9962
to
da0df38
Compare
37f23fa
to
be0a52c
Compare
ee045a1
to
598067d
Compare
be0a52c
to
f2a69aa
Compare
f2a69aa
to
93ed469
Compare
598067d
to
9f03d81
Compare
93ed469
to
633373a
Compare
9f03d81
to
e77d0cf
Compare
633373a
to
3ca1517
Compare
e77d0cf
to
3044a87
Compare
3ca1517
to
988837b
Compare
3044a87
to
9854971
Compare
988837b
to
a9ef139
Compare
9854971
to
37bdcfa
Compare
a9ef139
to
ca7db9a
Compare
37bdcfa
to
b5a6c5e
Compare
ca7db9a
to
ec56941
Compare
b5a6c5e
to
c59b408
Compare
ec56941
to
16f9f9a
Compare
c59b408
to
99529ae
Compare
16f9f9a
to
059ed3f
Compare
99529ae
to
87ba694
Compare
In this commit, we add a migration to add a block_height to the universe leaf table. We'll use this in the future to be able to allow clients to sync block by block for the new supply universe trees.
059ed3f
to
5025c8c
Compare
Rebased. |
In this commit, we add a new method to the SupplyTreeStore that is able to read out the leaves of a supply tree based on a start and end height. This will be useful for writing the new syncing state machine and the sub-system that serves the supply tree syncer.
5025c8c
to
acafde1
Compare
Pull Request Test Coverage Report for Build 16040068155Details
💛 - Coveralls |
@ffranr: review reminder |
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.
Looks great! Got a couple of suggestions and the linter isn't fully happy yet. Other than that LGTM 🎉
blockHeight = lfn.Some(height) | ||
} | ||
|
||
sqlBlockHeight := lfn.MapOptionZ( |
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.
Looks like we already have a helper for this: sqlOptInt32
.
) ON CONFLICT (minting_point, script_key_bytes, leaf_node_namespace) | ||
-- This is a NOP, minting_point and script_key_bytes are the unique fields | ||
-- that caused the conflict. | ||
DO UPDATE SET minting_point = EXCLUDED.minting_point, | ||
script_key_bytes = EXCLUDED.script_key_bytes, | ||
leaf_node_namespace = EXCLUDED.leaf_node_namespace; | ||
leaf_node_namespace = EXCLUDED.leaf_node_namespace, | ||
block_height = EXCLUDED.block_height; |
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 invalidates the This is a NOP,
comment above! This would allow updating the block height specifically. Is that the intention? If yes, then we should update the comment.
// If the block height isn't specified, then we'll attempt to extract it | ||
// from the proof itself. | ||
if blockHeight.IsNone() { | ||
if leafProof.BlockHeight > 0 { |
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.
nit: could combine in a single &&
condition?
} | ||
} | ||
|
||
sqlBlockHeight := lfn.MapOptionZ( |
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.
nit: use sqlOptInt32
.
|
||
readTx := NewBaseUniverseReadTx() | ||
dbErr := s.db.ExecTx(ctx, &readTx, func(db BaseUniverseStore) error { | ||
for _, treeType := range []supplycommit.SupplySubTree{ |
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.
nit: feels like this would make a good package-level variable with the list of tree types we often iterate over? Would also help a bit with the formatting/readability.
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.
Pretty much there. One question on SQL query re-use.
-- name: QuerySupplyLeavesByHeight :many | ||
SELECT | ||
leaves.script_key_bytes, | ||
gen.gen_asset_id, | ||
nodes.value AS supply_leaf_bytes, | ||
nodes.sum AS sum_amt, | ||
gen.asset_id, | ||
leaves.block_height | ||
FROM universe_leaves AS leaves | ||
JOIN mssmt_nodes AS nodes | ||
ON leaves.leaf_node_key = nodes.key | ||
AND leaves.leaf_node_namespace = nodes.namespace |
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 already have a where
clause in QueryUniverseSupplyLeaves
. Instead of adding a new query here, can't we just extend QueryUniverseSupplyLeaves
with an optional block height?
In this PR, we add a new method
FetchSupplyLeavesByHeight
, that can be used to query for the leaves of a supply tree by height. This will be useful for writing the new syncing state machine and the sub-system that serves the supply tree syncer. Such a syncer would start from the initially created pre-commitment, then fetch all the leaves for the future updates, assemble those into the supply tree, then verify that everything matches up.Prompts used during development (aider+Gemini 2.5-pro-06-5)
Initial draft creation
Based on by working memory of this new feature, I scanned the relevant files, then made mental nodes of what needed to be updated. I then drafted this fairly detailed prompt that guided
aider
w.r.t which files to update, and the set of high level changes to make.Subsequent iterations
From here I made an edit or two to get things compiling. Then I executed a series of prompts to refine the code, refactor slightly, then add unit tests.
I messed when committing and dropped a commit entirely (lol), so I had
aider
re-add it: