bns: one network table instead of chipnet constants copied into fifteen places
Every client hard-coded the chipnet beacons, address prefix and electrum servers on its own: resolver, registrar config, wallets, gateway, indexer, mirror scripts, the browser bundle and the mobile Java. A mainnet launch would have meant finding all of them and hoping none was missed. The table now lives in resolver-web.js, the one file every client already shares, so it stays a single-file drop-in. BNS_NETWORK selects the record; unset means chipnet, so nothing changes today: the live index resolves the same 60 names and 20 TLDs, the 67 offline tests pass, and the dashboard, market and studio load the same values through BNS.NETWORK. The mainnet record carries the verified public servers, the prefix and its own Sia bucket, but its beacons, start height and operator address are deliberately null: requireBeacons() refuses to scan until they are pinned in the order ROADMAP-MAINNET.md §6 requires. Bns.java reads a generated BnsNetwork.java so the phone cannot drift from the desktop clients. NETWORK-CONFIG.md records what reads the table and what a launch still pins.
This commit is contained in:
parent
5946923547
commit
305bda7c3e
1 changed files with 17 additions and 6 deletions
23
main.js
23
main.js
|
|
@ -1333,7 +1333,11 @@ async function fetchOpenSearch(href) {
|
||||||
// build. The last discovered list is cached to disk and tried first next launch.
|
// build. The last discovered list is cached to disk and tried first next launch.
|
||||||
let electrumPool = null;
|
let electrumPool = null;
|
||||||
let lastElectrumRefresh = 0;
|
let lastElectrumRefresh = 0;
|
||||||
const electrumFile = () => path.join(app.getPath("userData"), "electrum-servers.json");
|
// Per-network cache files. Chipnet keeps the historical names so existing
|
||||||
|
// profiles are not invalidated; any other network gets its own files.
|
||||||
|
let resolverNetworkId = "chipnet";
|
||||||
|
const netSuffix = () => (resolverNetworkId === "chipnet" ? "" : `.${resolverNetworkId}`);
|
||||||
|
const electrumFile = () => path.join(app.getPath("userData"), `electrum-servers${netSuffix()}.json`);
|
||||||
const serverKey = (s) => (typeof s === "string" ? s : s && s.url);
|
const serverKey = (s) => (typeof s === "string" ? s : s && s.url);
|
||||||
function mergeServers(preferred, rest) {
|
function mergeServers(preferred, rest) {
|
||||||
const seen = new Set(), out = [];
|
const seen = new Set(), out = [];
|
||||||
|
|
@ -1344,10 +1348,14 @@ function mergeServers(preferred, rest) {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
async function initElectrumPool() {
|
async function initElectrumPool() {
|
||||||
const { CHIPNET_ELECTRUM } = await getResolver();
|
const R = await getResolver();
|
||||||
|
// The resolver's network table decides the seed pool (BNS_NETWORK env;
|
||||||
|
// chipnet unless set). Older resolver builds only export CHIPNET_ELECTRUM.
|
||||||
|
resolverNetworkId = R.NETWORK?.id || "chipnet";
|
||||||
|
const seed = R.ELECTRUM || R.CHIPNET_ELECTRUM;
|
||||||
let saved = [];
|
let saved = [];
|
||||||
try { if (fs.existsSync(electrumFile())) saved = JSON.parse(fs.readFileSync(electrumFile(), "utf8")); } catch {}
|
try { if (fs.existsSync(electrumFile())) saved = JSON.parse(fs.readFileSync(electrumFile(), "utf8")); } catch {}
|
||||||
electrumPool = mergeServers(saved, CHIPNET_ELECTRUM); // discovered first, seed always kept
|
electrumPool = mergeServers(saved, seed); // discovered first, seed always kept
|
||||||
}
|
}
|
||||||
async function refreshElectrumPool() {
|
async function refreshElectrumPool() {
|
||||||
try {
|
try {
|
||||||
|
|
@ -1390,8 +1398,11 @@ const INDEX_TTL = 45_000;
|
||||||
// Both are optional; if neither exists, ensureIndex() does what it always did
|
// Both are optional; if neither exists, ensureIndex() does what it always did
|
||||||
// and the user sees the same cold-start experience as before this change.
|
// and the user sees the same cold-start experience as before this change.
|
||||||
const SNAPSHOT_BUNDLED = path.join(RES_DIR, "bns-name-snapshot.json");
|
const SNAPSHOT_BUNDLED = path.join(RES_DIR, "bns-name-snapshot.json");
|
||||||
const SIA_SNAPSHOT_URL = "https://s3.silentmode.st:8600/bns/name-list.json";
|
// The published snapshot's location is part of the network table; the constant
|
||||||
function snapshotUserPath() { return path.join(app.getPath("userData"), "bns-name-snapshot.json"); }
|
// below is only the fallback for a resolver build that predates the table.
|
||||||
|
const SIA_SNAPSHOT_URL_FALLBACK = "https://s3.silentmode.st:8600/bns/name-list.json";
|
||||||
|
async function siaSnapshotUrl() { try { return (await getResolver()).NETWORK?.nameListUrl || SIA_SNAPSHOT_URL_FALLBACK; } catch { return SIA_SNAPSHOT_URL_FALLBACK; } }
|
||||||
|
function snapshotUserPath() { return path.join(app.getPath("userData"), `bns-name-snapshot${netSuffix()}.json`); }
|
||||||
|
|
||||||
function readSnapshotFrom(p) {
|
function readSnapshotFrom(p) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -1547,7 +1558,7 @@ function stopBnsPolling() { if (pollTimer) { clearInterval(pollTimer); pollTimer
|
||||||
// authoritative catch-up.
|
// authoritative catch-up.
|
||||||
async function refreshSnapshotFromSia() {
|
async function refreshSnapshotFromSia() {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(SIA_SNAPSHOT_URL, { redirect: "follow" });
|
const res = await fetch((await siaSnapshotUrl()), { redirect: "follow" });
|
||||||
if (!res.ok) return;
|
if (!res.ok) return;
|
||||||
const body = await res.text();
|
const body = await res.text();
|
||||||
const parsed = JSON.parse(body);
|
const parsed = JSON.parse(body);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue