From acc12cf12ef2e1b120586f973915040fda7fa3b7 Mon Sep 17 00:00:00 2001 From: xash Date: Thu, 14 Nov 2024 10:18:00 +0100 Subject: [PATCH] willSort and Store.queryRance sort now by subspace, then path Fixes #24 --- src/store/store.ts | 12 ++++++------ src/wgps/reconciliation/announcer.ts | 2 +- src/wgps/types.ts | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/store/store.ts b/src/store/store.ts index 5a438d6..c6ac885 100644 --- a/src/store/store.ts +++ b/src/store/store.ts @@ -763,12 +763,12 @@ export class Store< /** Retrieve an asynchronous iterator of entry-payload-authorisation triples from the store for a given [`Range`](https://willowprotocol.org/specs/grouping-entries/index.html#ranges). * - * Always returns entries in chronological order. + * Returns entries in order by subspace, then path, then timestamp. */ async *queryRange( range: Range3d, - /** Whether to return entries newest or oldest first. */ - order: "newest" | "oldest", + /** Whether to return entries descending or ascending. */ + order: "descending" | "ascending", ): AsyncIterable< [ Entry, @@ -783,8 +783,8 @@ export class Store< maxCount: 0, maxSize: BigInt(0), }, - "timestamp", - order === "newest" ? true : false, + "subspace", + order === "descending" ? true : false, ) ) { const payload = await this.payloadDriver.get(entry.payloadDigest); @@ -828,7 +828,7 @@ export class Store< start: entry.timestamp, end: entry.timestamp + 1n, }, - }, "newest") + }, "descending") ) { authToken = token; } diff --git a/src/wgps/reconciliation/announcer.ts b/src/wgps/reconciliation/announcer.ts index 1619b54..86c4934 100644 --- a/src/wgps/reconciliation/announcer.ts +++ b/src/wgps/reconciliation/announcer.ts @@ -149,7 +149,7 @@ export class Announcer< entry, payload, authToken, - ] of announcement.store.queryRange(announcement.range, "oldest") + ] of announcement.store.queryRange(announcement.range, "ascending") ) { const [staticToken, dynamicToken] = this.authorisationTokenScheme .decomposeAuthToken(authToken); diff --git a/src/wgps/types.ts b/src/wgps/types.ts index ee1036f..19a3445 100644 --- a/src/wgps/types.ts +++ b/src/wgps/types.ts @@ -319,7 +319,7 @@ export type MsgReconciliationAnnounceEntries = Msg< isEmpty: boolean; /** A boolean flag to indicate whether the sender wishes to receive a ReconciliationAnnounceEntries message for the same 3dRange in return. */ wantResponse: boolean; - /** Whether the sender promises to send the Entries in the range sorted from oldest to newest. */ + /** Whether the sender promises to send the Entries in the range sorted ascendingly by subspace_id first, path second. */ willSort: boolean; /** An AreaOfInterestHandle, bound by the sender of this message, that fully contains the range. */ senderHandle: bigint;