@peerbit/shared-log 13.1.4 → 13.1.6
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/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +37 -1
- package/dist/src/index.js.map +1 -1
- package/package.json +12 -12
- package/src/index.ts +54 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peerbit/shared-log",
|
|
3
|
-
"version": "13.1.
|
|
3
|
+
"version": "13.1.6",
|
|
4
4
|
"description": "Shared log",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -61,28 +61,28 @@
|
|
|
61
61
|
"pidusage": "^4.0.1",
|
|
62
62
|
"pino": "^9.4.0",
|
|
63
63
|
"uint8arrays": "^5.1.0",
|
|
64
|
-
"@peerbit/blocks": "4.1.2",
|
|
65
64
|
"@peerbit/any-store": "2.2.9",
|
|
66
|
-
"@peerbit/blocks
|
|
67
|
-
"@peerbit/
|
|
65
|
+
"@peerbit/blocks": "4.1.3",
|
|
66
|
+
"@peerbit/blocks-interface": "2.0.10",
|
|
68
67
|
"@peerbit/cache": "3.0.0",
|
|
68
|
+
"@peerbit/crypto": "3.1.1",
|
|
69
69
|
"@peerbit/indexer-interface": "3.0.3",
|
|
70
|
-
"@peerbit/
|
|
70
|
+
"@peerbit/log": "6.0.27",
|
|
71
71
|
"@peerbit/logger": "2.0.1",
|
|
72
|
-
"@peerbit/
|
|
73
|
-
"@peerbit/program": "6.0.
|
|
72
|
+
"@peerbit/indexer-sqlite3": "3.0.6",
|
|
73
|
+
"@peerbit/program": "6.0.22",
|
|
74
|
+
"@peerbit/pubsub-interface": "5.1.2",
|
|
74
75
|
"@peerbit/riblt": "1.2.0",
|
|
75
|
-
"@peerbit/
|
|
76
|
-
"@peerbit/pubsub
|
|
77
|
-
"@peerbit/
|
|
78
|
-
"@peerbit/stream-interface": "6.0.7",
|
|
76
|
+
"@peerbit/rpc": "6.0.26",
|
|
77
|
+
"@peerbit/pubsub": "5.2.3",
|
|
78
|
+
"@peerbit/stream-interface": "6.0.8",
|
|
79
79
|
"@peerbit/time": "3.0.0"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
82
|
"@types/libsodium-wrappers": "^0.7.14",
|
|
83
83
|
"@types/pidusage": "^2.0.5",
|
|
84
84
|
"uuid": "^10.0.0",
|
|
85
|
-
"@peerbit/test-utils": "3.0.
|
|
85
|
+
"@peerbit/test-utils": "3.0.26"
|
|
86
86
|
},
|
|
87
87
|
"repository": {
|
|
88
88
|
"type": "git",
|
package/src/index.ts
CHANGED
|
@@ -6553,10 +6553,11 @@ export class SharedLog<
|
|
|
6553
6553
|
// If it is still warming up (for example, only contains self), supplement with
|
|
6554
6554
|
// current subscribers until we have enough candidates for this decision.
|
|
6555
6555
|
let peerFilter: Set<string> | undefined = undefined;
|
|
6556
|
+
let selfReplicating = false;
|
|
6556
6557
|
if (options?.candidates) {
|
|
6557
6558
|
peerFilter = new Set(options.candidates);
|
|
6558
6559
|
} else {
|
|
6559
|
-
|
|
6560
|
+
selfReplicating = await this.isReplicating();
|
|
6560
6561
|
if (this.uniqueReplicators.size > 0) {
|
|
6561
6562
|
peerFilter = new Set(this.uniqueReplicators);
|
|
6562
6563
|
if (selfReplicating) {
|
|
@@ -6598,6 +6599,17 @@ export class SharedLog<
|
|
|
6598
6599
|
}
|
|
6599
6600
|
}
|
|
6600
6601
|
|
|
6602
|
+
if (!options?.candidates) {
|
|
6603
|
+
// Reachability snapshots can briefly under-report peers. Do not let that
|
|
6604
|
+
// turn a known mature indexed range into a false self-only full replica.
|
|
6605
|
+
peerFilter = await this.includeIndexedLeaderCandidatesWhenUnderfilled(
|
|
6606
|
+
peerFilter,
|
|
6607
|
+
roleAge,
|
|
6608
|
+
cursors.length,
|
|
6609
|
+
selfReplicating,
|
|
6610
|
+
);
|
|
6611
|
+
}
|
|
6612
|
+
|
|
6601
6613
|
if (!options?.candidates) {
|
|
6602
6614
|
const fullReplicaLeaders = await this.findFullReplicaLeaders(
|
|
6603
6615
|
cursors.length,
|
|
@@ -6621,6 +6633,47 @@ export class SharedLog<
|
|
|
6621
6633
|
);
|
|
6622
6634
|
}
|
|
6623
6635
|
|
|
6636
|
+
private async includeIndexedLeaderCandidatesWhenUnderfilled(
|
|
6637
|
+
peerFilter: Set<string> | undefined,
|
|
6638
|
+
roleAge: number,
|
|
6639
|
+
replicas: number,
|
|
6640
|
+
selfReplicating: boolean,
|
|
6641
|
+
): Promise<Set<string> | undefined> {
|
|
6642
|
+
if (!peerFilter || peerFilter.size > replicas) {
|
|
6643
|
+
return peerFilter;
|
|
6644
|
+
}
|
|
6645
|
+
|
|
6646
|
+
const selfHash = this.node.identity.publicKey.hashcode();
|
|
6647
|
+
const now = Date.now();
|
|
6648
|
+
const iterator = this.replicationIndex.iterate(
|
|
6649
|
+
{},
|
|
6650
|
+
{ shape: { hash: true, timestamp: true }, reference: true },
|
|
6651
|
+
);
|
|
6652
|
+
|
|
6653
|
+
try {
|
|
6654
|
+
for (;;) {
|
|
6655
|
+
const batch = await iterator.next(64);
|
|
6656
|
+
if (batch.length === 0) {
|
|
6657
|
+
break;
|
|
6658
|
+
}
|
|
6659
|
+
for (const result of batch) {
|
|
6660
|
+
const range = result.value;
|
|
6661
|
+
if (range.hash === selfHash && !selfReplicating) {
|
|
6662
|
+
continue;
|
|
6663
|
+
}
|
|
6664
|
+
if (!isMatured(range, now, roleAge)) {
|
|
6665
|
+
continue;
|
|
6666
|
+
}
|
|
6667
|
+
peerFilter.add(range.hash);
|
|
6668
|
+
}
|
|
6669
|
+
}
|
|
6670
|
+
} finally {
|
|
6671
|
+
await iterator.close();
|
|
6672
|
+
}
|
|
6673
|
+
|
|
6674
|
+
return peerFilter;
|
|
6675
|
+
}
|
|
6676
|
+
|
|
6624
6677
|
private async findFullReplicaLeaders(
|
|
6625
6678
|
replicas: number,
|
|
6626
6679
|
roleAge: number,
|