Skip to content

Commit 3f5f816

Browse files
committed
multi: move inclusion proof feature to FetchSupplyLeaves RPC
The FetchSupplyCommit RPC previously accepted leaf keys and returned inclusion proofs for those leaves. This feature is now moved to the FetchSupplyLeaves RPC. The FetchSupplyLeaves endpoint is not served publicly by the universe server (mostly used in itests), whereas FetchSupplyCommit is public. Limiting FetchSupplyCommit avoids on-the-fly inclusion proof generation.
1 parent 8863e9e commit 3f5f816

File tree

7 files changed

+629
-577
lines changed

7 files changed

+629
-577
lines changed

cmd/commands/universe.go

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,21 +1638,6 @@ var fetchSupplyCommitCmd = cli.Command{
16381638
Usage: "the group key of the asset group to fetch",
16391639
Required: true,
16401640
},
1641-
&cli.StringSliceFlag{
1642-
Name: "issuance_leaf_keys",
1643-
Usage: "a list of issuance leaf keys to fetch " +
1644-
"inclusion proofs for",
1645-
},
1646-
&cli.StringSliceFlag{
1647-
Name: "burn_leaf_keys",
1648-
Usage: "a list of burn leaf keys to fetch inclusion " +
1649-
"proofs for",
1650-
},
1651-
&cli.StringSliceFlag{
1652-
Name: "ignore_leaf_keys",
1653-
Usage: "a list of ignore leaf keys to fetch " +
1654-
"inclusion proofs for",
1655-
},
16561641
},
16571642
Action: fetchSupplyCommit,
16581643
}
@@ -1668,26 +1653,6 @@ func fetchSupplyCommit(ctx *cli.Context) error {
16681653
},
16691654
}
16701655

1671-
issuanceKeys, err := parseHexStrings(
1672-
ctx.StringSlice("issuance_leaf_keys"),
1673-
)
1674-
if err != nil {
1675-
return fmt.Errorf("invalid issuance_leaf_keys: %w", err)
1676-
}
1677-
req.IssuanceLeafKeys = issuanceKeys
1678-
1679-
burnKeys, err := parseHexStrings(ctx.StringSlice("burn_leaf_keys"))
1680-
if err != nil {
1681-
return fmt.Errorf("invalid burn_leaf_keys: %w", err)
1682-
}
1683-
req.BurnLeafKeys = burnKeys
1684-
1685-
ignoreKeys, err := parseHexStrings(ctx.StringSlice("ignore_leaf_keys"))
1686-
if err != nil {
1687-
return fmt.Errorf("invalid ignore_leaf_keys: %w", err)
1688-
}
1689-
req.IgnoreLeafKeys = ignoreKeys
1690-
16911656
resp, err := client.FetchSupplyCommit(cliCtx, req)
16921657
if err != nil {
16931658
return err
@@ -1719,6 +1684,21 @@ var fetchSupplyLeavesCmd = cli.Command{
17191684
Usage: "the end of the block height range",
17201685
Required: true,
17211686
},
1687+
&cli.StringSliceFlag{
1688+
Name: "issuance_leaf_keys",
1689+
Usage: "a list of issuance leaf keys to fetch " +
1690+
"inclusion proofs for",
1691+
},
1692+
&cli.StringSliceFlag{
1693+
Name: "burn_leaf_keys",
1694+
Usage: "a list of burn leaf keys to fetch inclusion " +
1695+
"proofs for",
1696+
},
1697+
&cli.StringSliceFlag{
1698+
Name: "ignore_leaf_keys",
1699+
Usage: "a list of ignore leaf keys to fetch " +
1700+
"inclusion proofs for",
1701+
},
17221702
},
17231703
Action: fetchSupplyLeaves,
17241704
}
@@ -1736,6 +1716,26 @@ func fetchSupplyLeaves(ctx *cli.Context) error {
17361716
BlockHeightEnd: uint32(ctx.Uint64("block_height_end")),
17371717
}
17381718

