Skip to content

Commit

Permalink
Merge pull request #447 from lightninglabs/rename-uni-forest
Browse files Browse the repository at this point in the history
Rename universe forest instances to multiverse
  • Loading branch information
ffranr authored Aug 14, 2023
2 parents 7077464 + 66f341b commit 5cd6878
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 58 deletions.
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type DatabaseConfig struct {

TapAddrBook *tapdb.TapAddressBook

UniverseForest *tapdb.BaseUniverseForest
Multiverse *tapdb.BaseMultiverse

FederationDB *tapdb.UniverseFederationDB
}
Expand Down
20 changes: 10 additions & 10 deletions tapcfg/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
return db.WithTx(tx)
},
)
uniForestDB := tapdb.NewTransactionExecutor(
db, func(tx *sql.Tx) tapdb.BaseUniverseForestStore {
multiverseDB := tapdb.NewTransactionExecutor(
db, func(tx *sql.Tx) tapdb.BaseMultiverseStore {
return db.WithTx(tx)
},
)
uniForest := tapdb.NewBaseUniverseForest(uniForestDB)
multiverse := tapdb.NewBaseMultiverse(multiverseDB)

uniStatsDB := tapdb.NewTransactionExecutor(
db, func(tx *sql.Tx) tapdb.UniverseStatsStore {
Expand All @@ -133,7 +133,7 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
)
},
HeaderVerifier: headerVerifier,
UniverseForest: uniForest,
Multiverse: multiverse,
UniverseStats: universeStats,
}

Expand Down Expand Up @@ -282,12 +282,12 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
UniverseStats: universeStats,
LogWriter: cfg.LogWriter,
DatabaseConfig: &tap.DatabaseConfig{
RootKeyStore: tapdb.NewRootKeyStore(rksDB),
MintingStore: assetMintingStore,
AssetStore: assetStore,
TapAddrBook: tapdbAddrBook,
UniverseForest: uniForest,
FederationDB: federationDB,
RootKeyStore: tapdb.NewRootKeyStore(rksDB),
MintingStore: assetMintingStore,
AssetStore: assetStore,
TapAddrBook: tapdbAddrBook,
Multiverse: multiverse,
FederationDB: federationDB,
},
}, nil
}
Expand Down
62 changes: 31 additions & 31 deletions tapdb/universe_forest.go → tapdb/multiverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,70 +18,70 @@ type (
BaseUniverseRoot = sqlc.UniverseRootsRow
)

