@peerbit/shared-log 13.2.33 → 13.2.34

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peerbit/shared-log",
3
- "version": "13.2.33",
3
+ "version": "13.2.34",
4
4
  "description": "Shared log",
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -68,17 +68,17 @@
68
68
  "@peerbit/crypto": "3.1.5",
69
69
  "@peerbit/blocks-interface": "2.1.5",
70
70
  "@peerbit/diagnostics": "0.0.1",
71
+ "@peerbit/indexer-interface": "3.0.9",
71
72
  "@peerbit/indexer-sqlite3": "3.0.14",
72
73
  "@peerbit/log": "6.2.16",
73
- "@peerbit/indexer-interface": "3.0.9",
74
74
  "@peerbit/logger": "2.0.1",
75
75
  "@peerbit/program": "6.0.48",
76
76
  "@peerbit/pubsub": "5.4.0",
77
+ "@peerbit/pubsub-interface": "5.2.0",
78
+ "@peerbit/rpc": "6.1.16",
77
79
  "@peerbit/riblt": "1.2.0",
78
80
  "@peerbit/time": "3.0.1",
79
- "@peerbit/stream-interface": "6.0.15",
80
- "@peerbit/rpc": "6.1.16",
81
- "@peerbit/pubsub-interface": "5.2.0"
81
+ "@peerbit/stream-interface": "6.0.15"
82
82
  },
83
83
  "optionalDependencies": {
84
84
  "@peerbit/native-backbone": "0.2.5",
@@ -88,10 +88,10 @@
88
88
  "@types/libsodium-wrappers": "^0.7.14",
89
89
  "@types/pidusage": "^2.0.5",
90
90
  "uuid": "^11.1.1",
91
- "@peerbit/any-store-rust": "0.1.4",
92
- "@peerbit/indexer-rust": "1.0.7",
93
91
  "@peerbit/test-utils": "3.1.22",
94
- "peerbit": "5.3.22"
92
+ "peerbit": "5.3.22",
93
+ "@peerbit/any-store-rust": "0.1.4",
94
+ "@peerbit/indexer-rust": "1.0.7"
95
95
  },
96
96
  "repository": {
97
97
  "type": "git",
package/src/index.ts CHANGED
@@ -3415,6 +3415,8 @@ export class SharedLog<
3415
3415
  validatePersistedReplicationRangeSnapshot: (ranges) =>
3416
3416
  this.validatePersistedReplicationRangeSnapshot(ranges),
3417
3417
  isClosed: () => this.closed,
3418
+ isPeerSessionCurrent: (peerHash, peerSession) =>
3419
+ this._peerSessions.isCurrent(peerHash, peerSession),
3418
3420
  isPeerSessionOpen: (peerHash, peerSession) =>
3419
3421
  this._peerSessions.isCurrent(peerHash, peerSession) &&
3420
3422
  (peerSession as PeerSession).phase === "open" &&
@@ -3495,6 +3497,12 @@ export class SharedLog<
3495
3497
  (this.node.services.pubsub as unknown as { session: number }).session,
3496
3498
  ),
3497
3499
  isClosed: () => this.closed,
3500
+ isPeerSessionCurrent: (peerHash, peerSession) =>
3501
+ this._peerSessions.isCurrent(peerHash, peerSession) &&
3502
+ (peerSession as PeerSession).phase === "open" &&
3503
+ (peerSession as PeerSession).isActive(),
3504
+ isReceiveEpochCurrent: (peerHash, receiveEpoch) =>
3505
+ this._peerSessions.isReceiveEpochCurrent(peerHash, receiveEpoch),
3498
3506
  isPeerStateCurrent: (peerHash, peerSession, receiveEpoch) =>
3499
3507
  this._peerSessions.isCurrent(peerHash, peerSession) &&
3500
3508
  (peerSession as PeerSession).phase === "open" &&