1719+
issuanceKeys, err := parseHexStrings(
1720+
ctx.StringSlice("issuance_leaf_keys"),
1721+
)
1722+
if err != nil {
1723+
return fmt.Errorf("invalid issuance_leaf_keys: %w", err)
1724+
}
1725+
req.IssuanceLeafKeys = issuanceKeys
1726+
1727+
burnKeys, err := parseHexStrings(ctx.StringSlice("burn_leaf_keys"))
1728+
if err != nil {
1729+
return fmt.Errorf("invalid burn_leaf_keys: %w", err)
1730+
}
1731+
req.BurnLeafKeys = burnKeys
1732+
1733+
ignoreKeys, err := parseHexStrings(ctx.StringSlice("ignore_leaf_keys"))
1734+
if err != nil {
1735+
return fmt.Errorf("invalid ignore_leaf_keys: %w", err)
1736+
}
1737+
req.IgnoreLeafKeys = ignoreKeys
1738+
17391739
resp, err := client.FetchSupplyLeaves(cliCtx, req)
17401740
if err != nil {
17411741
return err

itest/supply_commit_test.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,6 @@ func testSupplyCommitIgnoreAsset(t *harnessTest) {
230230
GroupKey: &unirpc.FetchSupplyCommitRequest_GroupKeyBytes{
231231
GroupKeyBytes: groupKeyBytes,
232232
},
233-
IgnoreLeafKeys: [][]byte{
234-
respIgnore.LeafKey,
235-
},
236233
},
237234
)
238235
require.Nil(t.t, fetchRespNil)
@@ -266,9 +263,6 @@ func testSupplyCommitIgnoreAsset(t *harnessTest) {
266263
GroupKey: &unirpc.FetchSupplyCommitRequest_GroupKeyBytes{
267264
GroupKeyBytes: groupKeyBytes,
268265
},
269-
IgnoreLeafKeys: [][]byte{
270-
respIgnore.LeafKey,
271-
},
272266
},
273267
)
274268
require.NoError(t.t, err)
@@ -308,10 +302,26 @@ func testSupplyCommitIgnoreAsset(t *harnessTest) {
308302
ignoreRootLeafKey, supplyTreeIgnoreLeafNode,
309303
)
310304

305+
// Now fetch the inclusion proofs using FetchSupplyLeaves instead of
306+
// FetchSupplyCommit.
307+
t.Log("Fetch supply leaves with inclusion proofs")
308+
// nolint: lll
309+
fetchLeavesResp, err := t.tapd.FetchSupplyLeaves(
310+
ctxb, &unirpc.FetchSupplyLeavesRequest{
311+
GroupKey: &unirpc.FetchSupplyLeavesRequest_GroupKeyBytes{
312+
GroupKeyBytes: groupKeyBytes,
313+
},
314+
IgnoreLeafKeys: [][]byte{
315+
respIgnore.LeafKey,
316+
},
317+
},
318+
)
319+
require.NoError(t.t, err)
320+
311321
// Unmarshal ignore tree leaf inclusion proof to verify that the
312322
// ignored asset outpoint is included in the ignore tree.
313-
require.Len(t.t, fetchResp.IgnoreLeafInclusionProofs, 1)
314-
inclusionProofBytes := fetchResp.IgnoreLeafInclusionProofs[0]
323+
require.Len(t.t, fetchLeavesResp.IgnoreLeafInclusionProofs, 1)
324+
inclusionProofBytes := fetchLeavesResp.IgnoreLeafInclusionProofs[0]
315325

316326
// Verify that the ignore tree root can be computed from the ignore leaf
317327
// inclusion proof.

rpcserver.go

Lines changed: 67 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4366,38 +4366,6 @@ func (r *rpcServer) FetchSupplyCommit(ctx context.Context,
43664366
"root: %w", err)
43674367
}
43684368

4369-
// Get inclusion proofs for any issuance leaf key specified in the
4370-
// request.
4371-
issuanceTree := resp.Subtrees[supplycommit.MintTreeType]
4372-
issuanceInclusionProofs, err := inclusionProofs(
4373-
ctx, issuanceTree, req.IssuanceLeafKeys,
4374-
)
4375-
if err != nil {
4376-
return nil, fmt.Errorf("failed to fetch issuance tree "+
4377-
"inclusion proofs: %w", err)
4378-
}
4379-
4380-
// Get inclusion proofs for any burn leaf key specified in the request.
4381-
burnTree := resp.Subtrees[supplycommit.BurnTreeType]
4382-
burnInclusionProofs, err := inclusionProofs(
4383-
ctx, burnTree, req.BurnLeafKeys,
4384-
)
4385-
if err != nil {
4386-
return nil, fmt.Errorf("failed to fetch burn tree "+
4387-
"inclusion proofs: %w", err)
4388-
}
4389-
4390-
// Get inclusion proofs for any ignore leaf key specified in the
4391-
// request.
4392-
ignoreTree := resp.Subtrees[supplycommit.IgnoreTreeType]
4393-
ignoreInclusionProofs, err := inclusionProofs(
4394-
ctx, ignoreTree, req.IgnoreLeafKeys,
4395-
)
4396-
if err != nil {
4397-
return nil, fmt.Errorf("failed to fetch ignore tree "+
4398-
"inclusion proofs: %w", err)
4399-
}
4400-
44014369
// Sanity check: ensure the supply root derived from the supply tree
44024370
// matches the root provided in the chain commitment.
44034371
if resp.ChainCommitment.SupplyRoot.NodeHash() !=
@@ -4443,10 +4411,6 @@ func (r *rpcServer) FetchSupplyCommit(ctx context.Context,
44434411
IssuanceSubtreeRoot: rpcIssuanceSubtreeRoot,
44444412
BurnSubtreeRoot: rpcBurnSubtreeRoot,
44454413
IgnoreSubtreeRoot: rpcIgnoreSubtreeRoot,
4446-
4447-
IssuanceLeafInclusionProofs: issuanceInclusionProofs,
4448-
BurnLeafInclusionProofs: burnInclusionProofs,
4449-
IgnoreLeafInclusionProofs: ignoreInclusionProofs,
44504414
}, nil
44514415
}
44524416

