Skip to content

Commit 2d29156

Browse files
authored
Merge pull request #253 from uibeka/fix/discovery-scan-limit-and-ordering
fix(discovery): raise maxScanCount default and sort before slice
2 parents 21ff766 + ca363de commit 2d29156

2 files changed

Lines changed: 9 additions & 13 deletions

File tree

src/registry/erc8004.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -631,23 +631,19 @@ export async function getRegisteredAgentsByEvents(
631631
return true;
632632
});
633633

634-
// Extract token IDs and owners, most recent first
634+
// Extract token IDs and owners, sorted by tokenId descending (most recent first).
635+
// tokenIds are monotonically increasing on mint, so this gives correct
636+
// newest-first ordering regardless of chunk collection order.
635637
const agents = uniqueLogs
636638
.map((log) => ({
637639
tokenId: (log.args.tokenId!).toString(),
638640
owner: log.args.to as string,
639641
}))
640-
.reverse()
642+
.sort((a, b) => {
643+
const diff = BigInt(b.tokenId) - BigInt(a.tokenId);
644+
return diff > 0n ? 1 : diff < 0n ? -1 : 0;
645+
})
641646
.slice(0, limit);
642-
643-
// The chunks were scanned newest-first, but within each chunk logs are
644-
// ascending. A simple .reverse() no longer yields a correct descending
645-
// order, so re-sort by tokenId descending (tokenIds are monotonically
646-
// increasing on mint).
647-
agents.sort((a, b) => {
648-
const diff = BigInt(b.tokenId) - BigInt(a.tokenId);
649-
return diff > 0n ? 1 : diff < 0n ? -1 : 0;
650-
});
651647

652648
logger.info(`Event scan found ${agents.length} minted agents (scanned ${allLogs.length} Transfer events across ${Math.ceil(Number(currentBlock - earliestBlock) / Number(MAX_BLOCK_RANGE))} chunks)`);
653649
return agents;

src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,15 +1349,15 @@ export interface MessageValidationResult {
13491349

13501350
export interface DiscoveryConfig {
13511351
ipfsGateway: string; // default: "https://ipfs.io"
1352-
maxScanCount: number; // default: 20
1352+
maxScanCount: number; // default: 100
13531353
maxConcurrentFetches: number; // default: 5
13541354
maxCardSizeBytes: number; // default: 64000
13551355
fetchTimeoutMs: number; // default: 10000
13561356
}
13571357

13581358
export const DEFAULT_DISCOVERY_CONFIG: DiscoveryConfig = {
13591359
ipfsGateway: "https://ipfs.io",
1360-
maxScanCount: 20,
1360+
maxScanCount: 100,
13611361
maxConcurrentFetches: 5,
13621362
maxCardSizeBytes: 64_000,
13631363
fetchTimeoutMs: 10_000,

0 commit comments

Comments
 (0)