@le-space/orbitdb-storage-bridge 0.27.2 → 0.28.0
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/README.md +3 -2
- package/lib/backends/aleph-pin.js +61 -0
- package/lib/backends/aleph.js +35 -9
- package/lib/live-backup.js +213 -4
- package/lib/peer-fetch.js +30 -15
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ entry is the Storacha-era class and the helpers it grew.
|
|
|
56
56
|
| `/restore-cid` | `restoreFromCID`, `restoreFromBlocks`: a database back from a CID, or from blocks verified one by one |
|
|
57
57
|
| `/extract-blocks` | `extractDatabaseBlocks`, `bundleDatabases`: one database's blocks, or several databases' in one bundle |
|
|
58
58
|
| `/app-backup` | one sealed file for an application: `buildAppBackup`, `openAppBackup`, `restoreAppBackup`, `readAppBackupHeader`, `isAppBackup` |
|
|
59
|
-
| `/live-backup` | increments: `createLiveBackup`, `collectIncrement`, `readIncrement`, `mergeIncrements`, `restoreFromIncrements`, `joinIncrements` |
|
|
59
|
+
| `/live-backup` | increments: `createLiveBackup`, `collectIncrement`, `readIncrement`, `mergeIncrements`, `restoreFromIncrements`, `joinIncrements`, and `advanceConfirmation` / `reconcileConfirmation` for a store that refuses later |
|
|
60
60
|
| `/dehydrate` | `dehydrate`, `hydrate`: a database where a second device finds it from a secret alone |
|
|
61
61
|
| `/pointer-ipns` | `publishPointer`, `resolvePointer`: the IPNS pointer `dehydrate` publishes, under a name derived from a seed |
|
|
62
62
|
| `/gateway-fetch` | `fetchFromGateways`: bytes by CID over HTTP, verified against the CID |
|
|
@@ -66,7 +66,7 @@ entry is the Storacha-era class and the helpers it grew.
|
|
|
66
66
|
| `/backends/types` | the contract: `defineBackend`, `BackendError`, the capability flags |
|
|
67
67
|
| `/backends/memory` | the in-process driver |
|
|
68
68
|
| `/backends/aleph` | `createAlephBackend`: ingest to Aleph – its IPFS host, else an API node – with no key, or with `aleph-pin`'s pin to keep in the same call; `onProgress` for the upload |
|
|
69
|
-
| `/backends/aleph-pin` | `createAlephPin`, `createAlephAuthorizer`, `listAlephStores`, `waitForMessage`, `createAlephForget`, `forgetAlephStores`: what makes Aleph keep a file, and lets it go |
|
|
69
|
+
| `/backends/aleph-pin` | `createAlephPin`, `createAlephAuthorizer`, `listAlephStores`, `waitForMessage`, `messageStatus`, `alephCredits`, `createAlephForget`, `forgetAlephStores`: what makes Aleph keep a file, and lets it go |
|
|
70
70
|
| `/backends/aleph-upload` | `unixfsCid`: the CID Aleph gives a file, before the upload; `postFile`, the limits and the upload errors |
|
|
71
71
|
| `/backends/pinata` | Pinata: pin by CID or upload, with a scoped JWT; `remove()` by file id |
|
|
72
72
|
| `/backends/lighthouse` | Lighthouse: upload with an API key; `list()` and `remove()` |
|
|
@@ -130,6 +130,7 @@ Galaxy A57 with the same key brought the database back and wrote to it. Source:
|
|
|
130
130
|
| [docs/APP-BACKUP.md](docs/APP-BACKUP.md) | an application's backup in one sealed file: several databases, a keyring header, kept on Aleph from the browser, restored by merging |
|
|
131
131
|
| [docs/LIVE-BACKUP.md](docs/LIVE-BACKUP.md) | increments between two full backups: what was written since the last one, shipped as one small CAR, with nobody clicking and no peer online |
|
|
132
132
|
| [SVELTE-COMPONENTS.md](SVELTE-COMPONENTS.md) | the browser components — older than this repository's copy of them; [docs/STORACHA-UI-HISTORY.md](docs/STORACHA-UI-HISTORY.md) records what each piece could do and where it went |
|
|
133
|
+
| [docs/POST-QUANTUM.md](docs/POST-QUANTUM.md) | what a quantum computer would and would not break: the encryption holds, the signatures do not, and the restore is gated on the AEAD rather than on a signature |
|
|
133
134
|
| [docs/LOGGING.md](docs/LOGGING.md) | debug namespaces, in Node and in a browser |
|
|
134
135
|
| [ROADMAP.md](ROADMAP.md) | what is planned |
|
|
135
136
|
| [docs/STORACHA-SUNSET.md](docs/STORACHA-SUNSET.md) | why Storacha stopped being the default, with dates and evidence |
|
|
@@ -350,6 +350,67 @@ export async function waitForMessage(itemHash, options = {}) {
|
|
|
350
350
|
return { itemHash, status, timedOut: true };
|
|
351
351
|
}
|
|
352
352
|
|
|
353
|
+
/**
|
|
354
|
+
* What Aleph says about a message now, asked once: `processed`, `pending`,
|
|
355
|
+
* `rejected`, `removing`, `removed`, `forgotten` – or `unknown` when it does
|
|
356
|
+
* not know the message at all (a request that never arrived, or was dropped
|
|
357
|
+
* before it was checked). `waitForMessage` follows a pending one; this is for
|
|
358
|
+
* coming back later, e.g. to an increment that was still pending when its
|
|
359
|
+
* flush ended (`createLiveBackup().reconcile`).
|
|
360
|
+
*
|
|
361
|
+
* @param {string} itemHash
|
|
362
|
+
* @param {object} [options]
|
|
363
|
+
* @param {string} [options.apiHost]
|
|
364
|
+
* @param {typeof fetch} [options.fetch]
|
|
365
|
+
* @returns {Promise<{ itemHash: string, status: string, errorCode?: number, details?: unknown }>}
|
|
366
|
+
* @throws when Aleph does not answer (anything but 200 or 404)
|
|
367
|
+
*/
|
|
368
|
+
export async function messageStatus(itemHash, options = {}) {
|
|
369
|
+
const apiHost = options.apiHost || DEFAULT_ALEPH_API_HOST;
|
|
370
|
+
const doFetch = options.fetch || globalThis.fetch;
|
|
371
|
+
if (!itemHash)
|
|
372
|
+
throw new BackendError(
|
|
373
|
+
"INVALID_BACKEND",
|
|
374
|
+
"messageStatus needs the message's item hash",
|
|
375
|
+
);
|
|
376
|
+
const response = await doFetch(
|
|
377
|
+
`${apiHost}/api/v0/messages/${encodeURIComponent(itemHash)}`,
|
|
378
|
+
);
|
|
379
|
+
if (response.status === 404) return { itemHash, status: "unknown" };
|
|
380
|
+
if (!response.ok)
|
|
381
|
+
throw new BackendError(
|
|
382
|
+
"UNSUPPORTED",
|
|
383
|
+
`Aleph did not answer: ${response.status}`,
|
|
384
|
+
);
|
|
385
|
+
const body = await response.json().catch(() => ({}));
|
|
386
|
+
return {
|
|
387
|
+
itemHash,
|
|
388
|
+
status: typeof body?.status === "string" ? body.status : "unknown",
|
|
389
|
+
...(body?.error_code != null ? { errorCode: body.error_code } : {}),
|
|
390
|
+
...(body?.details != null ? { details: body.details } : {}),
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* An account's credits, or null when Aleph does not say.
|
|
396
|
+
*
|
|
397
|
+
* @param {string} address - EIP-55 checksummed (Aleph keys accounts by that form)
|
|
398
|
+
* @param {object} [options]
|
|
399
|
+
* @param {string} [options.apiHost]
|
|
400
|
+
* @param {typeof fetch} [options.fetch]
|
|
401
|
+
* @returns {Promise<number|null>}
|
|
402
|
+
*/
|
|
403
|
+
export async function alephCredits(address, options = {}) {
|
|
404
|
+
const apiHost = options.apiHost || DEFAULT_ALEPH_API_HOST;
|
|
405
|
+
const doFetch = options.fetch || globalThis.fetch;
|
|
406
|
+
const response = await doFetch(
|
|
407
|
+
`${apiHost}/api/v0/addresses/${address}/balance`,
|
|
408
|
+
).catch(() => null);
|
|
409
|
+
if (!response?.ok) return null;
|
|
410
|
+
const body = await response.json().catch(() => ({}));
|
|
411
|
+
return Number.isFinite(body?.credit_balance) ? body.credit_balance : null;
|
|
412
|
+
}
|
|
413
|
+
|
|
353
414
|
/**
|
|
354
415
|
* The STORE messages kept for an account, newest first: its own, and those a
|
|
355
416
|
* delegate sent for it.
|
package/lib/backends/aleph.js
CHANGED
|
@@ -38,6 +38,27 @@
|
|
|
38
38
|
* being ingest-only. `./aleph-pin.js` is that implementation: `createAlephPin`
|
|
39
39
|
* builds and signs the STORE, and is what a caller passes as `pin`.
|
|
40
40
|
*
|
|
41
|
+
* ## Upload and STORE in one call, when the pin can sign
|
|
42
|
+
*
|
|
43
|
+
* Ingest first and a STORE afterwards is two steps with a gap between them:
|
|
44
|
+
* the STORE names a CID that Aleph's nodes (CCNs) must then fetch from the
|
|
45
|
+
* IPFS host, which holds the upload unpinned. Since about 2026-11-04 that
|
|
46
|
+
* fetch fails — Belege's backups were rejected with `error_code` 4, "File not
|
|
47
|
+
* found: <cid> (could not retrieve IPFS content at this time)", and the host
|
|
48
|
+
* dropped the file later (gateway 504). Measured again on 2026-11-11 with a
|
|
49
|
+
* throwaway account: `/api/v0/add` on the IPFS host answers 200 again, the
|
|
50
|
+
* file is on the gateway, the API node's `/storage/raw/<cid>` does not have
|
|
51
|
+
* it, and the separate STORE stays `pending` for many minutes.
|
|
52
|
+
*
|
|
53
|
+
* So a `pin` with `sign` (`createAlephPin`) now sends every upload to the API
|
|
54
|
+
* node's `add_file` with the signed STORE beside the file: the node pins it
|
|
55
|
+
* itself and answers with the message's status, nothing has to be fetched
|
|
56
|
+
* from anywhere. The ingest host is used only without a signing pin, where
|
|
57
|
+
* nothing would keep the file anyway. `pinCid` (a STORE for a CID already
|
|
58
|
+
* elsewhere) still exists and still depends on the CCNs finding the file;
|
|
59
|
+
* follow its item hash with `waitForMessage` and treat `error_code` 4 as
|
|
60
|
+
* "upload it again, signed".
|
|
61
|
+
*
|
|
41
62
|
* @author @NiKrause
|
|
42
63
|
* @requires ./types.js - the backend contract
|
|
43
64
|
*/
|
|
@@ -71,10 +92,11 @@ export const ALEPH_GATEWAYS = Object.freeze(["https://ipfs.aleph.cloud/ipfs"]);
|
|
|
71
92
|
|
|
72
93
|
const ALEPH_INGEST = "https://ipfs.aleph.cloud/api/v0/add";
|
|
73
94
|
/**
|
|
74
|
-
* Where an upload goes when the IPFS host takes none
|
|
75
|
-
* `/api/v0/ipfs/add_file`.
|
|
76
|
-
* IPFS hosts
|
|
77
|
-
* take a file, with the limits
|
|
95
|
+
* Where an upload goes when the IPFS host takes none, and always when the pin
|
|
96
|
+
* can sign: an API node's `/api/v0/ipfs/add_file`. From 2026-10-26 every
|
|
97
|
+
* `/api/v0/` call on Aleph's IPFS hosts answered 404 (on 2026-11-11 `add`
|
|
98
|
+
* answered 200 again); the API nodes take a file, with the limits
|
|
99
|
+
* `./aleph-upload.js` names.
|
|
78
100
|
*/
|
|
79
101
|
export const DEFAULT_ALEPH_API_HOST = "https://api2.aleph.im";
|
|
80
102
|
const DEFAULT_TIMEOUT_MS = 120_000;
|
|
@@ -201,10 +223,15 @@ export function createAlephBackend(options = {}) {
|
|
|
201
223
|
...(meta.name ? { name: meta.name } : {}),
|
|
202
224
|
};
|
|
203
225
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
//
|
|
207
|
-
|
|
226
|
+
const signed = typeof pin?.sign === "function";
|
|
227
|
+
|
|
228
|
+
// The IPFS host first, while it answers at all and no STORE can go
|
|
229
|
+
// beside the file: an upload there is free of any limit below 1 GiB and
|
|
230
|
+
// needs no message. A 404 or 405 says it takes none, and is remembered
|
|
231
|
+
// for this backend's lifetime. With a pin that signs it is skipped: a
|
|
232
|
+
// STORE sent after it, separately, has to fetch the file back from that
|
|
233
|
+
// host, and since 2026-11-04 that fails (see the header).
|
|
234
|
+
if (ingestUrl && !ingestGone && !signed) {
|
|
208
235
|
try {
|
|
209
236
|
const id = await viaIngest({ bytes, name, contentType, onProgress });
|
|
210
237
|
// Said out loud in the handle, because "stored" and "kept" are not
|
|
@@ -221,7 +248,6 @@ export function createAlephBackend(options = {}) {
|
|
|
221
248
|
// The API node. With a signed STORE message beside the file the node
|
|
222
249
|
// keeps it in the same call; without one it takes at most 25 MiB and
|
|
223
250
|
// keeps it for a day, until a STORE names it.
|
|
224
|
-
const signed = typeof pin?.sign === "function";
|
|
225
251
|
// The node measures the request body, the form around the file included.
|
|
226
252
|
const limit =
|
|
227
253
|
(signed ? ALEPH_API_SIGNED_LIMIT : ALEPH_API_UNSIGNED_LIMIT) -
|
package/lib/live-backup.js
CHANGED
|
@@ -46,6 +46,19 @@
|
|
|
46
46
|
* says how many updates are waiting, when the last increment went out and
|
|
47
47
|
* what the last failure was, so an application can show "last backed up …".
|
|
48
48
|
*
|
|
49
|
+
* ## A store that answers "pending" and refuses later
|
|
50
|
+
*
|
|
51
|
+
* Aleph takes a STORE with "pending" and may reject it minutes later – a file
|
|
52
|
+
* its nodes could not fetch, credit that ran out. An increment shipped under
|
|
53
|
+
* such an answer has moved the chain on, and nothing would ship its content
|
|
54
|
+
* again. So the chain also remembers how far the store has *confirmed* it
|
|
55
|
+
* (`kept`) and the increments shipped since (`unconfirmed`); `reconcile()`
|
|
56
|
+
* asks about those again and, when one turns out refused or unknown, goes
|
|
57
|
+
* back to `kept`: the next flush ships everything since, under the next
|
|
58
|
+
* number after the last one kept, so a restore finds no gap. The bookkeeping
|
|
59
|
+
* is `advanceConfirmation` / `reconcileConfirmation`, exported for an
|
|
60
|
+
* application that keeps its own chain state.
|
|
61
|
+
*
|
|
49
62
|
* @requires ./backup-car.js - createCARFromBlocks
|
|
50
63
|
* @requires ./restore-cid.js - readBlocksFromCAR, restoreFromBlocks
|
|
51
64
|
*/
|
|
@@ -56,7 +69,12 @@ import { CID } from "multiformats/cid";
|
|
|
56
69
|
import { sha256 } from "multiformats/hashes/sha2";
|
|
57
70
|
import { base58btc } from "multiformats/bases/base58";
|
|
58
71
|
import { createCARFromBlocks } from "./backup-car.js";
|
|
59
|
-
import {
|
|
72
|
+
import {
|
|
73
|
+
readBlocksFromCAR,
|
|
74
|
+
restoreFromBlocks,
|
|
75
|
+
entryDatabaseId,
|
|
76
|
+
standalone,
|
|
77
|
+
} from "./restore-cid.js";
|
|
60
78
|
|
|
61
79
|
/** What the manifest at an increment's root calls itself. */
|
|
62
80
|
export const INCREMENT_KIND = "increment";
|
|
@@ -76,6 +94,10 @@ const DAG_CBOR = dagCbor.code;
|
|
|
76
94
|
* @property {string|null} base - the full backup the increments build on, as the caller named it
|
|
77
95
|
* @property {string|null} previous - the backend's id of the last increment
|
|
78
96
|
* @property {Object<string, { heads: string[] }>} databases - by address: the heads last shipped
|
|
97
|
+
* @property {{ sequence: number, previous: string|null, databases: object }|null} [kept] - the last
|
|
98
|
+
* point the store confirmed; null before any
|
|
99
|
+
* @property {Array<{ sequence: number, previous: string|null, databases: object, cid: string }>} [unconfirmed] -
|
|
100
|
+
* increments shipped since that the store has not confirmed, oldest first
|
|
79
101
|
*/
|
|
80
102
|
|
|
81
103
|
/**
|
|
@@ -517,7 +539,10 @@ export async function joinIncrements(
|
|
|
517
539
|
// OrbitDB names its blocks in base58btc; a CAR in base32. The log reads
|
|
518
540
|
// its own names, and identities are looked up by theirs, so each block
|
|
519
541
|
// goes in under the name its reader will ask for.
|
|
520
|
-
await database.log.storage.put(
|
|
542
|
+
await database.log.storage.put(
|
|
543
|
+
cid.toV1().toString(base58btc),
|
|
544
|
+
standalone(bytes),
|
|
545
|
+
);
|
|
521
546
|
}
|
|
522
547
|
|
|
523
548
|
let joined = 0;
|
|
@@ -538,6 +563,95 @@ export async function joinIncrements(
|
|
|
538
563
|
};
|
|
539
564
|
}
|
|
540
565
|
|
|
566
|
+
/** Statuses that mean the store does not keep a blob. */
|
|
567
|
+
export const NOT_KEPT = Object.freeze(["rejected", "unknown", "forgotten"]);
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* How far a store has confirmed a chain, and what was shipped since.
|
|
571
|
+
*
|
|
572
|
+
* A *point* is whatever the caller needs to go back to – `sequence`,
|
|
573
|
+
* `previous` and its own fields (the heads shipped by then, a count of
|
|
574
|
+
* files, …). It is kept as given, never read here beyond `sequence`.
|
|
575
|
+
*
|
|
576
|
+
* @typedef {object} Confirmation
|
|
577
|
+
* @property {object|null} kept - the last point the store confirmed
|
|
578
|
+
* @property {Array<object & { cid: string }>} pending - points shipped since, oldest first
|
|
579
|
+
*/
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* The confirmation after an increment was shipped.
|
|
583
|
+
*
|
|
584
|
+
* `processed` with nothing open before it moves `kept` to this point; any
|
|
585
|
+
* other answer puts the point aside as pending, with the blob's id to ask
|
|
586
|
+
* about later.
|
|
587
|
+
*
|
|
588
|
+
* @param {Confirmation|null|undefined} confirmation
|
|
589
|
+
* @param {object} point - where the chain stands with this increment
|
|
590
|
+
* @param {string} cid - the increment's id in the store
|
|
591
|
+
* @param {string} [status="processed"] - the store's answer
|
|
592
|
+
* @returns {Confirmation}
|
|
593
|
+
*/
|
|
594
|
+
export function advanceConfirmation(
|
|
595
|
+
confirmation,
|
|
596
|
+
point,
|
|
597
|
+
cid,
|
|
598
|
+
status = "processed",
|
|
599
|
+
) {
|
|
600
|
+
const pending = confirmation?.pending ?? [];
|
|
601
|
+
if (status === "processed" && pending.length === 0) {
|
|
602
|
+
return { kept: point, pending: [] };
|
|
603
|
+
}
|
|
604
|
+
return {
|
|
605
|
+
kept: confirmation?.kept ?? null,
|
|
606
|
+
pending: [...pending, { ...point, cid }],
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* The confirmation by what the store says now.
|
|
612
|
+
*
|
|
613
|
+
* Walks the pending points oldest first: a `processed` one moves `kept` on; a
|
|
614
|
+
* refused, unknown or forgotten one ends it – everything pending is dropped
|
|
615
|
+
* and `rewind` is the point to go back to (`null`: before anything was
|
|
616
|
+
* confirmed, the caller's own start). A point the store has not decided on
|
|
617
|
+
* stops the walk. `gap` says an increment *after* a refused one is kept: a
|
|
618
|
+
* restore cannot cross that, and only a new full backup mends it.
|
|
619
|
+
*
|
|
620
|
+
* @param {Confirmation} confirmation
|
|
621
|
+
* @param {(cid: string) => string|undefined} statusOf - the store's word on a blob, if known
|
|
622
|
+
* @returns {{ kept: object|null, pending: object[], changed: boolean, rewound: boolean, rewind: object|null, gap: boolean }}
|
|
623
|
+
*/
|
|
624
|
+
export function reconcileConfirmation(confirmation, statusOf) {
|
|
625
|
+
let kept = confirmation?.kept ?? null;
|
|
626
|
+
const pending = [...(confirmation?.pending ?? [])];
|
|
627
|
+
let changed = false;
|
|
628
|
+
while (pending.length) {
|
|
629
|
+
const status = statusOf(pending[0].cid);
|
|
630
|
+
if (status === "processed") {
|
|
631
|
+
const point = { ...pending.shift() };
|
|
632
|
+
delete point.cid;
|
|
633
|
+
kept = point;
|
|
634
|
+
changed = true;
|
|
635
|
+
continue;
|
|
636
|
+
}
|
|
637
|
+
if (status && NOT_KEPT.includes(status)) {
|
|
638
|
+
const gap = pending
|
|
639
|
+
.slice(1)
|
|
640
|
+
.some((point) => statusOf(point.cid) === "processed");
|
|
641
|
+
return {
|
|
642
|
+
kept,
|
|
643
|
+
pending: [],
|
|
644
|
+
changed: true,
|
|
645
|
+
rewound: true,
|
|
646
|
+
rewind: kept,
|
|
647
|
+
gap,
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
break;
|
|
651
|
+
}
|
|
652
|
+
return { kept, pending, changed, rewound: false, rewind: null, gap: false };
|
|
653
|
+
}
|
|
654
|
+
|
|
541
655
|
/** A state with nothing shipped yet. */
|
|
542
656
|
export const emptyLiveBackupState = () => ({
|
|
543
657
|
v: LIVE_BACKUP_STATE_VERSION,
|
|
@@ -545,6 +659,8 @@ export const emptyLiveBackupState = () => ({
|
|
|
545
659
|
base: null,
|
|
546
660
|
previous: null,
|
|
547
661
|
databases: {},
|
|
662
|
+
kept: null,
|
|
663
|
+
unconfirmed: [],
|
|
548
664
|
});
|
|
549
665
|
|
|
550
666
|
/**
|
|
@@ -576,7 +692,7 @@ export const emptyLiveBackupState = () => ({
|
|
|
576
692
|
* flush and the state stays, so the next one ships it all again.
|
|
577
693
|
* @param {() => Date} [params.now]
|
|
578
694
|
* @returns {{ watch: Function, unwatch: Function, start: Function, stop: Function, close: Function,
|
|
579
|
-
* flush: () => Promise<object|null>, rebase: Function, status: () => object }}
|
|
695
|
+
* flush: () => Promise<object|null>, rebase: Function, reconcile: Function, status: () => object }}
|
|
580
696
|
*/
|
|
581
697
|
export function createLiveBackup({
|
|
582
698
|
databases,
|
|
@@ -754,6 +870,20 @@ export function createLiveBackup({
|
|
|
754
870
|
w.shipped.heads = heads;
|
|
755
871
|
state.databases[address] = { heads };
|
|
756
872
|
}
|
|
873
|
+
// How far the store has confirmed the chain: a pending answer is put
|
|
874
|
+
// aside, so `reconcile()` can go back if it is refused later.
|
|
875
|
+
const confirmation = advanceConfirmation(
|
|
876
|
+
{ kept: state.kept, pending: state.unconfirmed },
|
|
877
|
+
{
|
|
878
|
+
sequence: state.sequence,
|
|
879
|
+
previous: state.previous,
|
|
880
|
+
databases: JSON.parse(JSON.stringify(state.databases)),
|
|
881
|
+
},
|
|
882
|
+
state.previous,
|
|
883
|
+
kept?.status ?? "processed",
|
|
884
|
+
);
|
|
885
|
+
state.kept = confirmation.kept;
|
|
886
|
+
state.unconfirmed = confirmation.pending;
|
|
757
887
|
pending = Math.max(0, pending - countedPending);
|
|
758
888
|
await save();
|
|
759
889
|
|
|
@@ -819,10 +949,77 @@ export function createLiveBackup({
|
|
|
819
949
|
w.shipped.heads = heads;
|
|
820
950
|
state.databases[address] = { heads };
|
|
821
951
|
}
|
|
952
|
+
// A full backup is where the chain is kept from.
|
|
953
|
+
if (base !== undefined) {
|
|
954
|
+
state.kept = {
|
|
955
|
+
sequence: 0,
|
|
956
|
+
previous: null,
|
|
957
|
+
databases: JSON.parse(JSON.stringify(state.databases)),
|
|
958
|
+
};
|
|
959
|
+
state.unconfirmed = [];
|
|
960
|
+
}
|
|
822
961
|
pending = 0;
|
|
823
962
|
await save();
|
|
824
963
|
};
|
|
825
964
|
|
|
965
|
+
/**
|
|
966
|
+
* Ask the store again about the increments it had not confirmed, and go
|
|
967
|
+
* back to the last confirmed point when one was refused.
|
|
968
|
+
*
|
|
969
|
+
* @param {(cid: string, point: object) => Promise<string|undefined>|string|undefined} statusOf -
|
|
970
|
+
* the store's word on an increment by its id: `processed`, `pending`,
|
|
971
|
+
* `rejected`, `unknown`, `forgotten` (for Aleph: `messageStatus` on the
|
|
972
|
+
* STORE's item hash, which the caller kept from `onShipped`)
|
|
973
|
+
* @returns {Promise<{ changed: boolean, rewound: boolean, gap: boolean, sequence: number }>}
|
|
974
|
+
* `gap`: an increment after a refused one is kept – make a full backup and `rebase({ base })`
|
|
975
|
+
*/
|
|
976
|
+
const reconcile = async (statusOf) => {
|
|
977
|
+
if (inflight) await inflight.catch(() => {});
|
|
978
|
+
await load();
|
|
979
|
+
const answers = new Map();
|
|
980
|
+
for (const point of state.unconfirmed ?? []) {
|
|
981
|
+
answers.set(point.cid, await statusOf(point.cid, point));
|
|
982
|
+
}
|
|
983
|
+
const now_ = reconcileConfirmation(
|
|
984
|
+
{ kept: state.kept ?? null, pending: state.unconfirmed ?? [] },
|
|
985
|
+
(cid) => answers.get(cid),
|
|
986
|
+
);
|
|
987
|
+
if (!now_.changed)
|
|
988
|
+
return {
|
|
989
|
+
changed: false,
|
|
990
|
+
rewound: false,
|
|
991
|
+
gap: false,
|
|
992
|
+
sequence: state.sequence,
|
|
993
|
+
};
|
|
994
|
+
state.kept = now_.kept;
|
|
995
|
+
state.unconfirmed = now_.pending;
|
|
996
|
+
if (now_.rewound) {
|
|
997
|
+
const back = now_.rewind ?? {
|
|
998
|
+
sequence: 0,
|
|
999
|
+
previous: null,
|
|
1000
|
+
databases: {},
|
|
1001
|
+
};
|
|
1002
|
+
state.sequence = back.sequence;
|
|
1003
|
+
state.previous = back.previous;
|
|
1004
|
+
state.databases = JSON.parse(JSON.stringify(back.databases ?? {}));
|
|
1005
|
+
for (const [address, w] of watched) {
|
|
1006
|
+
const heads = state.databases[address]?.heads ?? [];
|
|
1007
|
+
w.shipped = await reachable(w.database, heads);
|
|
1008
|
+
w.shipped.heads = heads;
|
|
1009
|
+
}
|
|
1010
|
+
// Nothing announces what has to go again: count it, so a flush ships it.
|
|
1011
|
+
pending = Math.max(pending, 1);
|
|
1012
|
+
if (running && (after || every)) scheduleFlush();
|
|
1013
|
+
}
|
|
1014
|
+
await save();
|
|
1015
|
+
return {
|
|
1016
|
+
changed: true,
|
|
1017
|
+
rewound: now_.rewound,
|
|
1018
|
+
gap: now_.gap,
|
|
1019
|
+
sequence: state.sequence,
|
|
1020
|
+
};
|
|
1021
|
+
};
|
|
1022
|
+
|
|
826
1023
|
const start = async () => {
|
|
827
1024
|
if (running) return;
|
|
828
1025
|
running = true;
|
|
@@ -853,13 +1050,25 @@ export function createLiveBackup({
|
|
|
853
1050
|
base: state.base,
|
|
854
1051
|
previous: state.previous,
|
|
855
1052
|
pending,
|
|
1053
|
+
unconfirmed: (state.unconfirmed ?? []).length,
|
|
1054
|
+
keptSequence: state.kept?.sequence ?? null,
|
|
856
1055
|
watched: watched.size,
|
|
857
1056
|
lastShipped,
|
|
858
1057
|
lastError,
|
|
859
1058
|
failures,
|
|
860
1059
|
});
|
|
861
1060
|
|
|
862
|
-
return {
|
|
1061
|
+
return {
|
|
1062
|
+
watch,
|
|
1063
|
+
unwatch,
|
|
1064
|
+
start,
|
|
1065
|
+
stop,
|
|
1066
|
+
close,
|
|
1067
|
+
flush,
|
|
1068
|
+
rebase,
|
|
1069
|
+
reconcile,
|
|
1070
|
+
status,
|
|
1071
|
+
};
|
|
863
1072
|
}
|
|
864
1073
|
|
|
865
1074
|
export default createLiveBackup;
|
package/lib/peer-fetch.js
CHANGED
|
@@ -99,27 +99,42 @@ export const PINATA_BITSWAP =
|
|
|
99
99
|
* whatever address this constant holds. See `offNetworkRisk` in the
|
|
100
100
|
* webrtc-qr package for how differently browsers report that.
|
|
101
101
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* `
|
|
106
|
-
*
|
|
102
|
+
* - **There is more than one node, and the routing names one at a time.**
|
|
103
|
+
* On 2026-11-11 it answered `12D3KooWACE5…` again, for six fresh blobs in a
|
|
104
|
+
* row — now over IPv4 (`46.255.204.211`), with a `/dns4/…libp2p.direct`
|
|
105
|
+
* name — while `12D3KooWJBw9…` (IPv6 only) was what it said two weeks
|
|
106
|
+
* earlier. So this constant holds both, the one the routing names now
|
|
107
|
+
* first; a dial to the other costs a failed attempt, not a wrong answer.
|
|
108
|
+
*
|
|
109
|
+
* The `/dns4/` and `/dns6/…libp2p.direct/tcp/4001/tls/ws` addresses carry no
|
|
110
|
+
* certificate hash and so do not rot when a node restarts; the
|
|
111
|
+
* `webrtc-direct` ones do. `test/peer-fetch-live.test.js` checks, every day in
|
|
112
|
+
* the live smoke test, that the routing names one of {@link ALEPH_PEER_IDS},
|
|
113
|
+
* which is how this gets noticed next time rather than in a demo six weeks
|
|
114
|
+
* later.
|
|
107
115
|
*/
|
|
116
|
+
const ACE5 = "12D3KooWACE5dRw5V9WXuDTcngjE3ZaDSZ4qYJGfuhXZbENnL54y";
|
|
117
|
+
const JBW9 = "12D3KooWJBw9CSUWQi7P7amZsjrsBAzoB2gJzyUUGkuBkdLc87co";
|
|
118
|
+
|
|
108
119
|
export const ALEPH_BITSWAP = Object.freeze([
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
120
|
+
// What the routing announced on 2026-11-11.
|
|
121
|
+
`/dns4/46-255-204-211.k51qzi5uqu5dgbm3weyum8p0k8k4a97eea0fkepym4bhy1g862d5av7yezl2fy.libp2p.direct/tcp/4001/tls/ws/p2p/${ACE5}`,
|
|
122
|
+
`/ip4/46.255.204.211/udp/4001/webrtc-direct/certhash/uEiCbM9yMfnP02vviIL26n8bI0-vU0DGUHx20POBLKGjEmg/p2p/${ACE5}`,
|
|
123
|
+
// What it announced on 2026-10-29.
|
|
124
|
+
`/dns6/2a01-240-ad00-0-a81e-30ff-fe24-e1c8.k51qzi5uqu5dja77dpum225l7jiqrxsfjg2cflzyewf8ixq3r7dmcku10s6l5o.libp2p.direct/tcp/4001/tls/ws/p2p/${JBW9}`,
|
|
125
|
+
`/dns6/2a01-240-ad00-2-a81e-30ff-fe24-e1c8.k51qzi5uqu5dja77dpum225l7jiqrxsfjg2cflzyewf8ixq3r7dmcku10s6l5o.libp2p.direct/tcp/4001/tls/ws/p2p/${JBW9}`,
|
|
126
|
+
`/ip6/2a01:240:ad00:0:a81e:30ff:fe24:e1c8/udp/4001/webrtc-direct/certhash/uEiBshqkW727Q236d7ivxBGMuc0E9Tsj3FZJMKJJgDuP4Lg/p2p/${JBW9}`,
|
|
127
|
+
`/ip6/2a01:240:ad00:2:a81e:30ff:fe24:e1c8/udp/4001/webrtc-direct/certhash/uEiBshqkW727Q236d7ivxBGMuc0E9Tsj3FZJMKJJgDuP4Lg/p2p/${JBW9}`,
|
|
113
128
|
]);
|
|
114
129
|
|
|
115
130
|
/**
|
|
116
|
-
* Aleph's peer
|
|
117
|
-
*
|
|
118
|
-
* Not the stable part: it changed once already, which is what made every
|
|
119
|
-
* address above dead until this commit.
|
|
131
|
+
* Aleph's peer ids, the one the routing named most recently (2026-11-11)
|
|
132
|
+
* first. Not the stable part: the routing has switched between them.
|
|
120
133
|
*/
|
|
121
|
-
export const
|
|
122
|
-
|
|
134
|
+
export const ALEPH_PEER_IDS = Object.freeze([ACE5, JBW9]);
|
|
135
|
+
|
|
136
|
+
/** The first of {@link ALEPH_PEER_IDS}: the node the routing named last. */
|
|
137
|
+
export const ALEPH_PEER_ID = ACE5;
|
|
123
138
|
|
|
124
139
|
/**
|
|
125
140
|
* Routers that answer a page.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@le-space/orbitdb-storage-bridge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"description": "Back up, restore and replicate OrbitDB databases through pluggable storage backends, with hash and identity preservation",
|
|
5
5
|
"main": "lib/orbitdb-storacha-bridge.js",
|
|
6
6
|
"type": "module",
|
|
@@ -119,6 +119,8 @@
|
|
|
119
119
|
"@jest/globals": "^30.5.1",
|
|
120
120
|
"@le-space/ucanto-principal": "^9.1.1",
|
|
121
121
|
"@libp2p/websockets": "^10.1.17",
|
|
122
|
+
"@noble/curves": "^1.9.7",
|
|
123
|
+
"@noble/hashes": "^1.8.0",
|
|
122
124
|
"@orbitdb/identity-provider-did": "^1.0.2",
|
|
123
125
|
"@storacha/capabilities": "^2.0.0",
|
|
124
126
|
"@storacha/client": "^2.0.0",
|