tapdb+universe: implement initial version of universe ignore tree#1420
tapdb+universe: implement initial version of universe ignore tree#1420ffranr merged 4 commits intolightninglabs:mainfrom
Conversation
9db6b54 to
9d067df
Compare
Pull Request Test Coverage Report for Build 14483915227Details
💛 - Coveralls |
2f50f47 to
11b67f8
Compare
|
Removed from draft. |
11b67f8 to
4a29c11
Compare
|
Pushed up a new version (CI was failing as we had two migration 30's). PTAL. |
|
@GeorgeTsagk: review reminder |
|
Will fix the collision issues in the burn tree PR. This is ready for review (no changes since my last push to fix CI after the rebase). |
guggero
left a comment
There was a problem hiding this comment.
Nice!
Most of my comments are around the SQL migration, the rest looks great.
Love all the rapid tests 💯
| timestamp TIMESTAMP NOT NULL, | ||
| attempt_counter BIGINT NOT NULL DEFAULT 0, | ||
| sync_direction TEXT NOT NULL CHECK(sync_direction IN ('push', 'pull')), | ||
| proof_leaf_id BIGINT NOT NULL, -- FK constraint intentionally omitted for now. |
There was a problem hiding this comment.
Instead of making yet another copy at the end, we could re-add the foreign key constraint to this table by using ALTER TABLE ADD FOREIGN KEY. That way we'd have a named constraint that we can just disable in the future.
The only downside is that it's not directly apparent on the table definition anymore...
And this table shouldn't be super large, so perhaps easier to just create it a couple of times, so just a thought.
There was a problem hiding this comment.
IIUC with sqlite, we can't do ALTER TABLE ADD FOREIGN KEY. We can only: rename a table/column, add/drop a table/column.
Need to revisit this, but the reason I needed to make a version w/o the constraint was that the migration fails otherwise either due to the rename of one of the tables above, or because we didn't update all the refs to point to the new version.
There was a problem hiding this comment.
Ah, yeah, SQLite doesn't support ALTER TABLE ... ADD CONSTRAINT: https://sqlite.org/omitted.html
| , event_timestamp BIGINT NOT NULL DEFAULT 0); | ||
|
|
||
| CREATE TABLE universe_leaves ( | ||
| CREATE TABLE "universe_leaves" ( |
There was a problem hiding this comment.
hmm, is this up-to-date? I wonder where the double quotes come from...
There was a problem hiding this comment.
Yeah not sure why that was added. The way the tool works, it just reads the schema directly from the meta table in sqlite itself...
Perhaps there was some formatting or extra white space in the migration that resulted in this? Will fiddle with it a bit.
There was a problem hiding this comment.
I feel as if "tuple" is used as a a bit of a filler word here. We haven't used the word "coin" much, but this might be the right time to use it.
IgnoreCoin, AddCoins(...),
// AddCoin adds a new coin to the ignore tree.
I think the programming rule of thumb is "Name the thing, not the container.", basically encapsulation which makes it cheaper to change the underlying data type if we ever need to.
Tuple as in: https://en.wikipedia.org/wiki/Tuple. It's not really a "coin" in the context we usually use that term within Bitcoin. |
4a29c11 to
5219a17
Compare
I think a term like “asset coin” could be useful. Or something similar, I'm not sure what the convention is around "coin". Basically a higher level term for an asset leaf in a Taproot Asset MS-SMT—something that conveys spendability. |
| // TupleQueryResp is the response to a query for ignore tuples. | ||
| type TupleQueryResp = lfn.Result[lfn.Option[[]AuthenticatedIgnoreTuple]] |
There was a problem hiding this comment.
Why include lfn.Option here? Wouldn't an empty slice signal the same thing as a None?
I think a similar sort of question can be asked for SumQueryResp below. I assume that if there are any leaves in the tree then the sum is always > 0, am I wrong? In which case None and 0 mean the same thing.
There was a problem hiding this comment.
I went back and forth a bit here: the None value makes it explicit when the query has no response value, while the empty slice is an implicit indicator.
I assume that if there are any leaves in the tree then the sum is always > 0, am I wrong? In which case None and 0 mean the same thing.
Same thing here re implicit vs explicit. If there's no tree, then a sum value isn't defined. An implicit interpretation is that if there's no tree, then the sum is zero.
I tend to prefer the explicit route.
f04a2a8 to
ee41b84
Compare
In this commit, we fix a bug in the existing final schema generation script to ensure it includes named indexes. From the sqlite docs: > The sqlite_schema.type column will be one of the following text strings: 'table', 'index', 'view', or 'trigger' according to the type of object defined. The 'table' string is used for both ordinary and virtual tables.
… table This commit introduces a new migration (Migration 30) that modifies the unique index on the `universe_leaves` table. The unique constraint is updated from two columns (`minting_point`, `script_key_bytes`) to three columns (`minting_point`, `script_key_bytes`, `leaf_node_namespace`). Additionally, a new test case, `TestMigration30`, is added to verify the behavior of the database before and after the migration. The test ensures that inserting a duplicate row with the same `minting_point` and `script_key_bytes` but a different `leaf_node_namespace` fails before the migration and succeeds after the migration is applied. Furthermore, the `universe_leaves` table schema is updated in the generated SQL schema file to reflect the new unique constraint. Other minor changes include the addition of new proof types in the `universe` package and the introduction of new types related to ignore tuples, enhancing the overall functionality of the codebase.
ee41b84 to
9668caa
Compare
| timestamp TIMESTAMP NOT NULL, | ||
| attempt_counter BIGINT NOT NULL DEFAULT 0, | ||
| sync_direction TEXT NOT NULL CHECK(sync_direction IN ('push', 'pull')), | ||
| proof_leaf_id BIGINT NOT NULL, -- FK constraint intentionally omitted for now. |
There was a problem hiding this comment.
Ah, yeah, SQLite doesn't support ALTER TABLE ... ADD CONSTRAINT: https://sqlite.org/omitted.html
In this PR, we implement the initial version of the universe Ignore Tree.
Along the way, we need a migration to the universe leaves, as the current unique index structure prevents us from adding two leaves that have the same script key, but distinct namespace (eg: transfer to a script key, then a burn of that).
With that in place, we're able to implement the ignore tree using the existing MS-SMT/Universe routines we already have in the database.
TODO