fix: remove some magic numbers

This commit is contained in:
jm-clius 2025-10-23 14:50:34 +01:00
parent 5580f2f1e9
commit 13ed84bd6f
No known key found for this signature in database
GPG Key ID: 5FCD9D5211B952DA
2 changed files with 19 additions and 5 deletions

View File

@ -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<MessageChannelEvents> {
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<MessageChannelEvents> {
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,

View File

@ -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<RepairConfig> = {
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`