Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Universe events stats handle universe identity proof type #561

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 54 additions & 6 deletions cmd/tapcli/universe.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ import (
"github.com/lightninglabs/taproot-assets/taprpc"
"github.com/lightninglabs/taproot-assets/taprpc/universerpc"
unirpc "github.com/lightninglabs/taproot-assets/taprpc/universerpc"
"github.com/lightninglabs/taproot-assets/universe"
"github.com/lightningnetwork/lnd/lncfg"
"github.com/urfave/cli"
)

const (
proofTypeName = "proof_type"
)

func getUniverseClient(ctx *cli.Context) (universerpc.UniverseClient, func()) {
conn := getClientConn(ctx, false)

Expand Down Expand Up @@ -59,11 +64,26 @@ var universeRootsCommand = cli.Command{
Name: groupKeyName,
Usage: "the group key of the universe to query for",
},
cli.StringFlag{
Name: proofTypeName,
Usage: "the type of proof to show the roots for, " +
"either 'issuance' or 'transfer'",
Value: universe.ProofTypeIssuance.String(),
},
},
Action: universeRoots,
}

func parseUniverseID(ctx *cli.Context, mustParse bool) (*universerpc.ID, error) {
proofType, err := universe.ParseStrProofType(ctx.String(proofTypeName))
if err != nil {
return nil, err
}
rpcProofType, err := tap.MarshalUniProofType(proofType)
if err != nil {
return nil, err
}

switch {
// Both the asset ID and the group key can't be set.
case ctx.IsSet(assetIDName) && ctx.IsSet(groupKeyName):
Expand All @@ -83,6 +103,7 @@ func parseUniverseID(ctx *cli.Context, mustParse bool) (*universerpc.ID, error)
Id: &universerpc.ID_AssetId{
AssetId: assetIDBytes,
},
ProofType: rpcProofType,
}, nil

case ctx.IsSet(groupKeyName):
Expand All @@ -97,6 +118,7 @@ func parseUniverseID(ctx *cli.Context, mustParse bool) (*universerpc.ID, error)
Id: &universerpc.ID_GroupKey{
GroupKey: groupKeyBytes,
},
ProofType: rpcProofType,
}, nil

// Neither was set, so we'll return nil.
Expand Down Expand Up @@ -156,6 +178,12 @@ var universeDeleteRootCommand = cli.Command{
Name: groupKeyName,
Usage: "the group key of the universe to delete",
},
cli.StringFlag{
Name: proofTypeName,
Usage: "the type of proof to delete the roots for, " +
"either 'issuance' or 'transfer'",
Value: universe.ProofTypeIssuance.String(),
},
},
Action: deleteUniverseRoot,
}
Expand Down Expand Up @@ -201,6 +229,12 @@ var universeKeysCommand = cli.Command{
Name: groupKeyName,
Usage: "the group key of the universe to query for",
},
cli.StringFlag{
Name: proofTypeName,
Usage: "the type of proof to show the keys for, " +
"either 'issuance' or 'transfer'",
Value: universe.ProofTypeIssuance.String(),
},
},
Action: universeKeys,
}
Expand Down Expand Up @@ -242,6 +276,12 @@ var universeLeavesCommand = cli.Command{
Name: groupKeyName,
Usage: "the group key of the universe to query for",
},
cli.StringFlag{
Name: proofTypeName,
Usage: "the type of proof to show the leaves for, " +
"either 'issuance' or 'transfer'",
Value: universe.ProofTypeIssuance.String(),
},
},
Action: universeLeaves,
}
Expand Down Expand Up @@ -279,23 +319,31 @@ var universeProofArgs = []cli.Flag{
Usage: "the group key of the universe to query for",
},
cli.StringFlag{
Name: outpointName,
Usage: "the target outpoint on chain to locate a tap proof within",
Name: outpointName,
Usage: "the target outpoint on chain to locate a tap proof " +
"within",
},
cli.StringFlag{
Name: scriptKeyName,
Usage: "the script key (scoped to an assetID) to query a " +
"proof for",
},
cli.StringFlag{
Name: scriptKeyName,
Usage: "the script key (scoped to an assetID) to query a proof for",
Name: proofTypeName,
Usage: "the type of proof to query for, either 'issuance' or " +
"'transfer'",
Value: universe.ProofTypeIssuance.String(),
},
}

