Skip to content
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

Generalise multiverse method names to support all proofs. #496

Merged
merged 6 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type DatabaseConfig struct {

TapAddrBook *tapdb.TapAddressBook

Multiverse *tapdb.BaseMultiverse
Multiverse *tapdb.MultiverseStore

FederationDB *tapdb.UniverseFederationDB
}
Expand Down
2 changes: 1 addition & 1 deletion itest/tapd_harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const (
// defaultProofTransferReceiverAckTimeout is the default itest specific
// timeout we'll use for waiting for a receiver to acknowledge a proof
// transfer.
defaultProofTransferReceiverAckTimeout = 5 * time.Second
defaultProofTransferReceiverAckTimeout = 15 * time.Second
)

// tapdHarness is a test harness that holds everything that is needed to
Expand Down
2 changes: 1 addition & 1 deletion tapcfg/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
32 changes: 16 additions & 16 deletions tapdb/multiverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,27 @@ 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?
// * mapping: assetID -> baseUniverseRoot => outpoint || scriptKey => transfer
// * 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 (
Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tapdb/universe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions universe/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -347,7 +347,7 @@ func (a *MintingArchive) getPrevAssetSnapshot(ctx context.Context,
ScriptKey: &prevScriptKey,
}

prevProofs, err := a.cfg.Multiverse.FetchIssuanceProof(
prevProofs, err := a.cfg.Multiverse.FetchProofLeaf(
ctx, uniID, prevBaseKey,
)
if err != nil {
Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions universe/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down