@peerbit/shared-log 8.0.7-aa577a5 → 8.0.7-cccc078
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/benchmark/get-samples.d.ts +2 -0
- package/dist/benchmark/get-samples.d.ts.map +1 -0
- package/dist/benchmark/get-samples.js +69 -0
- package/dist/benchmark/get-samples.js.map +1 -0
- package/dist/benchmark/index.js +15 -16
- package/dist/benchmark/index.js.map +1 -1
- package/dist/benchmark/replication-prune.d.ts +2 -0
- package/dist/benchmark/replication-prune.d.ts.map +1 -0
- package/dist/benchmark/replication-prune.js +103 -0
- package/dist/benchmark/replication-prune.js.map +1 -0
- package/dist/benchmark/replication.d.ts +2 -0
- package/dist/benchmark/replication.d.ts.map +1 -0
- package/dist/benchmark/replication.js +91 -0
- package/dist/benchmark/replication.js.map +1 -0
- package/dist/src/blocks.js +1 -1
- package/dist/src/blocks.js.map +1 -1
- package/dist/src/cpu.js.map +1 -1
- package/dist/src/exchange-heads.d.ts +1 -1
- package/dist/src/exchange-heads.d.ts.map +1 -1
- package/dist/src/exchange-heads.js +8 -8
- package/dist/src/exchange-heads.js.map +1 -1
- package/dist/src/index.d.ts +53 -47
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +513 -365
- package/dist/src/index.js.map +1 -1
- package/dist/src/pid.d.ts.map +1 -1
- package/dist/src/pid.js +20 -20
- package/dist/src/pid.js.map +1 -1
- package/dist/src/ranges.d.ts +9 -12
- package/dist/src/ranges.d.ts.map +1 -1
- package/dist/src/ranges.js +528 -133
- package/dist/src/ranges.js.map +1 -1
- package/dist/src/replication.d.ts +70 -12
- package/dist/src/replication.d.ts.map +1 -1
- package/dist/src/replication.js +258 -17
- package/dist/src/replication.js.map +1 -1
- package/dist/src/role.d.ts +1 -38
- package/dist/src/role.d.ts.map +1 -1
- package/dist/src/role.js +92 -116
- package/dist/src/role.js.map +1 -1
- package/package.json +11 -10
- package/src/blocks.ts +1 -1
- package/src/cpu.ts +4 -4
- package/src/exchange-heads.ts +18 -18
- package/src/index.ts +797 -550
- package/src/pid.ts +23 -22
- package/src/ranges.ts +693 -147
- package/src/replication.ts +271 -19
- package/src/role.ts +63 -83
package/dist/src/role.js
CHANGED
|
@@ -1,130 +1,106 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
var NoType_1, Observer_1, Replicator_1;
|
|
11
|
-
import { field, variant, vec } from "@dao-xyz/borsh";
|
|
12
|
-
export const overlaps = (x1, x2, y1, y2) => {
|
|
1
|
+
/* import { field, variant, vec } from "@dao-xyz/borsh"; */
|
|
2
|
+
/* export const overlaps = (x1: number, x2: number, y1: number, y2: number) => {
|
|
13
3
|
if (x1 <= y2 && y1 <= x2) {
|
|
14
4
|
return true;
|
|
15
5
|
}
|
|
16
6
|
return false;
|
|
17
|
-
};
|
|
18
|
-
export class Role {
|
|
7
|
+
}; */
|
|
8
|
+
/* export abstract class Role {
|
|
9
|
+
abstract equals(other: Role): boolean;
|
|
19
10
|
}
|
|
11
|
+
|
|
20
12
|
export const NO_TYPE_VARIANT = new Uint8Array([0]);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
|
|
14
|
+
@variant(0)
|
|
15
|
+
export class NoType extends Role {
|
|
16
|
+
equals(other: Role) {
|
|
17
|
+
return other instanceof NoType;
|
|
24
18
|
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
variant(0)
|
|
28
|
-
], NoType);
|
|
29
|
-
export { NoType };
|
|
19
|
+
}
|
|
20
|
+
|
|
30
21
|
export const OBSERVER_TYPE_VARIANT = new Uint8Array([1]);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
Observer = Observer_1 = __decorate([
|
|
37
|
-
variant(1)
|
|
38
|
-
], Observer);
|
|
39
|
-
export { Observer };
|
|
40
|
-
export const REPLICATOR_TYPE_VARIANT = new Uint8Array([2]);
|
|
41
|
-
export class ReplicationSegment {
|
|
42
|
-
timestamp;
|
|
43
|
-
factorNominator;
|
|
44
|
-
offsetNominator;
|
|
45
|
-
constructor(properties) {
|
|
46
|
-
const { factor, timestamp, offset } = properties;
|
|
47
|
-
if (factor > 1 || factor < 0) {
|
|
48
|
-
throw new Error("Expecting factor to be between 0 and 1, got: " + factor);
|
|
49
|
-
}
|
|
50
|
-
this.timestamp = timestamp ?? BigInt(+new Date());
|
|
51
|
-
this.factorNominator = Math.round(4294967295 * factor);
|
|
52
|
-
if (offset > 1 || offset < 0) {
|
|
53
|
-
throw new Error("Expecting offset to be between 0 and 1, got: " + offset);
|
|
54
|
-
}
|
|
55
|
-
this.offsetNominator = Math.round(4294967295 * offset);
|
|
22
|
+
|
|
23
|
+
@variant(1)
|
|
24
|
+
export class Observer extends Role {
|
|
25
|
+
equals(other: Role) {
|
|
26
|
+
return other instanceof Observer;
|
|
56
27
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const REPLICATOR_TYPE_VARIANT = new Uint8Array([2]);*/
|
|
31
|
+
export const SEGMENT_COORDINATE_SCALE = 4294967295;
|
|
32
|
+
/* export class ReplicationSegment {
|
|
33
|
+
|
|
34
|
+
@field({ type: "u64" })
|
|
35
|
+
timestamp: bigint;
|
|
36
|
+
|
|
37
|
+
@field({ type: "u32" })
|
|
38
|
+
start: number;
|
|
39
|
+
|
|
40
|
+
@field({ type: 'u32' })
|
|
41
|
+
end: number;
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
constructor(properties: {
|
|
46
|
+
start: number;
|
|
47
|
+
end: number;
|
|
48
|
+
timestamp: bigint;
|
|
49
|
+
}) {
|
|
50
|
+
const { start, end, timestamp } = properties;
|
|
51
|
+
|
|
52
|
+
if (start > end) {
|
|
53
|
+
throw new Error("Range 'start' needs to be lower or equal to 'end'")
|
|
83
54
|
}
|
|
84
|
-
|
|
55
|
+
this.start = Math.round(start * SEGMENT_COORDINATE_SCALE);
|
|
56
|
+
this.end = Math.round(end * SEGMENT_COORDINATE_SCALE);
|
|
57
|
+
this.timestamp = timestamp
|
|
85
58
|
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
86
62
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
]
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
__metadata("design:type", Number)
|
|
98
|
-
], ReplicationSegment.prototype, "offsetNominator", void 0);
|
|
99
|
-
let Replicator = Replicator_1 = class Replicator extends Role {
|
|
100
|
-
segments;
|
|
101
|
-
constructor(properties) {
|
|
63
|
+
*/
|
|
64
|
+
/* abstract class Capacity { }
|
|
65
|
+
|
|
66
|
+
@variant(2)
|
|
67
|
+
export class Replicator extends Role {
|
|
68
|
+
|
|
69
|
+
@field({ type: vec(Capacity) })
|
|
70
|
+
capacity: Capacity[];
|
|
71
|
+
|
|
72
|
+
constructor(properties?: { capacity: Capacity[] }) {
|
|
102
73
|
super();
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
74
|
+
this.capacity = properties?.capacity || [];
|
|
75
|
+
} */
|
|
76
|
+
/* constructor(properties: {
|
|
77
|
+
timestamp?: bigint;
|
|
78
|
+
factor: number;
|
|
79
|
+
offset: number;
|
|
80
|
+
}) {
|
|
81
|
+
super();
|
|
82
|
+
let timestamp = properties.timestamp || BigInt(+new Date);
|
|
83
|
+
let ranges = getSegmentsFromOffsetAndRange(properties.offset, properties.factor);
|
|
84
|
+
this.segments = ranges.map(x => new ReplicationSegment({ start: x[0], end: x[1], timestamp }));
|
|
85
|
+
}
|
|
86
|
+
*/
|
|
87
|
+
/* get factor(): number {
|
|
88
|
+
return this.segments[0]!.factor;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
get offset(): number {
|
|
92
|
+
return this.segments[0]!.offset;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
get timestamp(): bigint {
|
|
96
|
+
return this.segments[0]!.timestamp;
|
|
97
|
+
} */
|
|
98
|
+
/* equals(other: Role) {
|
|
99
|
+
return (
|
|
100
|
+
other instanceof Replicator &&
|
|
101
|
+
other.factor === this.factor &&
|
|
102
|
+
other.offset === this.offset
|
|
103
|
+
);
|
|
104
|
+
} */
|
|
105
|
+
/* } */
|
|
130
106
|
//# sourceMappingURL=role.js.map
|
package/dist/src/role.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"role.js","sourceRoot":"","sources":["../../src/role.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"role.js","sourceRoot":"","sources":["../../src/role.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAE3D;;;;;KAKK;AAEL;;;;;;;;;;;;;;;;;;;;;;6DAsB6D;AAE7D,MAAM,CAAC,MAAM,wBAAwB,GAAG,UAAU,CAAC;AACnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH;;;;;;;;;;;QAWK;AAEL;;;;;;;;;;EAUE;AACF;;;;;;;;;;IAUI;AAEJ;;;;;;IAMI;AACJ,OAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peerbit/shared-log",
|
|
3
|
-
"version": "8.0.7-
|
|
3
|
+
"version": "8.0.7-cccc078",
|
|
4
4
|
"description": "Shared log",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"eslintConfig": {
|
|
38
|
-
"extends": "
|
|
38
|
+
"extends": "peerbit",
|
|
39
39
|
"parserOptions": {
|
|
40
40
|
"project": true,
|
|
41
41
|
"sourceType": "module"
|
|
@@ -52,20 +52,21 @@
|
|
|
52
52
|
"scripts": {
|
|
53
53
|
"clean": "aegir clean",
|
|
54
54
|
"build": "aegir build --no-bundle",
|
|
55
|
-
"test": "aegir test --target node"
|
|
55
|
+
"test": "aegir test --target node",
|
|
56
|
+
"lint": "aegir lint"
|
|
56
57
|
},
|
|
57
58
|
"author": "dao.xyz",
|
|
58
59
|
"license": "MIT",
|
|
59
60
|
"dependencies": {
|
|
60
|
-
"@dao-xyz/borsh": "^5.2.
|
|
61
|
-
"@peerbit/logger": "1.0.2-
|
|
62
|
-
"@peerbit/program": "4.0.7-
|
|
63
|
-
"@peerbit/log": "3.0.34-
|
|
64
|
-
"@peerbit/rpc": "4.0.7-
|
|
65
|
-
"@peerbit/time": "2.0.6-
|
|
61
|
+
"@dao-xyz/borsh": "^5.2.3",
|
|
62
|
+
"@peerbit/logger": "1.0.2-cccc078",
|
|
63
|
+
"@peerbit/program": "4.0.7-cccc078",
|
|
64
|
+
"@peerbit/log": "3.0.34-cccc078",
|
|
65
|
+
"@peerbit/rpc": "4.0.7-cccc078",
|
|
66
|
+
"@peerbit/time": "2.0.6-cccc078",
|
|
66
67
|
"p-debounce": "^4.0.0"
|
|
67
68
|
},
|
|
68
69
|
"devDependencies": {
|
|
69
|
-
"@peerbit/test-utils": "2.0.33-
|
|
70
|
+
"@peerbit/test-utils": "2.0.33-cccc078"
|
|
70
71
|
}
|
|
71
72
|
}
|
package/src/blocks.ts
CHANGED
package/src/cpu.ts
CHANGED
|
@@ -20,8 +20,8 @@ export class CPUUsageIntervalLag implements CPUUsage {
|
|
|
20
20
|
windowSize: number;
|
|
21
21
|
intervalTime: number;
|
|
22
22
|
upperBoundLag: number;
|
|
23
|
-
} = { windowSize: 50, intervalTime: 100, upperBoundLag: 1000 }
|
|
24
|
-
) {
|
|
23
|
+
} = { windowSize: 50, intervalTime: 100, upperBoundLag: 1000 },
|
|
24
|
+
) {}
|
|
25
25
|
private mean() {
|
|
26
26
|
return this.sum / this.dt.length;
|
|
27
27
|
}
|
|
@@ -30,14 +30,14 @@ export class CPUUsageIntervalLag implements CPUUsage {
|
|
|
30
30
|
return (
|
|
31
31
|
Math.min(
|
|
32
32
|
Math.max(this.mean() - this.properties.intervalTime, 0),
|
|
33
|
-
this.properties.upperBoundLag
|
|
33
|
+
this.properties.upperBoundLag,
|
|
34
34
|
) / this.properties.upperBoundLag
|
|
35
35
|
); // 1 if lagging more than MAX_INTERVAL seconds
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
start() {
|
|
39
39
|
this.dt = new Array<number>(this.properties.windowSize).fill(
|
|
40
|
-
this.properties.intervalTime
|
|
40
|
+
this.properties.intervalTime,
|
|
41
41
|
);
|
|
42
42
|
this.sum = this.properties.windowSize * this.properties.intervalTime;
|
|
43
43
|
|
package/src/exchange-heads.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { field, fixedArray, variant, vec } from "@dao-xyz/borsh";
|
|
2
|
+
import { Cache } from "@peerbit/cache";
|
|
2
3
|
import { Entry, EntryType, type ShallowEntry } from "@peerbit/log";
|
|
3
4
|
import { Log } from "@peerbit/log";
|
|
4
5
|
import { logger as loggerFn } from "@peerbit/logger";
|
|
5
6
|
import { TransportMessage } from "./message.js";
|
|
6
|
-
import { Cache } from "@peerbit/cache";
|
|
7
7
|
|
|
8
8
|
const logger = loggerFn({ module: "exchange-heads" });
|
|
9
9
|
|
|
@@ -91,7 +91,7 @@ const MAX_EXCHANGE_MESSAGE_SIZE = 1e5; // 100kb. Too large size might not be fas
|
|
|
91
91
|
export const createExchangeHeadsMessages = async (
|
|
92
92
|
log: Log<any>,
|
|
93
93
|
heads: Entry<any>[],
|
|
94
|
-
gidParentCache: Cache<Entry<any>[]
|
|
94
|
+
gidParentCache: Cache<Entry<any>[]>,
|
|
95
95
|
): Promise<ExchangeHeadsMessage<any>[]> => {
|
|
96
96
|
const messages: ExchangeHeadsMessage<any>[] = [];
|
|
97
97
|
let size = 0;
|
|
@@ -117,8 +117,8 @@ export const createExchangeHeadsMessages = async (
|
|
|
117
117
|
current.push(
|
|
118
118
|
new EntryWithRefs({
|
|
119
119
|
entry: fromHead,
|
|
120
|
-
gidRefrences: refs.map((x) => x.meta.gid)
|
|
121
|
-
})
|
|
120
|
+
gidRefrences: refs.map((x) => x.meta.gid),
|
|
121
|
+
}),
|
|
122
122
|
);
|
|
123
123
|
|
|
124
124
|
size += fromHead.size;
|
|
@@ -126,8 +126,8 @@ export const createExchangeHeadsMessages = async (
|
|
|
126
126
|
size = 0;
|
|
127
127
|
messages.push(
|
|
128
128
|
new ExchangeHeadsMessage({
|
|
129
|
-
heads: current
|
|
130
|
-
})
|
|
129
|
+
heads: current,
|
|
130
|
+
}),
|
|
131
131
|
);
|
|
132
132
|
current = [];
|
|
133
133
|
continue;
|
|
@@ -136,8 +136,8 @@ export const createExchangeHeadsMessages = async (
|
|
|
136
136
|
if (current.length > 0) {
|
|
137
137
|
messages.push(
|
|
138
138
|
new ExchangeHeadsMessage({
|
|
139
|
-
heads: current
|
|
140
|
-
})
|
|
139
|
+
heads: current,
|
|
140
|
+
}),
|
|
141
141
|
);
|
|
142
142
|
}
|
|
143
143
|
return messages;
|
|
@@ -146,7 +146,7 @@ export const createExchangeHeadsMessages = async (
|
|
|
146
146
|
export const allEntriesWithUniqueGids = async (
|
|
147
147
|
log: Log<any>,
|
|
148
148
|
entry: Entry<any>,
|
|
149
|
-
gidParentCache: Cache<Entry<any>[]
|
|
149
|
+
gidParentCache: Cache<Entry<any>[]>,
|
|
150
150
|
): Promise<Entry<any>[]> => {
|
|
151
151
|
const cachedValue = gidParentCache.get(entry.hash);
|
|
152
152
|
if (cachedValue != null) {
|
|
@@ -154,23 +154,23 @@ export const allEntriesWithUniqueGids = async (
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
// TODO optimize this
|
|
157
|
-
const map: Map<string, ShallowEntry
|
|
158
|
-
let curr: ShallowEntry[] = [entry];
|
|
157
|
+
const map: Map<string, ShallowEntry | Entry<any>> = new Map();
|
|
158
|
+
let curr: (Entry<any> | ShallowEntry)[] = [entry];
|
|
159
159
|
while (curr.length > 0) {
|
|
160
|
-
const nexts: ShallowEntry[] = [];
|
|
160
|
+
const nexts: (Entry<any> | ShallowEntry)[] = [];
|
|
161
161
|
for (const element of curr) {
|
|
162
162
|
if (!map.has(element.meta.gid)) {
|
|
163
163
|
map.set(element.meta.gid, element);
|
|
164
164
|
if (element.meta.type === EntryType.APPEND) {
|
|
165
165
|
for (const next of element.meta.next) {
|
|
166
|
-
const indexedEntry = log.entryIndex.getShallow(next);
|
|
166
|
+
const indexedEntry = await log.entryIndex.getShallow(next);
|
|
167
167
|
if (!indexedEntry) {
|
|
168
168
|
logger.error(
|
|
169
169
|
"Failed to find indexed entry for hash when fetching references: " +
|
|
170
|
-
|
|
170
|
+
next,
|
|
171
171
|
);
|
|
172
172
|
} else {
|
|
173
|
-
nexts.push(indexedEntry);
|
|
173
|
+
nexts.push(indexedEntry.value);
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
}
|
|
@@ -180,8 +180,8 @@ export const allEntriesWithUniqueGids = async (
|
|
|
180
180
|
}
|
|
181
181
|
const value = [
|
|
182
182
|
...(await Promise.all(
|
|
183
|
-
[...map.values()].map((x) => log.entryIndex.get(x.hash))
|
|
184
|
-
))
|
|
183
|
+
[...map.values()].map((x) => log.entryIndex.get(x.hash)),
|
|
184
|
+
)),
|
|
185
185
|
].filter((x) => !!x) as Entry<any>[];
|
|
186
186
|
gidParentCache.add(entry.hash, value);
|
|
187
187
|
return value;
|