@needmoretruth/nmts-cli 0.54.2 → 0.55.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/CHANGELOG.md +12 -0
- package/README.ko.md +1 -1
- package/README.md +1 -1
- package/dist/artifact-about.d.ts +1 -1
- package/dist/commands/push.js +1 -1
- package/dist/commands/put-wallet.js +1 -1
- package/dist/commands/put.js +1 -1
- package/dist/manifest.js +3 -0
- package/dist/node-read.d.ts +2 -0
- package/dist/node-read.js +24 -0
- package/dist/product.d.ts +1 -1
- package/dist/product.js +1 -1
- package/dist/read-race.d.ts +35 -0
- package/dist/read-race.js +91 -0
- package/dist/road-hosts.generated.d.ts +4 -0
- package/dist/road-hosts.generated.js +284 -0
- package/dist/shared/lib/upload/wallet-storage-estimate.d.ts +16 -0
- package/dist/shared/lib/upload/wallet-storage-estimate.js +44 -0
- package/dist/shared/lib/wallet/graphql-history.d.ts +7 -2
- package/dist/shared/lib/wallet/graphql-history.js +7 -2
- package/dist/shared/lib/walrus/credit-tip.d.ts +24 -0
- package/dist/shared/lib/walrus/credit-tip.js +61 -0
- package/dist/shared/lib/walrus/node-certificate.d.ts +18 -0
- package/dist/shared/lib/walrus/node-certificate.js +77 -0
- package/dist/shared/lib/walrus/node-quorum.d.ts +17 -0
- package/dist/shared/lib/walrus/node-quorum.js +103 -0
- package/dist/shared/lib/walrus/tip-config.d.ts +33 -0
- package/dist/shared/lib/walrus/tip-config.js +68 -0
- package/dist/upload-road.d.ts +26 -4
- package/dist/upload-road.js +79 -17
- package/dist/upload-steps.js +1 -0
- package/dist/upload-wallet-chain.d.ts +1 -1
- package/dist/upload-wallet-chain.js +11 -4
- package/dist/upload-wallet.js +1 -0
- package/dist/upload-wire.d.ts +5 -0
- package/dist/upload.js +3 -3
- package/dist/walrus-write.js +68 -3
- package/dist/walrus.d.ts +20 -4
- package/dist/walrus.js +115 -36
- package/package.json +1 -1
- package/server.json +2 -2
package/dist/upload-steps.js
CHANGED
|
@@ -16,7 +16,7 @@ export declare const RELAY_TIP_CEILING_MIST: Readonly<Record<Network, number>>;
|
|
|
16
16
|
export declare function packageConfig(network: Network): {
|
|
17
17
|
systemObjectId: string;
|
|
18
18
|
};
|
|
19
|
-
declare function build(network: Network,
|
|
19
|
+
declare function build(network: Network, given: string): import("@mysten/sui/client").ClientWithExtensions<{
|
|
20
20
|
walrus: import("@mysten/walrus").WalrusClient;
|
|
21
21
|
}, import("@mysten/sui/grpc").SuiGrpcClient>;
|
|
22
22
|
export type PayingClient = ReturnType<typeof build>;
|
|
@@ -26,7 +26,7 @@ import { reachFetch } from "./reach.js";
|
|
|
26
26
|
import { readOwnedStorage, readStorageType } from "./shared/lib/storage-control/chain.js";
|
|
27
27
|
import { registerIntoStorage, splitStorageToFit } from "./shared/lib/storage-control/reuse.js";
|
|
28
28
|
import { dryRun, inspect, u64FromLe } from "./shared/lib/wallet/chain-calls.js";
|
|
29
|
-
import { isOwnRelay, relayFetch } from "./upload-road.js";
|
|
29
|
+
import { isNodeRoad, isOwnRelay, ownRelayFallback, relayFetch } from "./upload-road.js";
|
|
30
30
|
import { storageNodesThrough } from "./walrus.js";
|
|
31
31
|
import { freshWalrus } from "./walrus-fresh.js";
|
|
32
32
|
import { suiClient } from "./sui-rpc.js";
|
|
@@ -40,15 +40,22 @@ import { chainReader } from "./wallet-chain.js";
|
|
|
40
40
|
* tip configuration sets the amount, which the review prints — and a relay asking for more than
|
|
41
41
|
* this is refused by the SDK before anything is signed.
|
|
42
42
|
*/
|
|
43
|
+
// ⛔ Raised in D51 (2026-11-10) with the browser's, for Studio Mirai's relay: 3,000,000 MIST plus 60
|
|
44
|
+
// per encoded KiB, about 0.022 SUI for a 64 MiB part and 0.289 SUI for a 1 GiB one.
|
|
43
45
|
export const RELAY_TIP_CEILING_MIST = {
|
|
44
|
-
testnet:
|
|
45
|
-
mainnet:
|
|
46
|
+
testnet: 50_000_000,
|
|
47
|
+
mainnet: 400_000_000,
|
|
46
48
|
};
|
|
47
49
|
/** The Walrus package addresses of one network. Exported from the SDK; the system object survives upgrades. */
|
|
48
50
|
export function packageConfig(network) {
|
|
49
51
|
return network === "mainnet" ? MAINNET_WALRUS_PACKAGE_CONFIG : TESTNET_WALRUS_PACKAGE_CONFIG;
|
|
50
52
|
}
|
|
51
|
-
function build(network,
|
|
53
|
+
function build(network, given) {
|
|
54
|
+
// The direct road (D51) has no relay to tip; the client is the own relay's (no tip either), which
|
|
55
|
+
// also carries a part the nodes did not take. Without that fallback, a relay-free client.
|
|
56
|
+
const relayUrl = isNodeRoad(given) ? (ownRelayFallback() ?? given) : given;
|
|
57
|
+
if (isNodeRoad(relayUrl))
|
|
58
|
+
return suiClient(network).$extend(walrus({ ...storageNodesThrough() }));
|
|
52
59
|
return suiClient(network).$extend(walrus({
|
|
53
60
|
...storageNodesThrough(),
|
|
54
61
|
uploadRelay: {
|
package/dist/upload-wallet.js
CHANGED
package/dist/upload-wire.d.ts
CHANGED
|
@@ -28,6 +28,11 @@ export interface BlobProtocol {
|
|
|
28
28
|
nonce: Uint8Array;
|
|
29
29
|
registerTxDigest: string;
|
|
30
30
|
blobObjectId: string;
|
|
31
|
+
/**
|
|
32
|
+
* The road the registration was made for, from the record (D51). A part registered with no tip
|
|
33
|
+
* for the storage nodes must not go to a relay that checks for one on a resume.
|
|
34
|
+
*/
|
|
35
|
+
relayUrl?: string;
|
|
31
36
|
}): Promise<Certificate>;
|
|
32
37
|
}
|
|
33
38
|
/** The reservation as the server describes it. */
|
package/dist/upload.js
CHANGED
|
@@ -32,7 +32,7 @@ import { ServerError } from "./api.js";
|
|
|
32
32
|
import { readReservationBytes, readReservationRecord, writeReservation, } from "./upload-store.js";
|
|
33
33
|
import { refuseOtherSealing, runIdField } from "./upload-run.js";
|
|
34
34
|
import { pushPart } from "./upload-steps.js";
|
|
35
|
-
import {
|
|
35
|
+
import { isTipFree } from "./upload-road.js";
|
|
36
36
|
import { UploadError, } from "./upload-wire.js";
|
|
37
37
|
export * from "./upload-wire.js";
|
|
38
38
|
/** A reservation state that can still become storage. Anything else is dead. */
|
|
@@ -202,8 +202,8 @@ export async function buyAndPushPart(input) {
|
|
|
202
202
|
size: sealed.length,
|
|
203
203
|
epochs: input.epochs,
|
|
204
204
|
deposit_credits: input.depositCredits,
|
|
205
|
-
// The own relay (D50)
|
|
206
|
-
relay:
|
|
205
|
+
// The own relay (D50) and the storage nodes (D51) take no tip, so the treasury registers without one.
|
|
206
|
+
relay: isTipFree(input.relayUrl)
|
|
207
207
|
? null
|
|
208
208
|
: { host: input.relayUrl, blob_digest_b64: toBase64Url(meta.blobDigest), nonce_b64: nonceB64 },
|
|
209
209
|
});
|
package/dist/walrus-write.js
CHANGED
|
@@ -17,9 +17,11 @@ import { epochStartedMs as readEpochStart } from "./shared/lib/extend/epochs.js"
|
|
|
17
17
|
import { NmtsError } from "./errors.js";
|
|
18
18
|
import { countingFetch } from "./progress.js";
|
|
19
19
|
import { reachFetch } from "./reach.js";
|
|
20
|
-
import { isOwnRelay, relayFetch, uploadRelay } from "./upload-road.js";
|
|
20
|
+
import { isNodeRoad, isOwnRelay, ownRelayFallback, relayFetch, uploadRelay } from "./upload-road.js";
|
|
21
21
|
import { storageNodesThrough } from "./walrus.js";
|
|
22
22
|
import { suiClient } from "./sui-rpc.js";
|
|
23
|
+
import { stopAtQuorum } from "./shared/lib/walrus/node-quorum.js";
|
|
24
|
+
import { certifyByShardWeight } from "./shared/lib/walrus/node-certificate.js";
|
|
23
25
|
/**
|
|
24
26
|
* How long the relay gets for one blob PUT, sized to the body.
|
|
25
27
|
*
|
|
@@ -43,6 +45,29 @@ export function relayTimeoutMs(bodyBytes) {
|
|
|
43
45
|
* two level: the browser's number bounds a real payment made by a real wallet.
|
|
44
46
|
*/
|
|
45
47
|
const TIP_CEILING_UNUSED_MIST = 1;
|
|
48
|
+
/** What the storage nodes receive for one blob, about five times the blob (the erasure code). */
|
|
49
|
+
const NODE_WRITE_EXPANSION = 5;
|
|
50
|
+
/**
|
|
51
|
+
* A client with no relay, writing to the storage nodes itself (D51). Progress is the bodies the
|
|
52
|
+
* nodes accepted, counted in the blob's own bytes, and it stops just short of the end until the
|
|
53
|
+
* certificate is in.
|
|
54
|
+
*/
|
|
55
|
+
function direct(network, bodyBytes, onSent) {
|
|
56
|
+
let sent = 0;
|
|
57
|
+
const counted = async (input, init) => {
|
|
58
|
+
const res = await reachFetch(input, init);
|
|
59
|
+
const body = init?.body;
|
|
60
|
+
if (onSent && res.ok && body instanceof Uint8Array) {
|
|
61
|
+
sent += body.length;
|
|
62
|
+
onSent(Math.min(Math.floor(sent / NODE_WRITE_EXPANSION), Math.floor(bodyBytes * 0.99)), bodyBytes);
|
|
63
|
+
}
|
|
64
|
+
return res;
|
|
65
|
+
};
|
|
66
|
+
// The SDK would wait for every node; `stopAtQuorum` stops a little after a quorum confirmed (D51).
|
|
67
|
+
const client = suiClient(network === "mainnet" ? "mainnet" : "testnet").$extend(walrus({ storageNodeClientOptions: { fetch: counted, timeout: relayTimeoutMs(bodyBytes) } }));
|
|
68
|
+
certifyByShardWeight(stopAtQuorum(client.walrus));
|
|
69
|
+
return client;
|
|
70
|
+
}
|
|
46
71
|
function extend(network, relayUrl, bodyBytes, onSent) {
|
|
47
72
|
// ⛔ The network name reaches the SDK as well as the URL. A node pointed at the wrong chain
|
|
48
73
|
// would otherwise be discovered as a blob the storage nodes refuse, after the money moved.
|
|
@@ -76,7 +101,9 @@ function fail(what, error) {
|
|
|
76
101
|
*/
|
|
77
102
|
export function createBlobProtocol(network, bodyBytes, onSent) {
|
|
78
103
|
const relayUrl = uploadRelay(network);
|
|
79
|
-
|
|
104
|
+
// On the direct road this relay-shaped client computes the id, and carries a part to the own
|
|
105
|
+
// relay when the nodes did not take it; the bytes go to the nodes first.
|
|
106
|
+
const client = extend(network, isNodeRoad(relayUrl) ? (ownRelayFallback() ?? relayUrl) : relayUrl, bodyBytes, onSent);
|
|
80
107
|
return {
|
|
81
108
|
relayUrl,
|
|
82
109
|
async computeMetadata({ bytes, nonce }) {
|
|
@@ -101,7 +128,17 @@ export function createBlobProtocol(network, bodyBytes, onSent) {
|
|
|
101
128
|
blobDigest: await meta.blobDigest(),
|
|
102
129
|
};
|
|
103
130
|
},
|
|
104
|
-
async uploadToRelay({ blobId, bytes, nonce, registerTxDigest, blobObjectId }) {
|
|
131
|
+
async uploadToRelay({ blobId, bytes, nonce, registerTxDigest, blobObjectId, relayUrl: registeredFor }) {
|
|
132
|
+
if (isNodeRoad(registeredFor ?? relayUrl)) {
|
|
133
|
+
try {
|
|
134
|
+
return await writeToNodes(direct(network, bodyBytes, onSent), blobId, bytes, blobObjectId);
|
|
135
|
+
}
|
|
136
|
+
catch (nodeError) {
|
|
137
|
+
// The registration is road-free (no tip on either), so the same part can go to the own relay.
|
|
138
|
+
if (ownRelayFallback() === null || !isNodeRoad(relayUrl))
|
|
139
|
+
fail("The storage nodes did not take the bytes", nodeError);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
105
142
|
const { certificate } = await client.walrus
|
|
106
143
|
.writeBlobToUploadRelay({
|
|
107
144
|
blobId,
|
|
@@ -122,6 +159,34 @@ export function createBlobProtocol(network, bodyBytes, onSent) {
|
|
|
122
159
|
},
|
|
123
160
|
};
|
|
124
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Write one registered blob to the storage nodes and gather their signatures into the certificate
|
|
164
|
+
* the certify step needs: the same shape a relay hands back.
|
|
165
|
+
*/
|
|
166
|
+
async function writeToNodes(client, blobId, bytes, blobObjectId) {
|
|
167
|
+
const encoded = await client.walrus.encodeBlob(bytes);
|
|
168
|
+
// The id was computed and registered before; bytes that encode to another id would be refused.
|
|
169
|
+
if (encoded.blobId !== blobId)
|
|
170
|
+
throw new Error(`the bytes encode to ${encoded.blobId}, not the registered ${blobId}`);
|
|
171
|
+
const confirmations = await client.walrus.writeEncodedBlobToNodes({
|
|
172
|
+
blobId,
|
|
173
|
+
objectId: blobObjectId,
|
|
174
|
+
metadata: encoded.metadata,
|
|
175
|
+
sliversByNode: encoded.sliversByNode,
|
|
176
|
+
deletable: true,
|
|
177
|
+
});
|
|
178
|
+
const certificate = await client.walrus.certificateFromConfirmations({
|
|
179
|
+
confirmations,
|
|
180
|
+
blobId,
|
|
181
|
+
blobObjectId,
|
|
182
|
+
deletable: true,
|
|
183
|
+
});
|
|
184
|
+
return {
|
|
185
|
+
signers: certificate.signers,
|
|
186
|
+
serialized_message_b64: toBase64Url(certificate.serializedMessage),
|
|
187
|
+
signature_b64: toBase64Url(certificate.signature),
|
|
188
|
+
};
|
|
189
|
+
}
|
|
125
190
|
/**
|
|
126
191
|
* The storage network's current epoch, or `null` when it could not be read.
|
|
127
192
|
*
|
package/dist/walrus.d.ts
CHANGED
|
@@ -7,6 +7,12 @@
|
|
|
7
7
|
* provenance and the reason each host and not another; this copy exists because this package
|
|
8
8
|
* imports nothing from that tree, and `deploy/check-walrus-hosts.mjs` set-compares the two.
|
|
9
9
|
*/
|
|
10
|
+
export declare const PINNED_AGGREGATOR_HOSTS: Readonly<Record<string, readonly string[]>>;
|
|
11
|
+
/**
|
|
12
|
+
* ⭐ D51: the two rows above, then every other aggregator in Walrus's operator registry that served
|
|
13
|
+
* the probe blob (`deploy/gen-roads.mjs`, the same generated list the browser and its CSP read).
|
|
14
|
+
* A read asks them as a staggered race, so a dead row costs a second and a half, not a timeout.
|
|
15
|
+
*/
|
|
10
16
|
export declare const AGGREGATOR_HOSTS: Readonly<Record<string, readonly string[]>>;
|
|
11
17
|
/**
|
|
12
18
|
* Curated Walrus upload-relay (write) endpoints per network, preference order.
|
|
@@ -16,8 +22,15 @@ export declare const AGGREGATOR_HOSTS: Readonly<Record<string, readonly string[]
|
|
|
16
22
|
* reservation was made for. That is why a write picks its host BEFORE the storage is bought and
|
|
17
23
|
* then never moves: failing over to a second relay would push bytes nobody paid that relay for.
|
|
18
24
|
*
|
|
19
|
-
* ⭐ THE SECOND
|
|
20
|
-
*
|
|
25
|
+
* ⭐ THE SECOND ROW (D51, 2026-11-10) is Studio Mirai's public relay, an operator in Walrus's registry
|
|
26
|
+
* whose relay the registry does not list: found by asking each registry operator's relay-shaped
|
|
27
|
+
* name for `/v1/tip-config` (two of 366 answered, this one on both networks). Its tip is 3,000,000
|
|
28
|
+
* MIST plus 60 per encoded KiB, above Mysten's, so it is the second choice and only on a wallet
|
|
29
|
+
* upload (the person pays it and sees it first; the treasury pays only the relays the chain
|
|
30
|
+
* service allows). Picked once at the start of a run, like the roads after it (`upload-road.ts`).
|
|
31
|
+
*
|
|
32
|
+
* ⭐ THE LATER ROADS ARE NOT ROWS HERE (D50 · D51): the storage nodes, then NMTS's own no-tip relay,
|
|
33
|
+
* chosen once at the start of a run, before the price, only when no relay here answers.
|
|
21
34
|
*/
|
|
22
35
|
export declare const RELAY_HOSTS: Readonly<Record<string, readonly string[]>>;
|
|
23
36
|
/**
|
|
@@ -34,11 +47,14 @@ export declare const RELAY_HOSTS: Readonly<Record<string, readonly string[]>>;
|
|
|
34
47
|
* (mainnet). Every host below answered chain id, a balance, an object and the gas price over
|
|
35
48
|
* gRPC-web that morning. Two operators per network — Suiscan and Mysten Labs — in the browser's
|
|
36
49
|
* order (`web/src/lib/walrus/network-hosts.ts` says why mainnet keeps Suiscan first). A test
|
|
37
|
-
* and `deploy/check-walrus-hosts.mjs` hold this table to the browser's.
|
|
50
|
+
* and `deploy/check-walrus-hosts.mjs` hold this table to the browser's. Since 2026-11-10 (D51)
|
|
51
|
+
* mainnet adds 01NODE and PublicNode (Allnodes) after those two, measured answering.
|
|
38
52
|
*/
|
|
39
53
|
export declare const SUI_RPC_HOSTS: Readonly<Record<string, readonly string[]>>;
|
|
40
|
-
/** How long one host gets before
|
|
54
|
+
/** How long one host gets before it is given up. A read that stalls is a read that failed. */
|
|
41
55
|
export declare const READ_TIMEOUT_MS = 60000;
|
|
56
|
+
/** How long the race waits for an answer before it asks the next host as well (D51). */
|
|
57
|
+
export declare const READ_HEDGE_MS = 1500;
|
|
42
58
|
export { AGGREGATOR_ENV_VAR, RELAY_ENV_VAR, SUI_RPC_ENV_VAR } from "./env-vars.ts";
|
|
43
59
|
/**
|
|
44
60
|
* The relay this run writes through: the caller's if it named one, then the environment's, then
|
package/dist/walrus.js
CHANGED
|
@@ -14,6 +14,8 @@ import { AGGREGATOR_ENV_VAR, RELAY_ENV_VAR, SUI_RPC_ENV_VAR } from "./env-vars.j
|
|
|
14
14
|
import { NmtsError } from "./errors.js";
|
|
15
15
|
import { host as runtime } from "./host.js";
|
|
16
16
|
import { reach, reachFetch } from "./reach.js";
|
|
17
|
+
import { raceHosts } from "./read-race.js";
|
|
18
|
+
import { REGISTRY_AGGREGATORS } from "./road-hosts.generated.js";
|
|
17
19
|
/**
|
|
18
20
|
* Curated Walrus aggregator (read) endpoints per network, preference order.
|
|
19
21
|
*
|
|
@@ -23,7 +25,7 @@ import { reach, reachFetch } from "./reach.js";
|
|
|
23
25
|
* provenance and the reason each host and not another; this copy exists because this package
|
|
24
26
|
* imports nothing from that tree, and `deploy/check-walrus-hosts.mjs` set-compares the two.
|
|
25
27
|
*/
|
|
26
|
-
export const
|
|
28
|
+
export const PINNED_AGGREGATOR_HOSTS = {
|
|
27
29
|
testnet: [
|
|
28
30
|
"https://aggregator.walrus-testnet.walrus.space",
|
|
29
31
|
"https://walrus-testnet-aggregator.nodeinfra.com",
|
|
@@ -33,6 +35,19 @@ export const AGGREGATOR_HOSTS = {
|
|
|
33
35
|
"https://sui-walrus-mainnet-aggregator.bwarelabs.com",
|
|
34
36
|
],
|
|
35
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* ⭐ D51: the two rows above, then every other aggregator in Walrus's operator registry that served
|
|
40
|
+
* the probe blob (`deploy/gen-roads.mjs`, the same generated list the browser and its CSP read).
|
|
41
|
+
* A read asks them as a staggered race, so a dead row costs a second and a half, not a timeout.
|
|
42
|
+
*/
|
|
43
|
+
export const AGGREGATOR_HOSTS = {
|
|
44
|
+
testnet: withRegistry("testnet"),
|
|
45
|
+
mainnet: withRegistry("mainnet"),
|
|
46
|
+
};
|
|
47
|
+
function withRegistry(network) {
|
|
48
|
+
const pinned = PINNED_AGGREGATOR_HOSTS[network] ?? [];
|
|
49
|
+
return [...pinned, ...REGISTRY_AGGREGATORS[network].filter((h) => !pinned.includes(h))];
|
|
50
|
+
}
|
|
36
51
|
/**
|
|
37
52
|
* Curated Walrus upload-relay (write) endpoints per network, preference order.
|
|
38
53
|
*
|
|
@@ -41,12 +56,19 @@ export const AGGREGATOR_HOSTS = {
|
|
|
41
56
|
* reservation was made for. That is why a write picks its host BEFORE the storage is bought and
|
|
42
57
|
* then never moves: failing over to a second relay would push bytes nobody paid that relay for.
|
|
43
58
|
*
|
|
44
|
-
* ⭐ THE SECOND
|
|
45
|
-
*
|
|
59
|
+
* ⭐ THE SECOND ROW (D51, 2026-11-10) is Studio Mirai's public relay, an operator in Walrus's registry
|
|
60
|
+
* whose relay the registry does not list: found by asking each registry operator's relay-shaped
|
|
61
|
+
* name for `/v1/tip-config` (two of 366 answered, this one on both networks). Its tip is 3,000,000
|
|
62
|
+
* MIST plus 60 per encoded KiB, above Mysten's, so it is the second choice and only on a wallet
|
|
63
|
+
* upload (the person pays it and sees it first; the treasury pays only the relays the chain
|
|
64
|
+
* service allows). Picked once at the start of a run, like the roads after it (`upload-road.ts`).
|
|
65
|
+
*
|
|
66
|
+
* ⭐ THE LATER ROADS ARE NOT ROWS HERE (D50 · D51): the storage nodes, then NMTS's own no-tip relay,
|
|
67
|
+
* chosen once at the start of a run, before the price, only when no relay here answers.
|
|
46
68
|
*/
|
|
47
69
|
export const RELAY_HOSTS = {
|
|
48
|
-
testnet: ["https://upload-relay.testnet.walrus.space"],
|
|
49
|
-
mainnet: ["https://upload-relay.mainnet.walrus.space"],
|
|
70
|
+
testnet: ["https://upload-relay.testnet.walrus.space", "https://upload-relay.testnet.walrus.mirai.cloud"],
|
|
71
|
+
mainnet: ["https://upload-relay.mainnet.walrus.space", "https://upload-relay.mainnet.walrus.mirai.cloud"],
|
|
50
72
|
};
|
|
51
73
|
/**
|
|
52
74
|
* Sui node endpoints per network, spoken to over gRPC-web (`sui-rpc.ts`), first-that-answers.
|
|
@@ -62,14 +84,28 @@ export const RELAY_HOSTS = {
|
|
|
62
84
|
* (mainnet). Every host below answered chain id, a balance, an object and the gas price over
|
|
63
85
|
* gRPC-web that morning. Two operators per network — Suiscan and Mysten Labs — in the browser's
|
|
64
86
|
* order (`web/src/lib/walrus/network-hosts.ts` says why mainnet keeps Suiscan first). A test
|
|
65
|
-
* and `deploy/check-walrus-hosts.mjs` hold this table to the browser's.
|
|
87
|
+
* and `deploy/check-walrus-hosts.mjs` hold this table to the browser's. Since 2026-11-10 (D51)
|
|
88
|
+
* mainnet adds 01NODE and PublicNode (Allnodes) after those two, measured answering.
|
|
66
89
|
*/
|
|
67
90
|
export const SUI_RPC_HOSTS = {
|
|
68
91
|
testnet: ["https://fullnode.testnet.sui.io", "https://rpc-testnet.suiscan.xyz"],
|
|
69
|
-
mainnet: [
|
|
92
|
+
mainnet: [
|
|
93
|
+
"https://rpc-mainnet.suiscan.xyz",
|
|
94
|
+
"https://fullnode.mainnet.sui.io",
|
|
95
|
+
"https://sui.01.ro",
|
|
96
|
+
"https://sui-grpc-web.publicnode.com",
|
|
97
|
+
],
|
|
70
98
|
};
|
|
71
|
-
/** How long one host gets before
|
|
99
|
+
/** How long one host gets before it is given up. A read that stalls is a read that failed. */
|
|
72
100
|
export const READ_TIMEOUT_MS = 60_000;
|
|
101
|
+
/** How long the race waits for an answer before it asks the next host as well (D51). */
|
|
102
|
+
export const READ_HEDGE_MS = 1_500;
|
|
103
|
+
/** At most this many hosts waiting at once, hanging ones included. */
|
|
104
|
+
const READ_MAX_IN_FLIGHT = 12;
|
|
105
|
+
/** A host that sends no headers in this long is given up, so hanging hosts do not hold the race. */
|
|
106
|
+
const READ_HEADER_TIMEOUT_MS = 20_000;
|
|
107
|
+
/** This many 404s, and no other answer, mean the bytes are not there; asking dozens more says the same. */
|
|
108
|
+
const NOT_FOUND_QUORUM = 3;
|
|
73
109
|
// Re-exported so every caller still finds them here; the names themselves live in a module with no
|
|
74
110
|
// imports, because `nmts --help` prints them (`env-vars.ts`).
|
|
75
111
|
export { AGGREGATOR_ENV_VAR, RELAY_ENV_VAR, SUI_RPC_ENV_VAR } from "./env-vars.js";
|
|
@@ -155,13 +191,13 @@ function fromEnvironment() {
|
|
|
155
191
|
*/
|
|
156
192
|
function hostsFor(network, options) {
|
|
157
193
|
if (options.hosts !== undefined && options.hosts.length > 0)
|
|
158
|
-
return options.hosts;
|
|
194
|
+
return { hosts: options.hosts, named: true };
|
|
159
195
|
const asked = reach().aggregators;
|
|
160
196
|
if (asked !== undefined && asked.length > 0)
|
|
161
|
-
return asked;
|
|
197
|
+
return { hosts: asked, named: true };
|
|
162
198
|
const chosen = fromEnvironment();
|
|
163
199
|
if (chosen !== null)
|
|
164
|
-
return chosen;
|
|
200
|
+
return { hosts: chosen, named: true };
|
|
165
201
|
const known = AGGREGATOR_HOSTS[network];
|
|
166
202
|
if (known === undefined) {
|
|
167
203
|
throw new NmtsError(`No storage-network hosts are known for "${network}".`, {
|
|
@@ -169,28 +205,73 @@ function hostsFor(network, options) {
|
|
|
169
205
|
nextStep: "Use --network mainnet or --network testnet.",
|
|
170
206
|
});
|
|
171
207
|
}
|
|
172
|
-
return known;
|
|
208
|
+
return { hosts: known, named: false };
|
|
173
209
|
}
|
|
174
210
|
/**
|
|
175
|
-
* Fetch one stored object,
|
|
211
|
+
* Fetch one stored object: the hosts as a staggered race, then the storage nodes themselves (D51).
|
|
176
212
|
*
|
|
177
213
|
* ⛔ It reports what it tried. A read that fails everywhere is either a blob that is gone, a
|
|
178
214
|
* network that is wrong, or hosts that are all down, and those need different next steps — a
|
|
179
215
|
* bare "not found" would send somebody looking for the wrong one.
|
|
180
216
|
*/
|
|
181
|
-
async function readFrom(network, pathOf, what, options) {
|
|
182
|
-
const hosts = hostsFor(network, options);
|
|
217
|
+
async function readFrom(network, pathOf, what, options, node) {
|
|
218
|
+
const { hosts, named } = hostsFor(network, options);
|
|
183
219
|
const tried = [];
|
|
184
|
-
|
|
220
|
+
const raced = await readRace(hosts, pathOf, options, tried);
|
|
221
|
+
if (raced !== null)
|
|
222
|
+
return raced;
|
|
223
|
+
const notFound = tried.filter((t) => t.endsWith("→ 404")).length;
|
|
224
|
+
const sawOther = tried.length > notFound;
|
|
225
|
+
// ⭐ D51: the storage nodes, when no aggregator served the bytes for a reason other than "not
|
|
226
|
+
// found". Not when somebody named the hosts: naming them says "those", as above.
|
|
227
|
+
if (node !== undefined && !named && sawOther && options.signal?.aborted !== true) {
|
|
228
|
+
try {
|
|
229
|
+
const bytes = await (await import("./node-read.js")).readFromNodes(network, node.kind, node.id);
|
|
230
|
+
const range = options.range;
|
|
231
|
+
return range === undefined ? bytes : bytes.subarray(range.start, Math.min(range.end, bytes.length));
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
tried.push(`the storage nodes → ${error instanceof Error ? error.message : "no answer"}`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
throw new NmtsError(`${what} could not be read from the ${network} storage network.`, {
|
|
238
|
+
exitCode: 5,
|
|
239
|
+
nextStep: `Tried: ${tried.join(" · ")}. If every host answered 404, either the bytes are gone or ` +
|
|
240
|
+
`this is the wrong network — the same identifier does not exist on both.`,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Ask every host for one object as a staggered race (`read-race.ts`) and return the first body.
|
|
245
|
+
*
|
|
246
|
+
* ⛔ The reason each host failed is kept, not flattened to "failed". A timeout and a refused
|
|
247
|
+
* connection mean different things, and the reasons are what the person reads.
|
|
248
|
+
*/
|
|
249
|
+
function readRace(hosts, pathOf, options, tried) {
|
|
250
|
+
const overall = AbortSignal.timeout(options.timeoutMs ?? READ_TIMEOUT_MS);
|
|
251
|
+
const reason = (error) => (error instanceof Error ? error.message : "no answer");
|
|
252
|
+
return raceHosts(hosts, async (host, signal) => {
|
|
185
253
|
const url = pathOf(host.replace(/\/$/, ""));
|
|
186
|
-
const timer = AbortSignal.timeout(options.timeoutMs ?? READ_TIMEOUT_MS);
|
|
187
|
-
const signal = options.signal === undefined ? timer : AbortSignal.any([timer, options.signal]);
|
|
188
254
|
try {
|
|
189
|
-
const response = await reachFetch(url, {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
255
|
+
const response = await reachFetch(url, {
|
|
256
|
+
signal: AbortSignal.any([signal, overall]),
|
|
257
|
+
redirect: "follow",
|
|
258
|
+
...headersFor(options),
|
|
259
|
+
});
|
|
260
|
+
if (response.ok)
|
|
261
|
+
return { response };
|
|
262
|
+
tried.push(`${host} → ${response.status}`);
|
|
263
|
+
void response.body?.cancel();
|
|
264
|
+
return response.status === 404 ? "not-found" : "failed";
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
// A host stopped because another one answered first is not a failure worth reporting.
|
|
268
|
+
if (!(signal.aborted && signal.reason instanceof DOMException && signal.reason.name === "AbortError")) {
|
|
269
|
+
tried.push(`${host} → ${reason(error)}`);
|
|
193
270
|
}
|
|
271
|
+
return "failed";
|
|
272
|
+
}
|
|
273
|
+
}, async (host, response) => {
|
|
274
|
+
try {
|
|
194
275
|
const body = new Uint8Array(await response.arrayBuffer());
|
|
195
276
|
const range = options.range;
|
|
196
277
|
if (range === undefined)
|
|
@@ -199,22 +280,20 @@ async function readFrom(network, pathOf, what, options) {
|
|
|
199
280
|
// A 206 already holds exactly the asked-for bytes; a 200 holds the object from byte zero.
|
|
200
281
|
if (body.length === want)
|
|
201
282
|
return body;
|
|
202
|
-
if (body.length < range.end)
|
|
203
|
-
|
|
204
|
-
continue;
|
|
205
|
-
}
|
|
283
|
+
if (body.length < range.end)
|
|
284
|
+
throw new Error(`answered ${body.length} bytes for a ${want}-byte range`);
|
|
206
285
|
return body.subarray(range.start, range.end);
|
|
207
286
|
}
|
|
208
287
|
catch (error) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
tried.push(`${host} → ${error instanceof Error ? error.message : "no answer"}`);
|
|
288
|
+
tried.push(`${host} → ${reason(error)}`);
|
|
289
|
+
throw error;
|
|
212
290
|
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
291
|
+
}, {
|
|
292
|
+
hedgeMs: READ_HEDGE_MS,
|
|
293
|
+
maxInFlight: READ_MAX_IN_FLIGHT,
|
|
294
|
+
headerTimeoutMs: READ_HEADER_TIMEOUT_MS,
|
|
295
|
+
notFoundQuorum: NOT_FOUND_QUORUM,
|
|
296
|
+
signal: options.signal,
|
|
218
297
|
});
|
|
219
298
|
}
|
|
220
299
|
/** The `Range` header for a partial read, or nothing at all for a whole one. */
|
|
@@ -227,7 +306,7 @@ function headersFor(options) {
|
|
|
227
306
|
}
|
|
228
307
|
/** Whole-blob read: `GET {aggregator}/v1/blobs/{blobId}`. */
|
|
229
308
|
export function readBlob(network, blobId, options = {}) {
|
|
230
|
-
return readFrom(network, (host) => `${host}/v1/blobs/${encodeURIComponent(blobId)}`, `Blob ${blobId}`, options);
|
|
309
|
+
return readFrom(network, (host) => `${host}/v1/blobs/${encodeURIComponent(blobId)}`, `Blob ${blobId}`, options, { kind: "blob", id: blobId });
|
|
231
310
|
}
|
|
232
311
|
/**
|
|
233
312
|
* Quilt-patch read: `GET {aggregator}/v1/blobs/by-quilt-patch-id/{patchId}`.
|
|
@@ -236,5 +315,5 @@ export function readBlob(network, blobId, options = {}) {
|
|
|
236
315
|
* under 64 MiB share a quilt, so this is the common path rather than the exotic one.
|
|
237
316
|
*/
|
|
238
317
|
export function readQuiltPatch(network, patchId, options = {}) {
|
|
239
|
-
return readFrom(network, (host) => `${host}/v1/blobs/by-quilt-patch-id/${encodeURIComponent(patchId)}`, `Quilt patch ${patchId}`, options);
|
|
318
|
+
return readFrom(network, (host) => `${host}/v1/blobs/by-quilt-patch-id/${encodeURIComponent(patchId)}`, `Quilt patch ${patchId}`, options, { kind: "patch", id: patchId });
|
|
240
319
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needmoretruth/nmts-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.55.0",
|
|
4
4
|
"description": "Command-line and MCP access to NMTS (NeedMoreTruthStorage, https://nmts.me): open-source, end-to-end encrypted storage on the Walrus network. No fee to NMTS; you pay the network from your own wallet. For people and for their agents.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"publishConfig": {
|
package/server.json
CHANGED
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
"url": "https://github.com/needmoretruth/nmts-cli",
|
|
7
7
|
"source": "github"
|
|
8
8
|
},
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.55.0",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"registryBaseUrl": "https://registry.npmjs.org",
|
|
14
14
|
"identifier": "@needmoretruth/nmts-cli",
|
|
15
|
-
"version": "0.
|
|
15
|
+
"version": "0.55.0",
|
|
16
16
|
"transport": {
|
|
17
17
|
"type": "stdio"
|
|
18
18
|
},
|