@@ -4496,6 +4460,24 @@ func (r *rpcServer) FetchSupplyLeaves(ctx context.Context,
44964460
return nil, fmt.Errorf("failed to fetch supply leaves: %w", err)
44974461
}
44984462

4463+
// Check if inclusion proofs are requested.
4464+
needsInclusionProofs := len(req.IssuanceLeafKeys) > 0 ||
4465+
len(req.BurnLeafKeys) > 0 || len(req.IgnoreLeafKeys) > 0
4466+
4467+
// If inclusion proofs are requested, fetch the subtrees.
4468+
var subtrees supplycommit.SupplyTrees
4469+
if needsInclusionProofs {
4470+
subtreeResult, err := r.cfg.SupplyCommitManager.FetchSubTrees(
4471+
ctx, assetSpec,
4472+
)
4473+
if err != nil {
4474+
return nil, fmt.Errorf("failed to fetch subtrees for "+
4475+
"inclusion proofs: %w", err)
4476+
}
4477+
4478+
subtrees = subtreeResult
4479+
}
4480+
44994481
rpcMarshalLeafEntry := func(leafEntry supplycommit.SupplyUpdateEvent) (
45004482
*unirpc.SupplyLeafEntry, error) {
45014483

@@ -4587,10 +4569,56 @@ func (r *rpcServer) FetchSupplyLeaves(ctx context.Context,
45874569
rpcIgnoreLeaves = append(rpcIgnoreLeaves, rpcLeaf)
45884570
}
45894571

4572+
// Generate inclusion proofs if requested.
4573+
var (
4574+
issuanceInclusionProofs [][]byte
4575+
burnInclusionProofs [][]byte
4576+
ignoreInclusionProofs [][]byte
4577+
)
4578+
4579+
if needsInclusionProofs {
4580+
// Get inclusion proofs for any issuance leaf key specified in
4581+
// the request.
4582+
issuanceTree := subtrees[supplycommit.MintTreeType]
4583+
var err error
4584+
issuanceInclusionProofs, err = inclusionProofs(
4585+
ctx, issuanceTree, req.IssuanceLeafKeys,
4586+
)
4587+
if err != nil {
4588+
return nil, fmt.Errorf("failed to fetch issuance tree "+
4589+
"inclusion proofs: %w", err)
4590+
}
4591+
4592+
// Get inclusion proofs for any burn leaf key specified in the
4593+
// request.
4594+
burnTree := subtrees[supplycommit.BurnTreeType]
4595+
burnInclusionProofs, err = inclusionProofs(
4596+
ctx, burnTree, req.BurnLeafKeys,
4597+
)
4598+
if err != nil {
4599+
return nil, fmt.Errorf("failed to fetch burn tree "+
4600+
"inclusion proofs: %w", err)
4601+
}
4602+
4603+
// Get inclusion proofs for any ignore leaf key specified in the
4604+
// request.
4605+
ignoreTree := subtrees[supplycommit.IgnoreTreeType]
4606+
ignoreInclusionProofs, err = inclusionProofs(
4607+
ctx, ignoreTree, req.IgnoreLeafKeys,
4608+
)
4609+
if err != nil {
4610+
return nil, fmt.Errorf("failed to fetch ignore tree "+
4611+
"inclusion proofs: %w", err)
4612+
}
4613+
}
4614+
45904615
return &unirpc.FetchSupplyLeavesResponse{
4591-
IssuanceLeaves: rpcIssuanceLeaves,
4592-
BurnLeaves: rpcBurnLeaves,
4593-
IgnoreLeaves: rpcIgnoreLeaves,
4616+
IssuanceLeaves: rpcIssuanceLeaves,
4617+
BurnLeaves: rpcBurnLeaves,
4618+
IgnoreLeaves: rpcIgnoreLeaves,
4619+
IssuanceLeafInclusionProofs: issuanceInclusionProofs,
4620+
BurnLeafInclusionProofs: burnInclusionProofs,
4621+
IgnoreLeafInclusionProofs: ignoreInclusionProofs,
45944622
}, nil
45954623
}
45964624

0 commit comments

Comments
 (0)