@@ -3532,6 +3540,8 @@ export class SharedLog<
3532
3540
  }`,
3533
3541
  );
3534
3542
  },
3543
+ onLocalCapabilityError: (error) =>
3544
+ this.handleReplicationLifecycleSendError(error),
3535
3545
  });
3536
3546
  }
3537
3547
 
@@ -6527,10 +6537,16 @@ export class SharedLog<
6527
6537
  // deliver the authoritative Full that completes recovery.
6528
6538
  const peerSession = this._peerSessions.current(keyHash);
6529
6539
  if (peerSession?.phase === "open") {
6540
+ const receiveEpoch = this._peerSessions.receiveEpoch(keyHash);
6530
6541
  this._v2Receive.advanceRecovery({
6531
6542
  peerHash: keyHash,
6532
6543
  peerSession,
6533
- receiveEpoch: this._peerSessions.receiveEpoch(keyHash),
6544
+ receiveEpoch,
6545
+ });
6546
+ this._v2Receive.reAdvertiseLocalCapabilityForRecovery({
6547
+ peerHash: keyHash,
6548
+ peerSession,
6549
+ receiveEpoch,
6534
6550
  });
6535
6551
  }
6536
6552
  }
@@ -23548,76 +23564,46 @@ export class SharedLog<
23548
23564
  expectedSubscriptionEpoch,
23549
23565
  );
23550
23566
 
23551
- // Decode, sender and authenticated apply readiness are separate bits. Start
23552
- // the ACKed receiver-led negotiation before the legacy snapshot, but do not
23553
- // hold mixed-version replication discovery behind that round trip. Attach
23554
- // the rejection handler now because a lifecycle fence below may return before
23555
- // awaiting the advert. RequestV2 is armed only after both sends settle.
23567
+ // Decode, sender and authenticated apply readiness are separate bits. An
23568
+ // ACKed capability advert is the local half of receiver-led negotiation;
23569
+ // readiness is promoted only after the legacy startup path has completed.
23570
+ // This preserves mixed-version discovery without putting capability ACK
23571
+ // latency on the subscription callback's critical path.
23556
23572
  const receiveEpoch = this._peerSessions.receiveEpoch(peerHash);
23557
23573
  const localCapabilityAdvertisement =
23558
- this.advertiseReplicationInfoV2ReceiveCapability({
23574
+ this._v2Receive.advertiseLocalCapability({
23559
23575
  target: publicKey,
23560
23576
  peerSession: expectedSubscriptionEpoch,
23561
23577
  receiveEpoch,
23562
23578
  signal: replicationLifecycleController.signal,
23563
- }).catch((error) => {
23564
- this.handleReplicationLifecycleSendError(
23565
- error,
23566
- replicationLifecycleController,
23567
- );
23568
- return undefined;
23569
23579
  });
23570
23580
 
23571
- let replicationSegments: ReplicationRangeIndexable<R>[];
23572
23581
  try {
23573
- replicationSegments = await this.getMyReplicationSegments();
23574
- } catch (error) {
23575
- if (
23576
- !this.isReplicationLifecycleActive(replicationLifecycleController) &&
23577
- isNotStartedError(error as Error)
23578
- ) {
23579
- return;
23582
+ let replicationSegments: ReplicationRangeIndexable<R>[];
23583
+ try {
23584
+ replicationSegments = await this.getMyReplicationSegments();
23585
+ } catch (error) {
23586
+ if (
23587
+ !this.isReplicationLifecycleActive(replicationLifecycleController) &&
23588
+ isNotStartedError(error as Error)
23589
+ ) {
23590
+ return;
23591
+ }
23592
+ throw error;
23580
23593
  }
23581
- throw error;
23582
- }
23583
- if (
23584
- !this.isReplicationLifecycleActive(replicationLifecycleController) ||
23585
- !ownsSubscriptionEpoch()
23586
- ) {
23587
- return;
23588
- }
23589
- if (replicationSegments.length > 0) {
23590
- const segments = replicationSegments.map((x) => x.toReplicationRange());
23591
- this.validatePersistedReplicationRangeSnapshot(segments);
23592
- await this.rpc
23593
- .send(
23594
- new AllReplicatingSegmentsMessage({
23595
- segments,
23596
- }),
23597
- {
23598
- mode: new AcknowledgeDelivery({ redundancy: 1, to: [publicKey] }),
23599
- signal: replicationLifecycleController.signal,
23600
- },
23601
- )
23602
- .catch((error) =>
23603
- this.handleReplicationLifecycleSendError(
23604
- error,
23605
- replicationLifecycleController,
23606
- ),
23607
- );
23608
23594
  if (
23609
23595
  !this.isReplicationLifecycleActive(replicationLifecycleController) ||
23610
23596
  !ownsSubscriptionEpoch()
23611
23597
  ) {
23612
23598
  return;
23613
23599
  }
23614
-
23615
- if (this.v8Behaviour) {
23616
- // for backwards compatibility
23600
+ if (replicationSegments.length > 0) {
23601
+ const segments = replicationSegments.map((x) => x.toReplicationRange());
23602
+ this.validatePersistedReplicationRangeSnapshot(segments);
23617
23603
  await this.rpc
23618
23604
  .send(
23619
- new ResponseRoleMessage({
23620
- role: this.getRoleFromReplicationSegments(replicationSegments),
23605
+ new AllReplicatingSegmentsMessage({
23606
+ segments,
23621
23607
  }),
23622
23608
  {
23623
23609
  mode: new AcknowledgeDelivery({
@@ -23633,30 +23619,51 @@ export class SharedLog<
23633
23619
  replicationLifecycleController,
23634
23620
  ),
23635
23621
  );
23636
- }
23637
- }
23622
+ if (
23623
+ !this.isReplicationLifecycleActive(replicationLifecycleController) ||
23624
+ !ownsSubscriptionEpoch()
23625
+ ) {
23626
+ return;
23627
+ }
23638
23628
 
23639
- // Keep legacy request-based discovery independent of the capability ACK too.
23640
- // This makes mixed-version joins resilient to timing-sensitive delivery/order
23641
- // issues where we may miss the remote peer's initial announcement.
23642
- if (
23643
- this.isReplicationLifecycleActive(replicationLifecycleController) &&
23644
- ownsSubscriptionEpoch()
23645
- ) {
23646
- this.scheduleReplicationInfoRequests(
23647
- publicKey,
23648
- replicationLifecycleController,
23649
- );
23650
- }
23629
+ if (this.v8Behaviour) {
23630
+ // for backwards compatibility
23631
+ await this.rpc
23632
+ .send(
23633
+ new ResponseRoleMessage({
23634
+ role: this.getRoleFromReplicationSegments(replicationSegments),
23635
+ }),
23636
+ {
23637
+ mode: new AcknowledgeDelivery({
23638
+ redundancy: 1,
23639
+ to: [publicKey],
23640
+ }),
23641
+ signal: replicationLifecycleController.signal,
23642
+ },
23643
+ )
23644
+ .catch((error) =>
23645
+ this.handleReplicationLifecycleSendError(
23646
+ error,
23647
+ replicationLifecycleController,
23648
+ ),
23649
+ );
23650
+ }
23651
+ }
23651
23652
 
23652
- const localCapabilityReady = await localCapabilityAdvertisement;
23653
- if (localCapabilityReady) {
23654
- this._v2Receive.markLocalCapabilityReady({
23655
- peerHash,
23656
- peerSession: expectedSubscriptionEpoch,
23657
- receiveEpoch,
23658
- ...localCapabilityReady,
23659
- });
23653
+ // Keep legacy request-based discovery independent of the capability ACK.
23654
+ // This makes mixed-version joins resilient to timing-sensitive delivery/order
23655
+ // issues where we may miss the remote peer's initial announcement.
23656
+ if (
23657
+ this.isReplicationLifecycleActive(replicationLifecycleController) &&
23658
+ ownsSubscriptionEpoch()
23659
+ ) {
23660
+ this.scheduleReplicationInfoRequests(
23661
+ publicKey,
23662
+ replicationLifecycleController,
23663
+ );
23664
+ }
23665
+ } finally {
23666
+ localCapabilityAdvertisement.releaseLegacyBarrier();
23660
23667
  }
23661
23668
  }
23662
23669