diff --git a/packages/sds/src/message_channel/message_channel.ts b/packages/sds/src/message_channel/message_channel.ts index 00b13311c2..5a50193072 100644 --- a/packages/sds/src/message_channel/message_channel.ts +++ b/packages/sds/src/message_channel/message_channel.ts @@ -28,6 +28,11 @@ export const DEFAULT_BLOOM_FILTER_OPTIONS = { errorRate: 0.001 }; +/** + * Maximum number of repair requests to include in a single message + */ +const MAX_REPAIR_REQUESTS_PER_MESSAGE = 3; + const DEFAULT_CAUSAL_HISTORY_SIZE = 200; const DEFAULT_POSSIBLE_ACKS_THRESHOLD = 2; @@ -421,7 +426,9 @@ export class MessageChannel extends TypedEventEmitter { this.lamportTimestamp = lamportTimestampIncrement(this.lamportTimestamp); // Get repair requests to include in sync message (SDS-R) - const repairRequests = this.repairManager.getRepairRequests(3); + const repairRequests = this.repairManager.getRepairRequests( + MAX_REPAIR_REQUESTS_PER_MESSAGE + ); const message = new SyncMessage( // does not need to be secure randomness @@ -641,7 +648,9 @@ export class MessageChannel extends TypedEventEmitter { log.info(this.senderId, "sending new message", messageId); // Get repair requests to include in the message (SDS-R) - const repairRequests = this.repairManager.getRepairRequests(3); + const repairRequests = this.repairManager.getRepairRequests( + MAX_REPAIR_REQUESTS_PER_MESSAGE + ); message = new ContentMessage( messageId, diff --git a/packages/sds/src/message_channel/repair/repair.ts b/packages/sds/src/message_channel/repair/repair.ts index e833015213..d099cff68d 100644 --- a/packages/sds/src/message_channel/repair/repair.ts +++ b/packages/sds/src/message_channel/repair/repair.ts @@ -15,6 +15,11 @@ import { const log = new Logger("sds:repair:manager"); +/** + * Per SDS-R spec: One response group per 128 participants + */ +const PARTICIPANTS_PER_RESPONSE_GROUP = 128; + /** * Event emitter callback for repair events */ @@ -42,7 +47,7 @@ export interface RepairConfig { export const DEFAULT_REPAIR_CONFIG: Required = { tMin: 30000, // 30 seconds tMax: 120000, // 120 seconds - numResponseGroups: 1, // Recommendation is 1 group per 128 participants + numResponseGroups: 1, // Recommendation is 1 group per PARTICIPANTS_PER_RESPONSE_GROUP participants bufferSize: 1000, enabled: true }; @@ -332,10 +337,10 @@ export class RepairManager { numParticipants = Number.MAX_SAFE_INTEGER; } - // Per spec: num_response_groups = max(1, num_participants / 128) + // Per spec: num_response_groups = max(1, num_participants / PARTICIPANTS_PER_RESPONSE_GROUP) this.config.numResponseGroups = Math.max( 1, - Math.floor(numParticipants / 128) + Math.floor(numParticipants / PARTICIPANTS_PER_RESPONSE_GROUP) ); log.info( `Updated response groups to ${this.config.numResponseGroups} for ${numParticipants} participants`