@peerbit/shared-log 13.0.2 → 13.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -114,6 +114,16 @@ export class StoppedReplicating extends TransportMessage {
114
114
  }
115
115
  }
116
116
 
117
+ @variant([1, 5])
118
+ export class ReplicationPingMessage extends TransportMessage {
119
+ // Lightweight unicast liveness probe for replicator membership.
120
+ // This exists to avoid using RequestReplicationInfoMessage as a "ping"
121
+ // (which can cause large replication segment snapshots to be sent).
122
+ constructor() {
123
+ super();
124
+ }
125
+ }
126
+
117
127
  /*
118
128
  @variant(1)
119
129
  export class RelativeMinReplicas extends MinReplicas {
@@ -590,7 +590,7 @@ export class SimpleSyncronizer<R extends "u32" | "u64">
590
590
  }
591
591
 
592
592
  async queueSync(
593
- keys: string[] | bigint[],
593
+ keys: SyncableKey[],
594
594
  from: PublicSignKey,
595
595
  options?: { skipCheck?: boolean },
596
596
  ) {
@@ -618,15 +618,10 @@ export class SimpleSyncronizer<R extends "u32" | "u64">
618
618
  }
619
619
 
620
620
  requestHashes.length > 0 &&
621
- (await this.requestSync(requestHashes as string[] | bigint[], [
622
- from!.hashcode(),
623
- ]));
621
+ (await this.requestSync(requestHashes, [from!.hashcode()]));
624
622
  }
625
623
 
626
- private async requestSync(
627
- hashes: string[] | bigint[],
628
- to: Set<string> | string[],
629
- ) {
624
+ private async requestSync(hashes: SyncableKey[], to: Set<string> | string[]) {
630
625
  if (hashes.length === 0) {
631
626
  return;
632
627
  }
@@ -643,12 +638,18 @@ export class SimpleSyncronizer<R extends "u32" | "u64">
643
638
  }
644
639
  }
645
640
 
646
- const isBigInt = typeof hashes[0] === "bigint";
647
- if (isBigInt) {
648
- const chunks = this.chunk(
649
- hashes as bigint[],
650
- this.maxCoordinatesPerMessage,
651
- );
641
+ const coordinateHashes: bigint[] = [];
642
+ const stringHashes: string[] = [];
643
+ for (const hash of hashes) {
644
+ if (typeof hash === "bigint") {
645
+ coordinateHashes.push(hash);
646
+ } else {
647
+ stringHashes.push(hash);
648
+ }
649
+ }
650
+
651
+ if (coordinateHashes.length > 0) {
652
+ const chunks = this.chunk(coordinateHashes, this.maxCoordinatesPerMessage);
652
653
  for (const chunk of chunks) {
653
654
  await this.rpc.send(
654
655
  new RequestMaybeSyncCoordinate({ hashNumbers: chunk }),
@@ -658,8 +659,9 @@ export class SimpleSyncronizer<R extends "u32" | "u64">
658
659
  },
659
660
  );
660
661
  }
661
- } else {
662
- const chunks = this.chunk(hashes as string[], this.maxHashesPerMessage);
662
+ }
663
+ if (stringHashes.length > 0) {
664
+ const chunks = this.chunk(stringHashes, this.maxHashesPerMessage);
663
665
  for (const chunk of chunks) {
664
666
  await this.rpc.send(new ResponseMaybeSync({ hashes: chunk }), {
665
667
  mode: new SilentDelivery({ to, redundancy: 1 }),
@@ -729,14 +731,12 @@ export class SimpleSyncronizer<R extends "u32" | "u64">
729
731
  this.syncInFlight.delete(key);
730
732
  }
731
733
  }
732
- this.requestSync(requestHashes as string[] | bigint[], from).finally(
733
- () => {
734
- if (this.closed) {
735
- return;
736
- }
737
- this.syncMoreInterval = setTimeout(requestSyncLoop, 3e3);
738
- },
739
- );
734
+ this.requestSync(requestHashes, from).finally(() => {
735
+ if (this.closed) {
736
+ return;
737
+ }
738
+ this.syncMoreInterval = setTimeout(requestSyncLoop, 3e3);
739
+ });
740
740
  };
741
741
 
742
742
  requestSyncLoop();