Skip to content

Commit

Permalink
Merge pull request #584 from lightninglabs/fix-universe-group-roots
Browse files Browse the repository at this point in the history
tapdb: populate proof type when fetching uni roots
  • Loading branch information
Roasbeef authored Oct 14, 2023
2 parents 02ea446 + dde1006 commit 4208bc6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
18 changes: 9 additions & 9 deletions tapdb/multiverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ func (b *MultiverseStore) RootNodes(
groupedAssets map[asset.ID]uint64
)

// Parse universe proof type and populate the universe
// ID.
id.ProofType, err = universe.ParseStrProofType(
dbRoot.ProofType,
)
if err != nil {
return err
}

if dbRoot.AssetID != nil {
copy(id.AssetID[:], dbRoot.AssetID)
}
Expand Down Expand Up @@ -189,15 +198,6 @@ func (b *MultiverseStore) RootNodes(
}
}

// Parse universe proof type and populate the universe
// ID.
id.ProofType, err = universe.ParseStrProofType(
dbRoot.ProofType,
)
if err != nil {
return err
}

var nodeHash mssmt.NodeHash
copy(nodeHash[:], dbRoot.RootHash)
uniRoot := universe.BaseRoot{
Expand Down
34 changes: 32 additions & 2 deletions tapdb/universe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,16 @@ func TestUniverseTreeIsolation(t *testing.T) {

// For this test, we'll create two different Universes: one based on a
// group key, and the other with a plain asset ID.
idGroup := randUniverseID(t, true)
//
// One will be an issuance tree, while the other a transfer tree.
idGroup := randUniverseID(
t, true, withProofType(universe.ProofTypeIssuance),
)
groupUniverse, _ := newTestUniverseWithDb(db.BaseDB, idGroup)

idNormal := randUniverseID(t, false)
idNormal := randUniverseID(
t, false, withProofType(universe.ProofTypeTransfer),
)
normalUniverse, _ := newTestUniverseWithDb(db.BaseDB, idNormal)

// For each of the Universes, we'll now insert a random leaf that
Expand Down Expand Up @@ -473,6 +479,30 @@ func TestUniverseTreeIsolation(t *testing.T) {
return false
}))

// Similarly, each of the roots should have the proper proof type set.
require.True(t, fn.All(rootNodes, func(root universe.BaseRoot) bool {
switch root.ID.ProofType {
case universe.ProofTypeIssuance:
return mssmt.IsEqualNode(root.Node, groupRoot)
case universe.ProofTypeTransfer:
return mssmt.IsEqualNode(root.Node, normalRoot)
default:
return false
}
}))

// Finally, the grouped root should have the GroupedAssets field
// properly set.
for _, root := range rootNodes {
if mssmt.IsEqualNode(root.Node, groupRoot) {
require.True(t, len(root.GroupedAssets) != 0)

groupAmt, ok := root.GroupedAssets[groupLeaf.Leaf.ID()]
require.True(t, ok)
require.Equal(t, groupLeaf.Leaf.Amt, groupAmt)
}
}

// We should be able to delete one Universe with no effect on the other.
normalNamespace, err := normalUniverse.DeleteUniverse(ctx)
require.NoError(t, err)
Expand Down

0 comments on commit 4208bc6

Please sign in to comment.