// BaseUniverseForestStore is used to interact with a set of base universe
// roots, also known as a universe forest.
type BaseUniverseForestStore interface {
// BaseMultiverseStore is used to interact with a set of base universe
// roots, also known as a multiverse.
type BaseMultiverseStore interface {
BaseUniverseStore

UniverseRoots(ctx context.Context) ([]BaseUniverseRoot, error)
}

// BaseUniverseForestOptions is the set of options for universe grove queries.
type BaseUniverseForestOptions struct {
// BaseMultiverseOptions is the set of options for multiverse queries.
type BaseMultiverseOptions struct {
readOnly bool
}

// ReadOnly returns true if the transaction is read-only.
func (b *BaseUniverseForestOptions) ReadOnly() bool {
func (b *BaseMultiverseOptions) ReadOnly() bool {
return b.readOnly
}

// NewBaseUniverseForestReadTx creates a new read-only transaction for the
// universe forest.
func NewBaseUniverseForestReadTx() BaseUniverseForestOptions {
return BaseUniverseForestOptions{
// NewBaseMultiverseReadTx creates a new read-only transaction for the
// multiverse.
func NewBaseMultiverseReadTx() BaseMultiverseOptions {
return BaseMultiverseOptions{
readOnly: true,
}
}

// BatchedUniverseForest is a wrapper around the base universe forest that
// allows us to perform batch transactional database queries with all the
// relevant query interfaces.
type BatchedUniverseForest interface {
BaseUniverseForestStore
// BatchedMultiverse is a wrapper around the base multiverse that allows us to
// perform batch transactional database queries with all the relevant query
// interfaces.
type BatchedMultiverse interface {
BaseMultiverseStore

BatchedTx[BaseUniverseForestStore]
BatchedTx[BaseMultiverseStore]
}

// BaseUniverseForest implements the persistent storage for a universe forest.
// BaseMultiverse implements the persistent storage for a multiverse.
//
// NOTE: This implements the universe.BaseMultiverse interface.
type BaseUniverseForest struct {
db BatchedUniverseForest
type BaseMultiverse struct {
db BatchedMultiverse

// TODO(roasbeef): actually the start of multiverse?
// * mapping: assetID -> baseUniverseRoot => outpoint || scriptKey => transfer
// * drop base in front?
}

// NewBaseUniverseForest creates a new base universe forest.
func NewBaseUniverseForest(db BatchedUniverseForest) *BaseUniverseForest {
return &BaseUniverseForest{
// NewBaseMultiverse creates a new base multiverse.
func NewBaseMultiverse(db BatchedMultiverse) *BaseMultiverse {
return &BaseMultiverse{
db: db,
}
}

// RootNodes returns the complete set of known base universe root nodes for the
// set of base universes tracked in the universe forest.
func (b *BaseUniverseForest) RootNodes(
// set of base universes tracked in the multiverse.
func (b *BaseMultiverse) RootNodes(
ctx context.Context) ([]universe.BaseRoot, error) {

var (
uniRoots []universe.BaseRoot
readTx = NewBaseUniverseForestReadTx()
readTx = NewBaseMultiverseReadTx()
)

dbErr := b.db.ExecTx(ctx, &readTx, func(db BaseUniverseForestStore) error {
dbErr := b.db.ExecTx(ctx, &readTx, func(db BaseMultiverseStore) error {
dbRoots, err := db.UniverseRoots(ctx)
if err != nil {
return err
Expand Down Expand Up @@ -135,7 +135,7 @@ func (b *BaseUniverseForest) RootNodes(
// doesn't have a script key specified, then all the proofs for the minting
// outpoint will be returned. If neither are specified, then proofs for all the
// inserted leaves will be returned.
func (b *BaseUniverseForest) FetchIssuanceProof(ctx context.Context,
func (b *BaseMultiverse) FetchIssuanceProof(ctx context.Context,
id universe.Identifier,
universeKey universe.BaseKey) ([]*universe.IssuanceProof, error) {

Expand All @@ -144,7 +144,7 @@ func (b *BaseUniverseForest) FetchIssuanceProof(ctx context.Context,
proofs []*universe.IssuanceProof
)

dbErr := b.db.ExecTx(ctx, &readTx, func(dbTx BaseUniverseForestStore) error {
dbErr := b.db.ExecTx(ctx, &readTx, func(dbTx BaseMultiverseStore) error {
var err error
proofs, err = universeFetchIssuanceProof(
ctx, id, universeKey, dbTx,
Expand Down Expand Up @@ -194,17 +194,17 @@ func (b *BaseUniverseForest) FetchIssuanceProof(ctx context.Context,

// RegisterIssuance inserts a new minting leaf within the multiverse tree and
// the universe tree that corresponds to the given base key.
func (b *BaseUniverseForest) RegisterIssuance(ctx context.Context,
func (b *BaseMultiverse) RegisterIssuance(ctx context.Context,
id universe.Identifier, key universe.BaseKey,
leaf *universe.MintingLeaf,
metaReveal *proof.MetaReveal) (*universe.IssuanceProof, error) {

var (
writeTx BaseUniverseForestOptions
writeTx BaseMultiverseOptions
issuanceProof *universe.IssuanceProof
)

execTxFunc := func(dbTx BaseUniverseForestStore) error {
execTxFunc := func(dbTx BaseMultiverseStore) error {
// Register issuance in the asset (group) specific universe
// tree.
var (
Expand Down
16 changes: 8 additions & 8 deletions tapdb/universe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,16 +366,16 @@ func TestUniverseTreeIsolation(t *testing.T) {
require.Equal(t, groupLeaf.Leaf.Amt, groupRoot.NodeSum())
require.Equal(t, normalLeaf.Leaf.Amt, normalRoot.NodeSum())

// If we make a new Universe forest, then we should be able to fetch
// both the roots above.
forestDB := NewTransactionExecutor(db,
func(tx *sql.Tx) BaseUniverseForestStore {
// If we make a new multiverse, then we should be able to fetch both the
// roots above.
multiverseDB := NewTransactionExecutor(db,
func(tx *sql.Tx) BaseMultiverseStore {
return db.WithTx(tx)
},
)
universeForest := NewBaseUniverseForest(forestDB)
multiverse := NewBaseMultiverse(multiverseDB)

rootNodes, err := universeForest.RootNodes(ctx)
rootNodes, err := multiverse.RootNodes(ctx)
require.NoError(t, err)

// We should be able to find both of the roots we've inserted above.
Expand All @@ -401,8 +401,8 @@ func TestUniverseTreeIsolation(t *testing.T) {
require.Nil(t, normalRoot)
require.ErrorIs(t, err, universe.ErrNoUniverseRoot)

// The deleted universe should not be present in the universe forest.
rootNodes, err = universeForest.RootNodes(ctx)
// The deleted universe should not be present in the multiverse.
rootNodes, err = multiverse.RootNodes(ctx)
require.NoError(t, err)
require.Len(t, rootNodes, 1)
require.True(t, mssmt.IsEqualNode(rootNodes[0].Node, groupRoot))
Expand Down
15 changes: 7 additions & 8 deletions universe/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ type MintingArchiveConfig struct {
// genesis proof.
HeaderVerifier proof.HeaderVerifier

// UniverseForest is used to interact with the set of known base
// Multiverse is used to interact with the set of known base
// universe trees, and also obtain associated metadata and statistics.
UniverseForest BaseMultiverse
Multiverse BaseMultiverse

// UniverseStats is used to export statistics related to the set of
// external/internal queries to the base universe instance.
Expand Down Expand Up @@ -126,7 +126,7 @@ func (a *MintingArchive) RootNode(ctx context.Context,
func (a *MintingArchive) RootNodes(ctx context.Context) ([]BaseRoot, error) {
log.Debugf("Fetching all known Universe roots")

return a.cfg.UniverseForest.RootNodes(ctx)
return a.cfg.Multiverse.RootNodes(ctx)
}

// RegisterIssuance attempts to register a new issuance proof for a new minting
Expand All @@ -140,9 +140,8 @@ func (a *MintingArchive) RegisterIssuance(ctx context.Context, id Identifier,
id.StringForLog(), spew.Sdump(key))

// We'll first check to see if we already know of this leaf within the
// universe forest. If so, then we'll return the existing issuance
// proof.
issuanceProofs, err := a.cfg.UniverseForest.FetchIssuanceProof(
// multiverse. If so, then we'll return the existing issuance proof.
issuanceProofs, err := a.cfg.Multiverse.FetchIssuanceProof(
ctx, id, key,
)
switch {
Expand Down Expand Up @@ -213,7 +212,7 @@ func (a *MintingArchive) RegisterIssuance(ctx context.Context, id Identifier,

// Now that we know the proof is valid, we'll insert it into the base
// multiverse backend, and return the new issuance proof.
issuanceProof, err := a.cfg.UniverseForest.RegisterIssuance(
issuanceProof, err := a.cfg.Multiverse.RegisterIssuance(
ctx, id, key, leaf, assetSnapshot.MetaReveal,
)
if err != nil {
Expand Down Expand Up @@ -259,7 +258,7 @@ func (a *MintingArchive) FetchIssuanceProof(ctx context.Context, id Identifier,
}()
}()

return a.cfg.UniverseForest.FetchIssuanceProof(ctx, id, key)
return a.cfg.Multiverse.FetchIssuanceProof(ctx, id, key)
}

// MintingKeys returns the set of minting keys known for the specified base
Expand Down

0 comments on commit 5cd6878

Please sign in to comment.