From 39efa48b52513036b0f74fd3ed78b17f51f5a6f9 Mon Sep 17 00:00:00 2001 From: ffranr Date: Tue, 26 Sep 2023 14:41:55 +0100 Subject: [PATCH 01/16] multi: rename universe.BaseKey into universe.LeafKey --- rpcserver.go | 6 +++--- tapdb/multiverse.go | 4 ++-- tapdb/universe.go | 16 ++++++++-------- tapdb/universe_stats.go | 4 ++-- tapdb/universe_test.go | 18 +++++++++--------- tapgarden/caretaker.go | 2 +- tapgarden/planter.go | 2 +- universe/auto_syncer.go | 6 +++--- universe/base.go | 12 ++++++------ universe/interface.go | 38 +++++++++++++++++++------------------- universe/syncer.go | 2 +- universe_rpc_diff.go | 6 +++--- universe_rpc_registrar.go | 2 +- 13 files changed, 59 insertions(+), 59 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index 3f8a5e303..f89e5d05f 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -2628,7 +2628,7 @@ func (r *rpcServer) DeleteAssetRoot(ctx context.Context, return &unirpc.DeleteRootResponse{}, nil } -func marshalLeafKey(leafKey universe.BaseKey) *unirpc.AssetKey { +func marshalLeafKey(leafKey universe.LeafKey) *unirpc.AssetKey { return &unirpc.AssetKey{ Outpoint: &unirpc.AssetKey_OpStr{ OpStr: leafKey.MintingOutpoint.String(), @@ -2765,9 +2765,9 @@ func UnmarshalOutpoint(outpoint string) (*wire.OutPoint, error) { } // unmarshalLeafKey unmarshals a leaf key from the RPC form. -func unmarshalLeafKey(key *unirpc.AssetKey) (universe.BaseKey, error) { +func unmarshalLeafKey(key *unirpc.AssetKey) (universe.LeafKey, error) { var ( - baseKey universe.BaseKey + baseKey universe.LeafKey err error ) diff --git a/tapdb/multiverse.go b/tapdb/multiverse.go index e403c25dd..2864c488b 100644 --- a/tapdb/multiverse.go +++ b/tapdb/multiverse.go @@ -158,7 +158,7 @@ func (b *MultiverseStore) RootNodes( // leafs will be returned. func (b *MultiverseStore) FetchProofLeaf(ctx context.Context, id universe.Identifier, - universeKey universe.BaseKey) ([]*universe.IssuanceProof, error) { + universeKey universe.LeafKey) ([]*universe.IssuanceProof, error) { var ( readTx = NewBaseUniverseReadTx() @@ -216,7 +216,7 @@ func (b *MultiverseStore) FetchProofLeaf(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, + id universe.Identifier, key universe.LeafKey, leaf *universe.MintingLeaf, metaReveal *proof.MetaReveal) (*universe.IssuanceProof, error) { diff --git a/tapdb/universe.go b/tapdb/universe.go index 1d081fb15..4b440a4ce 100644 --- a/tapdb/universe.go +++ b/tapdb/universe.go @@ -279,7 +279,7 @@ func upsertAssetGen(ctx context.Context, db UpsertAssetStore, // RegisterIssuance inserts a new minting leaf within the universe tree, stored // at the base key. func (b *BaseUniverseTree) RegisterIssuance(ctx context.Context, - key universe.BaseKey, leaf *universe.MintingLeaf, + key universe.LeafKey, leaf *universe.MintingLeaf, metaReveal *proof.MetaReveal) (*universe.IssuanceProof, error) { var ( @@ -310,7 +310,7 @@ func (b *BaseUniverseTree) RegisterIssuance(ctx context.Context, // NOTE: This function accepts a db transaction, as it's used when making // broader DB updates. func universeRegisterIssuance(ctx context.Context, dbTx BaseUniverseStore, - id universe.Identifier, key universe.BaseKey, + id universe.Identifier, key universe.LeafKey, leaf *universe.MintingLeaf, metaReveal *proof.MetaReveal) (*universe.IssuanceProof, mssmt.Node, error) { @@ -426,7 +426,7 @@ func universeRegisterIssuance(ctx context.Context, dbTx BaseUniverseStore, // outpoint will be returned. If neither are specified, then proofs for all the // inserted leaves will be returned. func (b *BaseUniverseTree) FetchIssuanceProof(ctx context.Context, - universeKey universe.BaseKey) ([]*universe.IssuanceProof, error) { + universeKey universe.LeafKey) ([]*universe.IssuanceProof, error) { var ( readTx = NewBaseUniverseReadTx() @@ -455,7 +455,7 @@ func (b *BaseUniverseTree) FetchIssuanceProof(ctx context.Context, // NOTE: This function accepts a database transaction and is called when making // broader DB updates. func universeFetchIssuanceProof(ctx context.Context, - id universe.Identifier, universeKey universe.BaseKey, + id universe.Identifier, universeKey universe.LeafKey, dbTx BaseUniverseStore) ([]*universe.IssuanceProof, error) { namespace := id.String() @@ -521,7 +521,7 @@ func universeFetchIssuanceProof(ctx context.Context, // Next, we'll fetch the leaf node from the tree and also obtain // a merkle proof for the leaf alongside it. - universeKey := universe.BaseKey{ + universeKey := universe.LeafKey{ MintingOutpoint: universeKey.MintingOutpoint, ScriptKey: &scriptKey, } @@ -585,9 +585,9 @@ func universeFetchIssuanceProof(ctx context.Context, // MintingKeys returns all the keys inserted in the universe. func (b *BaseUniverseTree) MintingKeys(ctx context.Context, -) ([]universe.BaseKey, error) { +) ([]universe.LeafKey, error) { - var baseKeys []universe.BaseKey + var baseKeys []universe.LeafKey readTx := NewBaseUniverseReadTx() dbErr := b.db.ExecTx(ctx, &readTx, func(db BaseUniverseStore) error { @@ -614,7 +614,7 @@ func (b *BaseUniverseTree) MintingKeys(ctx context.Context, return err } - baseKeys = append(baseKeys, universe.BaseKey{ + baseKeys = append(baseKeys, universe.LeafKey{ MintingOutpoint: genPoint, ScriptKey: &scriptKey, }) diff --git a/tapdb/universe_stats.go b/tapdb/universe_stats.go index a558085f6..081489f09 100644 --- a/tapdb/universe_stats.go +++ b/tapdb/universe_stats.go @@ -127,7 +127,7 @@ func NewUniverseStats(db BatchedUniverseStats, // LogSyncEvent logs a sync event for the target universe. func (u *UniverseStats) LogSyncEvent(ctx context.Context, - uniID universe.Identifier, key universe.BaseKey) error { + uniID universe.Identifier, key universe.LeafKey) error { var writeTxOpts UniverseStatsOptions return u.db.ExecTx(ctx, &writeTxOpts, func(db UniverseStatsStore) error { @@ -178,7 +178,7 @@ func (u *UniverseStats) LogSyncEvents(ctx context.Context, // LogNewProofEvent logs a new proof insertion event for the target universe. func (u *UniverseStats) LogNewProofEvent(ctx context.Context, - uniID universe.Identifier, key universe.BaseKey) error { + uniID universe.Identifier, key universe.LeafKey) error { var writeTxOpts UniverseStatsOptions return u.db.ExecTx(ctx, &writeTxOpts, func(db UniverseStatsStore) error { diff --git a/tapdb/universe_test.go b/tapdb/universe_test.go index 4ae13658c..8ffe8850f 100644 --- a/tapdb/universe_test.go +++ b/tapdb/universe_test.go @@ -77,8 +77,8 @@ func TestUniverseEmptyTree(t *testing.T) { require.ErrorIs(t, err, universe.ErrNoUniverseRoot) } -func randBaseKey(t *testing.T) universe.BaseKey { - return universe.BaseKey{ +func randBaseKey(t *testing.T) universe.LeafKey { + return universe.LeafKey{ MintingOutpoint: test.RandOp(t), ScriptKey: fn.Ptr( asset.NewScriptKey(test.RandPubKey(t)), @@ -127,7 +127,7 @@ func randMintingLeaf(t *testing.T, assetGen asset.Genesis, // leaWithKey is a two tuple that associates new minting leaf with a key. type leafWithKey struct { - universe.BaseKey + universe.LeafKey universe.MintingLeaf } @@ -166,7 +166,7 @@ func TestUniverseIssuanceProofs(t *testing.T) { // Each new leaf should add to the accumulated sum. leafSum += testLeaf.Amt - targetKey := testLeaf.BaseKey + targetKey := testLeaf.LeafKey leaf := testLeaf.MintingLeaf issuanceProof, err := baseUniverse.RegisterIssuance( @@ -228,9 +228,9 @@ func TestUniverseIssuanceProofs(t *testing.T) { require.Equal(t, numLeaves, len(mintingKeys)) // The set of leaves we created above should match what was returned. - require.True(t, fn.All(mintingKeys, func(key universe.BaseKey) bool { + require.True(t, fn.All(mintingKeys, func(key universe.LeafKey) bool { return fn.Any(testLeaves, func(testLeaf leafWithKey) bool { - return reflect.DeepEqual(key, testLeaf.BaseKey) + return reflect.DeepEqual(key, testLeaf.LeafKey) }) })) @@ -257,7 +257,7 @@ func TestUniverseIssuanceProofs(t *testing.T) { testLeaf := &testLeaves[idx] testLeaf.MintingLeaf.GenesisProof = randProof(t) - targetKey := testLeaf.BaseKey + targetKey := testLeaf.LeafKey issuanceProof, err := baseUniverse.RegisterIssuance( ctx, targetKey, &testLeaf.MintingLeaf, nil, ) @@ -472,7 +472,7 @@ func TestUniverseLeafQuery(t *testing.T) { // If we query for only the minting point, then all three leaves should // be returned. - proofs, err := baseUniverse.FetchIssuanceProof(ctx, universe.BaseKey{ + proofs, err := baseUniverse.FetchIssuanceProof(ctx, universe.LeafKey{ MintingOutpoint: rootMintingPoint, }) require.NoError(t, err) @@ -484,7 +484,7 @@ func TestUniverseLeafQuery(t *testing.T) { scriptKey, err := btcec.ParsePubKey(scriptKeyBytes[:]) require.NoError(t, err) - p, err := baseUniverse.FetchIssuanceProof(ctx, universe.BaseKey{ + p, err := baseUniverse.FetchIssuanceProof(ctx, universe.LeafKey{ MintingOutpoint: rootMintingPoint, ScriptKey: &asset.ScriptKey{ PubKey: scriptKey, diff --git a/tapgarden/caretaker.go b/tapgarden/caretaker.go index 3054fbd51..23850e61f 100644 --- a/tapgarden/caretaker.go +++ b/tapgarden/caretaker.go @@ -1046,7 +1046,7 @@ func (b *BatchCaretaker) storeMintingProof(ctx context.Context, // The base key is the set of bytes that keys into the universe, this'll // be the outpoint where it was created at and the script key for that // asset. - baseKey := universe.BaseKey{ + baseKey := universe.LeafKey{ MintingOutpoint: wire.OutPoint{ Hash: mintTxHash, Index: b.anchorOutputIndex, diff --git a/tapgarden/planter.go b/tapgarden/planter.go index 9f083f267..815bd3ceb 100644 --- a/tapgarden/planter.go +++ b/tapgarden/planter.go @@ -880,7 +880,7 @@ func (c *ChainPlanter) updateMintingProofs(proofs []*proof.Proof) error { // The base key is the set of bytes that keys into the universe, // this'll be the outpoint where it was created at and the // script key for that asset. - baseKey := universe.BaseKey{ + baseKey := universe.LeafKey{ MintingOutpoint: wire.OutPoint{ Hash: p.AnchorTx.TxHash(), Index: p.InclusionProof.OutputIndex, diff --git a/universe/auto_syncer.go b/universe/auto_syncer.go index 503f162dc..2ec10bfaa 100644 --- a/universe/auto_syncer.go +++ b/universe/auto_syncer.go @@ -64,7 +64,7 @@ type FederationPushReq struct { // Key is the leaf key in the Universe that the new leaf should be // added to. - Key BaseKey + Key LeafKey // Leaf is the new leaf to add. Leaf *MintingLeaf @@ -225,7 +225,7 @@ func (f *FederationEnvoy) syncUniverseState(ctx context.Context, // pushProofToFederation attempts to push out a new proof to the current // federation in parallel. -func (f *FederationEnvoy) pushProofToFederation(uniID Identifier, key BaseKey, +func (f *FederationEnvoy) pushProofToFederation(uniID Identifier, key LeafKey, leaf *MintingLeaf) { ctx, cancel := f.WithCtxQuit() @@ -419,7 +419,7 @@ func (f *FederationEnvoy) syncer() { // // NOTE: This is part of the universe.Registrar interface. func (f *FederationEnvoy) RegisterIssuance(_ context.Context, id Identifier, - key BaseKey, leaf *MintingLeaf) (*IssuanceProof, error) { + key LeafKey, leaf *MintingLeaf) (*IssuanceProof, error) { pushReq := &FederationPushReq{ ID: id, diff --git a/universe/base.go b/universe/base.go index cc3211892..ca4e171a0 100644 --- a/universe/base.go +++ b/universe/base.go @@ -136,7 +136,7 @@ func (a *MintingArchive) RootNodes(ctx context.Context) ([]BaseRoot, error) { // error if the passed minting proof is invalid. If the leaf is already known, // then no action is taken and the existing issuance commitment proof returned. func (a *MintingArchive) RegisterIssuance(ctx context.Context, id Identifier, - key BaseKey, leaf *MintingLeaf) (*IssuanceProof, error) { + key LeafKey, leaf *MintingLeaf) (*IssuanceProof, error) { log.Debugf("Inserting new proof into Universe: id=%v, base_key=%v", id.StringForLog(), spew.Sdump(key)) @@ -219,7 +219,7 @@ func (a *MintingArchive) RegisterIssuance(ctx context.Context, id Identifier, // verifyIssuanceProof verifies the passed minting leaf is a valid issuance // proof, returning the asset snapshot if so. func (a *MintingArchive) verifyIssuanceProof(ctx context.Context, id Identifier, - key BaseKey, leaf *MintingLeaf, + key LeafKey, leaf *MintingLeaf, prevAssetSnapshot *proof.AssetSnapshot) (*proof.AssetSnapshot, error) { assetSnapshot, err := leaf.GenesisProof.Verify( @@ -342,7 +342,7 @@ func (a *MintingArchive) getPrevAssetSnapshot(ctx context.Context, } prevScriptKey := asset.NewScriptKey(prevScriptKeyPubKey) - prevBaseKey := BaseKey{ + prevBaseKey := LeafKey{ MintingOutpoint: prevID.OutPoint, ScriptKey: &prevScriptKey, } @@ -370,7 +370,7 @@ func (a *MintingArchive) getPrevAssetSnapshot(ctx context.Context, // FetchIssuanceProof attempts to fetch an issuance proof for the target base // leaf based on the universe identifier (assetID/groupKey). func (a *MintingArchive) FetchIssuanceProof(ctx context.Context, id Identifier, - key BaseKey) ([]*IssuanceProof, error) { + key LeafKey) ([]*IssuanceProof, error) { log.Debugf("Retrieving Universe proof for: id=%v, base_key=%v", id.StringForLog(), spew.Sdump(key)) @@ -396,11 +396,11 @@ func (a *MintingArchive) FetchIssuanceProof(ctx context.Context, id Identifier, // MintingKeys returns the set of minting keys known for the specified base // universe identifier. func (a *MintingArchive) MintingKeys(ctx context.Context, - id Identifier) ([]BaseKey, error) { + id Identifier) ([]LeafKey, error) { log.Debugf("Retrieving all keys for Universe: id=%v", id.StringForLog()) - return withBaseUni(a, id, func(baseUni BaseBackend) ([]BaseKey, error) { + return withBaseUni(a, id, func(baseUni BaseBackend) ([]LeafKey, error) { return baseUni.MintingKeys(ctx) }) } diff --git a/universe/interface.go b/universe/interface.go index f7278cfee..1dbea5013 100644 --- a/universe/interface.go +++ b/universe/interface.go @@ -105,11 +105,11 @@ func (m *MintingLeaf) SmtLeafNode() (*mssmt.LeafNode, error) { return mssmt.NewLeafNode(buf.Bytes(), m.Amt), nil } -// BaseKey is the top level key for a Base/Root universe. This will be used to -// key into the MS-SMT. The final key is: sha256(mintingOutpoint || scriptKey). -// This ensures that all leaves for a given asset will be uniquely keyed in the -// universe tree. -type BaseKey struct { +// LeafKey is the top level leaf key for a universe. This will be used to key +// into a universe's MS-SMT data structure. The final serialized key is: +// sha256(mintingOutpoint || scriptKey). This ensures that all +// leaves for a given asset will be uniquely keyed in the universe tree. +type LeafKey struct { // MintingOutpoint is the minting outpoint, or the outpoint where the // newly created assets reside within. MintingOutpoint wire.OutPoint @@ -123,7 +123,7 @@ type BaseKey struct { } // UniverseKey is the key for a universe. -func (b BaseKey) UniverseKey() [32]byte { +func (b LeafKey) UniverseKey() [32]byte { // key = sha256(mintingOutpoint || scriptKey) h := sha256.New() _ = wire.WriteOutPoint(h, 0, 0, &b.MintingOutpoint) @@ -141,7 +141,7 @@ func (b BaseKey) UniverseKey() [32]byte { // the universe root. type IssuanceProof struct { // MintingKey is the minting key for the asset. - MintingKey BaseKey + MintingKey LeafKey // UniverseRoot is the root of the universe that the asset is located // within. @@ -193,7 +193,7 @@ type BaseBackend interface { // tree, stored at the base key. The metaReveal type is purely // optional, and should be specified if the genesis proof committed to // a non-zero meta hash. - RegisterIssuance(ctx context.Context, key BaseKey, leaf *MintingLeaf, + RegisterIssuance(ctx context.Context, key LeafKey, leaf *MintingLeaf, metaReveal *proof.MetaReveal) (*IssuanceProof, error) // FetchIssuanceProof returns an issuance proof for the target key. If @@ -203,10 +203,10 @@ type BaseBackend interface { // // TODO(roasbeef): can eventually do multi-proofs for the SMT FetchIssuanceProof(ctx context.Context, - key BaseKey) ([]*IssuanceProof, error) + key LeafKey) ([]*IssuanceProof, error) // MintingKeys returns all the keys inserted in the universe. - MintingKeys(ctx context.Context) ([]BaseKey, error) + MintingKeys(ctx context.Context) ([]LeafKey, error) // MintingLeaves returns all the minting leaves inserted into the // universe. @@ -245,7 +245,7 @@ type MultiverseArchive interface { // 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, + UpsertProofLeaf(ctx context.Context, id Identifier, key LeafKey, leaf *MintingLeaf, metaReveal *proof.MetaReveal) (*IssuanceProof, error) @@ -259,7 +259,7 @@ type MultiverseArchive interface { // 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) + key LeafKey) ([]*IssuanceProof, error) // TODO(roasbeef): other stats stuff here, like total number of assets, etc // * also eventually want pull/fetch stats, can be pulled out into another instance @@ -270,7 +270,7 @@ type MultiverseArchive interface { type Registrar interface { // RegisterIssuance inserts a new minting leaf within the target // universe tree (based on the ID), stored at the base key. - RegisterIssuance(ctx context.Context, id Identifier, key BaseKey, + RegisterIssuance(ctx context.Context, id Identifier, key LeafKey, leaf *MintingLeaf) (*IssuanceProof, error) } @@ -282,7 +282,7 @@ type IssuanceItem struct { ID Identifier // Key is the base key that the leaf is or will be stored at. - Key BaseKey + Key LeafKey // Leaf is the minting leaf that was created. Leaf *MintingLeaf @@ -464,7 +464,7 @@ type DiffEngine interface { RootNodes(ctx context.Context) ([]BaseRoot, error) // MintingKeys returns all the keys inserted in the universe. - MintingKeys(ctx context.Context, id Identifier) ([]BaseKey, error) + MintingKeys(ctx context.Context, id Identifier) ([]LeafKey, error) // FetchIssuanceProof attempts to fetch an issuance proof for the // target base leaf based on the universe identifier (assetID/groupKey). @@ -473,7 +473,7 @@ type DiffEngine interface { // asymmetric, as just need this to complete final portion // of diff FetchIssuanceProof(ctx context.Context, id Identifier, - key BaseKey) ([]*IssuanceProof, error) + key LeafKey) ([]*IssuanceProof, error) } // Commitment is an on chain universe commitment. This includes the merkle @@ -521,7 +521,7 @@ type Canonical interface { BaseBackend // Query returns a fully proved response for the target base key. - Query(context.Context, BaseKey) (*CommittedIssuanceProof, error) + Query(context.Context, LeafKey) (*CommittedIssuanceProof, error) // LatestCommitment returns the latest chain commitment. LatestCommitment() (*Commitment, error) @@ -721,7 +721,7 @@ type Telemetry interface { // * alternatively, can log when a set of leaves are queried, as // that's still a sync event, but can be a noop LogSyncEvent(ctx context.Context, uniID Identifier, - key BaseKey) error + key LeafKey) error // LogSyncEvents logs sync events for the target universe. LogSyncEvents(ctx context.Context, uniIDs ...Identifier) error @@ -729,7 +729,7 @@ type Telemetry interface { // LogNewProofEvent logs a new proof insertion event for the target // universe. LogNewProofEvent(ctx context.Context, uniID Identifier, - key BaseKey) error + key LeafKey) error // LogNewProofEvents logs new proof insertion events for the target // universe. diff --git a/universe/syncer.go b/universe/syncer.go index f931472ff..2c51cb387 100644 --- a/universe/syncer.go +++ b/universe/syncer.go @@ -205,7 +205,7 @@ func (s *SimpleSyncer) syncRoot(ctx context.Context, remoteRoot BaseRoot, // Now that we know where the divergence is, we can fetch the issuance // proofs from the remote party. err = fn.ParSlice( - ctx, keysToFetch, func(ctx context.Context, key BaseKey) error { + ctx, keysToFetch, func(ctx context.Context, key LeafKey) error { newProof, err := diffEngine.FetchIssuanceProof( ctx, uniID, key, ) diff --git a/universe_rpc_diff.go b/universe_rpc_diff.go index b6e49083b..2599cbc37 100644 --- a/universe_rpc_diff.go +++ b/universe_rpc_diff.go @@ -109,14 +109,14 @@ func (r *RpcUniverseDiff) RootNode(ctx context.Context, // MintingKeys returns all the keys inserted in the universe. func (r *RpcUniverseDiff) MintingKeys(ctx context.Context, - id universe.Identifier) ([]universe.BaseKey, error) { + id universe.Identifier) ([]universe.LeafKey, error) { assetKeys, err := r.conn.AssetLeafKeys(ctx, marshalUniID(id)) if err != nil { return nil, err } - keys := make([]universe.BaseKey, len(assetKeys.AssetKeys)) + keys := make([]universe.LeafKey, len(assetKeys.AssetKeys)) for i, key := range assetKeys.AssetKeys { baseKey, err := unmarshalLeafKey(key) if err != nil { @@ -138,7 +138,7 @@ func (r *RpcUniverseDiff) MintingKeys(ctx context.Context, // of diff func (r *RpcUniverseDiff) FetchIssuanceProof(ctx context.Context, id universe.Identifier, - key universe.BaseKey) ([]*universe.IssuanceProof, error) { + key universe.LeafKey) ([]*universe.IssuanceProof, error) { uProofs, err := r.conn.QueryProof(ctx, &universerpc.UniverseKey{ Id: marshalUniID(id), diff --git a/universe_rpc_registrar.go b/universe_rpc_registrar.go index 28ac0effd..54df81b11 100644 --- a/universe_rpc_registrar.go +++ b/universe_rpc_registrar.go @@ -81,7 +81,7 @@ func unmarshalIssuanceProof(ctx context.Context, uniKey *unirpc.UniverseKey, // RegisterIssuance is an implementation of the universe.Registrar interface // that uses a remote Universe server as the Registry instance. func (r *RpcUniverseRegistrar) RegisterIssuance(ctx context.Context, - id universe.Identifier, key universe.BaseKey, + id universe.Identifier, key universe.LeafKey, leaf *universe.MintingLeaf) (*universe.IssuanceProof, error) { // First, we'll parse the proofs and key into their RPC counterparts. From 5a6f1aba49b777d62f9960c8e14a314e7d842d49 Mon Sep 17 00:00:00 2001 From: ffranr Date: Tue, 26 Sep 2023 15:38:34 +0100 Subject: [PATCH 02/16] multi: rename universe LeafKey.MintingOutpoint into LeafKey.OutPoint --- rpcserver.go | 6 +++--- tapdb/universe.go | 12 ++++++------ tapdb/universe_test.go | 10 +++++----- tapgarden/caretaker.go | 2 +- tapgarden/planter.go | 2 +- universe/base.go | 4 ++-- universe/interface.go | 8 ++++---- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index f89e5d05f..5356af472 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -2631,7 +2631,7 @@ func (r *rpcServer) DeleteAssetRoot(ctx context.Context, func marshalLeafKey(leafKey universe.LeafKey) *unirpc.AssetKey { return &unirpc.AssetKey{ Outpoint: &unirpc.AssetKey_OpStr{ - OpStr: leafKey.MintingOutpoint.String(), + OpStr: leafKey.OutPoint.String(), }, ScriptKey: &unirpc.AssetKey_ScriptKeyBytes{ ScriptKeyBytes: schnorr.SerializePubKey( @@ -2812,7 +2812,7 @@ func unmarshalLeafKey(key *unirpc.AssetKey) (universe.LeafKey, error) { return baseKey, err } - baseKey.MintingOutpoint = *outpoint + baseKey.OutPoint = *outpoint case key.GetOutpoint() != nil: op := key.GetOp() @@ -2822,7 +2822,7 @@ func unmarshalLeafKey(key *unirpc.AssetKey) (universe.LeafKey, error) { return baseKey, err } - baseKey.MintingOutpoint = wire.OutPoint{ + baseKey.OutPoint = wire.OutPoint{ Hash: *hash, Index: uint32(op.Index), } diff --git a/tapdb/universe.go b/tapdb/universe.go index 4b440a4ce..f7f72f8c8 100644 --- a/tapdb/universe.go +++ b/tapdb/universe.go @@ -333,7 +333,7 @@ func universeRegisterIssuance(ctx context.Context, dbTx BaseUniverseStore, groupKeyBytes = schnorr.SerializePubKey(id.GroupKey) } - mintingPointBytes, err := encodeOutpoint(key.MintingOutpoint) + mintingPointBytes, err := encodeOutpoint(key.OutPoint) if err != nil { return nil, nil, err } @@ -469,7 +469,7 @@ func universeFetchIssuanceProof(ctx context.Context, ) } - mintingPointBytes, err := encodeOutpoint(universeKey.MintingOutpoint) + mintingPointBytes, err := encodeOutpoint(universeKey.OutPoint) if err != nil { return nil, err } @@ -522,8 +522,8 @@ func universeFetchIssuanceProof(ctx context.Context, // Next, we'll fetch the leaf node from the tree and also obtain // a merkle proof for the leaf alongside it. universeKey := universe.LeafKey{ - MintingOutpoint: universeKey.MintingOutpoint, - ScriptKey: &scriptKey, + OutPoint: universeKey.OutPoint, + ScriptKey: &scriptKey, } smtKey := universeKey.UniverseKey() leafProof, err := universeTree.MerkleProof( @@ -615,8 +615,8 @@ func (b *BaseUniverseTree) MintingKeys(ctx context.Context, } baseKeys = append(baseKeys, universe.LeafKey{ - MintingOutpoint: genPoint, - ScriptKey: &scriptKey, + OutPoint: genPoint, + ScriptKey: &scriptKey, }) return nil diff --git a/tapdb/universe_test.go b/tapdb/universe_test.go index 8ffe8850f..44be7a5e9 100644 --- a/tapdb/universe_test.go +++ b/tapdb/universe_test.go @@ -79,7 +79,7 @@ func TestUniverseEmptyTree(t *testing.T) { func randBaseKey(t *testing.T) universe.LeafKey { return universe.LeafKey{ - MintingOutpoint: test.RandOp(t), + OutPoint: test.RandOp(t), ScriptKey: fn.Ptr( asset.NewScriptKey(test.RandPubKey(t)), ), @@ -451,12 +451,12 @@ func TestUniverseLeafQuery(t *testing.T) { // We'll create three new leaves, all of them will share the exact same // minting outpoint, but will have distinct script keys. - rootMintingPoint := randBaseKey(t).MintingOutpoint + rootMintingPoint := randBaseKey(t).OutPoint leafToScriptKey := make(map[asset.SerializedKey]universe.MintingLeaf) for i := 0; i < numLeafs; i++ { targetKey := randBaseKey(t) - targetKey.MintingOutpoint = rootMintingPoint + targetKey.OutPoint = rootMintingPoint leaf := randMintingLeaf(t, assetGen, id.GroupKey) @@ -473,7 +473,7 @@ func TestUniverseLeafQuery(t *testing.T) { // If we query for only the minting point, then all three leaves should // be returned. proofs, err := baseUniverse.FetchIssuanceProof(ctx, universe.LeafKey{ - MintingOutpoint: rootMintingPoint, + OutPoint: rootMintingPoint, }) require.NoError(t, err) require.Len(t, proofs, numLeafs) @@ -485,7 +485,7 @@ func TestUniverseLeafQuery(t *testing.T) { require.NoError(t, err) p, err := baseUniverse.FetchIssuanceProof(ctx, universe.LeafKey{ - MintingOutpoint: rootMintingPoint, + OutPoint: rootMintingPoint, ScriptKey: &asset.ScriptKey{ PubKey: scriptKey, }, diff --git a/tapgarden/caretaker.go b/tapgarden/caretaker.go index 23850e61f..f6f355cf9 100644 --- a/tapgarden/caretaker.go +++ b/tapgarden/caretaker.go @@ -1047,7 +1047,7 @@ func (b *BatchCaretaker) storeMintingProof(ctx context.Context, // be the outpoint where it was created at and the script key for that // asset. baseKey := universe.LeafKey{ - MintingOutpoint: wire.OutPoint{ + OutPoint: wire.OutPoint{ Hash: mintTxHash, Index: b.anchorOutputIndex, }, diff --git a/tapgarden/planter.go b/tapgarden/planter.go index 815bd3ceb..533c9017d 100644 --- a/tapgarden/planter.go +++ b/tapgarden/planter.go @@ -881,7 +881,7 @@ func (c *ChainPlanter) updateMintingProofs(proofs []*proof.Proof) error { // this'll be the outpoint where it was created at and the // script key for that asset. baseKey := universe.LeafKey{ - MintingOutpoint: wire.OutPoint{ + OutPoint: wire.OutPoint{ Hash: p.AnchorTx.TxHash(), Index: p.InclusionProof.OutputIndex, }, diff --git a/universe/base.go b/universe/base.go index ca4e171a0..7ecea2025 100644 --- a/universe/base.go +++ b/universe/base.go @@ -343,8 +343,8 @@ func (a *MintingArchive) getPrevAssetSnapshot(ctx context.Context, prevScriptKey := asset.NewScriptKey(prevScriptKeyPubKey) prevBaseKey := LeafKey{ - MintingOutpoint: prevID.OutPoint, - ScriptKey: &prevScriptKey, + OutPoint: prevID.OutPoint, + ScriptKey: &prevScriptKey, } prevProofs, err := a.cfg.Multiverse.FetchProofLeaf( diff --git a/universe/interface.go b/universe/interface.go index 1dbea5013..b664ee15b 100644 --- a/universe/interface.go +++ b/universe/interface.go @@ -110,9 +110,9 @@ func (m *MintingLeaf) SmtLeafNode() (*mssmt.LeafNode, error) { // sha256(mintingOutpoint || scriptKey). This ensures that all // leaves for a given asset will be uniquely keyed in the universe tree. type LeafKey struct { - // MintingOutpoint is the minting outpoint, or the outpoint where the - // newly created assets reside within. - MintingOutpoint wire.OutPoint + // OutPoint is the outpoint at which the asset referenced by this key + // resides. + OutPoint wire.OutPoint // ScriptKey is the script key of the base asset. If this isn't // specified, then the caller is attempting to query for all the script @@ -126,7 +126,7 @@ type LeafKey struct { func (b LeafKey) UniverseKey() [32]byte { // key = sha256(mintingOutpoint || scriptKey) h := sha256.New() - _ = wire.WriteOutPoint(h, 0, 0, &b.MintingOutpoint) + _ = wire.WriteOutPoint(h, 0, 0, &b.OutPoint) h.Write(schnorr.SerializePubKey(b.ScriptKey.PubKey)) var k [32]byte From 62b89b423572e130e6a5c3251441fae09dbee787 Mon Sep 17 00:00:00 2001 From: ffranr Date: Tue, 26 Sep 2023 15:47:29 +0100 Subject: [PATCH 03/16] multi: rename variable instances of baseKey to leafKey --- rpcserver.go | 28 ++++++++++++++-------------- tapdb/universe.go | 6 +++--- tapgarden/caretaker.go | 4 ++-- tapgarden/planter.go | 4 ++-- universe/base.go | 4 ++-- universe_rpc_diff.go | 4 ++-- universe_rpc_registrar.go | 4 ++-- 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index 5356af472..2acb7b2f6 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -2764,10 +2764,10 @@ func UnmarshalOutpoint(outpoint string) (*wire.OutPoint, error) { }, nil } -// unmarshalLeafKey unmarshals a leaf key from the RPC form. +// unmarshalLeafKey un-marshals a leaf key from the RPC form. func unmarshalLeafKey(key *unirpc.AssetKey) (universe.LeafKey, error) { var ( - baseKey universe.LeafKey + leafKey universe.LeafKey err error ) @@ -2775,31 +2775,31 @@ func unmarshalLeafKey(key *unirpc.AssetKey) (universe.LeafKey, error) { case key.GetScriptKeyBytes() != nil: pubKey, err := parseUserKey(key.GetScriptKeyBytes()) if err != nil { - return baseKey, err + return leafKey, err } - baseKey.ScriptKey = &asset.ScriptKey{ + leafKey.ScriptKey = &asset.ScriptKey{ PubKey: pubKey, } case key.GetScriptKeyStr() != "": scriptKeyBytes, sErr := hex.DecodeString(key.GetScriptKeyStr()) if sErr != nil { - return baseKey, err + return leafKey, err } pubKey, err := parseUserKey(scriptKeyBytes) if err != nil { - return baseKey, err + return leafKey, err } - baseKey.ScriptKey = &asset.ScriptKey{ + leafKey.ScriptKey = &asset.ScriptKey{ PubKey: pubKey, } default: // TODO(roasbeef): can actually allow not to be, then would // fetch all for the given outpoint - return baseKey, fmt.Errorf("script key must be set") + return leafKey, fmt.Errorf("script key must be set") } switch { @@ -2809,29 +2809,29 @@ func unmarshalLeafKey(key *unirpc.AssetKey) (universe.LeafKey, error) { outpointStr := key.GetOpStr() outpoint, err := UnmarshalOutpoint(outpointStr) if err != nil { - return baseKey, err + return leafKey, err } - baseKey.OutPoint = *outpoint + leafKey.OutPoint = *outpoint case key.GetOutpoint() != nil: op := key.GetOp() hash, err := chainhash.NewHashFromStr(op.HashStr) if err != nil { - return baseKey, err + return leafKey, err } - baseKey.OutPoint = wire.OutPoint{ + leafKey.OutPoint = wire.OutPoint{ Hash: *hash, Index: uint32(op.Index), } default: - return baseKey, fmt.Errorf("outpoint not set: %v", err) + return leafKey, fmt.Errorf("outpoint not set: %v", err) } - return baseKey, nil + return leafKey, nil } // marshalMssmtProof marshals a MS-SMT proof into the RPC form. diff --git a/tapdb/universe.go b/tapdb/universe.go index f7f72f8c8..ec6ff5ac6 100644 --- a/tapdb/universe.go +++ b/tapdb/universe.go @@ -587,7 +587,7 @@ func universeFetchIssuanceProof(ctx context.Context, func (b *BaseUniverseTree) MintingKeys(ctx context.Context, ) ([]universe.LeafKey, error) { - var baseKeys []universe.LeafKey + var leafKeys []universe.LeafKey readTx := NewBaseUniverseReadTx() dbErr := b.db.ExecTx(ctx, &readTx, func(db BaseUniverseStore) error { @@ -614,7 +614,7 @@ func (b *BaseUniverseTree) MintingKeys(ctx context.Context, return err } - baseKeys = append(baseKeys, universe.LeafKey{ + leafKeys = append(leafKeys, universe.LeafKey{ OutPoint: genPoint, ScriptKey: &scriptKey, }) @@ -626,7 +626,7 @@ func (b *BaseUniverseTree) MintingKeys(ctx context.Context, return nil, dbErr } - return baseKeys, nil + return leafKeys, nil } // MintingLeaves returns all the minting leaves inserted into the universe. diff --git a/tapgarden/caretaker.go b/tapgarden/caretaker.go index f6f355cf9..624ad6c06 100644 --- a/tapgarden/caretaker.go +++ b/tapgarden/caretaker.go @@ -1046,7 +1046,7 @@ func (b *BatchCaretaker) storeMintingProof(ctx context.Context, // The base key is the set of bytes that keys into the universe, this'll // be the outpoint where it was created at and the script key for that // asset. - baseKey := universe.LeafKey{ + leafKey := universe.LeafKey{ OutPoint: wire.OutPoint{ Hash: mintTxHash, Index: b.anchorOutputIndex, @@ -1074,7 +1074,7 @@ func (b *BatchCaretaker) storeMintingProof(ctx context.Context, return blob, &universe.IssuanceItem{ ID: uniID, - Key: baseKey, + Key: leafKey, Leaf: mintingLeaf, }, nil } diff --git a/tapgarden/planter.go b/tapgarden/planter.go index 533c9017d..735d90a81 100644 --- a/tapgarden/planter.go +++ b/tapgarden/planter.go @@ -880,7 +880,7 @@ func (c *ChainPlanter) updateMintingProofs(proofs []*proof.Proof) error { // The base key is the set of bytes that keys into the universe, // this'll be the outpoint where it was created at and the // script key for that asset. - baseKey := universe.LeafKey{ + leafKey := universe.LeafKey{ OutPoint: wire.OutPoint{ Hash: p.AnchorTx.TxHash(), Index: p.InclusionProof.OutputIndex, @@ -902,7 +902,7 @@ func (c *ChainPlanter) updateMintingProofs(proofs []*proof.Proof) error { Amt: p.Asset.Amount, } _, err = c.cfg.Universe.RegisterIssuance( - ctx, uniID, baseKey, mintingLeaf, + ctx, uniID, leafKey, mintingLeaf, ) if err != nil { return fmt.Errorf("unable to update issuance: %v", err) diff --git a/universe/base.go b/universe/base.go index 7ecea2025..72cec2e45 100644 --- a/universe/base.go +++ b/universe/base.go @@ -342,13 +342,13 @@ func (a *MintingArchive) getPrevAssetSnapshot(ctx context.Context, } prevScriptKey := asset.NewScriptKey(prevScriptKeyPubKey) - prevBaseKey := LeafKey{ + prevLeafKey := LeafKey{ OutPoint: prevID.OutPoint, ScriptKey: &prevScriptKey, } prevProofs, err := a.cfg.Multiverse.FetchProofLeaf( - ctx, uniID, prevBaseKey, + ctx, uniID, prevLeafKey, ) if err != nil { return nil, fmt.Errorf("unable to fetch previous "+ diff --git a/universe_rpc_diff.go b/universe_rpc_diff.go index 2599cbc37..4ca39bb65 100644 --- a/universe_rpc_diff.go +++ b/universe_rpc_diff.go @@ -118,12 +118,12 @@ func (r *RpcUniverseDiff) MintingKeys(ctx context.Context, keys := make([]universe.LeafKey, len(assetKeys.AssetKeys)) for i, key := range assetKeys.AssetKeys { - baseKey, err := unmarshalLeafKey(key) + leafKey, err := unmarshalLeafKey(key) if err != nil { return nil, err } - keys[i] = baseKey + keys[i] = leafKey } return keys, nil diff --git a/universe_rpc_registrar.go b/universe_rpc_registrar.go index 54df81b11..f0aaedb4f 100644 --- a/universe_rpc_registrar.go +++ b/universe_rpc_registrar.go @@ -42,7 +42,7 @@ func NewRpcUniverseRegistrar( func unmarshalIssuanceProof(ctx context.Context, uniKey *unirpc.UniverseKey, proofResp *unirpc.AssetProofResponse) (*universe.IssuanceProof, error) { - baseKey, err := unmarshalLeafKey(uniKey.LeafKey) + leafKey, err := unmarshalLeafKey(uniKey.LeafKey) if err != nil { return nil, err } @@ -66,7 +66,7 @@ func unmarshalIssuanceProof(ctx context.Context, uniKey *unirpc.UniverseKey, } return &universe.IssuanceProof{ - MintingKey: baseKey, + MintingKey: leafKey, UniverseRoot: mssmt.NewComputedBranch( fn.ToArray[mssmt.NodeHash]( proofResp.UniverseRoot.MssmtRoot.RootHash, From 0eaeb7efb868c523a6aee7866b34ab037ff07fa3 Mon Sep 17 00:00:00 2001 From: ffranr Date: Tue, 26 Sep 2023 15:42:58 +0100 Subject: [PATCH 04/16] tapdb: rename randBaseKey to randLeafKey --- tapdb/universe_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tapdb/universe_test.go b/tapdb/universe_test.go index 44be7a5e9..eeaf12c91 100644 --- a/tapdb/universe_test.go +++ b/tapdb/universe_test.go @@ -77,7 +77,7 @@ func TestUniverseEmptyTree(t *testing.T) { require.ErrorIs(t, err, universe.ErrNoUniverseRoot) } -func randBaseKey(t *testing.T) universe.LeafKey { +func randLeafKey(t *testing.T) universe.LeafKey { return universe.LeafKey{ OutPoint: test.RandOp(t), ScriptKey: fn.Ptr( @@ -153,7 +153,7 @@ func TestUniverseIssuanceProofs(t *testing.T) { // scriptKey) leaf pairs. testLeaves := make([]leafWithKey, numLeaves) for i := 0; i < numLeaves; i++ { - targetKey := randBaseKey(t) + targetKey := randLeafKey(t) leaf := randMintingLeaf(t, assetGen, id.GroupKey) testLeaves[i] = leafWithKey{targetKey, leaf} @@ -323,7 +323,7 @@ func TestUniverseMetaBlob(t *testing.T) { // With the meta constructed, we can insert a test leaf into the DB // now. - targetKey := randBaseKey(t) + targetKey := randLeafKey(t) leaf := randMintingLeaf(t, assetGen, id.GroupKey) _, err := baseUniverse.RegisterIssuance(ctx, targetKey, &leaf, meta) @@ -350,7 +350,7 @@ func insertRandLeaf(t *testing.T, ctx context.Context, tree *BaseUniverseTree, targetGen = asset.RandGenesis(t, asset.Normal) } - targetKey := randBaseKey(t) + targetKey := randLeafKey(t) leaf := randMintingLeaf(t, targetGen, tree.id.GroupKey) return tree.RegisterIssuance(ctx, targetKey, &leaf, nil) @@ -451,11 +451,11 @@ func TestUniverseLeafQuery(t *testing.T) { // We'll create three new leaves, all of them will share the exact same // minting outpoint, but will have distinct script keys. - rootMintingPoint := randBaseKey(t).OutPoint + rootMintingPoint := randLeafKey(t).OutPoint leafToScriptKey := make(map[asset.SerializedKey]universe.MintingLeaf) for i := 0; i < numLeafs; i++ { - targetKey := randBaseKey(t) + targetKey := randLeafKey(t) targetKey.OutPoint = rootMintingPoint leaf := randMintingLeaf(t, assetGen, id.GroupKey) From b3213c3c4b2ff4e5ae204eeb8410c0d0aff89971 Mon Sep 17 00:00:00 2001 From: ffranr Date: Tue, 26 Sep 2023 15:57:30 +0100 Subject: [PATCH 05/16] universe: remove unused context paramater --- universe_rpc_registrar.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/universe_rpc_registrar.go b/universe_rpc_registrar.go index f0aaedb4f..070731572 100644 --- a/universe_rpc_registrar.go +++ b/universe_rpc_registrar.go @@ -37,9 +37,9 @@ func NewRpcUniverseRegistrar( }, nil } -// unmarshalIssuanceProof unmarshals an issuance proof response into a struct +// unmarshalIssuanceProof un-marshals an issuance proof response into a struct // usable by the universe package. -func unmarshalIssuanceProof(ctx context.Context, uniKey *unirpc.UniverseKey, +func unmarshalIssuanceProof(uniKey *unirpc.UniverseKey, proofResp *unirpc.AssetProofResponse) (*universe.IssuanceProof, error) { leafKey, err := unmarshalLeafKey(uniKey.LeafKey) @@ -105,9 +105,9 @@ func (r *RpcUniverseRegistrar) RegisterIssuance(ctx context.Context, return nil, err } - // Finally, we'll map the response back into the IssuanceProof we - // expect as a response. - return unmarshalIssuanceProof(ctx, uniKey, proofResp) + // Finally, we'll map the response back into the IssuanceProof we expect + // as a response. + return unmarshalIssuanceProof(uniKey, proofResp) } // A compile time interface to ensure that RpcUniverseRegistrar implements the From a251c142a18cb4ed9605cfbd56b4739a2e6e90b8 Mon Sep 17 00:00:00 2001 From: ffranr Date: Tue, 26 Sep 2023 16:00:02 +0100 Subject: [PATCH 06/16] rpcserver: fix function doc --- rpcserver.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpcserver.go b/rpcserver.go index 2acb7b2f6..42cf8b391 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -2736,7 +2736,7 @@ func (r *rpcServer) AssetLeaves(ctx context.Context, return resp, nil } -// unmarshalOutpoint unmarshals an outpoint from a string received via RPC. +// UnmarshalOutpoint un-marshals an outpoint from a string received via RPC. func UnmarshalOutpoint(outpoint string) (*wire.OutPoint, error) { parts := strings.Split(outpoint, ":") if len(parts) != 2 { From bdfa14cfa275a29ffd6355125b1f2b7183efebb4 Mon Sep 17 00:00:00 2001 From: ffranr Date: Tue, 26 Sep 2023 16:53:11 +0100 Subject: [PATCH 07/16] universe: rename universeFetchIssuanceProof to universeFetchProofLeaf --- tapdb/multiverse.go | 2 +- tapdb/universe.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tapdb/multiverse.go b/tapdb/multiverse.go index 2864c488b..cb7454c47 100644 --- a/tapdb/multiverse.go +++ b/tapdb/multiverse.go @@ -167,7 +167,7 @@ func (b *MultiverseStore) FetchProofLeaf(ctx context.Context, dbErr := b.db.ExecTx(ctx, &readTx, func(dbTx BaseMultiverseStore) error { var err error - proofs, err = universeFetchIssuanceProof( + proofs, err = universeFetchProofLeaf( ctx, id, universeKey, dbTx, ) if err != nil { diff --git a/tapdb/universe.go b/tapdb/universe.go index ec6ff5ac6..3a056f847 100644 --- a/tapdb/universe.go +++ b/tapdb/universe.go @@ -435,7 +435,7 @@ func (b *BaseUniverseTree) FetchIssuanceProof(ctx context.Context, dbErr := b.db.ExecTx(ctx, &readTx, func(dbTx BaseUniverseStore) error { var err error - proofs, err = universeFetchIssuanceProof( + proofs, err = universeFetchProofLeaf( ctx, b.id, universeKey, dbTx, ) return err @@ -447,14 +447,14 @@ func (b *BaseUniverseTree) FetchIssuanceProof(ctx context.Context, return proofs, nil } -// universeFetchIssuanceProof returns issuance proofs for the target universe. +// universeFetchProofLeaf returns proof leaves for the target universe. // -// If the given universe key doesn't have a script key specified, then a proof -// will be returned for each minting outpoint. +// If the given universe leaf key doesn't have a script key specified, then a +// proof will be returned for each minting outpoint. // // NOTE: This function accepts a database transaction and is called when making // broader DB updates. -func universeFetchIssuanceProof(ctx context.Context, +func universeFetchProofLeaf(ctx context.Context, id universe.Identifier, universeKey universe.LeafKey, dbTx BaseUniverseStore) ([]*universe.IssuanceProof, error) { From 29bdab0803e728b27ec7736690aeb0df0b6889e4 Mon Sep 17 00:00:00 2001 From: ffranr Date: Tue, 26 Sep 2023 16:57:58 +0100 Subject: [PATCH 08/16] universe: rename universeRegisterIssuance to universeUpsertProofLeaf --- tapdb/multiverse.go | 4 ++-- tapdb/universe.go | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tapdb/multiverse.go b/tapdb/multiverse.go index cb7454c47..2a7b6b9cf 100644 --- a/tapdb/multiverse.go +++ b/tapdb/multiverse.go @@ -232,7 +232,7 @@ func (b *MultiverseStore) UpsertProofLeaf(ctx context.Context, universeRoot mssmt.Node err error ) - issuanceProof, universeRoot, err = universeRegisterIssuance( + issuanceProof, universeRoot, err = universeUpsertProofLeaf( ctx, dbTx, id, key, leaf, metaReveal, ) if err != nil { @@ -305,7 +305,7 @@ func (b *MultiverseStore) RegisterBatchIssuance(ctx context.Context, // Register issuance in the asset (group) specific universe // tree. - _, universeRoot, err := universeRegisterIssuance( + _, universeRoot, err := universeUpsertProofLeaf( ctx, dbTx, item.ID, item.Key, item.Leaf, item.MetaReveal, ) diff --git a/tapdb/universe.go b/tapdb/universe.go index 3a056f847..9a6ca902b 100644 --- a/tapdb/universe.go +++ b/tapdb/universe.go @@ -289,7 +289,7 @@ func (b *BaseUniverseTree) RegisterIssuance(ctx context.Context, issuanceProof *universe.IssuanceProof ) dbErr := b.db.ExecTx(ctx, &writeTx, func(dbTx BaseUniverseStore) error { - issuanceProof, _, err = universeRegisterIssuance( + issuanceProof, _, err = universeUpsertProofLeaf( ctx, dbTx, b.id, key, leaf, metaReveal, ) return err @@ -301,15 +301,15 @@ func (b *BaseUniverseTree) RegisterIssuance(ctx context.Context, return issuanceProof, nil } -// universeRegisterIssuance upserts a minting leaf within the universe tree, -// stored at the base key. +// universeUpsertProofLeaf upserts a proof leaf within the universe tree (stored +// at the proof leaf key). // -// This function returns the newly registered issuance proof and the new -// universe root. +// This function returns the inserted/updated proof leaf and the new universe +// root. // // NOTE: This function accepts a db transaction, as it's used when making // broader DB updates. -func universeRegisterIssuance(ctx context.Context, dbTx BaseUniverseStore, +func universeUpsertProofLeaf(ctx context.Context, dbTx BaseUniverseStore, id universe.Identifier, key universe.LeafKey, leaf *universe.MintingLeaf, metaReveal *proof.MetaReveal) (*universe.IssuanceProof, mssmt.Node, From 03be864c70bbc41c7aa4a5e7d792648344b9daa6 Mon Sep 17 00:00:00 2001 From: ffranr Date: Tue, 26 Sep 2023 17:01:28 +0100 Subject: [PATCH 09/16] universe: update leafWithKey doc --- tapdb/universe_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tapdb/universe_test.go b/tapdb/universe_test.go index eeaf12c91..53ea96caa 100644 --- a/tapdb/universe_test.go +++ b/tapdb/universe_test.go @@ -125,7 +125,7 @@ func randMintingLeaf(t *testing.T, assetGen asset.Genesis, return leaf } -// leaWithKey is a two tuple that associates new minting leaf with a key. +// leaWithKey is a two tuple that associates universe leaf key with a leaf. type leafWithKey struct { universe.LeafKey From 7b3063b2cdee17a662e8ba17813ae38dcce3030d Mon Sep 17 00:00:00 2001 From: ffranr Date: Tue, 26 Sep 2023 17:12:34 +0100 Subject: [PATCH 10/16] universe: rename MintingLeaf to Leaf --- rpcserver.go | 8 ++++---- tapdb/multiverse.go | 2 +- tapdb/universe.go | 14 +++++++------- tapdb/universe_test.go | 18 +++++++++--------- tapgarden/caretaker.go | 2 +- tapgarden/planter.go | 2 +- universe/auto_syncer.go | 6 +++--- universe/base.go | 8 ++++---- universe/interface.go | 22 +++++++++++----------- universe/syncer.go | 8 ++++---- universe_rpc_registrar.go | 2 +- 11 files changed, 46 insertions(+), 46 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index 42cf8b391..ed5957b09 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -2674,7 +2674,7 @@ func (r *rpcServer) AssetLeafKeys(ctx context.Context, } func marshalAssetLeaf(ctx context.Context, keys taprpc.KeyLookup, - assetLeaf *universe.MintingLeaf) (*unirpc.AssetLeaf, error) { + assetLeaf *universe.Leaf) (*unirpc.AssetLeaf, error) { // In order to display the full asset, we'll also encode the genesis // proof. @@ -2698,7 +2698,7 @@ func marshalAssetLeaf(ctx context.Context, keys taprpc.KeyLookup, // marshalAssetLeaf marshals an asset leaf into the RPC form. func (r *rpcServer) marshalAssetLeaf(ctx context.Context, - assetLeaf *universe.MintingLeaf) (*unirpc.AssetLeaf, error) { + assetLeaf *universe.Leaf) (*unirpc.AssetLeaf, error) { return marshalAssetLeaf(ctx, r.cfg.AddrBook, assetLeaf) } @@ -2935,7 +2935,7 @@ func (r *rpcServer) QueryProof(ctx context.Context, } // unmarshalAssetLeaf unmarshals an asset leaf from the RPC form. -func unmarshalAssetLeaf(leaf *unirpc.AssetLeaf) (*universe.MintingLeaf, error) { +func unmarshalAssetLeaf(leaf *unirpc.AssetLeaf) (*universe.Leaf, error) { // We'll just pull the asset details from the serialized issuance proof // itself. var assetProof proof.Proof @@ -2948,7 +2948,7 @@ func unmarshalAssetLeaf(leaf *unirpc.AssetLeaf) (*universe.MintingLeaf, error) { // TODO(roasbeef): double check posted file format everywhere // * raw proof, or within file? - return &universe.MintingLeaf{ + return &universe.Leaf{ GenesisWithGroup: universe.GenesisWithGroup{ Genesis: assetProof.Asset.Genesis, GroupKey: assetProof.Asset.GroupKey, diff --git a/tapdb/multiverse.go b/tapdb/multiverse.go index 2a7b6b9cf..c7d360113 100644 --- a/tapdb/multiverse.go +++ b/tapdb/multiverse.go @@ -217,7 +217,7 @@ func (b *MultiverseStore) FetchProofLeaf(ctx context.Context, // universe tree that corresponds to the given key. func (b *MultiverseStore) UpsertProofLeaf(ctx context.Context, id universe.Identifier, key universe.LeafKey, - leaf *universe.MintingLeaf, + leaf *universe.Leaf, metaReveal *proof.MetaReveal) (*universe.IssuanceProof, error) { var ( diff --git a/tapdb/universe.go b/tapdb/universe.go index 9a6ca902b..e575b4670 100644 --- a/tapdb/universe.go +++ b/tapdb/universe.go @@ -279,7 +279,7 @@ func upsertAssetGen(ctx context.Context, db UpsertAssetStore, // RegisterIssuance inserts a new minting leaf within the universe tree, stored // at the base key. func (b *BaseUniverseTree) RegisterIssuance(ctx context.Context, - key universe.LeafKey, leaf *universe.MintingLeaf, + key universe.LeafKey, leaf *universe.Leaf, metaReveal *proof.MetaReveal) (*universe.IssuanceProof, error) { var ( @@ -311,7 +311,7 @@ func (b *BaseUniverseTree) RegisterIssuance(ctx context.Context, // broader DB updates. func universeUpsertProofLeaf(ctx context.Context, dbTx BaseUniverseStore, id universe.Identifier, key universe.LeafKey, - leaf *universe.MintingLeaf, + leaf *universe.Leaf, metaReveal *proof.MetaReveal) (*universe.IssuanceProof, mssmt.Node, error) { @@ -321,7 +321,7 @@ func universeUpsertProofLeaf(ctx context.Context, dbTx BaseUniverseStore, // the minting key, as that'll be the key in the SMT itself. smtKey := key.UniverseKey() - // The value stored in the MS-SMT will be the serialized MintingLeaf, + // The value stored in the MS-SMT will be the serialized Leaf, // so we'll convert that into raw bytes now. leafNode, err := leaf.SmtLeafNode() if err != nil { @@ -550,7 +550,7 @@ func universeFetchProofLeaf(ctx context.Context, MintingKey: universeKey, UniverseRoot: rootNode, InclusionProof: leafProof, - Leaf: &universe.MintingLeaf{ + Leaf: &universe.Leaf{ GenesisWithGroup: universe.GenesisWithGroup{ Genesis: leafAssetGen, }, @@ -631,9 +631,9 @@ func (b *BaseUniverseTree) MintingKeys(ctx context.Context, // MintingLeaves returns all the minting leaves inserted into the universe. func (b *BaseUniverseTree) MintingLeaves( - ctx context.Context) ([]universe.MintingLeaf, error) { + ctx context.Context) ([]universe.Leaf, error) { - var leaves []universe.MintingLeaf + var leaves []universe.Leaf readTx := NewBaseUniverseReadTx() dbErr := b.db.ExecTx(ctx, &readTx, func(db BaseUniverseStore) error { @@ -671,7 +671,7 @@ func (b *BaseUniverseTree) MintingLeaves( // Now that we have the leaves, we'll encode them all // into the set of minting leaves. - leaf := universe.MintingLeaf{ + leaf := universe.Leaf{ GenesisWithGroup: universe.GenesisWithGroup{ Genesis: leafAssetGen, }, diff --git a/tapdb/universe_test.go b/tapdb/universe_test.go index 53ea96caa..13a4cd5d6 100644 --- a/tapdb/universe_test.go +++ b/tapdb/universe_test.go @@ -107,9 +107,9 @@ func randProof(t *testing.T) *proof.Proof { } func randMintingLeaf(t *testing.T, assetGen asset.Genesis, - groupKey *btcec.PublicKey) universe.MintingLeaf { + groupKey *btcec.PublicKey) universe.Leaf { - leaf := universe.MintingLeaf{ + leaf := universe.Leaf{ GenesisWithGroup: universe.GenesisWithGroup{ Genesis: assetGen, }, @@ -129,7 +129,7 @@ func randMintingLeaf(t *testing.T, assetGen asset.Genesis, type leafWithKey struct { universe.LeafKey - universe.MintingLeaf + universe.Leaf } // TestUniverseIssuanceProofs tests that we're able to insert issuance proofs @@ -167,7 +167,7 @@ func TestUniverseIssuanceProofs(t *testing.T) { leafSum += testLeaf.Amt targetKey := testLeaf.LeafKey - leaf := testLeaf.MintingLeaf + leaf := testLeaf.Leaf issuanceProof, err := baseUniverse.RegisterIssuance( ctx, targetKey, &leaf, nil, @@ -239,10 +239,10 @@ func TestUniverseIssuanceProofs(t *testing.T) { dbLeaves, err := baseUniverse.MintingLeaves(ctx) require.NoError(t, err) require.Equal(t, numLeaves, len(dbLeaves)) - require.True(t, fn.All(dbLeaves, func(leaf universe.MintingLeaf) bool { + require.True(t, fn.All(dbLeaves, func(leaf universe.Leaf) bool { return fn.All(testLeaves, func(testLeaf leafWithKey) bool { return leaf.Genesis.ID() == - testLeaf.MintingLeaf.Genesis.ID() + testLeaf.Leaf.Genesis.ID() }) })) @@ -255,11 +255,11 @@ func TestUniverseIssuanceProofs(t *testing.T) { // leaves we just inserted. for idx := range testLeaves { testLeaf := &testLeaves[idx] - testLeaf.MintingLeaf.GenesisProof = randProof(t) + testLeaf.Leaf.GenesisProof = randProof(t) targetKey := testLeaf.LeafKey issuanceProof, err := baseUniverse.RegisterIssuance( - ctx, targetKey, &testLeaf.MintingLeaf, nil, + ctx, targetKey, &testLeaf.Leaf, nil, ) require.NoError(t, err) @@ -453,7 +453,7 @@ func TestUniverseLeafQuery(t *testing.T) { // minting outpoint, but will have distinct script keys. rootMintingPoint := randLeafKey(t).OutPoint - leafToScriptKey := make(map[asset.SerializedKey]universe.MintingLeaf) + leafToScriptKey := make(map[asset.SerializedKey]universe.Leaf) for i := 0; i < numLeafs; i++ { targetKey := randLeafKey(t) targetKey.OutPoint = rootMintingPoint diff --git a/tapgarden/caretaker.go b/tapgarden/caretaker.go index 624ad6c06..b410ed95c 100644 --- a/tapgarden/caretaker.go +++ b/tapgarden/caretaker.go @@ -1062,7 +1062,7 @@ func (b *BatchCaretaker) storeMintingProof(ctx context.Context, if groupKey != nil { uniGen.GroupKey = groupKey } - mintingLeaf := &universe.MintingLeaf{ + mintingLeaf := &universe.Leaf{ GenesisWithGroup: uniGen, // The universe tree store only the asset state transition and diff --git a/tapgarden/planter.go b/tapgarden/planter.go index 735d90a81..cd8a5bbe2 100644 --- a/tapgarden/planter.go +++ b/tapgarden/planter.go @@ -896,7 +896,7 @@ func (c *ChainPlanter) updateMintingProofs(proofs []*proof.Proof) error { if p.Asset.GroupKey != nil { uniGen.GroupKey = p.Asset.GroupKey } - mintingLeaf := &universe.MintingLeaf{ + mintingLeaf := &universe.Leaf{ GenesisWithGroup: uniGen, GenesisProof: p, Amt: p.Asset.Amount, diff --git a/universe/auto_syncer.go b/universe/auto_syncer.go index 2ec10bfaa..eb25182f8 100644 --- a/universe/auto_syncer.go +++ b/universe/auto_syncer.go @@ -67,7 +67,7 @@ type FederationPushReq struct { Key LeafKey // Leaf is the new leaf to add. - Leaf *MintingLeaf + Leaf *Leaf resp chan *IssuanceProof err chan error @@ -226,7 +226,7 @@ func (f *FederationEnvoy) syncUniverseState(ctx context.Context, // pushProofToFederation attempts to push out a new proof to the current // federation in parallel. func (f *FederationEnvoy) pushProofToFederation(uniID Identifier, key LeafKey, - leaf *MintingLeaf) { + leaf *Leaf) { ctx, cancel := f.WithCtxQuit() defer cancel() @@ -419,7 +419,7 @@ func (f *FederationEnvoy) syncer() { // // NOTE: This is part of the universe.Registrar interface. func (f *FederationEnvoy) RegisterIssuance(_ context.Context, id Identifier, - key LeafKey, leaf *MintingLeaf) (*IssuanceProof, error) { + key LeafKey, leaf *Leaf) (*IssuanceProof, error) { pushReq := &FederationPushReq{ ID: id, diff --git a/universe/base.go b/universe/base.go index 72cec2e45..acec85810 100644 --- a/universe/base.go +++ b/universe/base.go @@ -136,7 +136,7 @@ func (a *MintingArchive) RootNodes(ctx context.Context) ([]BaseRoot, error) { // error if the passed minting proof is invalid. If the leaf is already known, // then no action is taken and the existing issuance commitment proof returned. func (a *MintingArchive) RegisterIssuance(ctx context.Context, id Identifier, - key LeafKey, leaf *MintingLeaf) (*IssuanceProof, error) { + key LeafKey, leaf *Leaf) (*IssuanceProof, error) { log.Debugf("Inserting new proof into Universe: id=%v, base_key=%v", id.StringForLog(), spew.Sdump(key)) @@ -219,7 +219,7 @@ func (a *MintingArchive) RegisterIssuance(ctx context.Context, id Identifier, // verifyIssuanceProof verifies the passed minting leaf is a valid issuance // proof, returning the asset snapshot if so. func (a *MintingArchive) verifyIssuanceProof(ctx context.Context, id Identifier, - key LeafKey, leaf *MintingLeaf, + key LeafKey, leaf *Leaf, prevAssetSnapshot *proof.AssetSnapshot) (*proof.AssetSnapshot, error) { assetSnapshot, err := leaf.GenesisProof.Verify( @@ -408,13 +408,13 @@ func (a *MintingArchive) MintingKeys(ctx context.Context, // MintingLeaves returns the set of minting leaves known for the specified base // universe. func (a *MintingArchive) MintingLeaves(ctx context.Context, - id Identifier) ([]MintingLeaf, error) { + id Identifier) ([]Leaf, error) { log.Debugf("Retrieving all leaves for Universe: id=%v", id.StringForLog()) return withBaseUni( - a, id, func(baseUni BaseBackend) ([]MintingLeaf, error) { + a, id, func(baseUni BaseBackend) ([]Leaf, error) { return baseUni.MintingLeaves(ctx) }, ) diff --git a/universe/interface.go b/universe/interface.go index b664ee15b..8f9c1d5df 100644 --- a/universe/interface.go +++ b/universe/interface.go @@ -82,10 +82,10 @@ type GenesisWithGroup struct { *asset.GroupKey } -// MintingLeaf is a leaf node in the SMT that represents a minting output. For -// each new asset created for a given asset/universe, a new minting leaf is +// Leaf is a leaf node in the SMT that represents an asset issuance or transfer. +// For each asset issued or transferred for a given universe, a new leaf is // created. -type MintingLeaf struct { +type Leaf struct { GenesisWithGroup // GenesisProof is the proof of the newly created asset. @@ -96,7 +96,7 @@ type MintingLeaf struct { } // SmtLeafNode returns the SMT leaf node for the given minting leaf. -func (m *MintingLeaf) SmtLeafNode() (*mssmt.LeafNode, error) { +func (m *Leaf) SmtLeafNode() (*mssmt.LeafNode, error) { var buf bytes.Buffer if err := m.GenesisProof.Encode(&buf); err != nil { return nil, err @@ -152,7 +152,7 @@ type IssuanceProof struct { InclusionProof *mssmt.Proof // Leaf is the leaf node for the asset within the universe tree. - Leaf *MintingLeaf + Leaf *Leaf // MultiverseRoot is the root of the multiverse tree that the asset is // located within. @@ -193,7 +193,7 @@ type BaseBackend interface { // tree, stored at the base key. The metaReveal type is purely // optional, and should be specified if the genesis proof committed to // a non-zero meta hash. - RegisterIssuance(ctx context.Context, key LeafKey, leaf *MintingLeaf, + RegisterIssuance(ctx context.Context, key LeafKey, leaf *Leaf, metaReveal *proof.MetaReveal) (*IssuanceProof, error) // FetchIssuanceProof returns an issuance proof for the target key. If @@ -210,7 +210,7 @@ type BaseBackend interface { // MintingLeaves returns all the minting leaves inserted into the // universe. - MintingLeaves(ctx context.Context) ([]MintingLeaf, error) + MintingLeaves(ctx context.Context) ([]Leaf, error) // DeleteUniverse deletes all leaves, and the root, for a given base // universe. @@ -246,7 +246,7 @@ type MultiverseArchive interface { // 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 LeafKey, - leaf *MintingLeaf, + leaf *Leaf, metaReveal *proof.MetaReveal) (*IssuanceProof, error) // RegisterBatchIssuance inserts a new minting leaf batch within the @@ -271,7 +271,7 @@ type Registrar interface { // RegisterIssuance inserts a new minting leaf within the target // universe tree (based on the ID), stored at the base key. RegisterIssuance(ctx context.Context, id Identifier, key LeafKey, - leaf *MintingLeaf) (*IssuanceProof, error) + leaf *Leaf) (*IssuanceProof, error) } // IssuanceItem is an item that can be used to register a new issuance within a @@ -285,7 +285,7 @@ type IssuanceItem struct { Key LeafKey // Leaf is the minting leaf that was created. - Leaf *MintingLeaf + Leaf *Leaf // MetaReveal is the meta reveal that was created. MetaReveal *proof.MetaReveal @@ -435,7 +435,7 @@ type AssetSyncDiff struct { // NewAssetLeaves is the set of new leaf proofs that were added to the // Universe. - NewLeafProofs []*MintingLeaf + NewLeafProofs []*Leaf // TODO(roasbeef): ability to return if things failed? // * can used a sealed interface to return the error diff --git a/universe/syncer.go b/universe/syncer.go index 2c51cb387..dcf45f5e3 100644 --- a/universe/syncer.go +++ b/universe/syncer.go @@ -190,7 +190,7 @@ func (s *SimpleSyncer) syncRoot(ctx context.Context, remoteRoot BaseRoot, // local registrar as they're fetched. var ( fetchedLeaves = make(chan *IssuanceItem, len(keysToFetch)) - newLeafProofs []*MintingLeaf + newLeafProofs []*Leaf batchSyncEG errgroup.Group ) @@ -275,11 +275,11 @@ func (s *SimpleSyncer) syncRoot(ctx context.Context, remoteRoot BaseRoot, // batches and returns the new leaf proofs. func (s *SimpleSyncer) batchStreamNewItems(ctx context.Context, uniID Identifier, fetchedLeaves chan *IssuanceItem, - numTotal int) ([]*MintingLeaf, error) { + numTotal int) ([]*Leaf, error) { var ( numItems int - newLeafProofs []*MintingLeaf + newLeafProofs []*Leaf ) err := fn.CollectBatch( ctx, fetchedLeaves, s.cfg.SyncBatchSize, @@ -302,7 +302,7 @@ func (s *SimpleSyncer) batchStreamNewItems(ctx context.Context, numItems, numTotal) newLeaves := fn.Map( - batch, func(i *IssuanceItem) *MintingLeaf { + batch, func(i *IssuanceItem) *Leaf { return i.Leaf }, ) diff --git a/universe_rpc_registrar.go b/universe_rpc_registrar.go index 070731572..5a07d9627 100644 --- a/universe_rpc_registrar.go +++ b/universe_rpc_registrar.go @@ -82,7 +82,7 @@ func unmarshalIssuanceProof(uniKey *unirpc.UniverseKey, // that uses a remote Universe server as the Registry instance. func (r *RpcUniverseRegistrar) RegisterIssuance(ctx context.Context, id universe.Identifier, key universe.LeafKey, - leaf *universe.MintingLeaf) (*universe.IssuanceProof, error) { + leaf *universe.Leaf) (*universe.IssuanceProof, error) { // First, we'll parse the proofs and key into their RPC counterparts. uniKey := &unirpc.UniverseKey{ From 41ac9a7a70426d97650646cacce64e328a381053 Mon Sep 17 00:00:00 2001 From: ffranr Date: Tue, 26 Sep 2023 17:21:20 +0100 Subject: [PATCH 11/16] multi: rename universe.Leaf.GenesisProof to universe.Leaf.Proof --- rpcserver.go | 8 ++++---- tapdb/universe.go | 10 +++++----- tapdb/universe_test.go | 6 +++--- tapgarden/caretaker.go | 4 ++-- tapgarden/planter.go | 2 +- universe/base.go | 8 ++++---- universe/interface.go | 7 ++++--- 7 files changed, 23 insertions(+), 22 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index ed5957b09..51838a80a 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -2679,12 +2679,12 @@ func marshalAssetLeaf(ctx context.Context, keys taprpc.KeyLookup, // In order to display the full asset, we'll also encode the genesis // proof. var buf bytes.Buffer - if err := assetLeaf.GenesisProof.Encode(&buf); err != nil { + if err := assetLeaf.Proof.Encode(&buf); err != nil { return nil, err } rpcAsset, err := taprpc.MarshalAsset( - ctx, &assetLeaf.GenesisProof.Asset, false, true, keys, + ctx, &assetLeaf.Proof.Asset, false, true, keys, ) if err != nil { return nil, err @@ -2953,8 +2953,8 @@ func unmarshalAssetLeaf(leaf *unirpc.AssetLeaf) (*universe.Leaf, error) { Genesis: assetProof.Asset.Genesis, GroupKey: assetProof.Asset.GroupKey, }, - GenesisProof: &assetProof, - Amt: assetProof.Asset.Amount, + Proof: &assetProof, + Amt: assetProof.Asset.Amount, }, nil } diff --git a/tapdb/universe.go b/tapdb/universe.go index e575b4670..a7b2f1646 100644 --- a/tapdb/universe.go +++ b/tapdb/universe.go @@ -380,7 +380,7 @@ func universeUpsertProofLeaf(ctx context.Context, dbTx BaseUniverseStore, } assetGenID, err := upsertAssetGen( - ctx, dbTx, leaf.Genesis, leaf.GroupKey, leaf.GenesisProof, + ctx, dbTx, leaf.Genesis, leaf.GroupKey, leaf.Proof, ) if err != nil { return nil, nil, err @@ -554,8 +554,8 @@ func universeFetchProofLeaf(ctx context.Context, GenesisWithGroup: universe.GenesisWithGroup{ Genesis: leafAssetGen, }, - GenesisProof: &genProof, - Amt: uint64(leaf.SumAmt), + Proof: &genProof, + Amt: uint64(leaf.SumAmt), }, } if id.GroupKey != nil { @@ -675,8 +675,8 @@ func (b *BaseUniverseTree) MintingLeaves( GenesisWithGroup: universe.GenesisWithGroup{ Genesis: leafAssetGen, }, - GenesisProof: &genProof, - Amt: uint64(dbLeaf.SumAmt), + Proof: &genProof, + Amt: uint64(dbLeaf.SumAmt), } if b.id.GroupKey != nil { leaf.GroupKey = &asset.GroupKey{ diff --git a/tapdb/universe_test.go b/tapdb/universe_test.go index 13a4cd5d6..729240634 100644 --- a/tapdb/universe_test.go +++ b/tapdb/universe_test.go @@ -113,8 +113,8 @@ func randMintingLeaf(t *testing.T, assetGen asset.Genesis, GenesisWithGroup: universe.GenesisWithGroup{ Genesis: assetGen, }, - GenesisProof: randProof(t), - Amt: uint64(rand.Int31()), + Proof: randProof(t), + Amt: uint64(rand.Int31()), } if groupKey != nil { leaf.GroupKey = &asset.GroupKey{ @@ -255,7 +255,7 @@ func TestUniverseIssuanceProofs(t *testing.T) { // leaves we just inserted. for idx := range testLeaves { testLeaf := &testLeaves[idx] - testLeaf.Leaf.GenesisProof = randProof(t) + testLeaf.Leaf.Proof = randProof(t) targetKey := testLeaf.LeafKey issuanceProof, err := baseUniverse.RegisterIssuance( diff --git a/tapgarden/caretaker.go b/tapgarden/caretaker.go index b410ed95c..4820a6ffb 100644 --- a/tapgarden/caretaker.go +++ b/tapgarden/caretaker.go @@ -1068,8 +1068,8 @@ func (b *BatchCaretaker) storeMintingProof(ctx context.Context, // The universe tree store only the asset state transition and // not also the proof file checksum (as the root is effectively // a checksum), so we'll use just the state transition. - GenesisProof: mintingProof, - Amt: a.Amount, + Proof: mintingProof, + Amt: a.Amount, } return blob, &universe.IssuanceItem{ diff --git a/tapgarden/planter.go b/tapgarden/planter.go index cd8a5bbe2..5978925c4 100644 --- a/tapgarden/planter.go +++ b/tapgarden/planter.go @@ -898,7 +898,7 @@ func (c *ChainPlanter) updateMintingProofs(proofs []*proof.Proof) error { } mintingLeaf := &universe.Leaf{ GenesisWithGroup: uniGen, - GenesisProof: p, + Proof: p, Amt: p.Asset.Amount, } _, err = c.cfg.Universe.RegisterIssuance( diff --git a/universe/base.go b/universe/base.go index acec85810..29dea47fc 100644 --- a/universe/base.go +++ b/universe/base.go @@ -141,7 +141,7 @@ func (a *MintingArchive) RegisterIssuance(ctx context.Context, id Identifier, log.Debugf("Inserting new proof into Universe: id=%v, base_key=%v", id.StringForLog(), spew.Sdump(key)) - newProof := leaf.GenesisProof + newProof := leaf.Proof // 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. @@ -154,7 +154,7 @@ func (a *MintingArchive) RegisterIssuance(ctx context.Context, id Identifier, // TX was re-organized out of the chain. If the block hash is // still the same, we don't see this as an update and just // return the existing proof. - existingProof := issuanceProof.Leaf.GenesisProof + existingProof := issuanceProof.Leaf.Proof if existingProof.BlockHeader.BlockHash() == newProof.BlockHeader.BlockHash() { @@ -222,7 +222,7 @@ func (a *MintingArchive) verifyIssuanceProof(ctx context.Context, id Identifier, key LeafKey, leaf *Leaf, prevAssetSnapshot *proof.AssetSnapshot) (*proof.AssetSnapshot, error) { - assetSnapshot, err := leaf.GenesisProof.Verify( + assetSnapshot, err := leaf.Proof.Verify( ctx, prevAssetSnapshot, a.cfg.HeaderVerifier, ) if err != nil { @@ -355,7 +355,7 @@ func (a *MintingArchive) getPrevAssetSnapshot(ctx context.Context, "proof: %v", err) } - prevProof := prevProofs[0].Leaf.GenesisProof + prevProof := prevProofs[0].Leaf.Proof // Construct minimal asset snapshot for previous asset. // This is a minimal the proof verification result for the diff --git a/universe/interface.go b/universe/interface.go index 8f9c1d5df..25ceb80f7 100644 --- a/universe/interface.go +++ b/universe/interface.go @@ -88,8 +88,9 @@ type GenesisWithGroup struct { type Leaf struct { GenesisWithGroup - // GenesisProof is the proof of the newly created asset. - GenesisProof *proof.Proof + // Proof is either an issuance proof or a transfer proof associated with + // the issuance or spend event which this leaf represents. + Proof *proof.Proof // Amt is the amount of units created. Amt uint64 @@ -98,7 +99,7 @@ type Leaf struct { // SmtLeafNode returns the SMT leaf node for the given minting leaf. func (m *Leaf) SmtLeafNode() (*mssmt.LeafNode, error) { var buf bytes.Buffer - if err := m.GenesisProof.Encode(&buf); err != nil { + if err := m.Proof.Encode(&buf); err != nil { return nil, err } From eb138db707d3d932c1ae2a278d4034a1c9740252 Mon Sep 17 00:00:00 2001 From: ffranr Date: Tue, 26 Sep 2023 17:25:37 +0100 Subject: [PATCH 12/16] universe: update docs associated with universe.Leaf --- universe/interface.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/universe/interface.go b/universe/interface.go index 25ceb80f7..a7f254bae 100644 --- a/universe/interface.go +++ b/universe/interface.go @@ -92,11 +92,11 @@ type Leaf struct { // the issuance or spend event which this leaf represents. Proof *proof.Proof - // Amt is the amount of units created. + // Amt is the amount of units associated with the coin. Amt uint64 } -// SmtLeafNode returns the SMT leaf node for the given minting leaf. +// SmtLeafNode returns the SMT leaf node for the given leaf. func (m *Leaf) SmtLeafNode() (*mssmt.LeafNode, error) { var buf bytes.Buffer if err := m.Proof.Encode(&buf); err != nil { From ff6c929eaafc52b02b85326a3aac14e5c042326a Mon Sep 17 00:00:00 2001 From: ffranr Date: Tue, 26 Sep 2023 17:38:26 +0100 Subject: [PATCH 13/16] multi: rename field universe.IssuanceProof.MintingKey to LeafKey --- tapdb/universe.go | 4 ++-- tapdb/universe_stats_test.go | 8 +++----- tapdb/universe_test.go | 4 ++-- universe/interface.go | 6 +++--- universe_rpc_diff.go | 2 +- universe_rpc_registrar.go | 2 +- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/tapdb/universe.go b/tapdb/universe.go index a7b2f1646..0faf80c8b 100644 --- a/tapdb/universe.go +++ b/tapdb/universe.go @@ -414,7 +414,7 @@ func universeUpsertProofLeaf(ctx context.Context, dbTx BaseUniverseStore, } return &universe.IssuanceProof{ - MintingKey: key, + LeafKey: key, UniverseRoot: universeRoot, InclusionProof: leafInclusionProof, Leaf: leaf, @@ -547,7 +547,7 @@ func universeFetchProofLeaf(ctx context.Context, } issuanceProof := &universe.IssuanceProof{ - MintingKey: universeKey, + LeafKey: universeKey, UniverseRoot: rootNode, InclusionProof: leafProof, Leaf: &universe.Leaf{ diff --git a/tapdb/universe_stats_test.go b/tapdb/universe_stats_test.go index 5ffa9637f..058867e84 100644 --- a/tapdb/universe_stats_test.go +++ b/tapdb/universe_stats_test.go @@ -80,7 +80,7 @@ func newUniStatsHarness(t *testing.T, numAssets int, db *BaseDB, func (u *uniStatsHarness) logProofEventByIndex(i int) { ctx := context.Background() err := u.db.LogNewProofEvent( - ctx, u.assetUniverses[i].id, u.universeLeaves[i].MintingKey, + ctx, u.assetUniverses[i].id, u.universeLeaves[i].LeafKey, ) require.NoError(u.t, err) } @@ -88,7 +88,7 @@ func (u *uniStatsHarness) logProofEventByIndex(i int) { func (u *uniStatsHarness) logSyncEventByIndex(i int) { ctx := context.Background() err := u.db.LogSyncEvent( - ctx, u.assetUniverses[i].id, u.universeLeaves[i].MintingKey, + ctx, u.assetUniverses[i].id, u.universeLeaves[i].LeafKey, ) require.NoError(u.t, err) } @@ -175,9 +175,7 @@ func TestUniverseStatsEvents(t *testing.T) { require.Equal(t, assetStat.TotalSupply, leaf.Leaf.Amt) - if sh.universeLeaves[assetToSync].MintingKey == - leaf.MintingKey { - + if sh.universeLeaves[assetToSync].LeafKey == leaf.LeafKey { require.Equal(t, int(assetStat.TotalSyncs), 1) } diff --git a/tapdb/universe_test.go b/tapdb/universe_test.go index 729240634..6498a43e8 100644 --- a/tapdb/universe_test.go +++ b/tapdb/universe_test.go @@ -204,7 +204,7 @@ func TestUniverseIssuanceProofs(t *testing.T) { uniProof := dbProof[0] // The proof should have the proper values populated. - require.Equal(t, targetKey, uniProof.MintingKey) + require.Equal(t, targetKey, uniProof.LeafKey) require.True( t, mssmt.IsEqualNode(rootNode, uniProof.UniverseRoot), ) @@ -214,7 +214,7 @@ func TestUniverseIssuanceProofs(t *testing.T) { node, err = uniProof.Leaf.SmtLeafNode() require.NoError(t, err) dbProofRoot := uniProof.InclusionProof.Root( - uniProof.MintingKey.UniverseKey(), node, + uniProof.LeafKey.UniverseKey(), node, ) require.True( t, mssmt.IsEqualNode(uniProof.UniverseRoot, dbProofRoot), diff --git a/universe/interface.go b/universe/interface.go index a7f254bae..1c7108fd8 100644 --- a/universe/interface.go +++ b/universe/interface.go @@ -141,8 +141,8 @@ func (b LeafKey) UniverseKey() [32]byte { // (based on the proof in the leaf), and that the asset is committed to within // the universe root. type IssuanceProof struct { - // MintingKey is the minting key for the asset. - MintingKey LeafKey + // LeafKey is the universe leaf key for the asset issuance or spend. + LeafKey LeafKey // UniverseRoot is the root of the universe that the asset is located // within. @@ -174,7 +174,7 @@ func (i *IssuanceProof) VerifyRoot(expectedRoot mssmt.Node) (bool, error) { } reconstructedRoot := i.InclusionProof.Root( - i.MintingKey.UniverseKey(), leafNode, + i.LeafKey.UniverseKey(), leafNode, ) return mssmt.IsEqualNode(i.UniverseRoot, expectedRoot) && diff --git a/universe_rpc_diff.go b/universe_rpc_diff.go index 4ca39bb65..571d59844 100644 --- a/universe_rpc_diff.go +++ b/universe_rpc_diff.go @@ -172,7 +172,7 @@ func (r *RpcUniverseDiff) FetchIssuanceProof(ctx context.Context, } uniProof := &universe.IssuanceProof{ - MintingKey: key, + LeafKey: key, UniverseRoot: uniRoot, InclusionProof: inclusionProof, Leaf: assetLeaf, diff --git a/universe_rpc_registrar.go b/universe_rpc_registrar.go index 5a07d9627..9ecfdc507 100644 --- a/universe_rpc_registrar.go +++ b/universe_rpc_registrar.go @@ -66,7 +66,7 @@ func unmarshalIssuanceProof(uniKey *unirpc.UniverseKey, } return &universe.IssuanceProof{ - MintingKey: leafKey, + LeafKey: leafKey, UniverseRoot: mssmt.NewComputedBranch( fn.ToArray[mssmt.NodeHash]( proofResp.UniverseRoot.MssmtRoot.RootHash, From f76d18a6b3fc202bec4093e186d288a85dcf983e Mon Sep 17 00:00:00 2001 From: ffranr Date: Tue, 26 Sep 2023 18:03:17 +0100 Subject: [PATCH 14/16] multi: rename field universe.IssuanceProof to Proof --- rpcserver.go | 2 +- tapdb/multiverse.go | 8 ++++---- tapdb/universe.go | 18 +++++++++--------- tapdb/universe_stats_test.go | 10 +++++----- tapdb/universe_test.go | 2 +- universe/auto_syncer.go | 6 +++--- universe/base.go | 4 ++-- universe/interface.go | 32 +++++++++++++++++--------------- universe_rpc_diff.go | 6 +++--- universe_rpc_registrar.go | 8 ++++---- 10 files changed, 49 insertions(+), 47 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index 51838a80a..b547e30a6 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -2849,7 +2849,7 @@ func marshalMssmtProof(proof *mssmt.Proof) ([]byte, error) { // marshalIssuanceProof marshals an issuance proof into the RPC form. func (r *rpcServer) marshalIssuanceProof(ctx context.Context, req *unirpc.UniverseKey, - proof *universe.IssuanceProof) (*unirpc.AssetProofResponse, error) { + proof *universe.Proof) (*unirpc.AssetProofResponse, error) { uniProof, err := marshalMssmtProof(proof.InclusionProof) if err != nil { diff --git a/tapdb/multiverse.go b/tapdb/multiverse.go index c7d360113..d137d4a91 100644 --- a/tapdb/multiverse.go +++ b/tapdb/multiverse.go @@ -158,11 +158,11 @@ func (b *MultiverseStore) RootNodes( // leafs will be returned. func (b *MultiverseStore) FetchProofLeaf(ctx context.Context, id universe.Identifier, - universeKey universe.LeafKey) ([]*universe.IssuanceProof, error) { + universeKey universe.LeafKey) ([]*universe.Proof, error) { var ( readTx = NewBaseUniverseReadTx() - proofs []*universe.IssuanceProof + proofs []*universe.Proof ) dbErr := b.db.ExecTx(ctx, &readTx, func(dbTx BaseMultiverseStore) error { @@ -218,11 +218,11 @@ func (b *MultiverseStore) FetchProofLeaf(ctx context.Context, func (b *MultiverseStore) UpsertProofLeaf(ctx context.Context, id universe.Identifier, key universe.LeafKey, leaf *universe.Leaf, - metaReveal *proof.MetaReveal) (*universe.IssuanceProof, error) { + metaReveal *proof.MetaReveal) (*universe.Proof, error) { var ( writeTx BaseMultiverseOptions - issuanceProof *universe.IssuanceProof + issuanceProof *universe.Proof ) execTxFunc := func(dbTx BaseMultiverseStore) error { diff --git a/tapdb/universe.go b/tapdb/universe.go index 0faf80c8b..e9d94a5ff 100644 --- a/tapdb/universe.go +++ b/tapdb/universe.go @@ -280,13 +280,13 @@ func upsertAssetGen(ctx context.Context, db UpsertAssetStore, // at the base key. func (b *BaseUniverseTree) RegisterIssuance(ctx context.Context, key universe.LeafKey, leaf *universe.Leaf, - metaReveal *proof.MetaReveal) (*universe.IssuanceProof, error) { + metaReveal *proof.MetaReveal) (*universe.Proof, error) { var ( writeTx BaseUniverseStoreOptions err error - issuanceProof *universe.IssuanceProof + issuanceProof *universe.Proof ) dbErr := b.db.ExecTx(ctx, &writeTx, func(dbTx BaseUniverseStore) error { issuanceProof, _, err = universeUpsertProofLeaf( @@ -312,7 +312,7 @@ func (b *BaseUniverseTree) RegisterIssuance(ctx context.Context, func universeUpsertProofLeaf(ctx context.Context, dbTx BaseUniverseStore, id universe.Identifier, key universe.LeafKey, leaf *universe.Leaf, - metaReveal *proof.MetaReveal) (*universe.IssuanceProof, mssmt.Node, + metaReveal *proof.MetaReveal) (*universe.Proof, mssmt.Node, error) { namespace := id.String() @@ -413,7 +413,7 @@ func universeUpsertProofLeaf(ctx context.Context, dbTx BaseUniverseStore, return nil, nil, err } - return &universe.IssuanceProof{ + return &universe.Proof{ LeafKey: key, UniverseRoot: universeRoot, InclusionProof: leafInclusionProof, @@ -426,11 +426,11 @@ func universeUpsertProofLeaf(ctx context.Context, dbTx BaseUniverseStore, // outpoint will be returned. If neither are specified, then proofs for all the // inserted leaves will be returned. func (b *BaseUniverseTree) FetchIssuanceProof(ctx context.Context, - universeKey universe.LeafKey) ([]*universe.IssuanceProof, error) { + universeKey universe.LeafKey) ([]*universe.Proof, error) { var ( readTx = NewBaseUniverseReadTx() - proofs []*universe.IssuanceProof + proofs []*universe.Proof ) dbErr := b.db.ExecTx(ctx, &readTx, func(dbTx BaseUniverseStore) error { @@ -456,7 +456,7 @@ func (b *BaseUniverseTree) FetchIssuanceProof(ctx context.Context, // broader DB updates. func universeFetchProofLeaf(ctx context.Context, id universe.Identifier, universeKey universe.LeafKey, - dbTx BaseUniverseStore) ([]*universe.IssuanceProof, error) { + dbTx BaseUniverseStore) ([]*universe.Proof, error) { namespace := id.String() @@ -474,7 +474,7 @@ func universeFetchProofLeaf(ctx context.Context, return nil, err } - var proofs []*universe.IssuanceProof + var proofs []*universe.Proof // First, we'll make a new instance of the universe tree, as we'll query // it directly to obtain the set of leaves we care about. @@ -546,7 +546,7 @@ func universeFetchProofLeaf(ctx context.Context, return fmt.Errorf("unable to decode proof: %w", err) } - issuanceProof := &universe.IssuanceProof{ + issuanceProof := &universe.Proof{ LeafKey: universeKey, UniverseRoot: rootNode, InclusionProof: leafProof, diff --git a/tapdb/universe_stats_test.go b/tapdb/universe_stats_test.go index 058867e84..74f7b45a9 100644 --- a/tapdb/universe_stats_test.go +++ b/tapdb/universe_stats_test.go @@ -31,8 +31,8 @@ func newUniverseStatsWithDB(db *BaseDB, clock clock.Clock) (*UniverseStats, type uniStatsHarness struct { assetUniverses []*BaseUniverseTree - universeLeaves []*universe.IssuanceProof - leafIndex map[asset.ID]*universe.IssuanceProof + universeLeaves []*universe.Proof + leafIndex map[asset.ID]*universe.Proof db *UniverseStats @@ -44,8 +44,8 @@ func newUniStatsHarness(t *testing.T, numAssets int, db *BaseDB, stats := &uniStatsHarness{ assetUniverses: make([]*BaseUniverseTree, numAssets), - universeLeaves: make([]*universe.IssuanceProof, numAssets), - leafIndex: make(map[asset.ID]*universe.IssuanceProof), + universeLeaves: make([]*universe.Proof, numAssets), + leafIndex: make(map[asset.ID]*universe.Proof), db: statsDB, t: t, } @@ -539,7 +539,7 @@ func TestUniverseQuerySyncFilters(t *testing.T) { typeFilter: fn.Ptr(asset.Type(rand.Int() % 2)), queryCheck: func(s *universe.AssetSyncStats) bool { typeCount := fn.Reduce(sh.universeLeaves, - func(acc int, p *universe.IssuanceProof) int { + func(acc int, p *universe.Proof) int { if p.Leaf.Type == *s.Query.AssetTypeFilter { return acc + 1 } diff --git a/tapdb/universe_test.go b/tapdb/universe_test.go index 6498a43e8..3414353ba 100644 --- a/tapdb/universe_test.go +++ b/tapdb/universe_test.go @@ -341,7 +341,7 @@ func TestUniverseMetaBlob(t *testing.T) { } func insertRandLeaf(t *testing.T, ctx context.Context, tree *BaseUniverseTree, - assetGen *asset.Genesis) (*universe.IssuanceProof, error) { + assetGen *asset.Genesis) (*universe.Proof, error) { var targetGen asset.Genesis if assetGen != nil { diff --git a/universe/auto_syncer.go b/universe/auto_syncer.go index eb25182f8..fad9788b6 100644 --- a/universe/auto_syncer.go +++ b/universe/auto_syncer.go @@ -69,7 +69,7 @@ type FederationPushReq struct { // Leaf is the new leaf to add. Leaf *Leaf - resp chan *IssuanceProof + resp chan *Proof err chan error } @@ -419,13 +419,13 @@ func (f *FederationEnvoy) syncer() { // // NOTE: This is part of the universe.Registrar interface. func (f *FederationEnvoy) RegisterIssuance(_ context.Context, id Identifier, - key LeafKey, leaf *Leaf) (*IssuanceProof, error) { + key LeafKey, leaf *Leaf) (*Proof, error) { pushReq := &FederationPushReq{ ID: id, Key: key, Leaf: leaf, - resp: make(chan *IssuanceProof, 1), + resp: make(chan *Proof, 1), err: make(chan error, 1), } diff --git a/universe/base.go b/universe/base.go index 29dea47fc..c9f9ec429 100644 --- a/universe/base.go +++ b/universe/base.go @@ -136,7 +136,7 @@ func (a *MintingArchive) RootNodes(ctx context.Context) ([]BaseRoot, error) { // error if the passed minting proof is invalid. If the leaf is already known, // then no action is taken and the existing issuance commitment proof returned. func (a *MintingArchive) RegisterIssuance(ctx context.Context, id Identifier, - key LeafKey, leaf *Leaf) (*IssuanceProof, error) { + key LeafKey, leaf *Leaf) (*Proof, error) { log.Debugf("Inserting new proof into Universe: id=%v, base_key=%v", id.StringForLog(), spew.Sdump(key)) @@ -370,7 +370,7 @@ func (a *MintingArchive) getPrevAssetSnapshot(ctx context.Context, // FetchIssuanceProof attempts to fetch an issuance proof for the target base // leaf based on the universe identifier (assetID/groupKey). func (a *MintingArchive) FetchIssuanceProof(ctx context.Context, id Identifier, - key LeafKey) ([]*IssuanceProof, error) { + key LeafKey) ([]*Proof, error) { log.Debugf("Retrieving Universe proof for: id=%v, base_key=%v", id.StringForLog(), spew.Sdump(key)) diff --git a/universe/interface.go b/universe/interface.go index 1c7108fd8..87ac44c5b 100644 --- a/universe/interface.go +++ b/universe/interface.go @@ -136,11 +136,16 @@ func (b LeafKey) UniverseKey() [32]byte { return k } -// IssuanceProof is a complete issuance proof for a given asset specified by -// the minting key. This proof can be used to verify that a valid asset exists +// Proof associates a universe leaf (and key) with its corresponding multiverse +// and universe inclusion proofs. +// +// These inclusion proofs can be used to verify that a valid asset exists // (based on the proof in the leaf), and that the asset is committed to within -// the universe root. -type IssuanceProof struct { +// the universe root and multiverse root. +type Proof struct { + // Leaf is the leaf node for the asset within the universe tree. + Leaf *Leaf + // LeafKey is the universe leaf key for the asset issuance or spend. LeafKey LeafKey @@ -152,9 +157,6 @@ type IssuanceProof struct { // universe tree. InclusionProof *mssmt.Proof - // Leaf is the leaf node for the asset within the universe tree. - Leaf *Leaf - // MultiverseRoot is the root of the multiverse tree that the asset is // located within. MultiverseRoot mssmt.Node @@ -167,7 +169,7 @@ type IssuanceProof struct { // VerifyRoot verifies that the inclusion proof for the root node matches the // specified root. This is useful for sanity checking an issuance proof against // the purported root, and the included leaf. -func (i *IssuanceProof) VerifyRoot(expectedRoot mssmt.Node) (bool, error) { +func (i *Proof) VerifyRoot(expectedRoot mssmt.Node) (bool, error) { leafNode, err := i.Leaf.SmtLeafNode() if err != nil { return false, err @@ -195,7 +197,7 @@ type BaseBackend interface { // optional, and should be specified if the genesis proof committed to // a non-zero meta hash. RegisterIssuance(ctx context.Context, key LeafKey, leaf *Leaf, - metaReveal *proof.MetaReveal) (*IssuanceProof, error) + metaReveal *proof.MetaReveal) (*Proof, 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 @@ -204,7 +206,7 @@ type BaseBackend interface { // // TODO(roasbeef): can eventually do multi-proofs for the SMT FetchIssuanceProof(ctx context.Context, - key LeafKey) ([]*IssuanceProof, error) + key LeafKey) ([]*Proof, error) // MintingKeys returns all the keys inserted in the universe. MintingKeys(ctx context.Context) ([]LeafKey, error) @@ -248,7 +250,7 @@ type MultiverseArchive interface { // the universe tree that corresponds to the given key. UpsertProofLeaf(ctx context.Context, id Identifier, key LeafKey, leaf *Leaf, - metaReveal *proof.MetaReveal) (*IssuanceProof, error) + metaReveal *proof.MetaReveal) (*Proof, error) // RegisterBatchIssuance inserts a new minting leaf batch within the // multiverse tree and the universe tree that corresponds to the given @@ -260,7 +262,7 @@ type MultiverseArchive interface { // minting outpoint will be returned. If neither are specified, then all // inserted proof leafs will be returned. FetchProofLeaf(ctx context.Context, id Identifier, - key LeafKey) ([]*IssuanceProof, error) + key LeafKey) ([]*Proof, error) // TODO(roasbeef): other stats stuff here, like total number of assets, etc // * also eventually want pull/fetch stats, can be pulled out into another instance @@ -272,7 +274,7 @@ type Registrar interface { // RegisterIssuance inserts a new minting leaf within the target // universe tree (based on the ID), stored at the base key. RegisterIssuance(ctx context.Context, id Identifier, key LeafKey, - leaf *Leaf) (*IssuanceProof, error) + leaf *Leaf) (*Proof, error) } // IssuanceItem is an item that can be used to register a new issuance within a @@ -474,7 +476,7 @@ type DiffEngine interface { // asymmetric, as just need this to complete final portion // of diff FetchIssuanceProof(ctx context.Context, id Identifier, - key LeafKey) ([]*IssuanceProof, error) + key LeafKey) ([]*Proof, error) } // Commitment is an on chain universe commitment. This includes the merkle @@ -504,7 +506,7 @@ type CommittedIssuanceProof struct { ChainProof *Commitment // TaprootAssetProof is a proof of new asset issuance. - TaprootAssetProof *IssuanceProof + TaprootAssetProof *Proof } // ChainCommitter is used to commit a Universe backend in the chain. diff --git a/universe_rpc_diff.go b/universe_rpc_diff.go index 571d59844..a636f4cb7 100644 --- a/universe_rpc_diff.go +++ b/universe_rpc_diff.go @@ -138,7 +138,7 @@ func (r *RpcUniverseDiff) MintingKeys(ctx context.Context, // of diff func (r *RpcUniverseDiff) FetchIssuanceProof(ctx context.Context, id universe.Identifier, - key universe.LeafKey) ([]*universe.IssuanceProof, error) { + key universe.LeafKey) ([]*universe.Proof, error) { uProofs, err := r.conn.QueryProof(ctx, &universerpc.UniverseKey{ Id: marshalUniID(id), @@ -171,14 +171,14 @@ func (r *RpcUniverseDiff) FetchIssuanceProof(ctx context.Context, return nil, err } - uniProof := &universe.IssuanceProof{ + uniProof := &universe.Proof{ LeafKey: key, UniverseRoot: uniRoot, InclusionProof: inclusionProof, Leaf: assetLeaf, } - return []*universe.IssuanceProof{uniProof}, nil + return []*universe.Proof{uniProof}, nil } // A compile time interface to ensure that RpcUniverseDiff implements the diff --git a/universe_rpc_registrar.go b/universe_rpc_registrar.go index 9ecfdc507..646cd9c7c 100644 --- a/universe_rpc_registrar.go +++ b/universe_rpc_registrar.go @@ -40,7 +40,7 @@ func NewRpcUniverseRegistrar( // unmarshalIssuanceProof un-marshals an issuance proof response into a struct // usable by the universe package. func unmarshalIssuanceProof(uniKey *unirpc.UniverseKey, - proofResp *unirpc.AssetProofResponse) (*universe.IssuanceProof, error) { + proofResp *unirpc.AssetProofResponse) (*universe.Proof, error) { leafKey, err := unmarshalLeafKey(uniKey.LeafKey) if err != nil { @@ -65,7 +65,7 @@ func unmarshalIssuanceProof(uniKey *unirpc.UniverseKey, return nil, err } - return &universe.IssuanceProof{ + return &universe.Proof{ LeafKey: leafKey, UniverseRoot: mssmt.NewComputedBranch( fn.ToArray[mssmt.NodeHash]( @@ -82,7 +82,7 @@ func unmarshalIssuanceProof(uniKey *unirpc.UniverseKey, // that uses a remote Universe server as the Registry instance. func (r *RpcUniverseRegistrar) RegisterIssuance(ctx context.Context, id universe.Identifier, key universe.LeafKey, - leaf *universe.Leaf) (*universe.IssuanceProof, error) { + leaf *universe.Leaf) (*universe.Proof, error) { // First, we'll parse the proofs and key into their RPC counterparts. uniKey := &unirpc.UniverseKey{ @@ -105,7 +105,7 @@ func (r *RpcUniverseRegistrar) RegisterIssuance(ctx context.Context, return nil, err } - // Finally, we'll map the response back into the IssuanceProof we expect + // Finally, we'll map the response back into the Proof we expect // as a response. return unmarshalIssuanceProof(uniKey, proofResp) } From e91b8f7ec548ac1e140876a7c25c17e26d7ba439 Mon Sep 17 00:00:00 2001 From: ffranr Date: Tue, 26 Sep 2023 18:05:29 +0100 Subject: [PATCH 15/16] multi: rename field InclusionProof to UniverseInclusionProof --- rpcserver.go | 2 +- tapdb/universe.go | 14 +++++++------- tapdb/universe_test.go | 4 ++-- universe/interface.go | 8 ++++---- universe_rpc_diff.go | 8 ++++---- universe_rpc_registrar.go | 4 ++-- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index b547e30a6..b5ad91fd5 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -2851,7 +2851,7 @@ func (r *rpcServer) marshalIssuanceProof(ctx context.Context, req *unirpc.UniverseKey, proof *universe.Proof) (*unirpc.AssetProofResponse, error) { - uniProof, err := marshalMssmtProof(proof.InclusionProof) + uniProof, err := marshalMssmtProof(proof.UniverseInclusionProof) if err != nil { return nil, err } diff --git a/tapdb/universe.go b/tapdb/universe.go index e9d94a5ff..7d7650b56 100644 --- a/tapdb/universe.go +++ b/tapdb/universe.go @@ -414,10 +414,10 @@ func universeUpsertProofLeaf(ctx context.Context, dbTx BaseUniverseStore, } return &universe.Proof{ - LeafKey: key, - UniverseRoot: universeRoot, - InclusionProof: leafInclusionProof, - Leaf: leaf, + LeafKey: key, + UniverseRoot: universeRoot, + UniverseInclusionProof: leafInclusionProof, + Leaf: leaf, }, universeRoot, nil } @@ -547,9 +547,9 @@ func universeFetchProofLeaf(ctx context.Context, } issuanceProof := &universe.Proof{ - LeafKey: universeKey, - UniverseRoot: rootNode, - InclusionProof: leafProof, + LeafKey: universeKey, + UniverseRoot: rootNode, + UniverseInclusionProof: leafProof, Leaf: &universe.Leaf{ GenesisWithGroup: universe.GenesisWithGroup{ Genesis: leafAssetGen, diff --git a/tapdb/universe_test.go b/tapdb/universe_test.go index 3414353ba..94fac0273 100644 --- a/tapdb/universe_test.go +++ b/tapdb/universe_test.go @@ -191,7 +191,7 @@ func TestUniverseIssuanceProofs(t *testing.T) { // root of the SMT. node, err := leaf.SmtLeafNode() require.NoError(t, err) - proofRoot := issuanceProof.InclusionProof.Root( + proofRoot := issuanceProof.UniverseInclusionProof.Root( targetKey.UniverseKey(), node, ) require.True(t, mssmt.IsEqualNode(rootNode, proofRoot)) @@ -213,7 +213,7 @@ func TestUniverseIssuanceProofs(t *testing.T) { // proof. node, err = uniProof.Leaf.SmtLeafNode() require.NoError(t, err) - dbProofRoot := uniProof.InclusionProof.Root( + dbProofRoot := uniProof.UniverseInclusionProof.Root( uniProof.LeafKey.UniverseKey(), node, ) require.True( diff --git a/universe/interface.go b/universe/interface.go index 87ac44c5b..453e16abf 100644 --- a/universe/interface.go +++ b/universe/interface.go @@ -153,9 +153,9 @@ type Proof struct { // within. UniverseRoot mssmt.Node - // InclusionProof is the inclusion proof for the asset within the - // universe tree. - InclusionProof *mssmt.Proof + // UniverseInclusionProof is the universe inclusion proof for the asset + // within the universe tree. + UniverseInclusionProof *mssmt.Proof // MultiverseRoot is the root of the multiverse tree that the asset is // located within. @@ -175,7 +175,7 @@ func (i *Proof) VerifyRoot(expectedRoot mssmt.Node) (bool, error) { return false, err } - reconstructedRoot := i.InclusionProof.Root( + reconstructedRoot := i.UniverseInclusionProof.Root( i.LeafKey.UniverseKey(), leafNode, ) diff --git a/universe_rpc_diff.go b/universe_rpc_diff.go index a636f4cb7..9721168fe 100644 --- a/universe_rpc_diff.go +++ b/universe_rpc_diff.go @@ -172,10 +172,10 @@ func (r *RpcUniverseDiff) FetchIssuanceProof(ctx context.Context, } uniProof := &universe.Proof{ - LeafKey: key, - UniverseRoot: uniRoot, - InclusionProof: inclusionProof, - Leaf: assetLeaf, + LeafKey: key, + UniverseRoot: uniRoot, + UniverseInclusionProof: inclusionProof, + Leaf: assetLeaf, } return []*universe.Proof{uniProof}, nil diff --git a/universe_rpc_registrar.go b/universe_rpc_registrar.go index 646cd9c7c..61c5f5f13 100644 --- a/universe_rpc_registrar.go +++ b/universe_rpc_registrar.go @@ -73,8 +73,8 @@ func unmarshalIssuanceProof(uniKey *unirpc.UniverseKey, ), uint64(proofResp.UniverseRoot.MssmtRoot.RootSum), ), - InclusionProof: inclusionProof, - Leaf: assetLeaf, + UniverseInclusionProof: inclusionProof, + Leaf: assetLeaf, }, nil } From 151cafc057000c13a71691c00d676fbd6df5da44 Mon Sep 17 00:00:00 2001 From: ffranr Date: Tue, 26 Sep 2023 18:45:29 +0100 Subject: [PATCH 16/16] multi: rename MintingKeys in diff engine and uni to UniverseLeafKeys --- rpcserver.go | 2 +- universe/base.go | 4 ++-- universe/interface.go | 4 ++-- universe/syncer.go | 4 ++-- universe_rpc_diff.go | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index b5ad91fd5..0cb5ee881 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -2657,7 +2657,7 @@ func (r *rpcServer) AssetLeafKeys(ctx context.Context, // TODO(roasbeef): tell above if was tring or not, then would set // below diff - leafKeys, err := r.cfg.BaseUniverse.MintingKeys(ctx, universeID) + leafKeys, err := r.cfg.BaseUniverse.UniverseLeafKeys(ctx, universeID) if err != nil { return nil, err } diff --git a/universe/base.go b/universe/base.go index c9f9ec429..745ec3a09 100644 --- a/universe/base.go +++ b/universe/base.go @@ -393,9 +393,9 @@ func (a *MintingArchive) FetchIssuanceProof(ctx context.Context, id Identifier, return a.cfg.Multiverse.FetchProofLeaf(ctx, id, key) } -// MintingKeys returns the set of minting keys known for the specified base +// UniverseLeafKeys returns the set of leaf keys known for the specified // universe identifier. -func (a *MintingArchive) MintingKeys(ctx context.Context, +func (a *MintingArchive) UniverseLeafKeys(ctx context.Context, id Identifier) ([]LeafKey, error) { log.Debugf("Retrieving all keys for Universe: id=%v", id.StringForLog()) diff --git a/universe/interface.go b/universe/interface.go index 453e16abf..00a4ba7c1 100644 --- a/universe/interface.go +++ b/universe/interface.go @@ -466,8 +466,8 @@ type DiffEngine interface { // RootNodes returns the set of root nodes for all known universes. RootNodes(ctx context.Context) ([]BaseRoot, error) - // MintingKeys returns all the keys inserted in the universe. - MintingKeys(ctx context.Context, id Identifier) ([]LeafKey, error) + // UniverseLeafKeys returns all the keys inserted in the universe. + UniverseLeafKeys(ctx context.Context, id Identifier) ([]LeafKey, error) // FetchIssuanceProof attempts to fetch an issuance proof for the // target base leaf based on the universe identifier (assetID/groupKey). diff --git a/universe/syncer.go b/universe/syncer.go index dcf45f5e3..c988833cf 100644 --- a/universe/syncer.go +++ b/universe/syncer.go @@ -167,11 +167,11 @@ func (s *SimpleSyncer) syncRoot(ctx context.Context, remoteRoot BaseRoot, // Otherwise, we'll need to perform a diff operation to find the set of // keys we need to fetch. - remoteUniKeys, err := diffEngine.MintingKeys(ctx, uniID) + remoteUniKeys, err := diffEngine.UniverseLeafKeys(ctx, uniID) if err != nil { return err } - localUniKeys, err := s.cfg.LocalDiffEngine.MintingKeys(ctx, uniID) + localUniKeys, err := s.cfg.LocalDiffEngine.UniverseLeafKeys(ctx, uniID) if err != nil { return err } diff --git a/universe_rpc_diff.go b/universe_rpc_diff.go index 9721168fe..6df361233 100644 --- a/universe_rpc_diff.go +++ b/universe_rpc_diff.go @@ -107,8 +107,8 @@ func (r *RpcUniverseDiff) RootNode(ctx context.Context, return unmarshalUniverseRoot(universeRoot.AssetRoot) } -// MintingKeys returns all the keys inserted in the universe. -func (r *RpcUniverseDiff) MintingKeys(ctx context.Context, +// UniverseLeafKeys returns all the keys inserted in the universe. +func (r *RpcUniverseDiff) UniverseLeafKeys(ctx context.Context, id universe.Identifier) ([]universe.LeafKey, error) { assetKeys, err := r.conn.AssetLeafKeys(ctx, marshalUniID(id))