cojson 0.9.11 → 0.9.12
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/.turbo/turbo-build.log +3 -3
- package/CHANGELOG.md +6 -0
- package/dist/native/PeerState.js +1 -2
- package/dist/native/PeerState.js.map +1 -1
- package/dist/native/base64url.js +6 -0
- package/dist/native/base64url.js.map +1 -1
- package/dist/native/coValueCore.js +10 -4
- package/dist/native/coValueCore.js.map +1 -1
- package/dist/native/coValueState.js +4 -5
- package/dist/native/coValueState.js.map +1 -1
- package/dist/native/coValues/account.js +1 -2
- package/dist/native/coValues/account.js.map +1 -1
- package/dist/native/coValues/coList.js +7 -0
- package/dist/native/coValues/coList.js.map +1 -1
- package/dist/native/coValues/coStream.js +8 -3
- package/dist/native/coValues/coStream.js.map +1 -1
- package/dist/native/coValues/group.js +2 -3
- package/dist/native/coValues/group.js.map +1 -1
- package/dist/native/crypto/PureJSCrypto.js +1 -2
- package/dist/native/crypto/PureJSCrypto.js.map +1 -1
- package/dist/native/crypto/WasmCrypto.js +1 -2
- package/dist/native/crypto/WasmCrypto.js.map +1 -1
- package/dist/native/crypto/crypto.js +4 -2
- package/dist/native/crypto/crypto.js.map +1 -1
- package/dist/native/exports.js +1 -2
- package/dist/native/exports.js.map +1 -1
- package/dist/native/localNode.js +6 -5
- package/dist/native/localNode.js.map +1 -1
- package/dist/native/permissions.js +4 -3
- package/dist/native/permissions.js.map +1 -1
- package/dist/native/storage/FileSystem.js +10 -0
- package/dist/native/storage/FileSystem.js.map +1 -1
- package/dist/native/storage/index.js +23 -14
- package/dist/native/storage/index.js.map +1 -1
- package/dist/native/sync.js +28 -20
- package/dist/native/sync.js.map +1 -1
- package/dist/web/PeerState.js +1 -2
- package/dist/web/PeerState.js.map +1 -1
- package/dist/web/base64url.js +6 -0
- package/dist/web/base64url.js.map +1 -1
- package/dist/web/coValueCore.js +10 -4
- package/dist/web/coValueCore.js.map +1 -1
- package/dist/web/coValueState.js +4 -5
- package/dist/web/coValueState.js.map +1 -1
- package/dist/web/coValues/account.js +1 -2
- package/dist/web/coValues/account.js.map +1 -1
- package/dist/web/coValues/coList.js +7 -0
- package/dist/web/coValues/coList.js.map +1 -1
- package/dist/web/coValues/coStream.js +8 -3
- package/dist/web/coValues/coStream.js.map +1 -1
- package/dist/web/coValues/group.js +2 -3
- package/dist/web/coValues/group.js.map +1 -1
- package/dist/web/crypto/PureJSCrypto.js +1 -2
- package/dist/web/crypto/PureJSCrypto.js.map +1 -1
- package/dist/web/crypto/WasmCrypto.js +1 -2
- package/dist/web/crypto/WasmCrypto.js.map +1 -1
- package/dist/web/crypto/crypto.js +4 -2
- package/dist/web/crypto/crypto.js.map +1 -1
- package/dist/web/exports.js +1 -2
- package/dist/web/exports.js.map +1 -1
- package/dist/web/localNode.js +6 -5
- package/dist/web/localNode.js.map +1 -1
- package/dist/web/permissions.js +4 -3
- package/dist/web/permissions.js.map +1 -1
- package/dist/web/storage/FileSystem.js +10 -0
- package/dist/web/storage/FileSystem.js.map +1 -1
- package/dist/web/storage/index.js +23 -14
- package/dist/web/storage/index.js.map +1 -1
- package/dist/web/sync.js +28 -20
- package/dist/web/sync.js.map +1 -1
- package/package.json +1 -1
- package/src/PeerState.ts +1 -2
- package/src/base64url.ts +6 -1
- package/src/coValueCore.ts +10 -4
- package/src/coValueState.ts +4 -5
- package/src/coValues/account.ts +1 -2
- package/src/coValues/coList.ts +7 -0
- package/src/coValues/coStream.ts +8 -3
- package/src/coValues/group.ts +2 -3
- package/src/crypto/PureJSCrypto.ts +1 -2
- package/src/crypto/WasmCrypto.ts +1 -2
- package/src/crypto/crypto.ts +4 -2
- package/src/exports.ts +0 -2
- package/src/localNode.ts +9 -5
- package/src/permissions.ts +5 -3
- package/src/storage/FileSystem.ts +12 -0
- package/src/storage/index.ts +37 -21
- package/src/sync.ts +29 -20
- package/src/tests/PeerState.test.ts +3 -0
- package/dist/native/logger.js +0 -58
- package/dist/native/logger.js.map +0 -1
- package/dist/web/logger.js +0 -58
- package/dist/web/logger.js.map +0 -1
- package/src/logger.ts +0 -78
- package/src/tests/logger.test.ts +0 -145
package/src/localNode.ts
CHANGED
|
@@ -27,7 +27,6 @@ import {
|
|
|
27
27
|
} from "./coValues/group.js";
|
|
28
28
|
import { AgentSecret, CryptoProvider } from "./crypto/crypto.js";
|
|
29
29
|
import { AgentID, RawCoID, SessionID, isAgentID } from "./ids.js";
|
|
30
|
-
import { logger } from "./logger.js";
|
|
31
30
|
import { Peer, PeerID, SyncManager } from "./sync.js";
|
|
32
31
|
import { expectGroup } from "./typeUtils/expectGroup.js";
|
|
33
32
|
|
|
@@ -231,7 +230,7 @@ export class LocalNode {
|
|
|
231
230
|
|
|
232
231
|
return node;
|
|
233
232
|
} catch (e) {
|
|
234
|
-
|
|
233
|
+
console.error("Error withLoadedAccount", e);
|
|
235
234
|
throw e;
|
|
236
235
|
}
|
|
237
236
|
}
|
|
@@ -270,7 +269,7 @@ export class LocalNode {
|
|
|
270
269
|
this.syncManager.getServerAndStoragePeers(skipLoadingFromPeer);
|
|
271
270
|
|
|
272
271
|
await entry.loadFromPeers(peers).catch((e) => {
|
|
273
|
-
|
|
272
|
+
console.error("Error loading from peers", id, e);
|
|
274
273
|
});
|
|
275
274
|
}
|
|
276
275
|
|
|
@@ -312,6 +311,8 @@ export class LocalNode {
|
|
|
312
311
|
let stopped = false;
|
|
313
312
|
let unsubscribe!: () => void;
|
|
314
313
|
|
|
314
|
+
// console.log("Subscribing to " + id);
|
|
315
|
+
|
|
315
316
|
this.load(id)
|
|
316
317
|
.then((coValue) => {
|
|
317
318
|
if (stopped) {
|
|
@@ -324,10 +325,11 @@ export class LocalNode {
|
|
|
324
325
|
unsubscribe = coValue.subscribe(callback);
|
|
325
326
|
})
|
|
326
327
|
.catch((e) => {
|
|
327
|
-
|
|
328
|
+
console.error("Error subscribing to ", id, e);
|
|
328
329
|
});
|
|
329
330
|
|
|
330
331
|
return () => {
|
|
332
|
+
console.log("Unsubscribing from " + id);
|
|
331
333
|
stopped = true;
|
|
332
334
|
unsubscribe?.();
|
|
333
335
|
};
|
|
@@ -388,7 +390,9 @@ export class LocalNode {
|
|
|
388
390
|
(existingRole === "reader" && inviteRole === "readerInvite") ||
|
|
389
391
|
(existingRole && inviteRole === "writeOnlyInvite")
|
|
390
392
|
) {
|
|
391
|
-
|
|
393
|
+
console.debug(
|
|
394
|
+
"Not accepting invite that would replace or downgrade role",
|
|
395
|
+
);
|
|
392
396
|
return;
|
|
393
397
|
}
|
|
394
398
|
|
package/src/permissions.ts
CHANGED
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
} from "./ids.js";
|
|
15
15
|
import { parseJSON } from "./jsonStringify.js";
|
|
16
16
|
import { JsonValue } from "./jsonValue.js";
|
|
17
|
-
import { logger } from "./logger.js";
|
|
18
17
|
import { accountOrAgentIDfromSessionID } from "./typeUtils/accountOrAgentIDfromSessionID.js";
|
|
19
18
|
import { expectGroup } from "./typeUtils/expectGroup.js";
|
|
20
19
|
|
|
@@ -47,7 +46,7 @@ function logPermissionError(...args: unknown[]) {
|
|
|
47
46
|
return;
|
|
48
47
|
}
|
|
49
48
|
|
|
50
|
-
|
|
49
|
+
console.warn(...args);
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
export function determineValidTransactions(
|
|
@@ -205,6 +204,7 @@ function determineValidTransactionsForGroup(
|
|
|
205
204
|
const writeKeys = new Set<string>();
|
|
206
205
|
|
|
207
206
|
for (const { sessionID, txIndex, tx } of allTransactionsSorted) {
|
|
207
|
+
// console.log("before", { memberState, validTransactions });
|
|
208
208
|
const transactor = accountOrAgentIDfromSessionID(sessionID);
|
|
209
209
|
|
|
210
210
|
if (tx.privacy === "private") {
|
|
@@ -458,6 +458,8 @@ function determineValidTransactionsForGroup(
|
|
|
458
458
|
|
|
459
459
|
memberState[affectedMember] = change.value;
|
|
460
460
|
validTransactions.push({ txID: { sessionID, txIndex }, tx });
|
|
461
|
+
|
|
462
|
+
// console.log("after", { memberState, validTransactions });
|
|
461
463
|
}
|
|
462
464
|
|
|
463
465
|
return { validTransactions, memberState };
|
|
@@ -471,7 +473,7 @@ function agentInAccountOrMemberInGroup(
|
|
|
471
473
|
return groupAtTime.currentAgentID().match(
|
|
472
474
|
(agentID) => agentID,
|
|
473
475
|
(e) => {
|
|
474
|
-
|
|
476
|
+
console.error(
|
|
475
477
|
"Error while determining current agent ID in valid transactions",
|
|
476
478
|
e,
|
|
477
479
|
);
|
|
@@ -87,15 +87,26 @@ export async function writeBlock<WH, RH, FS extends FileSystem<WH, RH>>(
|
|
|
87
87
|
const headerBytes = textEncoder.encode(JSON.stringify(blockHeader));
|
|
88
88
|
await fs.append(file, headerBytes);
|
|
89
89
|
|
|
90
|
+
// console.log(
|
|
91
|
+
// "full file",
|
|
92
|
+
// yield* $(
|
|
93
|
+
// fs.read(file as unknown as RH, 0, offset + headerBytes.length),
|
|
94
|
+
// ),
|
|
95
|
+
// );
|
|
96
|
+
|
|
90
97
|
const filename: BlockFilename = `L${level}-${(blockNumber + "").padStart(
|
|
91
98
|
3,
|
|
92
99
|
"0",
|
|
93
100
|
)}-${hash.digest().replace("hash_", "").slice(0, 15)}-H${
|
|
94
101
|
headerBytes.length
|
|
95
102
|
}.jsonl`;
|
|
103
|
+
// console.log("renaming to" + filename);
|
|
96
104
|
await fs.closeAndRename(file, filename);
|
|
97
105
|
|
|
98
106
|
return filename;
|
|
107
|
+
|
|
108
|
+
// console.log("Wrote block", filename, blockHeader);
|
|
109
|
+
// console.log("IDs in block", blockHeader.map(e => e.id));
|
|
99
110
|
}
|
|
100
111
|
|
|
101
112
|
export async function writeToWal<WH, RH, FS extends FileSystem<WH, RH>>(
|
|
@@ -109,5 +120,6 @@ export async function writeToWal<WH, RH, FS extends FileSystem<WH, RH>>(
|
|
|
109
120
|
...chunk,
|
|
110
121
|
};
|
|
111
122
|
const bytes = textEncoder.encode(JSON.stringify(walEntry) + "\n");
|
|
123
|
+
console.log("writing to WAL", handle, id, bytes.length);
|
|
112
124
|
return fs.append(handle, bytes);
|
|
113
125
|
}
|
package/src/storage/index.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { CoID, RawCoValue } from "../coValue.js";
|
|
|
2
2
|
import { CoValueHeader, Transaction } from "../coValueCore.js";
|
|
3
3
|
import { Signature } from "../crypto/crypto.js";
|
|
4
4
|
import { RawCoID } from "../ids.js";
|
|
5
|
-
import { logger } from "../logger.js";
|
|
6
5
|
import { connectedPeers } from "../streamUtils.js";
|
|
7
6
|
import {
|
|
8
7
|
CoValueKnownState,
|
|
@@ -69,6 +68,7 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
|
|
69
68
|
|
|
70
69
|
const processMessages = async () => {
|
|
71
70
|
for await (const msg of fromLocalNode) {
|
|
71
|
+
console.log("Storage msg start", nMsg);
|
|
72
72
|
try {
|
|
73
73
|
if (msg === "Disconnected" || msg === "PingTimeout") {
|
|
74
74
|
throw new Error("Unexpected Disconnected message");
|
|
@@ -83,29 +83,32 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
|
|
83
83
|
await this.sendNewContent(msg.id, msg, undefined);
|
|
84
84
|
}
|
|
85
85
|
} catch (e) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
msg
|
|
89
|
-
|
|
90
|
-
k
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
86
|
+
console.error(
|
|
87
|
+
new Error(
|
|
88
|
+
`Error reading from localNode, handling msg\n\n${JSON.stringify(
|
|
89
|
+
msg,
|
|
90
|
+
(k, v) =>
|
|
91
|
+
k === "changes" || k === "encryptedChanges"
|
|
92
|
+
? v.slice(0, 20) + "..."
|
|
93
|
+
: v,
|
|
94
|
+
)}`,
|
|
95
|
+
{ cause: e },
|
|
96
|
+
),
|
|
95
97
|
);
|
|
96
98
|
}
|
|
99
|
+
console.log("Storage msg end", nMsg);
|
|
97
100
|
nMsg++;
|
|
98
101
|
}
|
|
99
102
|
};
|
|
100
103
|
|
|
101
104
|
processMessages().catch((e) =>
|
|
102
|
-
|
|
105
|
+
console.error("Error in processMessages in storage", e),
|
|
103
106
|
);
|
|
104
107
|
|
|
105
108
|
setTimeout(
|
|
106
109
|
() =>
|
|
107
110
|
this.compact().catch((e) => {
|
|
108
|
-
|
|
111
|
+
console.error("Error while compacting", e);
|
|
109
112
|
}),
|
|
110
113
|
20000,
|
|
111
114
|
);
|
|
@@ -131,7 +134,7 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
|
|
131
134
|
sessions: {},
|
|
132
135
|
asDependencyOf,
|
|
133
136
|
})
|
|
134
|
-
.catch((e) =>
|
|
137
|
+
.catch((e) => console.error("Error while pushing known", e));
|
|
135
138
|
|
|
136
139
|
return;
|
|
137
140
|
}
|
|
@@ -187,13 +190,13 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
|
|
187
190
|
...ourKnown,
|
|
188
191
|
asDependencyOf,
|
|
189
192
|
})
|
|
190
|
-
.catch((e) =>
|
|
193
|
+
.catch((e) => console.error("Error while pushing known", e));
|
|
191
194
|
|
|
192
195
|
for (const message of newContentMessages) {
|
|
193
196
|
if (Object.keys(message.new).length === 0) continue;
|
|
194
197
|
this.toLocalNode
|
|
195
198
|
.push(message)
|
|
196
|
-
.catch((e) =>
|
|
199
|
+
.catch((e) => console.error("Error while pushing new content", e));
|
|
197
200
|
}
|
|
198
201
|
|
|
199
202
|
this.coValues[id] = coValue;
|
|
@@ -229,19 +232,20 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
|
|
229
232
|
|
|
230
233
|
if (!coValue) {
|
|
231
234
|
if (newContent.header) {
|
|
235
|
+
// console.log("Creating in WAL", newContent.id);
|
|
232
236
|
await this.withWAL((wal) =>
|
|
233
237
|
writeToWal(wal, this.fs, newContent.id, newContentAsChunk),
|
|
234
238
|
);
|
|
235
239
|
|
|
236
240
|
this.coValues[newContent.id] = newContentAsChunk;
|
|
237
241
|
} else {
|
|
238
|
-
|
|
242
|
+
console.warn("Incontiguous incoming update for " + newContent.id);
|
|
239
243
|
return;
|
|
240
244
|
}
|
|
241
245
|
} else {
|
|
242
246
|
const merged = mergeChunks(coValue, newContentAsChunk);
|
|
243
247
|
if (merged === "nonContigous") {
|
|
244
|
-
|
|
248
|
+
console.warn(
|
|
245
249
|
"Non-contigous new content for " + newContent.id,
|
|
246
250
|
Object.entries(coValue.sessionEntries).map(([session, entries]) =>
|
|
247
251
|
entries.map((entry) => ({
|
|
@@ -260,6 +264,7 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
|
|
260
264
|
),
|
|
261
265
|
);
|
|
262
266
|
} else {
|
|
267
|
+
// console.log("Appending to WAL", newContent.id);
|
|
263
268
|
await this.withWAL((wal) =>
|
|
264
269
|
writeToWal(wal, this.fs, newContent.id, newContentAsChunk),
|
|
265
270
|
);
|
|
@@ -296,6 +301,8 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
|
|
296
301
|
|
|
297
302
|
const { handle, size } = await this.getBlockHandle(blockFile, fs);
|
|
298
303
|
|
|
304
|
+
// console.log("Attempting to load", id, blockFile);
|
|
305
|
+
|
|
299
306
|
if (!cachedHeader) {
|
|
300
307
|
cachedHeader = {};
|
|
301
308
|
const header = await readHeader(blockFile, handle, size, fs);
|
|
@@ -310,13 +317,15 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
|
|
310
317
|
}
|
|
311
318
|
const headerEntry = cachedHeader[id];
|
|
312
319
|
|
|
320
|
+
// console.log("Header entry", id, headerEntry);
|
|
321
|
+
|
|
313
322
|
if (headerEntry) {
|
|
314
323
|
const nextChunk = await readChunk(handle, headerEntry, fs);
|
|
315
324
|
if (result) {
|
|
316
325
|
const merged = mergeChunks(result, nextChunk);
|
|
317
326
|
|
|
318
327
|
if (merged === "nonContigous") {
|
|
319
|
-
|
|
328
|
+
console.warn(
|
|
320
329
|
"Non-contigous chunks while loading " + id,
|
|
321
330
|
result,
|
|
322
331
|
nextChunk,
|
|
@@ -345,6 +354,7 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
|
|
345
354
|
|
|
346
355
|
const coValues = new Map<RawCoID, CoValueChunk>();
|
|
347
356
|
|
|
357
|
+
console.log("Compacting WAL files", walFiles);
|
|
348
358
|
if (walFiles.length === 0) return;
|
|
349
359
|
|
|
350
360
|
const oldWal = this.currentWal;
|
|
@@ -375,7 +385,7 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
|
|
375
385
|
if (existingChunk) {
|
|
376
386
|
const merged = mergeChunks(existingChunk, chunk);
|
|
377
387
|
if (merged === "nonContigous") {
|
|
378
|
-
|
|
388
|
+
console.log(
|
|
379
389
|
"Non-contigous chunks in " + chunk.id + ", " + fileName,
|
|
380
390
|
existingChunk,
|
|
381
391
|
chunk,
|
|
@@ -401,6 +411,8 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
|
|
401
411
|
return acc;
|
|
402
412
|
}, 0);
|
|
403
413
|
|
|
414
|
+
console.log([...coValues.keys()], fileNames, highestBlockNumber);
|
|
415
|
+
|
|
404
416
|
await writeBlock(coValues, MAX_N_LEVELS, highestBlockNumber + 1, this.fs);
|
|
405
417
|
|
|
406
418
|
for (const walFile of walFiles) {
|
|
@@ -426,11 +438,15 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
|
|
426
438
|
blockFilesByLevelInOrder[level]!.push(blockFile);
|
|
427
439
|
}
|
|
428
440
|
|
|
441
|
+
console.log(blockFilesByLevelInOrder);
|
|
442
|
+
|
|
429
443
|
for (let level = MAX_N_LEVELS; level > 0; level--) {
|
|
430
444
|
const nBlocksDesired = Math.pow(2, level);
|
|
431
445
|
const blocksInLevel = blockFilesByLevelInOrder[level];
|
|
432
446
|
|
|
433
447
|
if (blocksInLevel && blocksInLevel.length > nBlocksDesired) {
|
|
448
|
+
console.log("Compacting blocks in level", level, blocksInLevel);
|
|
449
|
+
|
|
434
450
|
const coValues = new Map<RawCoID, CoValueChunk>();
|
|
435
451
|
|
|
436
452
|
for (const blockFile of blocksInLevel) {
|
|
@@ -449,7 +465,7 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
|
|
449
465
|
if (existingChunk) {
|
|
450
466
|
const merged = mergeChunks(existingChunk, chunk);
|
|
451
467
|
if (merged === "nonContigous") {
|
|
452
|
-
|
|
468
|
+
console.log(
|
|
453
469
|
"Non-contigous chunks in " + entry.id + ", " + blockFile,
|
|
454
470
|
existingChunk,
|
|
455
471
|
chunk,
|
|
@@ -501,7 +517,7 @@ export class LSMStorage<WH, RH, FS extends FileSystem<WH, RH>> {
|
|
|
501
517
|
setTimeout(
|
|
502
518
|
() =>
|
|
503
519
|
this.compact().catch((e) => {
|
|
504
|
-
|
|
520
|
+
console.error("Error while compacting", e);
|
|
505
521
|
}),
|
|
506
522
|
5000,
|
|
507
523
|
);
|
package/src/sync.ts
CHANGED
|
@@ -6,7 +6,6 @@ import { CoValueCore } from "./coValueCore.js";
|
|
|
6
6
|
import { Signature } from "./crypto/crypto.js";
|
|
7
7
|
import { RawCoID, SessionID } from "./ids.js";
|
|
8
8
|
import { LocalNode } from "./localNode.js";
|
|
9
|
-
import { logger } from "./logger.js";
|
|
10
9
|
import { CoValuePriority } from "./priority.js";
|
|
11
10
|
|
|
12
11
|
export type CoValueKnownState = {
|
|
@@ -151,7 +150,7 @@ export class SyncManager {
|
|
|
151
150
|
|
|
152
151
|
async handleSyncMessage(msg: SyncMessage, peer: PeerState) {
|
|
153
152
|
if (peer.erroredCoValues.has(msg.id)) {
|
|
154
|
-
|
|
153
|
+
console.error(
|
|
155
154
|
`Skipping message ${msg.action} on errored coValue ${msg.id} from peer ${peer.id}`,
|
|
156
155
|
);
|
|
157
156
|
return;
|
|
@@ -183,7 +182,7 @@ export class SyncManager {
|
|
|
183
182
|
|
|
184
183
|
if (entry.state.type !== "available") {
|
|
185
184
|
entry.loadFromPeers([peer]).catch((e: unknown) => {
|
|
186
|
-
|
|
185
|
+
console.error("Error sending load", e);
|
|
187
186
|
});
|
|
188
187
|
return;
|
|
189
188
|
}
|
|
@@ -200,7 +199,7 @@ export class SyncManager {
|
|
|
200
199
|
action: "load",
|
|
201
200
|
...coValue.knownState(),
|
|
202
201
|
}).catch((e: unknown) => {
|
|
203
|
-
|
|
202
|
+
console.error("Error sending load", e);
|
|
204
203
|
});
|
|
205
204
|
}
|
|
206
205
|
}
|
|
@@ -230,7 +229,7 @@ export class SyncManager {
|
|
|
230
229
|
asDependencyOf,
|
|
231
230
|
...coValue.knownState(),
|
|
232
231
|
}).catch((e: unknown) => {
|
|
233
|
-
|
|
232
|
+
console.error("Error sending known state", e);
|
|
234
233
|
});
|
|
235
234
|
|
|
236
235
|
peer.toldKnownState.add(id);
|
|
@@ -257,8 +256,15 @@ export class SyncManager {
|
|
|
257
256
|
const sendPieces = async () => {
|
|
258
257
|
let lastYield = performance.now();
|
|
259
258
|
for (const [_i, piece] of newContentPieces.entries()) {
|
|
259
|
+
// console.log(
|
|
260
|
+
// `${id} -> ${peer.id}: Sending content piece ${i + 1}/${
|
|
261
|
+
// newContentPieces.length
|
|
262
|
+
// } header: ${!!piece.header}`,
|
|
263
|
+
// // Object.values(piece.new).map((s) => s.newTransactions)
|
|
264
|
+
// );
|
|
265
|
+
|
|
260
266
|
this.trySendToPeer(peer, piece).catch((e: unknown) => {
|
|
261
|
-
|
|
267
|
+
console.error("Error sending content piece", e);
|
|
262
268
|
});
|
|
263
269
|
|
|
264
270
|
if (performance.now() - lastYield > 10) {
|
|
@@ -271,7 +277,7 @@ export class SyncManager {
|
|
|
271
277
|
};
|
|
272
278
|
|
|
273
279
|
sendPieces().catch((e) => {
|
|
274
|
-
|
|
280
|
+
console.error("Error sending new content piece, retrying", e);
|
|
275
281
|
peer.optimisticKnownStates.dispatch({
|
|
276
282
|
type: "SET",
|
|
277
283
|
id,
|
|
@@ -331,7 +337,7 @@ export class SyncManager {
|
|
|
331
337
|
return;
|
|
332
338
|
}
|
|
333
339
|
if (msg === "PingTimeout") {
|
|
334
|
-
|
|
340
|
+
console.error("Ping timeout from peer", peer.id);
|
|
335
341
|
return;
|
|
336
342
|
}
|
|
337
343
|
try {
|
|
@@ -354,13 +360,13 @@ export class SyncManager {
|
|
|
354
360
|
processMessages()
|
|
355
361
|
.then(() => {
|
|
356
362
|
if (peer.crashOnClose) {
|
|
357
|
-
|
|
363
|
+
console.error("Unexepcted close from peer", peer.id);
|
|
358
364
|
this.local.crashed = new Error("Unexpected close from peer");
|
|
359
365
|
throw new Error("Unexpected close from peer");
|
|
360
366
|
}
|
|
361
367
|
})
|
|
362
368
|
.catch((e) => {
|
|
363
|
-
|
|
369
|
+
console.error("Error processing messages from peer", peer.id, e);
|
|
364
370
|
if (peer.crashOnClose) {
|
|
365
371
|
this.local.crashed = e;
|
|
366
372
|
throw new Error(e);
|
|
@@ -400,13 +406,13 @@ export class SyncManager {
|
|
|
400
406
|
// where we can get informations about the coValue
|
|
401
407
|
if (msg.header || Object.keys(msg.sessions).length > 0) {
|
|
402
408
|
entry.loadFromPeers([peer]).catch((e) => {
|
|
403
|
-
|
|
409
|
+
console.error("Error loading coValue in handleLoad", e);
|
|
404
410
|
});
|
|
405
411
|
}
|
|
406
412
|
return;
|
|
407
413
|
} else {
|
|
408
414
|
this.local.loadCoValueCore(msg.id, peer.id).catch((e) => {
|
|
409
|
-
|
|
415
|
+
console.error("Error loading coValue in handleLoad", e);
|
|
410
416
|
});
|
|
411
417
|
}
|
|
412
418
|
}
|
|
@@ -433,7 +439,7 @@ export class SyncManager {
|
|
|
433
439
|
header: false,
|
|
434
440
|
sessions: {},
|
|
435
441
|
}).catch((e) => {
|
|
436
|
-
|
|
442
|
+
console.error("Error sending known state back", e);
|
|
437
443
|
});
|
|
438
444
|
|
|
439
445
|
return;
|
|
@@ -443,7 +449,7 @@ export class SyncManager {
|
|
|
443
449
|
await this.sendNewContentIncludingDependencies(msg.id, peer);
|
|
444
450
|
})
|
|
445
451
|
.catch((e) => {
|
|
446
|
-
|
|
452
|
+
console.error("Error loading coValue in handleLoad loading state", e);
|
|
447
453
|
});
|
|
448
454
|
}
|
|
449
455
|
|
|
@@ -478,7 +484,7 @@ export class SyncManager {
|
|
|
478
484
|
peer.role === "storage" ? undefined : peer.id,
|
|
479
485
|
)
|
|
480
486
|
.catch((e) => {
|
|
481
|
-
|
|
487
|
+
console.error(
|
|
482
488
|
`Error loading coValue ${msg.id} to create loading state, as dependency of ${msg.asDependencyOf}`,
|
|
483
489
|
e,
|
|
484
490
|
);
|
|
@@ -515,7 +521,7 @@ export class SyncManager {
|
|
|
515
521
|
|
|
516
522
|
if (entry.state.type !== "available") {
|
|
517
523
|
if (!msg.header) {
|
|
518
|
-
|
|
524
|
+
console.error("Expected header to be sent in first message");
|
|
519
525
|
return;
|
|
520
526
|
}
|
|
521
527
|
|
|
@@ -578,7 +584,7 @@ export class SyncManager {
|
|
|
578
584
|
: t.changes.length,
|
|
579
585
|
)
|
|
580
586
|
.reduce((a, b) => a + b, 0);
|
|
581
|
-
|
|
587
|
+
console.log(
|
|
582
588
|
`Adding incoming transactions took ${(after - before).toFixed(
|
|
583
589
|
2,
|
|
584
590
|
)}ms for ${totalTxLength} bytes = bandwidth: ${(
|
|
@@ -596,7 +602,7 @@ export class SyncManager {
|
|
|
596
602
|
// );
|
|
597
603
|
|
|
598
604
|
if (result.isErr()) {
|
|
599
|
-
|
|
605
|
+
console.error(
|
|
600
606
|
"Failed to add transactions from",
|
|
601
607
|
peer.id,
|
|
602
608
|
result.error,
|
|
@@ -627,7 +633,7 @@ export class SyncManager {
|
|
|
627
633
|
isCorrection: true,
|
|
628
634
|
...coValue.knownState(),
|
|
629
635
|
}).catch((e) => {
|
|
630
|
-
|
|
636
|
+
console.error("Error sending known state correction", e);
|
|
631
637
|
});
|
|
632
638
|
} else {
|
|
633
639
|
/**
|
|
@@ -641,7 +647,7 @@ export class SyncManager {
|
|
|
641
647
|
action: "known",
|
|
642
648
|
...coValue.knownState(),
|
|
643
649
|
}).catch((e: unknown) => {
|
|
644
|
-
|
|
650
|
+
console.error("Error sending known state", e);
|
|
645
651
|
});
|
|
646
652
|
}
|
|
647
653
|
|
|
@@ -675,6 +681,9 @@ export class SyncManager {
|
|
|
675
681
|
const done = new Promise<void>((resolve) => {
|
|
676
682
|
queueMicrotask(async () => {
|
|
677
683
|
delete this.requestedSyncs[coValue.id];
|
|
684
|
+
// if (entry.nRequestsThisTick >= 2) {
|
|
685
|
+
// console.log("Syncing", coValue.id, "for", entry.nRequestsThisTick, "requests");
|
|
686
|
+
// }
|
|
678
687
|
await this.actuallySyncCoValue(coValue);
|
|
679
688
|
resolve();
|
|
680
689
|
});
|
|
@@ -49,9 +49,12 @@ describe("PeerState", () => {
|
|
|
49
49
|
|
|
50
50
|
test("should perform graceful shutdown", () => {
|
|
51
51
|
const { mockPeer, peerState } = setup();
|
|
52
|
+
const consoleSpy = vi.spyOn(console, "debug").mockImplementation(() => {});
|
|
52
53
|
peerState.gracefulShutdown();
|
|
53
54
|
expect(mockPeer.outgoing.close).toHaveBeenCalled();
|
|
54
55
|
expect(peerState.closed).toBe(true);
|
|
56
|
+
expect(consoleSpy).toHaveBeenCalledWith("Gracefully closing", "test-peer");
|
|
57
|
+
consoleSpy.mockRestore();
|
|
55
58
|
});
|
|
56
59
|
|
|
57
60
|
test("should empty the queue when closing", async () => {
|
package/dist/native/logger.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
export var LogLevel;
|
|
2
|
-
(function (LogLevel) {
|
|
3
|
-
LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
|
|
4
|
-
LogLevel[LogLevel["INFO"] = 1] = "INFO";
|
|
5
|
-
LogLevel[LogLevel["WARN"] = 2] = "WARN";
|
|
6
|
-
LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
|
|
7
|
-
LogLevel[LogLevel["NONE"] = 4] = "NONE";
|
|
8
|
-
})(LogLevel || (LogLevel = {}));
|
|
9
|
-
// Default console-based logging system
|
|
10
|
-
export class ConsoleLogSystem {
|
|
11
|
-
debug(message, ...args) {
|
|
12
|
-
console.debug(message, ...args);
|
|
13
|
-
}
|
|
14
|
-
info(message, ...args) {
|
|
15
|
-
console.info(message, ...args);
|
|
16
|
-
}
|
|
17
|
-
warn(message, ...args) {
|
|
18
|
-
console.warn(message, ...args);
|
|
19
|
-
}
|
|
20
|
-
error(message, ...args) {
|
|
21
|
-
console.error(message, ...args);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
export class Logger {
|
|
25
|
-
constructor(level = LogLevel.INFO, logSystem = new ConsoleLogSystem()) {
|
|
26
|
-
this.level = level;
|
|
27
|
-
this.logSystem = logSystem;
|
|
28
|
-
}
|
|
29
|
-
setLevel(level) {
|
|
30
|
-
this.level = level;
|
|
31
|
-
}
|
|
32
|
-
setLogSystem(logSystem) {
|
|
33
|
-
this.logSystem = logSystem;
|
|
34
|
-
}
|
|
35
|
-
debug(message, ...args) {
|
|
36
|
-
if (this.level <= LogLevel.DEBUG) {
|
|
37
|
-
this.logSystem.debug(message, ...args);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
info(message, ...args) {
|
|
41
|
-
if (this.level <= LogLevel.INFO) {
|
|
42
|
-
this.logSystem.info(message, ...args);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
warn(message, ...args) {
|
|
46
|
-
if (this.level <= LogLevel.WARN) {
|
|
47
|
-
this.logSystem.warn(message, ...args);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
error(message, ...args) {
|
|
51
|
-
if (this.level <= LogLevel.ERROR) {
|
|
52
|
-
this.logSystem.error(message, ...args);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
// Create default logger instance
|
|
57
|
-
export const logger = new Logger();
|
|
58
|
-
//# sourceMappingURL=logger.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
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AAC;YACjC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAED,IAAI,CAAC,OAAe,EAAE,GAAG,IAAW;QAClC,IAAI,IAAI,CAAC,KAAK,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC;YAChC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAED,IAAI,CAAC,OAAe,EAAE,GAAG,IAAW;QAClC,IAAI,IAAI,CAAC,KAAK,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC;YAChC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAED,KAAK,CAAC,OAAe,EAAE,GAAG,IAAW;QACnC,IAAI,IAAI,CAAC,KAAK,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC;YACjC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;CACF;AAED,iCAAiC;AACjC,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC"}
|
package/dist/web/logger.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
export var LogLevel;
|
|
2
|
-
(function (LogLevel) {
|
|
3
|
-
LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
|
|
4
|
-
LogLevel[LogLevel["INFO"] = 1] = "INFO";
|
|
5
|
-
LogLevel[LogLevel["WARN"] = 2] = "WARN";
|
|
6
|
-
LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
|
|
7
|
-
LogLevel[LogLevel["NONE"] = 4] = "NONE";
|
|
8
|
-
})(LogLevel || (LogLevel = {}));
|
|
9
|
-
// Default console-based logging system
|
|
10
|
-
export class ConsoleLogSystem {
|
|
11
|
-
debug(message, ...args) {
|
|
12
|
-
console.debug(message, ...args);
|
|
13
|
-
}
|
|
14
|
-
info(message, ...args) {
|
|
15
|
-
console.info(message, ...args);
|
|
16
|
-
}
|
|
17
|
-
warn(message, ...args) {
|
|
18
|
-
console.warn(message, ...args);
|
|
19
|
-
}
|
|
20
|
-
error(message, ...args) {
|
|
21
|
-
console.error(message, ...args);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
export class Logger {
|
|
25
|
-
constructor(level = LogLevel.INFO, logSystem = new ConsoleLogSystem()) {
|
|
26
|
-
this.level = level;
|
|
27
|
-
this.logSystem = logSystem;
|
|
28
|
-
}
|
|
29
|
-
setLevel(level) {
|
|
30
|
-
this.level = level;
|
|
31
|
-
}
|
|
32
|
-
setLogSystem(logSystem) {
|
|
33
|
-
this.logSystem = logSystem;
|
|
34
|
-
}
|
|
35
|
-
debug(message, ...args) {
|
|
36
|
-
if (this.level <= LogLevel.DEBUG) {
|
|
37
|
-
this.logSystem.debug(message, ...args);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
info(message, ...args) {
|
|
41
|
-
if (this.level <= LogLevel.INFO) {
|
|
42
|
-
this.logSystem.info(message, ...args);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
warn(message, ...args) {
|
|
46
|
-
if (this.level <= LogLevel.WARN) {
|
|
47
|
-
this.logSystem.warn(message, ...args);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
error(message, ...args) {
|
|
51
|
-
if (this.level <= LogLevel.ERROR) {
|
|
52
|
-
this.logSystem.error(message, ...args);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
// Create default logger instance
|
|
57
|
-
export const logger = new Logger();
|
|
58
|
-
//# sourceMappingURL=logger.js.map
|
package/dist/web/logger.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names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