@needmoretruth/nmts-cli 0.54.1 → 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 +20 -0
- package/README.ko.md +1 -1
- package/README.md +1 -1
- package/dist/artifact-about.d.ts +1 -1
- package/dist/client-id.d.ts +1 -1
- package/dist/client-id.js +1 -1
- package/dist/commands/push.js +5 -1
- package/dist/commands/put-wallet.js +5 -1
- package/dist/commands/put.js +5 -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 +55 -0
- package/dist/upload-road.js +155 -0
- package/dist/upload-steps.js +1 -0
- package/dist/upload-wallet-chain.d.ts +1 -1
- package/dist/upload-wallet-chain.js +17 -4
- package/dist/upload-wallet.js +1 -0
- package/dist/upload-wire.d.ts +7 -1
- package/dist/upload.js +5 -5
- package/dist/walrus-write.js +73 -6
- package/dist/walrus.d.ts +21 -2
- package/dist/walrus.js +116 -34
- package/package.json +1 -1
- package/server.json +2 -2
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The roads an upload from this tool can take (D50 · D51, 2026-11-09).
|
|
3
|
+
*
|
|
4
|
+
* ⭐ ORDER (owner, 2026-11-09). Mysten Labs' relay; when it does not answer, the Walrus storage
|
|
5
|
+
* nodes straight from this machine (`NODE_ROAD`, no relay, no tip); NMTS's own relay last, only
|
|
6
|
+
* for a part the direct write could not carry. The own relay is a server the owner pays for and
|
|
7
|
+
* shares with the site, so it is the road taken when nothing else carried the bytes.
|
|
8
|
+
* Between them, the other company relays of `RELAY_HOSTS` (Studio Mirai since 2026-11-10, found by
|
|
9
|
+
* a live probe; the registry lists no relays). On a wallet upload the person pays that relay's tip
|
|
10
|
+
* and sees it before signing. On a credit upload the treasury pays it only while its tip fits the
|
|
11
|
+
* credit ceiling at every size (`credit-tip.ts`, three times Mysten's formula; the chain service
|
|
12
|
+
* refuses above it), because this road is chosen before the size is known.
|
|
13
|
+
*
|
|
14
|
+
* ⭐ THE TWO LAST ROADS COST THE SAME AND CUT THE SAME. Neither takes a tip, and both send 64 MiB
|
|
15
|
+
* parts, so the price shown before the first signature holds whichever of them carries a part,
|
|
16
|
+
* and the registration a part was bought with serves either.
|
|
17
|
+
*
|
|
18
|
+
* ⛔ WHY. Every upload reached Walrus through Mysten Labs' relay alone; the day it stops answering,
|
|
19
|
+
* nobody can upload. NMTS runs the same relay software (Mysten's image, no tip) behind its own
|
|
20
|
+
* api at `/v1/relay`. This tool asks Mysten's relay once, before anything is priced, and takes
|
|
21
|
+
* the own road only when that relay refuses or does not answer. A relay the caller or the
|
|
22
|
+
* environment named is never second-guessed.
|
|
23
|
+
*
|
|
24
|
+
* ⛔ CHOSEN BEFORE THE PRICE. The own relay holds about five times a blob in memory (measured
|
|
25
|
+
* 2026-11-09: 64 MiB → 354 MiB peak), so on that road a file is cut into 64 MiB parts, and the
|
|
26
|
+
* credits quoted are the credits of those parts. A road chosen after a quote would charge a number
|
|
27
|
+
* nobody was shown; this module is asked first and the part size follows from its answer.
|
|
28
|
+
*
|
|
29
|
+
* The same path and part size as the browser's (`web/src/lib/walrus/own-relay.ts`); the route
|
|
30
|
+
* table (`deploy/core-routes.json`) names both.
|
|
31
|
+
*/
|
|
32
|
+
import { reachFetch } from "./reach.js";
|
|
33
|
+
import { RELAY_HOSTS, relayHost } from "./walrus.js";
|
|
34
|
+
import { creditTipFitsEverySize, tipLine } from "./shared/lib/walrus/credit-tip.js";
|
|
35
|
+
import { parseTipConfig } from "./shared/lib/walrus/tip-config.js";
|
|
36
|
+
/** Where the own relay answers, after the NMTS server's address. */
|
|
37
|
+
export const OWN_RELAY_PATH = "/v1/relay";
|
|
38
|
+
/** The part size on the own road: an existing preset, the size whose relay peak fits the server. */
|
|
39
|
+
export const OWN_RELAY_PART_BYTES = 64 * 2 ** 20;
|
|
40
|
+
/** How long Mysten's relay gets to answer before this run takes the own road. */
|
|
41
|
+
export const ROAD_PROBE_TIMEOUT_MS = 10_000;
|
|
42
|
+
/**
|
|
43
|
+
* The "relay address" of the direct road: no host, the storage nodes themselves (D51). The same
|
|
44
|
+
* value as the browser's (`web/src/lib/walrus/node-road.ts`), and it is what a resumable upload's
|
|
45
|
+
* record keeps, so a resumed part goes back to the nodes.
|
|
46
|
+
*/
|
|
47
|
+
export const NODE_ROAD = "walrus:storage-nodes";
|
|
48
|
+
/** True for the direct road. */
|
|
49
|
+
export function isNodeRoad(relayUrl) {
|
|
50
|
+
return relayUrl === NODE_ROAD;
|
|
51
|
+
}
|
|
52
|
+
/** True for a road that takes no tip: the own relay and the storage nodes. */
|
|
53
|
+
export function isTipFree(relayUrl) {
|
|
54
|
+
return isNodeRoad(relayUrl) || isOwnRelay(relayUrl);
|
|
55
|
+
}
|
|
56
|
+
let chosen = null;
|
|
57
|
+
/** A company relay after Mysten's, taken when Mysten's did not answer (D51). */
|
|
58
|
+
let companyRelay = null;
|
|
59
|
+
/** True for the own relay's address on any NMTS server. */
|
|
60
|
+
export function isOwnRelay(relayUrl) {
|
|
61
|
+
return relayUrl.replace(/\/+$/, "").endsWith(OWN_RELAY_PATH);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Decide this run's road, once, before anything is priced. True when a small road (the storage
|
|
65
|
+
* nodes, or the own relay) was taken.
|
|
66
|
+
*
|
|
67
|
+
* `probe` is the request that asks Mysten's relay (tests pass a fake one). `nodeRoad: false` is a
|
|
68
|
+
* machine that cannot write to the storage nodes itself; it goes to the own relay, as before D51.
|
|
69
|
+
*/
|
|
70
|
+
export async function chooseUploadRoad(input) {
|
|
71
|
+
chosen = null;
|
|
72
|
+
companyRelay = null;
|
|
73
|
+
const relays = RELAY_HOSTS[input.network] ?? [];
|
|
74
|
+
const known = relays[0];
|
|
75
|
+
// A caller or an environment that named a relay chose it; nothing is asked.
|
|
76
|
+
if (known === undefined || relayHost(input.network) !== known)
|
|
77
|
+
return false;
|
|
78
|
+
const probe = input.probe ?? reachFetch;
|
|
79
|
+
const answers = async (relay) => {
|
|
80
|
+
try {
|
|
81
|
+
const res = await probe(`${relay}/v1/tip-config`, {
|
|
82
|
+
signal: AbortSignal.timeout(input.timeoutMs ?? ROAD_PROBE_TIMEOUT_MS),
|
|
83
|
+
});
|
|
84
|
+
if (!res.ok)
|
|
85
|
+
return false;
|
|
86
|
+
// Mysten's own price is the reference; another company's must fit the credit ceiling.
|
|
87
|
+
if (input.credit !== true || relay === known)
|
|
88
|
+
return true;
|
|
89
|
+
const line = tipLine(parseTipConfig(await res.json()));
|
|
90
|
+
return line !== null && creditTipFitsEverySize(line);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
// Asked together, so a dead relay costs one timeout, not one each; Mysten's answer wins.
|
|
97
|
+
const others = input.otherCompanies === true || input.credit === true ? relays.slice(1) : [];
|
|
98
|
+
const answered = await Promise.all([known, ...others].map(answers));
|
|
99
|
+
if (answered[0])
|
|
100
|
+
return false;
|
|
101
|
+
const other = others.find((_, i) => answered[i + 1]);
|
|
102
|
+
if (other !== undefined) {
|
|
103
|
+
companyRelay = other;
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
const ownUrl = `${input.server.replace(/\/+$/, "")}${OWN_RELAY_PATH}`;
|
|
107
|
+
chosen = { relayUrl: input.nodeRoad === false ? ownUrl : NODE_ROAD, apiKey: input.apiKey, ownUrl };
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The own relay to try when a direct write failed, with the fetch that carries this account's key,
|
|
112
|
+
* or null when this run did not choose the small roads (a named relay, or Mysten's).
|
|
113
|
+
*/
|
|
114
|
+
export function ownRelayFallback() {
|
|
115
|
+
return chosen === null || chosen.relayUrl === chosen.ownUrl ? null : chosen.ownUrl;
|
|
116
|
+
}
|
|
117
|
+
/** Forget the choice (tests; a library caller between runs). */
|
|
118
|
+
export function resetUploadRoad() {
|
|
119
|
+
chosen = null;
|
|
120
|
+
companyRelay = null;
|
|
121
|
+
}
|
|
122
|
+
/** The road this run writes through: the storage nodes or the own relay when chosen, else the usual relay. */
|
|
123
|
+
export function uploadRelay(network) {
|
|
124
|
+
return chosen?.relayUrl ?? companyRelay ?? relayHost(network);
|
|
125
|
+
}
|
|
126
|
+
/** The part size a fresh upload uses: unchanged on Mysten's road, at most 64 MiB on the small roads. */
|
|
127
|
+
export function partSizeForRoad(partSize) {
|
|
128
|
+
return chosen === null ? partSize : Math.min(partSize, OWN_RELAY_PART_BYTES);
|
|
129
|
+
}
|
|
130
|
+
const wait = (ms, signal) => new Promise((resolve, reject) => {
|
|
131
|
+
if (signal?.aborted)
|
|
132
|
+
return reject(signal.reason);
|
|
133
|
+
const timer = setTimeout(resolve, ms);
|
|
134
|
+
signal?.addEventListener("abort", () => {
|
|
135
|
+
clearTimeout(timer);
|
|
136
|
+
reject(signal.reason);
|
|
137
|
+
}, { once: true });
|
|
138
|
+
});
|
|
139
|
+
export function relayFetch(relayUrl, inner, sleep = wait) {
|
|
140
|
+
const road = chosen;
|
|
141
|
+
if (road === null || road.ownUrl !== relayUrl)
|
|
142
|
+
return inner;
|
|
143
|
+
return async (input, init) => {
|
|
144
|
+
const headers = new Headers(init?.headers);
|
|
145
|
+
headers.set("authorization", `Bearer ${road.apiKey}`);
|
|
146
|
+
for (;;) {
|
|
147
|
+
const res = await inner(input, { ...init, headers });
|
|
148
|
+
const after = res.headers.get("retry-after");
|
|
149
|
+
if (res.status !== 503 || after === null)
|
|
150
|
+
return res;
|
|
151
|
+
const seconds = Number(after);
|
|
152
|
+
await sleep(Math.max(1, Number.isFinite(seconds) ? seconds : 15) * 1000, init?.signal);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
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,6 +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 { isNodeRoad, isOwnRelay, ownRelayFallback, relayFetch } from "./upload-road.js";
|
|
29
30
|
import { storageNodesThrough } from "./walrus.js";
|
|
30
31
|
import { freshWalrus } from "./walrus-fresh.js";
|
|
31
32
|
import { suiClient } from "./sui-rpc.js";
|
|
@@ -39,18 +40,30 @@ import { chainReader } from "./wallet-chain.js";
|
|
|
39
40
|
* tip configuration sets the amount, which the review prints — and a relay asking for more than
|
|
40
41
|
* this is refused by the SDK before anything is signed.
|
|
41
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.
|
|
42
45
|
export const RELAY_TIP_CEILING_MIST = {
|
|
43
|
-
testnet:
|
|
44
|
-
mainnet:
|
|
46
|
+
testnet: 50_000_000,
|
|
47
|
+
mainnet: 400_000_000,
|
|
45
48
|
};
|
|
46
49
|
/** The Walrus package addresses of one network. Exported from the SDK; the system object survives upgrades. */
|
|
47
50
|
export function packageConfig(network) {
|
|
48
51
|
return network === "mainnet" ? MAINNET_WALRUS_PACKAGE_CONFIG : TESTNET_WALRUS_PACKAGE_CONFIG;
|
|
49
52
|
}
|
|
50
|
-
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() }));
|
|
51
59
|
return suiClient(network).$extend(walrus({
|
|
52
60
|
...storageNodesThrough(),
|
|
53
|
-
uploadRelay: {
|
|
61
|
+
uploadRelay: {
|
|
62
|
+
host: relayUrl,
|
|
63
|
+
// The own relay (D50) takes no tip: no tip is paid and none is announced.
|
|
64
|
+
...(isOwnRelay(relayUrl) ? {} : { sendTip: { max: RELAY_TIP_CEILING_MIST[network] } }),
|
|
65
|
+
fetch: relayFetch(relayUrl, reachFetch),
|
|
66
|
+
},
|
|
54
67
|
}));
|
|
55
68
|
}
|
|
56
69
|
/** A Walrus client bound to ONE relay, able to pay that relay's tip. */
|
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. */
|
|
@@ -62,11 +67,12 @@ export interface UploadApi {
|
|
|
62
67
|
* already been told, which is how a screen and a ledger come to disagree.
|
|
63
68
|
*/
|
|
64
69
|
deposit_credits: number;
|
|
70
|
+
/** Null on NMTS's own relay, which takes no tip (D50). */
|
|
65
71
|
relay: {
|
|
66
72
|
host: string;
|
|
67
73
|
blob_digest_b64: string;
|
|
68
74
|
nonce_b64: string;
|
|
69
|
-
};
|
|
75
|
+
} | null;
|
|
70
76
|
}): Promise<ReserveReply>;
|
|
71
77
|
status(ledgerId: number): Promise<StatusReply>;
|
|
72
78
|
uploaded(ledgerId: number, certificate: Certificate): Promise<unknown>;
|
package/dist/upload.js
CHANGED
|
@@ -32,6 +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 { isTipFree } from "./upload-road.js";
|
|
35
36
|
import { UploadError, } from "./upload-wire.js";
|
|
36
37
|
export * from "./upload-wire.js";
|
|
37
38
|
/** A reservation state that can still become storage. Anything else is dead. */
|
|
@@ -201,11 +202,10 @@ export async function buyAndPushPart(input) {
|
|
|
201
202
|
size: sealed.length,
|
|
202
203
|
epochs: input.epochs,
|
|
203
204
|
deposit_credits: input.depositCredits,
|
|
204
|
-
relay
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
nonce_b64: nonceB64,
|
|
208
|
-
},
|
|
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
|
+
? null
|
|
208
|
+
: { host: input.relayUrl, blob_digest_b64: toBase64Url(meta.blobDigest), nonce_b64: nonceB64 },
|
|
209
209
|
});
|
|
210
210
|
}
|
|
211
211
|
catch (error) {
|
package/dist/walrus-write.js
CHANGED
|
@@ -17,8 +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 {
|
|
20
|
+
import { isNodeRoad, isOwnRelay, ownRelayFallback, relayFetch, uploadRelay } from "./upload-road.js";
|
|
21
|
+
import { storageNodesThrough } from "./walrus.js";
|
|
21
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";
|
|
22
25
|
/**
|
|
23
26
|
* How long the relay gets for one blob PUT, sized to the body.
|
|
24
27
|
*
|
|
@@ -42,6 +45,29 @@ export function relayTimeoutMs(bodyBytes) {
|
|
|
42
45
|
* two level: the browser's number bounds a real payment made by a real wallet.
|
|
43
46
|
*/
|
|
44
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
|
+
}
|
|
45
71
|
function extend(network, relayUrl, bodyBytes, onSent) {
|
|
46
72
|
// ⛔ The network name reaches the SDK as well as the URL. A node pointed at the wrong chain
|
|
47
73
|
// would otherwise be discovered as a blob the storage nodes refuse, after the money moved.
|
|
@@ -50,7 +76,8 @@ function extend(network, relayUrl, bodyBytes, onSent) {
|
|
|
50
76
|
...storageNodesThrough(),
|
|
51
77
|
uploadRelay: {
|
|
52
78
|
host: relayUrl,
|
|
53
|
-
|
|
79
|
+
// The own relay (D50) takes no tip, so it is not told which transaction paid one.
|
|
80
|
+
...(isOwnRelay(relayUrl) ? {} : { sendTip: { max: TIP_CEILING_UNUSED_MIST } }),
|
|
54
81
|
timeout: relayTimeoutMs(bodyBytes),
|
|
55
82
|
// ⛔ THE ONLY WAY TO SEE AN UPLOAD MOVE. The SDK does not report progress, and the relay
|
|
56
83
|
// PUT is the one step of an upload that takes real time — a person watching a large
|
|
@@ -59,7 +86,7 @@ function extend(network, relayUrl, bodyBytes, onSent) {
|
|
|
59
86
|
//
|
|
60
87
|
// ⛔ AND EITHER WAY IT IS THE CALLER'S `fetch`: the counting wrapper goes through it too,
|
|
61
88
|
// so the request that carries the file cannot be the one that misses a proxy.
|
|
62
|
-
fetch: onSent ? countingFetch(onSent) : reachFetch,
|
|
89
|
+
fetch: relayFetch(relayUrl, onSent ? countingFetch(onSent) : reachFetch),
|
|
63
90
|
},
|
|
64
91
|
}));
|
|
65
92
|
}
|
|
@@ -73,8 +100,10 @@ function fail(what, error) {
|
|
|
73
100
|
* is the only phase of one that anything can report on.
|
|
74
101
|
*/
|
|
75
102
|
export function createBlobProtocol(network, bodyBytes, onSent) {
|
|
76
|
-
const relayUrl =
|
|
77
|
-
|
|
103
|
+
const relayUrl = uploadRelay(network);
|
|
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);
|
|
78
107
|
return {
|
|
79
108
|
relayUrl,
|
|
80
109
|
async computeMetadata({ bytes, nonce }) {
|
|
@@ -99,7 +128,17 @@ export function createBlobProtocol(network, bodyBytes, onSent) {
|
|
|
99
128
|
blobDigest: await meta.blobDigest(),
|
|
100
129
|
};
|
|
101
130
|
},
|
|
102
|
-
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
|
+
}
|
|
103
142
|
const { certificate } = await client.walrus
|
|
104
143
|
.writeBlobToUploadRelay({
|
|
105
144
|
blobId,
|
|
@@ -120,6 +159,34 @@ export function createBlobProtocol(network, bodyBytes, onSent) {
|
|
|
120
159
|
},
|
|
121
160
|
};
|
|
122
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
|
+
}
|
|
123
190
|
/**
|
|
124
191
|
* The storage network's current epoch, or `null` when it could not be read.
|
|
125
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.
|
|
@@ -15,6 +21,16 @@ export declare const AGGREGATOR_HOSTS: Readonly<Record<string, readonly string[]
|
|
|
15
21
|
* register transaction the server pays a tip in, so the bytes have to go to the SAME host the
|
|
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.
|
|
24
|
+
*
|
|
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.
|
|
18
34
|
*/
|
|
19
35
|
export declare const RELAY_HOSTS: Readonly<Record<string, readonly string[]>>;
|
|
20
36
|
/**
|
|
@@ -31,11 +47,14 @@ export declare const RELAY_HOSTS: Readonly<Record<string, readonly string[]>>;
|
|
|
31
47
|
* (mainnet). Every host below answered chain id, a balance, an object and the gas price over
|
|
32
48
|
* gRPC-web that morning. Two operators per network — Suiscan and Mysten Labs — in the browser's
|
|
33
49
|
* order (`web/src/lib/walrus/network-hosts.ts` says why mainnet keeps Suiscan first). A test
|
|
34
|
-
* 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.
|
|
35
52
|
*/
|
|
36
53
|
export declare const SUI_RPC_HOSTS: Readonly<Record<string, readonly string[]>>;
|
|
37
|
-
/** 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. */
|
|
38
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;
|
|
39
58
|
export { AGGREGATOR_ENV_VAR, RELAY_ENV_VAR, SUI_RPC_ENV_VAR } from "./env-vars.ts";
|
|
40
59
|
/**
|
|
41
60
|
* The relay this run writes through: the caller's if it named one, then the environment's, then
|