Skip to content

Commit 3e6579c

Browse files
authored
Merge pull request #634 from GeorgeTsagk/universerpc-pages
Add pagination to universerpc calls
2 parents 263a22a + ddf7eaa commit 3e6579c

26 files changed

+1625
-864
lines changed

cmd/tapcli/universe.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,30 @@ func universeKeys(ctx *cli.Context) error {
270270
return err
271271
}
272272

273-
assetKeys, err := client.AssetLeafKeys(ctxc, universeID)
274-
if err != nil {
275-
return err
273+
assetKeys := &unirpc.AssetLeafKeyResponse{}
274+
offset := 0
275+
276+
for {
277+
tempKeys, err := client.AssetLeafKeys(
278+
ctxc, &unirpc.AssetLeafKeysRequest{
279+
Id: universeID,
280+
Offset: int32(offset),
281+
Limit: universe.MaxPageSize,
282+
},
283+
)
284+
285+
if err != nil {
286+
return err
287+
}
288+
289+
if len(tempKeys.AssetKeys) == 0 {
290+
break
291+
}
292+
293+
assetKeys.AssetKeys = append(
294+
assetKeys.AssetKeys, tempKeys.AssetKeys...,
295+
)
296+
offset += universe.MaxPageSize
276297
}
277298

278299
printRespJSON(assetKeys)

itest/assertions.go

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/lightninglabs/taproot-assets/taprpc"
2222
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
2323
unirpc "github.com/lightninglabs/taproot-assets/taprpc/universerpc"
24+
"github.com/lightninglabs/taproot-assets/universe"
2425
"github.com/lightningnetwork/lnd/lnrpc/chainrpc"
2526
"github.com/lightningnetwork/lnd/lntest/wait"
2627
"github.com/stretchr/testify/require"
@@ -1157,10 +1158,10 @@ func AssertUniverseRootsEqual(a, b *unirpc.AssetRootResponse) bool {
11571158
func AssertUniverseStateEqual(t *testing.T, a, b unirpc.UniverseClient) bool {
11581159
ctxb := context.Background()
11591160

1160-
rootsA, err := a.AssetRoots(ctxb, &unirpc.AssetRootRequest{})
1161+
rootsA, err := assetRoots(ctxb, a, universe.MaxPageSize/100)
11611162
require.NoError(t, err)
11621163

1163-
rootsB, err := b.AssetRoots(ctxb, &unirpc.AssetRootRequest{})
1164+
rootsB, err := assetRoots(ctxb, b, universe.MaxPageSize/100)
11641165
require.NoError(t, err)
11651166

11661167
return AssertUniverseRootsEqual(rootsA, rootsB)
@@ -1196,10 +1197,20 @@ func AssertUniverseKeysEqual(t *testing.T, uniIDs []*unirpc.ID,
11961197
a, b unirpc.UniverseClient) {
11971198

11981199
for _, uniID := range uniIDs {
1199-
aUniKeys, err := a.AssetLeafKeys(context.Background(), uniID)
1200+
aUniKeys, err := a.AssetLeafKeys(
1201+
context.Background(),
1202+
&unirpc.AssetLeafKeysRequest{
1203+
Id: uniID,
1204+
},
1205+
)
12001206
require.NoError(t, err)
12011207

1202-
bUniKeys, err := b.AssetLeafKeys(context.Background(), uniID)
1208+
bUniKeys, err := b.AssetLeafKeys(
1209+
context.Background(),
1210+
&unirpc.AssetLeafKeysRequest{
1211+
Id: uniID,
1212+
},
1213+
)
12031214
require.NoError(t, err)
12041215

12051216
require.Equal(
@@ -1506,3 +1517,39 @@ func assertGroups(t *testing.T, client taprpc.TaprootAssetsClient,
15061517
equalityCheck(issuableAssets[0].Asset, groupedAssets[0])
15071518
equalityCheck(issuableAssets[1].Asset, groupedAssets[1])
15081519
}
1520+
1521+
// assetRoots is a helper method that fetches all roots from a given universe
1522+
// rpc by scanning for all pages.
1523+
func assetRoots(ctx context.Context,
1524+
uni unirpc.UniverseClient, pageSize int32) (*unirpc.AssetRootResponse, error) {
1525+
1526+
offset := int32(0)
1527+
roots := make(map[string]*unirpc.UniverseRoot)
1528+
1529+
for {
1530+
res, err := uni.AssetRoots(
1531+
ctx,
1532+
&unirpc.AssetRootRequest{
1533+
Offset: offset,
1534+
Limit: pageSize,
1535+
},
1536+
)
1537+
if err != nil {
1538+
return nil, err
1539+
}
1540+
1541+
if len(res.UniverseRoots) == 0 {
1542+
break
1543+
}
1544+
1545+
for k, v := range res.UniverseRoots {
1546+
roots[k] = v
1547+
}
1548+
1549+
offset += pageSize
1550+
}
1551+
1552+
return &unirpc.AssetRootResponse{
1553+
UniverseRoots: roots,
1554+
}, nil
1555+
}

itest/collectible_split_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,11 @@ func testCollectibleGroupSend(t *harnessTest) {
316316
// The universe tree should also have a key for each asset, with all
317317
// outpoints matching the chain anchor of the group anchor.
318318
mintOutpoint := collectibleAnchor.ChainAnchor.AnchorOutpoint
319-
uniKeys, err := t.tapd.AssetLeafKeys(ctxb, &collectUniID)
319+
uniKeys, err := t.tapd.AssetLeafKeys(
320+
ctxb, &unirpc.AssetLeafKeysRequest{
321+
Id: &collectUniID,
322+
},
323+
)
320324
require.NoError(t.t, err)
321325
require.Len(t.t, uniKeys.AssetKeys, batchSize)
322326

itest/loadtest/mint_batch_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ func mintTest(t *testing.T, ctx context.Context, cfg *Config) {
151151
// The universe tree should also have a key for each asset, with all
152152
// outpoints matching the chain anchor of the group anchor.
153153
mintOutpoint := collectibleAnchor.ChainAnchor.AnchorOutpoint
154-
uniKeys, err := alice.AssetLeafKeys(ctx, &collectUniID)
154+
uniKeys, err := alice.AssetLeafKeys(
155+
ctx, &unirpc.AssetLeafKeysRequest{
156+
Id: &collectUniID,
157+
},
158+
)
155159
require.NoError(t, err)
156160
require.Len(t, uniKeys.AssetKeys, batchSize)
157161

itest/mint_batch_stress_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,13 @@ func mintBatchStressTest(
200200
// The universe tree should also have a key for each asset, with all
201201
// outpoints matching the chain anchor of the group anchor.
202202
mintOutpoint := collectibleAnchor.ChainAnchor.AnchorOutpoint
203-
uniKeys, err := alice.AssetLeafKeys(ctx, &collectUniID)
203+
204+
leafKeys, err := fetchAllLeafKeys(t, alice, &collectUniID)
204205
require.NoError(t, err)
205-
require.Len(t, uniKeys.AssetKeys, batchSize)
206206

207-
correctOp := fn.All(uniKeys.AssetKeys, func(key *unirpc.AssetKey) bool {
207+
require.Len(t, leafKeys, batchSize)
208+
209+
correctOp := fn.All(leafKeys, func(key *unirpc.AssetKey) bool {
208210
return key.GetOpStr() == mintOutpoint
209211
})
210212
require.True(t, correctOp)

itest/test_list_on_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ var testCases = []*testCase{
194194
name: "federation sync config",
195195
test: testFederationSyncConfig,
196196
},
197+
{
198+
name: "universe pagination simple",
199+
test: testUniversePaginationSimple,
200+
},
197201
}
198202

199203
var optionalTestCases = []*testCase{

0 commit comments

Comments
 (0)