From f34cfe87f3be85053fb5c2e9ae13969cffb60f2d Mon Sep 17 00:00:00 2001 From: Hanno Cornelius <68783915+jm-clius@users.noreply.github.com> Date: Fri, 24 Oct 2025 15:38:06 +0100 Subject: [PATCH] fix: suggestions from code review Co-authored-by: Sasha <118575614+weboko@users.noreply.github.com> Co-authored-by: fryorcraken <110212804+fryorcraken@users.noreply.github.com> --- packages/sds/src/index.ts | 2 +- packages/sds/src/message_channel/events.ts | 2 +- packages/sds/src/message_channel/repair/buffers.ts | 6 +++--- packages/sds/src/message_channel/repair/repair.ts | 10 +++++----- packages/sds/src/message_channel/repair/utils.ts | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/sds/src/index.ts b/packages/sds/src/index.ts index d228616bde..14960d36b4 100644 --- a/packages/sds/src/index.ts +++ b/packages/sds/src/index.ts @@ -22,6 +22,6 @@ export { * @deprecated Use ParticipantId instead. SenderId has been renamed to ParticipantId * to better reflect that it represents a channel participant, not just a message sender. */ -export type SenderId = import("./message_channel/index.js").ParticipantId; +export type { ParticipantId as SenderId } from "./message_channel/index.js"; export { BloomFilter }; diff --git a/packages/sds/src/message_channel/events.ts b/packages/sds/src/message_channel/events.ts index 1fcd21c38a..0a40dce2bb 100644 --- a/packages/sds/src/message_channel/events.ts +++ b/packages/sds/src/message_channel/events.ts @@ -43,7 +43,7 @@ export type MessageChannelEvents = { }>; [MessageChannelEvent.RepairRequestReceived]: CustomEvent<{ messageIds: MessageId[]; - fromSenderId?: string; + fromSenderId?: ParticipantId; }>; [MessageChannelEvent.RepairResponseQueued]: CustomEvent<{ messageId: MessageId; diff --git a/packages/sds/src/message_channel/repair/buffers.ts b/packages/sds/src/message_channel/repair/buffers.ts index 799832ced6..5f1102e3f6 100644 --- a/packages/sds/src/message_channel/repair/buffers.ts +++ b/packages/sds/src/message_channel/repair/buffers.ts @@ -10,7 +10,7 @@ const log = new Logger("sds:repair:buffers"); interface OutgoingBufferEntry { entry: HistoryEntry; tReq: number; // Timestamp when this repair request should be sent - requested: boolean; // Whether this repair has been requested already + requested: boolean; // Whether this repair has already been requested by the local node } /** @@ -55,7 +55,7 @@ export class OutgoingRepairBuffer { // Check buffer size limit if (this.items.length >= this.maxSize) { - // Evict furthest T_req entry (last in sorted array) to preserve most urgent repairs + // Evict furthest T_req entry (last in sorted array) to preserve repairs that need to be sent the soonest const evicted = this.items.pop()!; log.warn( `Buffer full, evicted furthest entry ${evicted.entry.messageId} with T_req ${evicted.tReq}` @@ -88,7 +88,7 @@ export class OutgoingRepairBuffer { * Returns up to maxRequests entries from the front of the sorted array * Marks returned entries as requested but keeps them in buffer until received */ - public getEligible(currentTime: number, maxRequests = 3): HistoryEntry[] { + public getEligible(currentTime: number = Date.now(), maxRequests = 3): HistoryEntry[] { const eligible: HistoryEntry[] = []; // Iterate from front of sorted array (earliest T_req first) diff --git a/packages/sds/src/message_channel/repair/repair.ts b/packages/sds/src/message_channel/repair/repair.ts index 439ba0a82b..099954bd08 100644 --- a/packages/sds/src/message_channel/repair/repair.ts +++ b/packages/sds/src/message_channel/repair/repair.ts @@ -80,9 +80,9 @@ export class RepairManager { /** * Calculate T_req - when to request repair for a missing message - * Per spec (with bug fix): T_req = current_time + hash(participant_id, message_id) % (T_max - T_min) + T_min + * Per spec: T_req = current_time + hash(participant_id, message_id) % (T_max - T_min) + T_min */ - public calculateTReq(messageId: string, currentTime = Date.now()): number { + public calculateTReq(messageId: MessageId, currentTime = Date.now()): number { const hash = combinedHash(this.participantId, messageId); const range = BigInt(this.config.tMax - this.config.tMin); const offset = bigintToNumber(hash % range) + this.config.tMin; @@ -137,7 +137,7 @@ export class RepairManager { * Handle missing dependencies by adding them to outgoing repair buffer * Called when causal dependencies are detected as missing */ - public onMissingDependencies( + public markDependenciesMissing( missingEntries: HistoryEntry[], currentTime = Date.now() ): void { @@ -170,7 +170,7 @@ export class RepairManager { * Handle receipt of a message - remove from repair buffers * Called when a message is successfully received */ - public onMessageReceived(messageId: string): void { + public markMessageReceived(messageId: string): void { // Remove from both buffers as we no longer need to request or respond const wasInOutgoing = this.outgoingBuffer.has(messageId); const wasInIncoming = this.incomingBuffer.has(messageId); @@ -338,7 +338,7 @@ export class RepairManager { !Number.isInteger(numParticipants) ) { throw new Error( - `Invalid numParticipants: ${numParticipants}. Must be a non-negative integer.` + `Invalid numParticipants: ${numParticipants}. Must be a positive integer.` ); } diff --git a/packages/sds/src/message_channel/repair/utils.ts b/packages/sds/src/message_channel/repair/utils.ts index c83be0f661..f37ff3f4f9 100644 --- a/packages/sds/src/message_channel/repair/utils.ts +++ b/packages/sds/src/message_channel/repair/utils.ts @@ -1,5 +1,5 @@ import { sha256 } from "@noble/hashes/sha2"; -import { bytesToHex } from "@noble/hashes/utils"; +import { bytesToHex } from "@waku/utils/bytes"; /** * ParticipantId can be a string or converted to a numeric representation for XOR operations