diff --git a/config.go b/config.go index fbc38e568..49c7f91ee 100644 --- a/config.go +++ b/config.go @@ -69,7 +69,7 @@ type DatabaseConfig struct { TapAddrBook *tapdb.TapAddressBook - Multiverse *tapdb.BaseMultiverse + Multiverse *tapdb.MultiverseStore FederationDB *tapdb.UniverseFederationDB } diff --git a/tapcfg/server.go b/tapcfg/server.go index de993e31d..d85c72b90 100644 --- a/tapcfg/server.go +++ b/tapcfg/server.go @@ -115,7 +115,7 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger, return db.WithTx(tx) }, ) - multiverse := tapdb.NewBaseMultiverse(multiverseDB) + multiverse := tapdb.NewMultiverseStore(multiverseDB) uniStatsDB := tapdb.NewTransactionExecutor( db, func(tx *sql.Tx) tapdb.UniverseStatsStore { diff --git a/tapdb/multiverse.go b/tapdb/multiverse.go index d6505770f..e403c25dd 100644 --- a/tapdb/multiverse.go +++ b/tapdb/multiverse.go @@ -52,10 +52,10 @@ type BatchedMultiverse interface { BatchedTx[BaseMultiverseStore] } -// BaseMultiverse implements the persistent storage for a multiverse. +// MultiverseStore implements the persistent storage for a multiverse. // -// NOTE: This implements the universe.BaseMultiverse interface. -type BaseMultiverse struct { +// NOTE: This implements the universe.MultiverseArchive interface. +type MultiverseStore struct { db BatchedMultiverse // TODO(roasbeef): actually the start of multiverse? @@ -63,16 +63,16 @@ type BaseMultiverse struct { // * drop base in front? } -// NewBaseMultiverse creates a new base multiverse. -func NewBaseMultiverse(db BatchedMultiverse) *BaseMultiverse { - return &BaseMultiverse{ +// NewMultiverseStore creates a new multiverse DB store handle. +func NewMultiverseStore(db BatchedMultiverse) *MultiverseStore { + return &MultiverseStore{ db: db, } } // RootNodes returns the complete set of known base universe root nodes for the // set of base universes tracked in the multiverse. -func (b *BaseMultiverse) RootNodes( +func (b *MultiverseStore) RootNodes( ctx context.Context) ([]universe.BaseRoot, error) { var ( @@ -152,11 +152,11 @@ func (b *BaseMultiverse) RootNodes( return uniRoots, nil } -// FetchIssuanceProof returns an issuance proof for the target key. If the key -// 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 *BaseMultiverse) FetchIssuanceProof(ctx context.Context, +// FetchProofLeaf returns a proof leaf for the target key. If the key +// doesn't have a script key specified, then all the proof leafs for the minting +// outpoint will be returned. If neither are specified, then all inserted proof +// leafs will be returned. +func (b *MultiverseStore) FetchProofLeaf(ctx context.Context, id universe.Identifier, universeKey universe.BaseKey) ([]*universe.IssuanceProof, error) { @@ -213,9 +213,9 @@ func (b *BaseMultiverse) FetchIssuanceProof(ctx context.Context, return proofs, nil } -// RegisterIssuance inserts a new minting leaf within the multiverse tree and -// the universe tree that corresponds to the given base key. -func (b *BaseMultiverse) RegisterIssuance(ctx context.Context, +// UpsertProofLeaf upserts a proof leaf within the multiverse tree and the +// universe tree that corresponds to the given key. +func (b *MultiverseStore) UpsertProofLeaf(ctx context.Context, id universe.Identifier, key universe.BaseKey, leaf *universe.MintingLeaf, metaReveal *proof.MetaReveal) (*universe.IssuanceProof, error) { @@ -297,7 +297,7 @@ func (b *BaseMultiverse) RegisterIssuance(ctx context.Context, // RegisterBatchIssuance inserts a new minting leaf batch within the multiverse // tree and the universe tree that corresponds to the given base key(s). -func (b *BaseMultiverse) RegisterBatchIssuance(ctx context.Context, +func (b *MultiverseStore) RegisterBatchIssuance(ctx context.Context, items []*universe.IssuanceItem) error { insertProof := func(item *universe.IssuanceItem, diff --git a/tapdb/universe_test.go b/tapdb/universe_test.go index e9e484d51..4ae13658c 100644 --- a/tapdb/universe_test.go +++ b/tapdb/universe_test.go @@ -400,7 +400,7 @@ func TestUniverseTreeIsolation(t *testing.T) { return db.WithTx(tx) }, ) - multiverse := NewBaseMultiverse(multiverseDB) + multiverse := NewMultiverseStore(multiverseDB) rootNodes, err := multiverse.RootNodes(ctx) require.NoError(t, err) diff --git a/universe/base.go b/universe/base.go index adc97415d..015fa8764 100644 --- a/universe/base.go +++ b/universe/base.go @@ -30,7 +30,7 @@ type MintingArchiveConfig struct { // Multiverse is used to interact with the set of known base // universe trees, and also obtain associated metadata and statistics. - Multiverse BaseMultiverse + Multiverse MultiverseArchive // UniverseStats is used to export statistics related to the set of // external/internal queries to the base universe instance. @@ -145,7 +145,7 @@ func (a *MintingArchive) RegisterIssuance(ctx context.Context, id Identifier, // We'll first check to see if we already know of this leaf within the // multiverse. If so, then we'll return the existing issuance proof. - issuanceProofs, err := a.cfg.Multiverse.FetchIssuanceProof(ctx, id, key) + issuanceProofs, err := a.cfg.Multiverse.FetchProofLeaf(ctx, id, key) switch { case err == nil && len(issuanceProofs) > 0: issuanceProof := issuanceProofs[0] @@ -193,7 +193,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.Multiverse.RegisterIssuance( + issuanceProof, err := a.cfg.Multiverse.UpsertProofLeaf( ctx, id, key, leaf, assetSnapshot.MetaReveal, ) if err != nil { @@ -390,7 +390,7 @@ func (a *MintingArchive) FetchIssuanceProof(ctx context.Context, id Identifier, }() }() - return a.cfg.Multiverse.FetchIssuanceProof(ctx, id, key) + return a.cfg.Multiverse.FetchProofLeaf(ctx, id, key) } // MintingKeys returns the set of minting keys known for the specified base diff --git a/universe/interface.go b/universe/interface.go index c521706a5..f7278cfee 100644 --- a/universe/interface.go +++ b/universe/interface.go @@ -234,18 +234,18 @@ type BaseRoot struct { GroupedAssets map[asset.ID]uint64 } -// BaseMultiverse is an interface used to keep track of the set of base universe +// MultiverseArchive is an interface used to keep track of the set of universe // roots that we know of. The BaseBackend interface is used to interact with a // particular base universe, while this is used to obtain aggregate information // about the universes. -type BaseMultiverse interface { +type MultiverseArchive interface { // RootNodes returns the complete set of known root nodes for the set // of assets tracked in the base Universe. RootNodes(ctx context.Context) ([]BaseRoot, error) - // RegisterIssuance inserts a new minting (issuance) leaf within the - // multiverse tree, stored at the given base key. - RegisterIssuance(ctx context.Context, id Identifier, key BaseKey, + // UpsertProofLeaf upserts a proof leaf within the multiverse tree and + // the universe tree that corresponds to the given key. + UpsertProofLeaf(ctx context.Context, id Identifier, key BaseKey, leaf *MintingLeaf, metaReveal *proof.MetaReveal) (*IssuanceProof, error) @@ -254,11 +254,11 @@ type BaseMultiverse interface { // base key(s). RegisterBatchIssuance(ctx context.Context, items []*IssuanceItem) error - // FetchIssuanceProof returns an issuance proof for the target key. If - // the key 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. - FetchIssuanceProof(ctx context.Context, id Identifier, + // FetchProofLeaf returns a proof leaf for the target key. If the key + // doesn't have a script key specified, then all the proof leafs for the + // minting outpoint will be returned. If neither are specified, then all + // inserted proof leafs will be returned. + FetchProofLeaf(ctx context.Context, id Identifier, key BaseKey) ([]*IssuanceProof, error) // TODO(roasbeef): other stats stuff here, like total number of assets, etc