@needmoretruth/nmts-cli 0.45.0 → 0.47.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/AGENTS.md +8 -8
- package/CHANGELOG.md +78 -0
- package/README.ko.md +6 -3
- package/README.md +31 -11
- package/dist/api-advice.js +17 -2
- package/dist/api.d.ts +22 -0
- package/dist/api.js +49 -1
- package/dist/arg-options.d.ts +19 -1
- package/dist/args.js +14 -2
- package/dist/artifact-about.d.ts +1 -1
- package/dist/autonomy.js +3 -3
- package/dist/collision.d.ts +20 -3
- package/dist/collision.js +21 -3
- package/dist/commands/erase.js +1 -0
- package/dist/commands/handover.d.ts +15 -0
- package/dist/commands/handover.js +376 -0
- package/dist/commands/heavy-run.d.ts +59 -0
- package/dist/commands/heavy-run.js +247 -0
- package/dist/commands/heavy.d.ts +7 -0
- package/dist/commands/heavy.js +123 -0
- package/dist/commands/link.d.ts +12 -0
- package/dist/commands/link.js +121 -0
- package/dist/commands/ls.d.ts +5 -0
- package/dist/commands/ls.js +9 -1
- package/dist/commands/public-code-manage.d.ts +24 -0
- package/dist/commands/public-code-manage.js +217 -0
- package/dist/commands/public-code.d.ts +12 -1
- package/dist/commands/public-code.js +140 -45
- package/dist/commands/push-heavy.d.ts +6 -0
- package/dist/commands/push-heavy.js +128 -0
- package/dist/commands/push-tree.d.ts +24 -0
- package/dist/commands/push-tree.js +91 -0
- package/dist/commands/push.d.ts +4 -13
- package/dist/commands/push.js +7 -77
- package/dist/commands/put-heavy.d.ts +9 -0
- package/dist/commands/put-heavy.js +120 -0
- package/dist/commands/put-payer.d.ts +21 -0
- package/dist/commands/put-payer.js +24 -0
- package/dist/commands/put.d.ts +2 -2
- package/dist/commands/put.js +8 -7
- package/dist/commands/receive.js +14 -8
- package/dist/commands/s3.js +44 -10
- package/dist/commands/share-dispatch.js +14 -1
- package/dist/commands/share.d.ts +2 -0
- package/dist/commands/share.js +45 -35
- package/dist/commands/shares-sent.js +8 -3
- package/dist/crypto-surface.d.ts +35 -0
- package/dist/crypto-surface.js +13 -0
- package/dist/crypto.d.ts +8 -0
- package/dist/crypto.js +8 -0
- package/dist/download-part.d.ts +32 -1
- package/dist/download-part.js +95 -6
- package/dist/download-range.d.ts +19 -0
- package/dist/download-range.js +108 -0
- package/dist/download-sink.d.ts +15 -0
- package/dist/download.d.ts +14 -0
- package/dist/download.js +19 -4
- package/dist/handover-codes.d.ts +25 -0
- package/dist/handover-codes.js +106 -0
- package/dist/handover.d.ts +62 -0
- package/dist/handover.js +217 -0
- package/dist/heavy-api.d.ts +36 -0
- package/dist/heavy-api.js +107 -0
- package/dist/heavy-copy.d.ts +72 -0
- package/dist/heavy-copy.js +108 -0
- package/dist/heavy-evm.d.ts +20 -0
- package/dist/heavy-evm.js +106 -0
- package/dist/heavy-self-pay.d.ts +92 -0
- package/dist/heavy-self-pay.js +167 -0
- package/dist/heavy-upload.d.ts +87 -0
- package/dist/heavy-upload.js +154 -0
- package/dist/heavy-wallet-pay.d.ts +39 -0
- package/dist/heavy-wallet-pay.js +73 -0
- package/dist/help-options.js +13 -4
- package/dist/help.js +24 -3
- package/dist/links.d.ts +58 -0
- package/dist/links.js +206 -0
- package/dist/list-tier.d.ts +7 -0
- package/dist/list-tier.js +47 -0
- package/dist/main.js +13 -10
- package/dist/manifest-write.d.ts +4 -3
- package/dist/mcp-tools/reads.js +20 -6
- package/dist/mcp-tools/share.js +47 -1
- package/dist/mcp-tools/tiers.js +16 -1
- package/dist/platform-sign.d.ts +4 -4
- package/dist/platform-sign.js +3 -3
- package/dist/portable.d.ts +23 -0
- package/dist/portable.js +19 -0
- package/dist/product.d.ts +1 -1
- package/dist/product.js +1 -1
- package/dist/public-code-activity.d.ts +35 -0
- package/dist/public-code-activity.js +88 -0
- package/dist/public-code-refusals.d.ts +25 -0
- package/dist/public-code-refusals.js +87 -0
- package/dist/public-codes.d.ts +76 -0
- package/dist/public-codes.js +182 -0
- package/dist/recovery-build.js +16 -0
- package/dist/recovery-map-part.d.ts +82 -0
- package/dist/recovery-map-part.js +83 -0
- package/dist/recovery-map.d.ts +5 -40
- package/dist/recovery-map.js +18 -1
- package/dist/recovery-source.d.ts +3 -0
- package/dist/recovery-source.js +9 -0
- package/dist/risk.d.ts +55 -1
- package/dist/risk.js +55 -3
- package/dist/run-log.d.ts +1 -1
- package/dist/run-log.js +7 -1
- package/dist/s3/address.d.ts +20 -0
- package/dist/s3/address.js +97 -0
- package/dist/s3/answer.d.ts +48 -0
- package/dist/s3/answer.js +330 -0
- package/dist/s3/body-deframe.d.ts +49 -0
- package/dist/s3/body-deframe.js +264 -0
- package/dist/s3/body-measure.d.ts +13 -0
- package/dist/s3/body-measure.js +48 -0
- package/dist/s3/body-plan.d.ts +31 -0
- package/dist/s3/body-plan.js +159 -0
- package/dist/s3/body.d.ts +46 -0
- package/dist/s3/body.js +117 -0
- package/dist/s3/call.d.ts +36 -0
- package/dist/s3/call.js +42 -0
- package/dist/s3/checksum.d.ts +26 -0
- package/dist/s3/checksum.js +176 -0
- package/dist/s3/content-type.d.ts +3 -0
- package/dist/s3/content-type.js +49 -0
- package/dist/s3/contract.d.ts +91 -14
- package/dist/s3/drive-conditions.d.ts +47 -0
- package/dist/s3/drive-conditions.js +134 -0
- package/dist/s3/drive-key.d.ts +11 -0
- package/dist/s3/drive-key.js +58 -0
- package/dist/s3/drive-limits.d.ts +33 -0
- package/dist/s3/drive-limits.js +53 -0
- package/dist/s3/drive-lock.d.ts +11 -0
- package/dist/s3/drive-lock.js +47 -0
- package/dist/s3/drive-trashed-name.d.ts +13 -0
- package/dist/s3/drive-trashed-name.js +59 -0
- package/dist/s3/drive-write.d.ts +38 -0
- package/dist/s3/drive-write.js +258 -0
- package/dist/s3/drive.d.ts +59 -25
- package/dist/s3/drive.js +46 -77
- package/dist/s3/listing.d.ts +27 -1
- package/dist/s3/listing.js +62 -20
- package/dist/s3/long-answer.d.ts +12 -0
- package/dist/s3/long-answer.js +104 -0
- package/dist/s3/multipart-assemble.d.ts +17 -0
- package/dist/s3/multipart-assemble.js +68 -0
- package/dist/s3/multipart-sweep.d.ts +15 -0
- package/dist/s3/multipart-sweep.js +87 -0
- package/dist/s3/multipart-view.d.ts +45 -0
- package/dist/s3/multipart-view.js +232 -0
- package/dist/s3/multipart.d.ts +26 -19
- package/dist/s3/multipart.js +193 -78
- package/dist/s3/object-read.d.ts +17 -0
- package/dist/s3/object-read.js +127 -0
- package/dist/s3/object-write.d.ts +35 -0
- package/dist/s3/object-write.js +198 -0
- package/dist/s3/range.d.ts +14 -0
- package/dist/s3/range.js +80 -0
- package/dist/s3/response-sink.d.ts +12 -2
- package/dist/s3/response-sink.js +71 -7
- package/dist/s3/routes.d.ts +0 -1
- package/dist/s3/routes.js +242 -217
- package/dist/s3/same-file.d.ts +4 -1
- package/dist/s3/same-file.js +12 -3
- package/dist/s3/server.d.ts +54 -4
- package/dist/s3/server.js +174 -14
- package/dist/s3/sigv4-canonical.d.ts +91 -0
- package/dist/s3/sigv4-canonical.js +148 -0
- package/dist/s3/sigv4-presigned.d.ts +13 -0
- package/dist/s3/sigv4-presigned.js +82 -0
- package/dist/s3/sigv4.d.ts +26 -27
- package/dist/s3/sigv4.js +137 -102
- package/dist/s3/spool.d.ts +37 -0
- package/dist/s3/spool.js +104 -0
- package/dist/s3/staging.d.ts +90 -7
- package/dist/s3/staging.js +97 -66
- package/dist/s3/xml-multipart.d.ts +38 -0
- package/dist/s3/xml-multipart.js +47 -0
- package/dist/s3/xml-read.d.ts +28 -0
- package/dist/s3/xml-read.js +235 -0
- package/dist/s3/xml.d.ts +45 -2
- package/dist/s3/xml.js +72 -13
- package/dist/s3-gateway.d.ts +11 -5
- package/dist/s3-gateway.js +5 -2
- package/dist/seal.d.ts +1 -1
- package/dist/share-codes.d.ts +40 -0
- package/dist/share-codes.js +151 -0
- package/dist/share.d.ts +39 -0
- package/dist/share.js +54 -13
- package/dist/shared/lib/api/types-heavy.d.ts +167 -0
- package/dist/shared/lib/api/types-heavy.js +60 -0
- package/dist/shared/lib/drive/rebuild-verify.js +1 -0
- package/dist/shared/lib/filecoin/providers.d.ts +25 -0
- package/dist/shared/lib/filecoin/providers.js +58 -0
- package/dist/shared/lib/heavy/download.d.ts +48 -0
- package/dist/shared/lib/heavy/download.js +116 -0
- package/dist/shared/lib/heavy/order-plan.d.ts +77 -0
- package/dist/shared/lib/heavy/order-plan.js +83 -0
- package/dist/shared/lib/heavy/order-runner.d.ts +9 -0
- package/dist/shared/lib/heavy/order-runner.js +300 -0
- package/dist/shared/lib/heavy/order-types.d.ts +90 -0
- package/dist/shared/lib/heavy/order-types.js +6 -0
- package/dist/shared/lib/heavy/order-wire.d.ts +55 -0
- package/dist/shared/lib/heavy/order-wire.js +113 -0
- package/dist/shared/lib/heavy/piece-cid.d.ts +24 -0
- package/dist/shared/lib/heavy/piece-cid.js +55 -0
- package/dist/shared/lib/heavy/sp-upload.d.ts +37 -0
- package/dist/shared/lib/heavy/sp-upload.js +112 -0
- package/dist/shared/lib/heavy/synapse-piece.d.ts +1 -0
- package/dist/shared/lib/heavy/synapse-piece.js +8 -0
- package/dist/shared/lib/share/handover-format.d.ts +129 -0
- package/dist/shared/lib/share/handover-format.js +323 -0
- package/dist/shared/lib/share/public-link.d.ts +41 -0
- package/dist/shared/lib/share/public-link.js +107 -0
- package/dist/shared/lib/share/shared-file-info.js +1 -0
- package/dist/shared/lib/storage-network.d.ts +4 -4
- package/dist/shared/lib/storage-network.js +7 -7
- package/dist/shared/lib/storage-tier.d.ts +28 -0
- package/dist/shared/lib/storage-tier.js +63 -0
- package/dist/shared/lib/wallet/send-rules.js +1 -0
- package/dist/upload-file.d.ts +8 -0
- package/dist/upload-file.js +57 -25
- package/dist/upload-price-node.d.ts +3 -0
- package/dist/upload-price-node.js +3 -6
- package/dist/upload-price.d.ts +10 -0
- package/dist/upload-price.js +13 -1
- package/dist/upload-run.d.ts +80 -0
- package/dist/upload-run.js +173 -0
- package/dist/upload-steps.js +15 -4
- package/dist/upload-store.d.ts +15 -6
- package/dist/upload-store.js +6 -0
- package/dist/upload-wallet-put.d.ts +9 -4
- package/dist/upload-wallet-put.js +16 -6
- package/dist/upload-wallet.js +4 -0
- package/dist/upload-wire.d.ts +25 -0
- package/dist/upload-wire.js +20 -1
- package/dist/upload.js +28 -13
- package/dist/wallet-sign.js +2 -2
- package/docs/commands/handover.md +54 -0
- package/docs/commands/heavy.md +35 -0
- package/docs/commands/link.md +27 -0
- package/docs/commands/mcp.md +2 -1
- package/docs/commands/public-code.md +25 -6
- package/docs/commands/push.md +4 -1
- package/docs/commands/put.md +15 -1
- package/docs/commands/share.md +8 -3
- package/package.json +5 -2
- package/server.json +2 -2
- package/vendor/nmts-crypto/nmts_crypto_wasm.d.ts +106 -4
- package/vendor/nmts-crypto/nmts_crypto_wasm.js +286 -3
- package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm +0 -0
- package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm.d.ts +12 -1
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// Which UPLOAD a record belongs to, and one upload of one file at a time.
|
|
2
|
+
//
|
|
3
|
+
// ⛔ WHY THIS EXISTS. The records of an unfinished upload are filed under a name that is a pure
|
|
4
|
+
// function of the account, the bytes, the name and the destination (`upload-store.ts`). Two
|
|
5
|
+
// things follow from that, and both were defects:
|
|
6
|
+
//
|
|
7
|
+
// · A LATER upload of the same bytes to the same place — after the first was trashed, erased or
|
|
8
|
+
// replaced — rebuilt the first one's idempotency keys once its records were forgotten. Every
|
|
9
|
+
// reservation was refused as "this key already names another blob" (each sealing is fresh, so
|
|
10
|
+
// the blob differs), and a commit under the old key was answered with the OLD file. A run id,
|
|
11
|
+
// made with an upload's first record and kept with it, is what gives each upload keys of its
|
|
12
|
+
// own while a resume still finds the ones it started with.
|
|
13
|
+
// · Two runs of the same put AT ONCE — a gateway retrying a request its client gave up on, or two
|
|
14
|
+
// programs putting the same file — share those records. Each run seals under a file key of its
|
|
15
|
+
// own, and a run that picked up a part the other wrote would commit a file whose parts open
|
|
16
|
+
// under two different keys: paid for, listed, and impossible to read.
|
|
17
|
+
//
|
|
18
|
+
// ⛔ TWO GUARDS AGAINST THE SECOND, BECAUSE THE RECORD STORE HAS NO LOCK. Inside one process a second
|
|
19
|
+
// run WAITS for the first. Across processes there is nothing to wait on: the store (a directory
|
|
20
|
+
// on a machine, IndexedDB in a page) offers no exclusive create, and a lock made of a read and a
|
|
21
|
+
// write lets both sides believe they hold it. So a run that meets a record another sealing wrote
|
|
22
|
+
// refuses — before it pushes, signs or commits anything of that part — and checks every part
|
|
23
|
+
// once more before the commit.
|
|
24
|
+
import { randomBytes } from "@noble/hashes/utils.js";
|
|
25
|
+
import { toBase64Url } from "./bytes.js";
|
|
26
|
+
import { clearItemRecord, clearReservation, partKey, readReservationRecord, } from "./upload-store.js";
|
|
27
|
+
import { UploadError } from "./upload-wire.js";
|
|
28
|
+
/** What a refusal over another run's records is known by, for a program to branch on. */
|
|
29
|
+
export const UPLOAD_CONFLICT = "UPLOAD_CONFLICT";
|
|
30
|
+
/** A name for one upload of a file. Random: it says nothing about the file or the account. */
|
|
31
|
+
export function newRunId() {
|
|
32
|
+
return toBase64Url(randomBytes(16));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The run this file's records belong to, or a new one when none of them names one.
|
|
36
|
+
*
|
|
37
|
+
* ⚠ A record an earlier version wrote names none. Its own key stays the one that version used
|
|
38
|
+
* (`runIdField`); the new id is only for the parts this run is the first to write down.
|
|
39
|
+
*/
|
|
40
|
+
export async function runIdFor(fileKey, parts) {
|
|
41
|
+
for (let index = 0; index < parts; index += 1) {
|
|
42
|
+
const record = await readReservationRecord(partKey(fileKey, index));
|
|
43
|
+
if (record?.runId !== undefined)
|
|
44
|
+
return record.runId;
|
|
45
|
+
}
|
|
46
|
+
return newRunId();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The run id a part's record is written with: the one it already has, or this upload's.
|
|
50
|
+
*
|
|
51
|
+
* ⛔ A RECORD KEEPS WHAT IT WAS WRITTEN WITH, including nothing. Its reservation is filed under the
|
|
52
|
+
* key it was made with; giving an earlier version's record a run id now would ask the server
|
|
53
|
+
* under a key it has never seen and buy the storage a second time.
|
|
54
|
+
*/
|
|
55
|
+
export function runIdField(existing, runId) {
|
|
56
|
+
if (existing === null)
|
|
57
|
+
return { runId };
|
|
58
|
+
return existing.runId === undefined ? {} : { runId: existing.runId };
|
|
59
|
+
}
|
|
60
|
+
/** The tail of each file's queue: what the next run of that file waits for. */
|
|
61
|
+
const queues = new Map();
|
|
62
|
+
/**
|
|
63
|
+
* Run `body` once every earlier run of the same file in this process has finished.
|
|
64
|
+
*
|
|
65
|
+
* ⚠ WAITING, NOT REFUSING. Inside one process the first run is known to be alive, so the honest
|
|
66
|
+
* answer to a second one is "after it": it then finds a finished upload's records and answers
|
|
67
|
+
* the same file, or finds none and starts an upload of its own.
|
|
68
|
+
*/
|
|
69
|
+
export async function oneUploadAtATime(fileKey, body) {
|
|
70
|
+
const before = queues.get(fileKey) ?? Promise.resolve();
|
|
71
|
+
let release = () => undefined;
|
|
72
|
+
const mine = new Promise((resolve) => {
|
|
73
|
+
release = resolve;
|
|
74
|
+
});
|
|
75
|
+
const tail = before.then(() => mine);
|
|
76
|
+
queues.set(fileKey, tail);
|
|
77
|
+
await before;
|
|
78
|
+
try {
|
|
79
|
+
return await body();
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
release();
|
|
83
|
+
// The last run out takes the queue with it, so a long-lived process keeps no entry per file.
|
|
84
|
+
if (queues.get(fileKey) === tail)
|
|
85
|
+
queues.delete(fileKey);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function conflict(paid) {
|
|
89
|
+
return new UploadError({
|
|
90
|
+
phase: "reserve",
|
|
91
|
+
code: UPLOAD_CONFLICT,
|
|
92
|
+
message: "Another run is uploading this same file to the same place.",
|
|
93
|
+
paid,
|
|
94
|
+
nextStep: "This run stopped before committing anything. Let the other run finish, then run this " +
|
|
95
|
+
"again — it finds that upload's records, or starts one of its own.",
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Refuse a part record that another sealing of this file wrote.
|
|
100
|
+
*
|
|
101
|
+
* ⛔ THE WRAPPED FILE KEY SAYS WHICH SEALING A RECORD BELONGS TO. It is sealed afresh by every
|
|
102
|
+
* upload that starts from nothing and carried unchanged by every resume, so a record whose key
|
|
103
|
+
* is not this run's was written by another run — and its bytes open under a key this file's
|
|
104
|
+
* list entry will not hold.
|
|
105
|
+
*/
|
|
106
|
+
export function refuseOtherSealing(existing, input) {
|
|
107
|
+
if (existing === null)
|
|
108
|
+
return;
|
|
109
|
+
const sameKey = existing.dekWrapped === input.entry.dekWrapped;
|
|
110
|
+
const sameRun = existing.runId === undefined || existing.runId === input.runId;
|
|
111
|
+
if (!sameKey || !sameRun) {
|
|
112
|
+
throw conflict(existing.ledgerId !== undefined || existing.registerTxDigest !== undefined);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The last look before the commit: every part is still written down as THIS run bought it.
|
|
117
|
+
*
|
|
118
|
+
* ⛔ THE READ AT THE START OF A PART IS NOT ENOUGH ACROSS PROCESSES. Another run can write its own
|
|
119
|
+
* record over one of these between that read and this commit; the commit names what this run
|
|
120
|
+
* paid for, so a record that no longer agrees means two sealings are interleaved, and a file
|
|
121
|
+
* made of both would not open.
|
|
122
|
+
*/
|
|
123
|
+
export async function confirmParts(fileKey, paid, entry) {
|
|
124
|
+
for (const part of paid) {
|
|
125
|
+
const record = await readReservationRecord(partKey(fileKey, part.partIndex));
|
|
126
|
+
if (record === null || record.dekWrapped !== entry.dekWrapped || record.blobId !== part.blobId) {
|
|
127
|
+
throw conflict(true);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Forget a finished upload's records: the parts from the last to the first, then the file's own.
|
|
133
|
+
*
|
|
134
|
+
* ⛔ THE ORDER IS WHAT A RUN THAT STARTS IN THE MIDDLE OF IT CAN READ. A live upload's parts are
|
|
135
|
+
* always written down from the first, so what is left at any moment is a finished upload the
|
|
136
|
+
* next run recognises — a committed file with the first of its parts still named — or a file
|
|
137
|
+
* record alone, which names another run and is passed over. Forgetting the file's record first,
|
|
138
|
+
* or the parts from the front, left the tail of a finished upload looking like the start of a
|
|
139
|
+
* live one, which the next run would resume into keys the server has already settled.
|
|
140
|
+
*/
|
|
141
|
+
export async function forgetUpload(fileKey, parts) {
|
|
142
|
+
for (let index = parts - 1; index >= 0; index -= 1)
|
|
143
|
+
await clearReservation(partKey(fileKey, index));
|
|
144
|
+
await clearItemRecord(fileKey);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Forget records that cannot belong to a live upload: a part written down after one that is not,
|
|
148
|
+
* or a file's record with none of its parts.
|
|
149
|
+
*
|
|
150
|
+
* ⛔ WHY THOSE SHAPES MEAN "LEFT OVER". A live upload writes its parts down from the first, one at a
|
|
151
|
+
* time and each before its money moves; it writes the file's record only once every part is
|
|
152
|
+
* written down; and nothing removes any of them until the file is committed AND listed. So a gap
|
|
153
|
+
* in front of a part, or a file record alone, is a finished upload whose forgetting stopped half
|
|
154
|
+
* way (or ran in the old order). Resuming the first would seal the missing part afresh under a
|
|
155
|
+
* key the server has already settled for other bytes; resuming the second would answer the old
|
|
156
|
+
* file for new storage.
|
|
157
|
+
*/
|
|
158
|
+
export async function dropLeftovers(fileKey, parts) {
|
|
159
|
+
let gap = false;
|
|
160
|
+
let any = false;
|
|
161
|
+
for (let index = 0; index < parts; index += 1) {
|
|
162
|
+
const present = (await readReservationRecord(partKey(fileKey, index))) !== null;
|
|
163
|
+
any ||= present;
|
|
164
|
+
if (!present)
|
|
165
|
+
gap = true;
|
|
166
|
+
else if (gap) {
|
|
167
|
+
await forgetUpload(fileKey, parts);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (!any)
|
|
172
|
+
await clearItemRecord(fileKey);
|
|
173
|
+
}
|
package/dist/upload-steps.js
CHANGED
|
@@ -48,6 +48,7 @@ export async function pushPart(input, step) {
|
|
|
48
48
|
phase: "certify",
|
|
49
49
|
message: why(error),
|
|
50
50
|
paid: true,
|
|
51
|
+
from: error,
|
|
51
52
|
nextStep: "The bytes are on the network. Certifying moves no money, so running the same command " +
|
|
52
53
|
"again finishes the job.",
|
|
53
54
|
});
|
|
@@ -70,14 +71,23 @@ export async function commitItem(input, fileKey, parts) {
|
|
|
70
71
|
// Advisory only — the chain is the authority on a blob's life. 0 when this machine could not
|
|
71
72
|
// read the epoch clock: a number we do not have is not a number to invent.
|
|
72
73
|
const expiryEpoch = input.currentEpoch === null ? 0 : input.currentEpoch + input.epochs;
|
|
73
|
-
const
|
|
74
|
+
const found = await readItemRecord(fileKey);
|
|
75
|
+
// ⛔ ONLY THIS UPLOAD'S RECORD COUNTS. One carrying another run id was left by an earlier upload
|
|
76
|
+
// of the same bytes to the same place, and answering its item for the parts just bought would
|
|
77
|
+
// name the OLD file for them. A record an earlier version wrote carries none, and is this
|
|
78
|
+
// upload's by the only rule that version had.
|
|
79
|
+
const previous = found !== null && (found.runId === undefined || found.runId === input.runId) ? found : null;
|
|
74
80
|
// ⛔ ALREADY COMMITTED IS NOT COMMITTED AGAIN. The record outlives the commit precisely so a run
|
|
75
81
|
// that died before writing the file list does not make a second file out of storage that is
|
|
76
82
|
// already named.
|
|
77
83
|
if (previous?.itemId !== undefined)
|
|
78
84
|
return previous.itemId;
|
|
79
85
|
const attempt = previous?.attempt ?? 0;
|
|
80
|
-
|
|
86
|
+
// ⚠ A commit an earlier version attempted keeps the key it was attempted under, because the server
|
|
87
|
+
// may already hold its row; every other commit is this upload's.
|
|
88
|
+
const runId = previous === null ? input.runId : previous.runId;
|
|
89
|
+
const record = runId === undefined ? { attempt } : { attempt, runId };
|
|
90
|
+
await writeItemRecord(fileKey, record);
|
|
81
91
|
let view;
|
|
82
92
|
try {
|
|
83
93
|
view = await input.api.createItem({
|
|
@@ -86,13 +96,14 @@ export async function commitItem(input, fileKey, parts) {
|
|
|
86
96
|
content_hash_ct: input.entry.contentHashCt,
|
|
87
97
|
visibility: VISIBILITY_PERSONAL,
|
|
88
98
|
parts: parts.map((part) => describePart(part, expiryEpoch)),
|
|
89
|
-
}, `nmts-cli-commit-${fileKey}-${attempt}`);
|
|
99
|
+
}, runId === undefined ? `nmts-cli-commit-${fileKey}-${attempt}` : `nmts-cli-commit-${fileKey}-${runId}-${attempt}`);
|
|
90
100
|
}
|
|
91
101
|
catch (error) {
|
|
92
102
|
throw new UploadError({
|
|
93
103
|
phase: "committing",
|
|
94
104
|
message: `The file is stored but saving it to the drive failed: ${why(error)}`,
|
|
95
105
|
paid: true,
|
|
106
|
+
from: error,
|
|
96
107
|
nextStep: "Nothing more will be spent. Running the same command again commits the same stored " +
|
|
97
108
|
"bytes — the retry is recognised and does not make a second file.",
|
|
98
109
|
});
|
|
@@ -100,7 +111,7 @@ export async function commitItem(input, fileKey, parts) {
|
|
|
100
111
|
// ⛔ Written down before returning: from here on the file EXISTS and is paid for, and the only
|
|
101
112
|
// thing still missing is the account's own list. Losing the record now would make it
|
|
102
113
|
// unreachable.
|
|
103
|
-
await writeItemRecord(fileKey, {
|
|
114
|
+
await writeItemRecord(fileKey, { ...record, itemId: view.id });
|
|
104
115
|
return view.id;
|
|
105
116
|
}
|
|
106
117
|
/**
|
package/dist/upload-store.d.ts
CHANGED
|
@@ -95,14 +95,21 @@ export interface Reservation {
|
|
|
95
95
|
/**
|
|
96
96
|
* How many reservations this file has needed. Part of the idempotency key.
|
|
97
97
|
*
|
|
98
|
-
* ⛔ WITHOUT IT, A FAILED RESERVATION BRICKS THIS
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* file again unless a byte of it changed. Counting up is what "start over" actually means.
|
|
98
|
+
* ⛔ WITHOUT IT, A FAILED RESERVATION BRICKS THIS UPLOAD. A resume asks under the key this
|
|
99
|
+
* record names, and the server replays a reservation row under its key WHATEVER STATE IT IS
|
|
100
|
+
* IN — including `failed`, which can never become storage. So every later attempt would be
|
|
101
|
+
* handed the same dead row, be told to start over, and start over into the same dead row.
|
|
102
|
+
* Counting up is what "start over" actually means.
|
|
104
103
|
*/
|
|
105
104
|
attempt: number;
|
|
105
|
+
/**
|
|
106
|
+
* Which UPLOAD of this file wrote the record — `newRunId` in `upload-run.ts` says why it exists.
|
|
107
|
+
* Part of the idempotency key.
|
|
108
|
+
*
|
|
109
|
+
* ⚠ ABSENT ON A RECORD AN EARLIER VERSION WROTE, and then the key is the one that version used:
|
|
110
|
+
* the reservation it may already have paid for is filed under that key and nowhere else.
|
|
111
|
+
*/
|
|
112
|
+
runId?: string;
|
|
106
113
|
/** Present once the server answered: the reservation row. */
|
|
107
114
|
ledgerId?: number;
|
|
108
115
|
/** Present once registered: the transaction the relay checks its tip in. */
|
|
@@ -183,6 +190,8 @@ export interface ItemRecord {
|
|
|
183
190
|
* storage twice says nothing about how many times the file was committed.
|
|
184
191
|
*/
|
|
185
192
|
attempt: number;
|
|
193
|
+
/** The upload that attempted the commit. Absent on a record an earlier version wrote. */
|
|
194
|
+
runId?: string;
|
|
186
195
|
}
|
|
187
196
|
/** What is known about this file's commit, or `null` when it has not been attempted. */
|
|
188
197
|
export declare function readItemRecord(fileKey: string): Promise<ItemRecord | null>;
|
package/dist/upload-store.js
CHANGED
|
@@ -100,6 +100,9 @@ function isReservation(value) {
|
|
|
100
100
|
if (typeof Reflect.get(value, name) !== "number")
|
|
101
101
|
return false;
|
|
102
102
|
}
|
|
103
|
+
const runId = Reflect.get(value, "runId");
|
|
104
|
+
if (runId !== undefined && typeof runId !== "string")
|
|
105
|
+
return false;
|
|
103
106
|
const parent = Reflect.get(value, "parentId");
|
|
104
107
|
return parent === null || typeof parent === "string";
|
|
105
108
|
}
|
|
@@ -201,6 +204,9 @@ function isItemRecord(value) {
|
|
|
201
204
|
return false;
|
|
202
205
|
if (typeof Reflect.get(value, "attempt") !== "number")
|
|
203
206
|
return false;
|
|
207
|
+
const runId = Reflect.get(value, "runId");
|
|
208
|
+
if (runId !== undefined && typeof runId !== "string")
|
|
209
|
+
return false;
|
|
204
210
|
const id = Reflect.get(value, "itemId");
|
|
205
211
|
return id === undefined || typeof id === "string";
|
|
206
212
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CollisionAsk } from "./collision.ts";
|
|
2
2
|
import { type CryptoGlue } from "./crypto.ts";
|
|
3
3
|
import type { Network } from "./network.ts";
|
|
4
4
|
import type { PaddingRule } from "./shared/lib/crypto/size-padding.ts";
|
|
5
5
|
import { type FileUploadStep, type PlaintextSource } from "./upload-file.ts";
|
|
6
6
|
import { type StorageChoice, type UploadBudget, type WalletUploadReads } from "./upload-wallet-plan.ts";
|
|
7
|
-
import type
|
|
7
|
+
import { type BlobProtocol, type UploadApi } from "./upload-wire.ts";
|
|
8
8
|
import type { Spend } from "./wallet-grant.ts";
|
|
9
9
|
import type { SignBlobCertify, SignBlobRegister } from "./wallet-sign.ts";
|
|
10
|
+
/** The `code` of the refusal a wallet known to be short of either coin is answered with. */
|
|
11
|
+
export declare const WALLET_SHORT = "WALLET_SHORT";
|
|
10
12
|
/** The account this upload belongs to, and how it seals. */
|
|
11
13
|
export interface WalletPutContext {
|
|
12
14
|
/** ⛔ The NMTS key. It seals the file AND derives the wallet that pays. It is never written down. */
|
|
@@ -20,8 +22,11 @@ export interface WalletPutContext {
|
|
|
20
22
|
partSize: number;
|
|
21
23
|
/** The rounding rule from the account's sealed list — it changes the stored size, so the price. */
|
|
22
24
|
rule: PaddingRule;
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
+
/**
|
|
26
|
+
* What to do about a name already in use, for this upload. Absent = the machine's setting, as
|
|
27
|
+
* `addEntry` reads it; a bare word is a command line's and is held to the modes (`collision.ts`).
|
|
28
|
+
*/
|
|
29
|
+
onCollision?: CollisionAsk | undefined;
|
|
25
30
|
/**
|
|
26
31
|
* Which of this key's wallets pays, by index (0 = the first one).
|
|
27
32
|
*
|
|
@@ -38,13 +38,16 @@ import { addEntry } from "./manifest-write.js";
|
|
|
38
38
|
import { sealedLenFor } from "./seal.js";
|
|
39
39
|
import { statusOf } from "./shared/lib/storage-control/plan.js";
|
|
40
40
|
import { createUploadApi } from "./upload-api.js";
|
|
41
|
-
import {
|
|
41
|
+
import { uploadFile } from "./upload-file.js";
|
|
42
42
|
import { CREDIT_BYTES, planAndPrice } from "./upload-price.js";
|
|
43
|
-
import {
|
|
43
|
+
import { forgetUpload } from "./upload-run.js";
|
|
44
44
|
import { walletRail } from "./upload-wallet.js";
|
|
45
45
|
import { chooseUploadEpochs, daysOf, parseStorageAsk, pickResource, uploadBudget, uploadShortfallNextStep, } from "./upload-wallet-plan.js";
|
|
46
|
+
import { UploadError } from "./upload-wire.js";
|
|
46
47
|
import { walletAddress } from "./wallet.js";
|
|
47
48
|
import { createBlobProtocol } from "./walrus-write.js";
|
|
49
|
+
/** The `code` of the refusal a wallet known to be short of either coin is answered with. */
|
|
50
|
+
export const WALLET_SHORT = "WALLET_SHORT";
|
|
48
51
|
/**
|
|
49
52
|
* Price, agree, sign, upload and record ONE file, paid from the wallet the NMTS key derives.
|
|
50
53
|
*
|
|
@@ -130,8 +133,17 @@ export async function walletPut(ctx, file, seams = {}) {
|
|
|
130
133
|
if (seams.dryRun === true)
|
|
131
134
|
return { kind: "review", review };
|
|
132
135
|
// ⛔ A WALLET KNOWN TO BE SHORT IS REFUSED BEFORE THE AGREEMENT IS ASKED FOR (`extend-budget.ts`).
|
|
136
|
+
// As the refusal a program branches on: `WALLET_SHORT`, where a credit shortfall carries the
|
|
137
|
+
// server's own code.
|
|
133
138
|
if (budget.shortfall !== null) {
|
|
134
|
-
throw new
|
|
139
|
+
throw new UploadError({
|
|
140
|
+
phase: "reserve",
|
|
141
|
+
message: budget.shortfall,
|
|
142
|
+
paid: false,
|
|
143
|
+
nextStep: uploadShortfallNextStep(budget),
|
|
144
|
+
exitCode: 4,
|
|
145
|
+
code: WALLET_SHORT,
|
|
146
|
+
});
|
|
135
147
|
}
|
|
136
148
|
seams.agree?.(review);
|
|
137
149
|
const sign = seams.sign ?? (await signers());
|
|
@@ -200,9 +212,7 @@ export async function walletPut(ctx, file, seams = {}) {
|
|
|
200
212
|
// ⛔ ONLY NOW, AND EVERY PART — the same order the credit rail keeps and for the same reason: a
|
|
201
213
|
// paid-for file the list does not name is invisible, and the records are what let a second
|
|
202
214
|
// call finish the job without signing again.
|
|
203
|
-
await
|
|
204
|
-
for (const record of partKeysOf(result.fileKey, result.parts))
|
|
205
|
-
await clearReservation(record);
|
|
215
|
+
await forgetUpload(result.fileKey, result.parts);
|
|
206
216
|
if (added.replaced)
|
|
207
217
|
await setTrashed(ctx.server, ctx.apiKey, added.replaced.id, true);
|
|
208
218
|
return {
|
package/dist/upload-wallet.js
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
// reach them.
|
|
21
21
|
import { fromBase64Url, toBase64Url } from "./bytes.js";
|
|
22
22
|
import { NmtsError } from "./errors.js";
|
|
23
|
+
import { refuseOtherSealing, runIdField } from "./upload-run.js";
|
|
23
24
|
import { readReservationBytes, readReservationRecord, writeReservation } from "./upload-store.js";
|
|
24
25
|
import { UploadError } from "./upload-wire.js";
|
|
25
26
|
function why(error) {
|
|
@@ -64,6 +65,8 @@ async function buyAndPushPartWithWallet(ctx, input) {
|
|
|
64
65
|
"records to start over. Nothing was sent.",
|
|
65
66
|
});
|
|
66
67
|
}
|
|
68
|
+
// ⛔ A record another sealing of this file wrote is refused, not resumed (`upload-run.ts`).
|
|
69
|
+
refuseOtherSealing(existing, input);
|
|
67
70
|
// ── already certified: nothing left to sign or send ──
|
|
68
71
|
if (existing?.certifyTxDigest !== undefined) {
|
|
69
72
|
onStep?.({ step: "resuming", ledgerId: 0, state: "certified" });
|
|
@@ -95,6 +98,7 @@ async function buyAndPushPartWithWallet(ctx, input) {
|
|
|
95
98
|
}
|
|
96
99
|
const record = {
|
|
97
100
|
attempt: existing?.attempt ?? 0,
|
|
101
|
+
...runIdField(existing, input.runId),
|
|
98
102
|
paidFrom: "wallet",
|
|
99
103
|
blobId: meta.blobId,
|
|
100
104
|
nonceB64: toBase64Url(meta.nonce),
|
package/dist/upload-wire.d.ts
CHANGED
|
@@ -108,15 +108,35 @@ export type UploadStep = {
|
|
|
108
108
|
* advice. After it, the credits are gone and the storage exists; the honest advice is that the
|
|
109
109
|
* same command will FINISH it rather than buy it again, and that saying otherwise would send
|
|
110
110
|
* somebody to spend twice.
|
|
111
|
+
*
|
|
112
|
+
* ⛔ AND A REFUSAL KEEPS WHAT THE SERVER SAID ABOUT ITSELF. A program deciding whether to top up,
|
|
113
|
+
* wait or give up reads `code`, `status` and `retryAfter`; the sentence is for a person, and a
|
|
114
|
+
* program that matched on it would break the day it was reworded.
|
|
111
115
|
*/
|
|
112
116
|
export declare class UploadError extends NmtsError {
|
|
113
117
|
readonly phase: UploadPhase;
|
|
114
118
|
readonly paid: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* The server's own code when the server refused, exactly as `ServerError.code` carries it — or
|
|
121
|
+
* `WALLET_SHORT` when the paying wallet was known to be short before anything was signed.
|
|
122
|
+
* Absent for every other failure.
|
|
123
|
+
*/
|
|
124
|
+
readonly code?: string | undefined;
|
|
125
|
+
/** The HTTP status the server answered with. Absent when no answer came back. */
|
|
126
|
+
readonly status?: number | undefined;
|
|
127
|
+
/** Seconds to wait before asking again, from the server's `Retry-After`; null when it named none. */
|
|
128
|
+
readonly retryAfter?: number | null | undefined;
|
|
115
129
|
constructor(input: {
|
|
116
130
|
phase: UploadPhase;
|
|
117
131
|
message: string;
|
|
118
132
|
paid: boolean;
|
|
119
133
|
nextStep?: string | null;
|
|
134
|
+
/** 1 unless this refusal has an exit code of its own. */
|
|
135
|
+
exitCode?: number;
|
|
136
|
+
/** What this refusal is known by, when it is not the server's to name. */
|
|
137
|
+
code?: string;
|
|
138
|
+
/** The failure this one wraps. A server refusal's code, status and wait are carried over. */
|
|
139
|
+
from?: unknown;
|
|
120
140
|
});
|
|
121
141
|
}
|
|
122
142
|
/**
|
|
@@ -130,6 +150,11 @@ export declare class UploadError extends NmtsError {
|
|
|
130
150
|
*/
|
|
131
151
|
export interface CommitInput {
|
|
132
152
|
api: UploadApi;
|
|
153
|
+
/**
|
|
154
|
+
* This upload's run id (`newRunId` in `upload-store.ts`): what every NEW record is written with,
|
|
155
|
+
* and what makes this upload's idempotency keys its own rather than the last upload's.
|
|
156
|
+
*/
|
|
157
|
+
runId: string;
|
|
133
158
|
/** Storage term in storage-network epochs. */
|
|
134
159
|
epochs: number;
|
|
135
160
|
/** The current storage-network epoch, or null when it could not be read. */
|
package/dist/upload-wire.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// ⛔ SEPARATE FROM THE MACHINE ON PURPOSE. `upload.ts` is a sequence of decisions about spending;
|
|
5
5
|
// keeping the vocabulary here means a test can name every seam without importing that sequence,
|
|
6
6
|
// and means the file that DOES spend stays short enough to read in one sitting.
|
|
7
|
+
import { HttpError, ServerError } from "./api.js";
|
|
7
8
|
import { NmtsError } from "./errors.js";
|
|
8
9
|
/**
|
|
9
10
|
* A failure that names its phase — and, crucially, whether the account has already paid.
|
|
@@ -12,14 +13,32 @@ import { NmtsError } from "./errors.js";
|
|
|
12
13
|
* advice. After it, the credits are gone and the storage exists; the honest advice is that the
|
|
13
14
|
* same command will FINISH it rather than buy it again, and that saying otherwise would send
|
|
14
15
|
* somebody to spend twice.
|
|
16
|
+
*
|
|
17
|
+
* ⛔ AND A REFUSAL KEEPS WHAT THE SERVER SAID ABOUT ITSELF. A program deciding whether to top up,
|
|
18
|
+
* wait or give up reads `code`, `status` and `retryAfter`; the sentence is for a person, and a
|
|
19
|
+
* program that matched on it would break the day it was reworded.
|
|
15
20
|
*/
|
|
16
21
|
export class UploadError extends NmtsError {
|
|
17
22
|
phase;
|
|
18
23
|
paid;
|
|
24
|
+
/**
|
|
25
|
+
* The server's own code when the server refused, exactly as `ServerError.code` carries it — or
|
|
26
|
+
* `WALLET_SHORT` when the paying wallet was known to be short before anything was signed.
|
|
27
|
+
* Absent for every other failure.
|
|
28
|
+
*/
|
|
29
|
+
code;
|
|
30
|
+
/** The HTTP status the server answered with. Absent when no answer came back. */
|
|
31
|
+
status;
|
|
32
|
+
/** Seconds to wait before asking again, from the server's `Retry-After`; null when it named none. */
|
|
33
|
+
retryAfter;
|
|
19
34
|
constructor(input) {
|
|
20
|
-
super(input.message, { exitCode: 1, nextStep: input.nextStep ?? null });
|
|
35
|
+
super(input.message, { exitCode: input.exitCode ?? 1, nextStep: input.nextStep ?? null });
|
|
21
36
|
this.name = "UploadError";
|
|
22
37
|
this.phase = input.phase;
|
|
23
38
|
this.paid = input.paid;
|
|
39
|
+
const from = input.from;
|
|
40
|
+
this.code = from instanceof ServerError ? from.code : input.code;
|
|
41
|
+
this.status = from instanceof ServerError || from instanceof HttpError ? from.status : undefined;
|
|
42
|
+
this.retryAfter = from instanceof ServerError ? from.retryAfter : undefined;
|
|
24
43
|
}
|
|
25
44
|
}
|
package/dist/upload.js
CHANGED
|
@@ -30,6 +30,7 @@ import { fromBase64Url, toBase64Url } from "./bytes.js";
|
|
|
30
30
|
import { NmtsError } from "./errors.js";
|
|
31
31
|
import { ServerError } from "./api.js";
|
|
32
32
|
import { readReservationBytes, readReservationRecord, writeReservation, } from "./upload-store.js";
|
|
33
|
+
import { refuseOtherSealing, runIdField } from "./upload-run.js";
|
|
33
34
|
import { pushPart } from "./upload-steps.js";
|
|
34
35
|
import { UploadError, } from "./upload-wire.js";
|
|
35
36
|
export * from "./upload-wire.js";
|
|
@@ -82,6 +83,9 @@ export async function buyAndPushPart(input) {
|
|
|
82
83
|
});
|
|
83
84
|
}
|
|
84
85
|
}
|
|
86
|
+
// ⛔ JUDGED ON THE SAME READ THAT WOULD RESUME IT. A record another sealing of this file wrote is
|
|
87
|
+
// refused here, not picked up (`upload-run.ts`).
|
|
88
|
+
refuseOtherSealing(existing, input);
|
|
85
89
|
// ── the credits already moved: ask where the reservation stands before doing anything ──
|
|
86
90
|
if (existing?.ledgerId !== undefined) {
|
|
87
91
|
const record = existing;
|
|
@@ -97,6 +101,7 @@ export async function buyAndPushPart(input) {
|
|
|
97
101
|
phase: "reserve",
|
|
98
102
|
message: `Could not ask about the paid reservation ${ledgerId}: ${why(error)}`,
|
|
99
103
|
paid: true,
|
|
104
|
+
from: error,
|
|
100
105
|
nextStep: "Nothing more was spent. The storage this account paid for is still bought — run the " +
|
|
101
106
|
"same command again when the server answers.",
|
|
102
107
|
});
|
|
@@ -106,12 +111,12 @@ export async function buyAndPushPart(input) {
|
|
|
106
111
|
return paidPart(record, ledgerId, true);
|
|
107
112
|
}
|
|
108
113
|
if (!isLive(status.state)) {
|
|
109
|
-
// ⛔ THE RECORD IS KEPT AND ITS ATTEMPT NUMBER GOES UP.
|
|
110
|
-
//
|
|
111
|
-
//
|
|
112
|
-
//
|
|
113
|
-
//
|
|
114
|
-
//
|
|
114
|
+
// ⛔ THE RECORD IS KEPT AND ITS ATTEMPT NUMBER GOES UP. The server replays a reservation row
|
|
115
|
+
// under its key whatever state it is in — `failed` included — so the next run, which reads
|
|
116
|
+
// its key off this record, would be handed the same dead row and told to start over into
|
|
117
|
+
// it. Forever. Counting up is what starting over actually means. (A record written before
|
|
118
|
+
// run ids existed has a key that is a pure function of the account, the bytes and the
|
|
119
|
+
// destination, so for it even deleting the record would not have helped.)
|
|
115
120
|
await writeReservation(key, { ...stripReservation(record), attempt: record.attempt + 1 }, await readReservationBytes(key));
|
|
116
121
|
throw new UploadError({
|
|
117
122
|
phase: "reserve",
|
|
@@ -166,6 +171,7 @@ export async function buyAndPushPart(input) {
|
|
|
166
171
|
// ⛔ The attempt number is CARRIED FORWARD, not reset. A record that survives a dead
|
|
167
172
|
// reservation is exactly the case that needs a different idempotency key.
|
|
168
173
|
attempt: existing?.attempt ?? 0,
|
|
174
|
+
...runIdField(existing, input.runId),
|
|
169
175
|
blobId: meta.blobId,
|
|
170
176
|
nonceB64,
|
|
171
177
|
rootHashB64: toBase64Url(meta.rootHash),
|
|
@@ -187,7 +193,7 @@ export async function buyAndPushPart(input) {
|
|
|
187
193
|
let reply;
|
|
188
194
|
try {
|
|
189
195
|
reply = await api.reserve({
|
|
190
|
-
idempotency_key: idempotencyKey(key, record
|
|
196
|
+
idempotency_key: idempotencyKey(key, record),
|
|
191
197
|
blob_id: meta.blobId,
|
|
192
198
|
root_hash_b64: record.rootHashB64,
|
|
193
199
|
// One number, measured: what the treasury is asked to buy and what the credits are charged
|
|
@@ -209,6 +215,9 @@ export async function buyAndPushPart(input) {
|
|
|
209
215
|
// ⛔ A refusal did not spend. A request that never got an answer MIGHT have — and the record
|
|
210
216
|
// is on disk either way, so the next run asks the server instead of guessing here.
|
|
211
217
|
paid: false,
|
|
218
|
+
// ⛔ THE SERVER'S CODE GOES WITH IT. Credits that ran out and a ceiling that was hit are two
|
|
219
|
+
// different things for a program to do, and the words alone do not say which.
|
|
220
|
+
from: error,
|
|
212
221
|
nextStep: error instanceof ServerError
|
|
213
222
|
? "Nothing was uploaded. No credits were spent on a refused reservation."
|
|
214
223
|
: "If the request reached the server, credits may have been spent — running the same " +
|
|
@@ -271,14 +280,20 @@ function paidPart(record, ledgerId, resumed) {
|
|
|
271
280
|
};
|
|
272
281
|
}
|
|
273
282
|
/**
|
|
274
|
-
* The idempotency key for one attempt at one
|
|
283
|
+
* The idempotency key for one attempt at one part of one upload.
|
|
275
284
|
*
|
|
276
|
-
* ⛔ THE ATTEMPT NUMBER
|
|
277
|
-
* and the destination — and the server replays whatever row it has under
|
|
278
|
-
* settled one that can never become storage
|
|
285
|
+
* ⛔ THE RUN ID AND THE ATTEMPT NUMBER ARE BOTH IN IT. Without them the key is a pure function of
|
|
286
|
+
* the account, the bytes and the destination — and the server replays whatever row it has under
|
|
287
|
+
* a key: a settled one that can never become storage, or the one an EARLIER upload of the same
|
|
288
|
+
* file bought for bytes that are not these (`newRunId` in `upload-store.ts`).
|
|
289
|
+
*
|
|
290
|
+
* ⚠ A record an earlier version wrote has no run id and keeps the key that version asked under,
|
|
291
|
+
* because that is where its reservation is.
|
|
279
292
|
*/
|
|
280
|
-
function idempotencyKey(key,
|
|
281
|
-
return
|
|
293
|
+
function idempotencyKey(key, record) {
|
|
294
|
+
return record.runId === undefined
|
|
295
|
+
? `nmts-cli-${key}-${record.attempt}`
|
|
296
|
+
: `nmts-cli-${key}-${record.runId}-${record.attempt}`;
|
|
282
297
|
}
|
|
283
298
|
/** What the file list must record about this upload. Always from the record, never from a run. */
|
|
284
299
|
export function entryOf(record) {
|
package/dist/wallet-sign.js
CHANGED
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
// exists so somebody can prove an address is theirs — all the hall of fame asks for.
|
|
14
14
|
//
|
|
15
15
|
// ⛔ IT IS REACHED FROM `commands/extend.ts`, `commands/wallet-send.ts`, `commands/wallet-donate.ts`,
|
|
16
|
-
// `commands/wallet-swap.ts
|
|
17
|
-
// drives), each after the price, the fee and the balances have been read and printed, and (a
|
|
16
|
+
// `commands/wallet-swap.ts`, `upload-wallet.ts` (the wallet rail `commands/put-wallet.ts`
|
|
17
|
+
// drives) and `commands/heavy-run.ts` (an NMTS Heavy order's one WAL payment), each after the price, the fee and the balances have been read and printed, and (a
|
|
18
18
|
// gift excepted) after `requireWalletGrant(…)`. Nothing else imports it, and it is loaded lazily
|
|
19
19
|
// so that a run which does not spend never even brings the code into memory.
|
|
20
20
|
//
|