Skip to content

Commit 8537b32

Browse files
committed
loadtest: add BaseUni noop implementation
Since we're going to use the SimpleSyncer from the universe package, we need to make sure it remains lightweight and doesn't persist anything. That's why we create an empty implementation of the local diff engine and registrar, which performs a noop on all its methods, except for the RootNode call, which returns an empty leaf.
1 parent 3e0f877 commit 8537b32

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

itest/loadtest/utils.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ import (
1414
"github.com/btcsuite/btcd/rpcclient"
1515
tap "github.com/lightninglabs/taproot-assets"
1616
"github.com/lightninglabs/taproot-assets/cmd/commands"
17+
"github.com/lightninglabs/taproot-assets/fn"
1718
"github.com/lightninglabs/taproot-assets/itest"
19+
"github.com/lightninglabs/taproot-assets/mssmt"
1820
"github.com/lightninglabs/taproot-assets/taprpc"
1921
"github.com/lightninglabs/taproot-assets/taprpc/assetwalletrpc"
2022
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
2123
"github.com/lightninglabs/taproot-assets/taprpc/rfqrpc"
2224
tchrpc "github.com/lightninglabs/taproot-assets/taprpc/tapchannelrpc"
2325
"github.com/lightninglabs/taproot-assets/taprpc/tapdevrpc"
2426
"github.com/lightninglabs/taproot-assets/taprpc/universerpc"
27+
"github.com/lightninglabs/taproot-assets/universe"
2528
"github.com/lightningnetwork/lnd/lntest/rpc"
2629
"github.com/lightningnetwork/lnd/macaroons"
2730
"github.com/stretchr/testify/require"
@@ -311,3 +314,80 @@ func stringToAssetType(t string) taprpc.AssetType {
311314
return taprpc.AssetType_NORMAL
312315
}
313316
}
317+
318+
// noopBaseUni is a dummy implementation of the universe.DiffEngine and
319+
// universe.LocalRegistrar interfaces. This is meant to be used by the simple
320+
// syncer used in the sync loadtest. As we don't care about persistence and we
321+
// always want to do a full sync, we always return an empty root node to trigger
322+
// a sync.
323+
type noopBaseUni struct{}
324+
325+
// RootNode returns the root node of the base universe corresponding to the
326+
// passed ID.
327+
func (n noopBaseUni) RootNode(ctx context.Context,
328+
id universe.Identifier) (universe.Root, error) {
329+
330+
return universe.Root{
331+
Node: mssmt.EmptyLeafNode,
332+
}, nil
333+
}
334+
335+
// RootNodes returns the set of root nodes for all known base universes assets.
336+
func (n noopBaseUni) RootNodes(ctx context.Context,
337+
q universe.RootNodesQuery) ([]universe.Root, error) {
338+
339+
return nil, nil
340+
}
341+
342+
// MultiverseRoot returns the root node of the multiverse for the specified
343+
// proof type. If the given list of universe IDs is non-empty, then the root
344+
// will be calculated just for those universes.
345+
func (n *noopBaseUni) MultiverseRoot(ctx context.Context,
346+
proofType universe.ProofType,
347+
filterByIDs []universe.Identifier) (fn.Option[universe.MultiverseRoot],
348+
error) {
349+
350+
return fn.None[universe.MultiverseRoot](), nil
351+
}
352+
353+
// UpsertProofLeaf attempts to upsert a proof for an asset issuance or transfer
354+
// event. This method will return an error if the passed proof is invalid. If
355+
// the leaf is already known, then no action is taken and the existing
356+
// commitment proof returned.
357+
func (n noopBaseUni) UpsertProofLeaf(ctx context.Context,
358+
id universe.Identifier, key universe.LeafKey,
359+
leaf *universe.Leaf) (*universe.Proof, error) {
360+
361+
return nil, nil
362+
}
363+
364+
// UpsertProofLeafBatch inserts a batch of proof leaves within the target
365+
// universe tree. We assume the proofs within the batch have already been
366+
// checked that they don't yet exist in the local database.
367+
func (n noopBaseUni) UpsertProofLeafBatch(ctx context.Context,
368+
items []*universe.Item) error {
369+
370+
return nil
371+
}
372+
373+
// Close closes the noopBaseUni, stopping all goroutines and freeing all
374+
// resources.
375+
func (n noopBaseUni) Close() error {
376+
return nil
377+
}
378+
379+
// FetchProofLeaf attempts to fetch a proof leaf for the target leaf key
380+
// and given a universe identifier (assetID/groupKey).
381+
func (n noopBaseUni) FetchProofLeaf(ctx context.Context, id universe.Identifier,
382+
key universe.LeafKey) ([]*universe.Proof, error) {
383+
384+
return nil, nil
385+
}
386+
387+
// UniverseLeafKeys returns the set of leaf keys known for the specified
388+
// universe identifier.
389+
func (n noopBaseUni) UniverseLeafKeys(ctx context.Context,
390+
q universe.UniverseLeafKeysQuery) ([]universe.LeafKey, error) {
391+
392+
return nil, nil
393+
}

0 commit comments

Comments
 (0)