var universeProofCommand = cli.Command{
Name: "proofs",
ShortName: "p",
Usage: "retreive or insert a new Universe proof",
Usage: "retrieve or insert a new Universe proof",
Description: `
Query for the set of proofs known by the target universe. A proof may
be either an issuance proof, or a proof that some transfer took place
on chain. Proofs are namesapced based on a top level assetID/groupKey,
on chain. Proofs are namespaced based on a top level assetID/groupKey,
so that must be specified for each command.

Two sub-commands are available: proof querying (query) and proof
Expand Down
1 change: 1 addition & 0 deletions itest/loadtest/mint_batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func mintTest(t *testing.T, ctx context.Context, cfg *Config) {
Id: &unirpc.ID_GroupKey{
GroupKey: collectGroupKey[1:],
},
ProofType: unirpc.ProofType_PROOF_TYPE_ISSUANCE,
}
uniLeaves, err := alice.AssetLeaves(ctx, &collectUniID)
require.NoError(t, err)
Expand Down
1 change: 1 addition & 0 deletions itest/mint_batch_stress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ func mintBatchStressTest(
Id: &unirpc.ID_GroupKey{
GroupKey: collectGroupKey[1:],
},
ProofType: unirpc.ProofType_PROOF_TYPE_ISSUANCE,
}
uniLeaves, err := alice.AssetLeaves(ctx, &collectUniID)
require.NoError(t, err)
Expand Down
16 changes: 7 additions & 9 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3200,9 +3200,8 @@ func (r *rpcServer) QueryProof(ctx context.Context,
return nil, err
}

rpcsLog.Debugf("[QueryProof]: fetching proof at "+
"(universeID=%x, leafKey=%x)", universeID,
leafKey.UniverseKey())
rpcsLog.Debugf("[QueryProof]: fetching proof at (universeID=%v, "+
"leafKey=%x)", universeID, leafKey.UniverseKey())

// Keep a record of whether the proof type was specified by the client.
unspecifiedArgProofType :=
Expand Down Expand Up @@ -3237,14 +3236,14 @@ func (r *rpcServer) QueryProof(ctx context.Context,
)
if err != nil {
rpcsLog.Debugf("[QueryProof]: error querying for "+
"proof at (universeID=%x, leafKey=%x)",
"proof at (universeID=%v, leafKey=%x)",
universeID, leafKey.UniverseKey())
return nil, err
}
}
if err != nil {
rpcsLog.Debugf("[QueryProof]: error querying for proof at "+
"(universeID=%x, leafKey=%x)", universeID,
"(universeID=%v, leafKey=%x)", universeID,
leafKey.UniverseKey())
return nil, err
}
Expand All @@ -3253,9 +3252,8 @@ func (r *rpcServer) QueryProof(ctx context.Context,
// not be fully specified
proof := proofs[0]

rpcsLog.Debugf("[QueryProof]: found proof at "+
"(universeID=%x, leafKey=%x)", universeID,
leafKey.UniverseKey())
rpcsLog.Debugf("[QueryProof]: found proof at (universeID=%v, "+
"leafKey=%x)", universeID, leafKey.UniverseKey())

return r.marshalIssuanceProof(ctx, req, proof)
}
Expand Down Expand Up @@ -3328,7 +3326,7 @@ func (r *rpcServer) InsertProof(ctx context.Context,
}

rpcsLog.Debugf("[InsertProof]: inserting proof at "+
"(universeID=%x, leafKey=%x)", universeID,
"(universeID=%v, leafKey=%x)", universeID,
leafKey.UniverseKey())

newUniverseState, err := r.cfg.BaseUniverse.RegisterIssuance(
Expand Down
5 changes: 2 additions & 3 deletions tapdb/sqlc/migrations/000007_universe.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ CREATE VIEW universe_stats AS
COUNT(CASE WHEN u.event_type = 'SYNC' THEN 1 ELSE NULL END) AS total_asset_syncs,
COUNT(CASE WHEN u.event_type = 'NEW_PROOF' THEN 1 ELSE NULL END) AS total_asset_proofs,
roots.asset_id,
roots.group_key,
roots.namespace_root
Roasbeef marked this conversation as resolved.
Show resolved Hide resolved
roots.group_key
FROM universe_events u
JOIN universe_roots roots ON u.universe_root_id = roots.id
GROUP BY roots.asset_id, roots.group_key, roots.namespace_root;
GROUP BY roots.asset_id, roots.group_key;

-- This table contains global configuration for universe federation syncing.
CREATE TABLE IF NOT EXISTS federation_global_sync_config (
Expand Down
1 change: 0 additions & 1 deletion tapdb/sqlc/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions tapdb/sqlc/queries/universe.sql
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,18 @@ SELECT * FROM universe_servers;
-- name: InsertNewSyncEvent :exec
WITH group_key_root_id AS (
SELECT id
FROM universe_roots
FROM universe_roots roots
WHERE group_key = @group_key_x_only
AND roots.proof_type = @proof_type
), asset_id_root_id AS (
SELECT leaves.universe_root_id AS id
FROM universe_leaves leaves
JOIN universe_roots roots
ffranr marked this conversation as resolved.
Show resolved Hide resolved
ON leaves.universe_root_id = roots.id
JOIN genesis_info_view gen
ON leaves.asset_genesis_id = gen.gen_asset_id
WHERE gen.asset_id = @asset_id
WHERE gen.asset_id = @asset_id
AND roots.proof_type = @proof_type
LIMIT 1
)
INSERT INTO universe_events (
Expand All @@ -138,14 +142,18 @@ INSERT INTO universe_events (
-- name: InsertNewProofEvent :exec
WITH group_key_root_id AS (
SELECT id
FROM universe_roots
FROM universe_roots roots
WHERE group_key = @group_key_x_only
AND roots.proof_type = @proof_type
), asset_id_root_id AS (
SELECT leaves.universe_root_id AS id
FROM universe_leaves leaves
JOIN genesis_info_view gen
ON leaves.asset_genesis_id = gen.gen_asset_id
JOIN universe_roots roots
ON leaves.universe_root_id = roots.id
JOIN genesis_info_view gen
ON leaves.asset_genesis_id = gen.gen_asset_id
Roasbeef marked this conversation as resolved.
Show resolved Hide resolved
WHERE gen.asset_id = @asset_id
AND roots.proof_type = @proof_type
LIMIT 1
)
INSERT INTO universe_events (
Expand Down
24 changes: 18 additions & 6 deletions tapdb/sqlc/universe.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tapdb/universe_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func (u *UniverseStats) LogSyncEvent(ctx context.Context,
EventTimestamp: u.clock.Now().UTC().Unix(),
AssetID: uniID.AssetID[:],
GroupKeyXOnly: groupKeyXOnly,
ProofType: uniID.ProofType.String(),
ffranr marked this conversation as resolved.
Show resolved Hide resolved
})
})
}
Expand All @@ -165,6 +166,7 @@ func (u *UniverseStats) LogSyncEvents(ctx context.Context,
EventTimestamp: u.clock.Now().UTC().Unix(),
AssetID: uniID.AssetID[:],
GroupKeyXOnly: groupKeyXOnly,
ProofType: uniID.ProofType.String(),
})
if err != nil {
return err
Expand All @@ -191,6 +193,7 @@ func (u *UniverseStats) LogNewProofEvent(ctx context.Context,
EventTimestamp: u.clock.Now().UTC().Unix(),
AssetID: uniID.AssetID[:],
GroupKeyXOnly: groupKeyXOnly,
ProofType: uniID.ProofType.String(),
})
})
}
Expand All @@ -215,6 +218,7 @@ func (u *UniverseStats) LogNewProofEvents(ctx context.Context,
EventTimestamp: u.clock.Now().UTC().Unix(),
AssetID: uniID.AssetID[:],
GroupKeyXOnly: groupKeyXOnly,
ProofType: uniID.ProofType.String(),
})
if err != nil {
return err
Expand Down