@bsv/overlay-express 2.4.9 → 2.5.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/dist/cjs/package.json +1 -1
- package/dist/cjs/src/BanService.d.ts +2 -4
- package/dist/cjs/src/BanService.d.ts.map +1 -1
- package/dist/cjs/src/BanService.js +18 -5
- package/dist/cjs/src/BanService.js.map +1 -1
- package/dist/cjs/src/JanitorService.d.ts +7 -0
- package/dist/cjs/src/JanitorService.d.ts.map +1 -1
- package/dist/cjs/src/JanitorService.js +61 -12
- package/dist/cjs/src/JanitorService.js.map +1 -1
- package/dist/cjs/src/OverlayExpress.d.ts +6 -0
- package/dist/cjs/src/OverlayExpress.d.ts.map +1 -1
- package/dist/cjs/src/OverlayExpress.js +182 -51
- package/dist/cjs/src/OverlayExpress.js.map +1 -1
- package/dist/cjs/src/ResourceBoundedLookupWrapper.d.ts +26 -0
- package/dist/cjs/src/ResourceBoundedLookupWrapper.d.ts.map +1 -0
- package/dist/cjs/src/ResourceBoundedLookupWrapper.js +70 -0
- package/dist/cjs/src/ResourceBoundedLookupWrapper.js.map +1 -0
- package/dist/cjs/src/security/edgePolicy.d.ts +27 -0
- package/dist/cjs/src/security/edgePolicy.d.ts.map +1 -1
- package/dist/cjs/src/security/edgePolicy.js +169 -15
- package/dist/cjs/src/security/edgePolicy.js.map +1 -1
- package/dist/esm/src/BanService.js +18 -5
- package/dist/esm/src/BanService.js.map +1 -1
- package/dist/esm/src/JanitorService.js +62 -11
- package/dist/esm/src/JanitorService.js.map +1 -1
- package/dist/esm/src/OverlayExpress.js +182 -49
- package/dist/esm/src/OverlayExpress.js.map +1 -1
- package/dist/esm/src/ResourceBoundedLookupWrapper.js +70 -0
- package/dist/esm/src/ResourceBoundedLookupWrapper.js.map +1 -0
- package/dist/esm/src/security/edgePolicy.js +160 -15
- package/dist/esm/src/security/edgePolicy.js.map +1 -1
- package/dist/types/src/BanService.d.ts +2 -4
- package/dist/types/src/BanService.d.ts.map +1 -1
- package/dist/types/src/JanitorService.d.ts +7 -0
- package/dist/types/src/JanitorService.d.ts.map +1 -1
- package/dist/types/src/OverlayExpress.d.ts +6 -0
- package/dist/types/src/OverlayExpress.d.ts.map +1 -1
- package/dist/types/src/ResourceBoundedLookupWrapper.d.ts +26 -0
- package/dist/types/src/ResourceBoundedLookupWrapper.d.ts.map +1 -0
- package/dist/types/src/security/edgePolicy.d.ts +27 -0
- package/dist/types/src/security/edgePolicy.d.ts.map +1 -1
- package/package.json +5 -5
|
@@ -12,6 +12,7 @@ import { createHash, timingSafeEqual } from 'node:crypto';
|
|
|
12
12
|
import { JanitorService } from './JanitorService.js';
|
|
13
13
|
import { BanService } from './BanService.js';
|
|
14
14
|
import { BanAwareLookupWrapper } from './BanAwareLookupWrapper.js';
|
|
15
|
+
import { ResourceBoundedLookupWrapper } from './ResourceBoundedLookupWrapper.js';
|
|
15
16
|
import { BanAwareTopicManager } from './BanAwareTopicManager.js';
|
|
16
17
|
import { BanAwareSHIPStorage, BanAwareSLAPStorage } from './BanAwareDiscoveryStorage.js';
|
|
17
18
|
import { ReorgSseAdapter } from './ReorgStream.js';
|
|
@@ -20,7 +21,7 @@ import { createAuthMiddleware } from '@bsv/auth-express-middleware';
|
|
|
20
21
|
import { ArcadeProvider, isTerminalArcStatus } from './ArcadeProvider.js';
|
|
21
22
|
import { ProviderChainBroadcaster } from './ProviderChainBroadcaster.js';
|
|
22
23
|
import { ChaintracksProvider } from './ChaintracksProvider.js';
|
|
23
|
-
import { bodyParserErrorHandler, concurrencyLimit, configureHttpServer, corsPolicy, readBodyLimitBytes, securityHeaders } from './security/edgePolicy.js';
|
|
24
|
+
import { bodyParserErrorHandler, concurrencyLimit, configureHttpServer, corsPolicy, initialDoubleSlashCompatibility, profileValue, readBodyLimitBytes, readResourceLimit, readResourceProfile, responseSizeLimit, securityHeaders } from './security/edgePolicy.js';
|
|
24
25
|
/**
|
|
25
26
|
* In-memory migration source for Knex migrations.
|
|
26
27
|
* Allows running migrations defined in code rather than files.
|
|
@@ -44,7 +45,9 @@ class InMemoryMigrationSource {
|
|
|
44
45
|
* @returns The name of the migration
|
|
45
46
|
*/
|
|
46
47
|
getMigrationName(migration) {
|
|
47
|
-
return typeof migration.name === 'string'
|
|
48
|
+
return typeof migration.name === 'string'
|
|
49
|
+
? migration.name
|
|
50
|
+
: `Migration at index ${this.migrations.indexOf(migration)}`;
|
|
48
51
|
}
|
|
49
52
|
/**
|
|
50
53
|
* Gets the migration object.
|
|
@@ -73,14 +76,13 @@ function parseTopicsHeader(header) {
|
|
|
73
76
|
const value = header.trim();
|
|
74
77
|
let parsed;
|
|
75
78
|
try {
|
|
76
|
-
parsed = value.startsWith('[')
|
|
77
|
-
? JSON.parse(value)
|
|
78
|
-
: value.split(',').map(topic => topic.trim());
|
|
79
|
+
parsed = value.startsWith('[') ? JSON.parse(value) : value.split(',').map(topic => topic.trim());
|
|
79
80
|
}
|
|
80
81
|
catch {
|
|
81
82
|
throw new PublicRequestError('Invalid x-topics header: expected a comma-separated list or JSON string array');
|
|
82
83
|
}
|
|
83
|
-
if (!Array.isArray(parsed) ||
|
|
84
|
+
if (!Array.isArray(parsed) ||
|
|
85
|
+
parsed.some(topic => typeof topic !== 'string' || topic.length === 0)) {
|
|
84
86
|
throw new PublicRequestError('Invalid x-topics header: expected a comma-separated list or JSON string array');
|
|
85
87
|
}
|
|
86
88
|
return parsed;
|
|
@@ -173,7 +175,9 @@ export default class OverlayExpress {
|
|
|
173
175
|
requestTimeoutMs: 10000, // 10 seconds
|
|
174
176
|
hostDownRevokeScore: 3,
|
|
175
177
|
autoBanOnRemoval: true,
|
|
176
|
-
allowPrivateHosts: false
|
|
178
|
+
allowPrivateHosts: false,
|
|
179
|
+
batchSize: undefined,
|
|
180
|
+
maxReportResults: undefined
|
|
177
181
|
};
|
|
178
182
|
// Ban service for persistent domain/outpoint blocking
|
|
179
183
|
banService;
|
|
@@ -259,6 +263,8 @@ export default class OverlayExpress {
|
|
|
259
263
|
* - hostDownRevokeScore: Number of consecutive failures before deleting output (default: 3)
|
|
260
264
|
* - autoBanOnRemoval: Whether to auto-ban domains when removed by janitor (default: true)
|
|
261
265
|
* - allowPrivateHosts: Permit private/HTTP targets for isolated local development (default: false)
|
|
266
|
+
* - batchSize: Mongo scan batch size; -1 uses the driver default
|
|
267
|
+
* - maxReportResults: Maximum retained result details; -1 retains all
|
|
262
268
|
*/
|
|
263
269
|
configureJanitor(config) {
|
|
264
270
|
this.janitorConfig = {
|
|
@@ -590,6 +596,12 @@ export default class OverlayExpress {
|
|
|
590
596
|
*/
|
|
591
597
|
async configureEngine(autoConfigureShipSlap = true) {
|
|
592
598
|
const knex = this.ensureKnex();
|
|
599
|
+
const maxLookupResults = this.engineConfig.maxLookupResults ??
|
|
600
|
+
readResourceLimit(this.edgePolicyConfig.environmentPrefix, 'MAX_LOOKUP_RESULTS', profileValue(readResourceProfile(this.edgePolicyConfig.environmentPrefix), {
|
|
601
|
+
small: 500,
|
|
602
|
+
standard: 1000,
|
|
603
|
+
highThroughput: 5000
|
|
604
|
+
}), 1_000_000);
|
|
593
605
|
if (autoConfigureShipSlap) {
|
|
594
606
|
const mongoDb = this.ensureMongo();
|
|
595
607
|
const shipStorage = new DiscoveryServices.SHIPStorage(mongoDb);
|
|
@@ -606,8 +618,8 @@ export default class OverlayExpress {
|
|
|
606
618
|
const slapStorageForLookup = this.banService === undefined
|
|
607
619
|
? slapStorage
|
|
608
620
|
: new BanAwareSLAPStorage(slapStorage, this.banService, this.logger);
|
|
609
|
-
this.services.ls_ship = new DiscoveryServices.SHIPLookupService(shipStorageForLookup);
|
|
610
|
-
this.services.ls_slap = new DiscoveryServices.SLAPLookupService(slapStorageForLookup);
|
|
621
|
+
this.services.ls_ship = new ResourceBoundedLookupWrapper(new DiscoveryServices.SHIPLookupService(shipStorageForLookup), maxLookupResults);
|
|
622
|
+
this.services.ls_slap = new ResourceBoundedLookupWrapper(new DiscoveryServices.SLAPLookupService(slapStorageForLookup), maxLookupResults);
|
|
611
623
|
this.logger.log(chalk.blue('Configured lookup service ls_ship with MongoDB'));
|
|
612
624
|
this.logger.log(chalk.blue('Configured lookup service ls_slap with MongoDB'));
|
|
613
625
|
}
|
|
@@ -620,7 +632,7 @@ export default class OverlayExpress {
|
|
|
620
632
|
const EngineWithBASM = Engine;
|
|
621
633
|
this.engine = new EngineWithBASM(this.managers, this.services, storage, this.engineConfig.chainTracker ?? this.chainTracker, `https://${this.advertisableFQDN}`, this.network === 'test'
|
|
622
634
|
? (this.engineConfig.shipTrackers ?? DEFAULT_TESTNET_SLAP_TRACKERS)
|
|
623
|
-
: this.engineConfig.shipTrackers, this.resolveSlapTrackers(), broadcaster ?? this.engineConfig.broadcaster, advertiser, syncConfig, this.engineConfig.logTime ?? false, this.engineConfig.logPrefix ?? '[OVERLAY_ENGINE] ', this.engineConfig.throwOnBroadcastFailure ?? true, this.engineConfig.overlayBroadcastFacilitator ?? new HTTPSOverlayBroadcastFacilitator(), this.logger, this.engineConfig.suppressDefaultSyncAdvertisements ?? true, this.buildTopicAnchorHeaderResolver(), this.engineConfig.enableBASMSync ?? this.enableBASMSync, this.engineConfig.unprovenEvictionBlocks ?? this.unprovenEvictionBlocks);
|
|
635
|
+
: this.engineConfig.shipTrackers, this.resolveSlapTrackers(), broadcaster ?? this.engineConfig.broadcaster, advertiser, syncConfig, this.engineConfig.logTime ?? false, this.engineConfig.logPrefix ?? '[OVERLAY_ENGINE] ', this.engineConfig.throwOnBroadcastFailure ?? true, this.engineConfig.overlayBroadcastFacilitator ?? new HTTPSOverlayBroadcastFacilitator(), this.logger, this.engineConfig.suppressDefaultSyncAdvertisements ?? true, this.buildTopicAnchorHeaderResolver(), this.engineConfig.enableBASMSync ?? this.enableBASMSync, this.engineConfig.unprovenEvictionBlocks ?? this.unprovenEvictionBlocks, maxLookupResults);
|
|
624
636
|
this.initServerWallet();
|
|
625
637
|
this.logger.log(chalk.green('Engine has been configured.'));
|
|
626
638
|
}
|
|
@@ -750,7 +762,7 @@ export default class OverlayExpress {
|
|
|
750
762
|
if (!response.ok) {
|
|
751
763
|
throw new Error(`WhatsOnChain header lookup failed for height ${blockHeight}: ${response.status}`);
|
|
752
764
|
}
|
|
753
|
-
const header = await response.json();
|
|
765
|
+
const header = (await response.json());
|
|
754
766
|
if (typeof header.hash !== 'string') {
|
|
755
767
|
throw new TypeError(`WhatsOnChain did not return a block hash for height ${blockHeight}`);
|
|
756
768
|
}
|
|
@@ -832,6 +844,8 @@ export default class OverlayExpress {
|
|
|
832
844
|
*/
|
|
833
845
|
createJanitor() {
|
|
834
846
|
const mongoDb = this.ensureMongo();
|
|
847
|
+
const prefix = this.edgePolicyConfig.environmentPrefix;
|
|
848
|
+
const profile = readResourceProfile(prefix);
|
|
835
849
|
return new JanitorService({
|
|
836
850
|
mongoDb,
|
|
837
851
|
logger: this.logger,
|
|
@@ -839,7 +853,11 @@ export default class OverlayExpress {
|
|
|
839
853
|
hostDownRevokeScore: this.janitorConfig.hostDownRevokeScore,
|
|
840
854
|
banService: this.banService,
|
|
841
855
|
autoBanOnRemoval: this.janitorConfig.autoBanOnRemoval,
|
|
842
|
-
allowPrivateHosts: this.janitorConfig.allowPrivateHosts
|
|
856
|
+
allowPrivateHosts: this.janitorConfig.allowPrivateHosts,
|
|
857
|
+
batchSize: this.janitorConfig.batchSize ??
|
|
858
|
+
readResourceLimit(prefix, 'JANITOR_BATCH_SIZE', profileValue(profile, { small: 100, standard: 250, highThroughput: 1000 }), 100_000),
|
|
859
|
+
maxReportResults: this.janitorConfig.maxReportResults ??
|
|
860
|
+
readResourceLimit(prefix, 'JANITOR_MAX_REPORT_RESULTS', profileValue(profile, { small: 500, standard: 1000, highThroughput: 5000 }), 1_000_000)
|
|
843
861
|
});
|
|
844
862
|
}
|
|
845
863
|
/** Ban a domain and remove all its SHIP/SLAP records from MongoDB. */
|
|
@@ -859,7 +877,9 @@ export default class OverlayExpress {
|
|
|
859
877
|
async handleBanOutpoint(res, engine, value, reason) {
|
|
860
878
|
const dotIndex = value.lastIndexOf('.');
|
|
861
879
|
if (dotIndex === -1) {
|
|
862
|
-
return res
|
|
880
|
+
return res
|
|
881
|
+
.status(400)
|
|
882
|
+
.json({ status: 'error', message: 'Outpoint format must be "txid.outputIndex"' });
|
|
863
883
|
}
|
|
864
884
|
const txid = value.substring(0, dotIndex);
|
|
865
885
|
const outputIndex = Number.parseInt(value.substring(dotIndex + 1));
|
|
@@ -885,7 +905,9 @@ export default class OverlayExpress {
|
|
|
885
905
|
try {
|
|
886
906
|
await svc.outputEvicted(txid, outputIndex);
|
|
887
907
|
}
|
|
888
|
-
catch {
|
|
908
|
+
catch {
|
|
909
|
+
/* best-effort */
|
|
910
|
+
}
|
|
889
911
|
}
|
|
890
912
|
}
|
|
891
913
|
/** Look up the domain of an outpoint from SHIP or SLAP records. */
|
|
@@ -1019,7 +1041,7 @@ export default class OverlayExpress {
|
|
|
1019
1041
|
handler: check.handler
|
|
1020
1042
|
});
|
|
1021
1043
|
}
|
|
1022
|
-
const filteredDefinitions = definitions.filter(
|
|
1044
|
+
const filteredDefinitions = definitions.filter(definition => {
|
|
1023
1045
|
if (mode === 'full') {
|
|
1024
1046
|
return true;
|
|
1025
1047
|
}
|
|
@@ -1188,7 +1210,51 @@ export default class OverlayExpress {
|
|
|
1188
1210
|
const knex = this.ensureKnex();
|
|
1189
1211
|
this.startTime = new Date();
|
|
1190
1212
|
const edgePolicy = this.edgePolicyConfig;
|
|
1213
|
+
const resourceProfile = readResourceProfile(edgePolicy.environmentPrefix);
|
|
1214
|
+
const maxResponseBytes = readResourceLimit(edgePolicy.environmentPrefix, 'MAX_RESPONSE_BYTES', profileValue(resourceProfile, {
|
|
1215
|
+
small: 4 * 1024 * 1024,
|
|
1216
|
+
standard: 8 * 1024 * 1024,
|
|
1217
|
+
highThroughput: 32 * 1024 * 1024
|
|
1218
|
+
}), 512 * 1024 * 1024);
|
|
1219
|
+
const maxBasmTxids = readResourceLimit(edgePolicy.environmentPrefix, 'MAX_BASM_TXIDS', profileValue(resourceProfile, { small: 500, standard: 1000, highThroughput: 5000 }), 1_000_000);
|
|
1220
|
+
const maxBasmAnchorRange = readResourceLimit(edgePolicy.environmentPrefix, 'MAX_BASM_ANCHOR_RANGE', profileValue(resourceProfile, { small: 500, standard: 1000, highThroughput: 5000 }), 1_000_000);
|
|
1221
|
+
const adminListDefaultLimit = readResourceLimit(edgePolicy.environmentPrefix, 'ADMIN_LIST_DEFAULT_LIMIT', profileValue(resourceProfile, { small: 25, standard: 50, highThroughput: 100 }), 1_000_000);
|
|
1222
|
+
const adminListMaxLimit = readResourceLimit(edgePolicy.environmentPrefix, 'ADMIN_LIST_MAX_LIMIT', profileValue(resourceProfile, { small: 100, standard: 200, highThroughput: 1000 }), 1_000_000);
|
|
1223
|
+
const adminListMaxOffset = readResourceLimit(edgePolicy.environmentPrefix, 'ADMIN_LIST_MAX_OFFSET', profileValue(resourceProfile, {
|
|
1224
|
+
small: 10_000,
|
|
1225
|
+
standard: 100_000,
|
|
1226
|
+
highThroughput: 1_000_000
|
|
1227
|
+
}), 100_000_000);
|
|
1228
|
+
if (adminListDefaultLimit !== -1 &&
|
|
1229
|
+
adminListMaxLimit !== -1 &&
|
|
1230
|
+
adminListDefaultLimit > adminListMaxLimit) {
|
|
1231
|
+
throw new TypeError('OVERLAY_ADMIN_LIST_DEFAULT_LIMIT cannot exceed OVERLAY_ADMIN_LIST_MAX_LIMIT');
|
|
1232
|
+
}
|
|
1233
|
+
const parseAdminPage = (rawPageValue, rawLimitValue) => {
|
|
1234
|
+
const rawPage = Number.parseInt(typeof rawPageValue === 'string' ? rawPageValue : '', 10);
|
|
1235
|
+
const requestedPage = Math.max(1, Number.isNaN(rawPage) ? 1 : rawPage);
|
|
1236
|
+
const rawLimitText = typeof rawLimitValue === 'string' ? rawLimitValue.trim().toLowerCase() : '';
|
|
1237
|
+
const parsedLimit = rawLimitText === '-1' || rawLimitText === 'unlimited'
|
|
1238
|
+
? -1
|
|
1239
|
+
: Number.parseInt(rawLimitText, 10);
|
|
1240
|
+
const requestedLimit = rawLimitText.length === 0 || Number.isNaN(parsedLimit) ? adminListDefaultLimit : parsedLimit;
|
|
1241
|
+
if (requestedLimit !== -1 && (!Number.isSafeInteger(requestedLimit) || requestedLimit < 1)) {
|
|
1242
|
+
throw new TypeError('limit must be a positive integer, -1, or unlimited');
|
|
1243
|
+
}
|
|
1244
|
+
let limit = requestedLimit;
|
|
1245
|
+
if (adminListMaxLimit !== -1) {
|
|
1246
|
+
limit =
|
|
1247
|
+
requestedLimit === -1 ? adminListMaxLimit : Math.min(requestedLimit, adminListMaxLimit);
|
|
1248
|
+
}
|
|
1249
|
+
const page = limit === -1 ? 1 : requestedPage;
|
|
1250
|
+
const skip = limit === -1 ? 0 : (page - 1) * limit;
|
|
1251
|
+
if (!Number.isSafeInteger(skip) || (adminListMaxOffset !== -1 && skip > adminListMaxOffset)) {
|
|
1252
|
+
throw new TypeError('requested page exceeds the configured maximum offset');
|
|
1253
|
+
}
|
|
1254
|
+
return { page, limit, skip };
|
|
1255
|
+
};
|
|
1191
1256
|
this.app.disable('x-powered-by');
|
|
1257
|
+
this.app.use(initialDoubleSlashCompatibility);
|
|
1192
1258
|
this.app.use(securityHeaders({
|
|
1193
1259
|
environmentPrefix: edgePolicy.environmentPrefix,
|
|
1194
1260
|
...edgePolicy.securityHeaders
|
|
@@ -1198,7 +1264,9 @@ export default class OverlayExpress {
|
|
|
1198
1264
|
allowedOrigins: edgePolicy.allowedOrigins,
|
|
1199
1265
|
methods: ['GET', 'POST', 'OPTIONS']
|
|
1200
1266
|
}));
|
|
1201
|
-
this.app.use(concurrencyLimit(edgePolicy.environmentPrefix, edgePolicy.maxConcurrentRequests
|
|
1267
|
+
this.app.use(concurrencyLimit(edgePolicy.environmentPrefix, edgePolicy.maxConcurrentRequests === 200
|
|
1268
|
+
? profileValue(resourceProfile, { small: 8, standard: 24, highThroughput: 96 })
|
|
1269
|
+
: edgePolicy.maxConcurrentRequests));
|
|
1202
1270
|
this.app.use(bodyParser.json({
|
|
1203
1271
|
limit: readBodyLimitBytes(`${edgePolicy.environmentPrefix}_JSON`, edgePolicy.jsonBodyLimitBytes),
|
|
1204
1272
|
type: 'application/json'
|
|
@@ -1208,6 +1276,7 @@ export default class OverlayExpress {
|
|
|
1208
1276
|
type: 'application/octet-stream'
|
|
1209
1277
|
}));
|
|
1210
1278
|
this.app.use(bodyParserErrorHandler);
|
|
1279
|
+
this.app.use(responseSizeLimit(edgePolicy.environmentPrefix, maxResponseBytes));
|
|
1211
1280
|
if (this.verboseRequestLogging) {
|
|
1212
1281
|
this.setupVerboseRequestLogging();
|
|
1213
1282
|
}
|
|
@@ -1225,7 +1294,7 @@ export default class OverlayExpress {
|
|
|
1225
1294
|
(async () => {
|
|
1226
1295
|
const report = await this.collectHealthReport('live');
|
|
1227
1296
|
return res.status(report.live ? 200 : 503).json(report);
|
|
1228
|
-
})().catch(
|
|
1297
|
+
})().catch(error => {
|
|
1229
1298
|
this.logger.error({ operation: 'overlay.health_live', error });
|
|
1230
1299
|
res.status(500).json({
|
|
1231
1300
|
status: 'error',
|
|
@@ -1233,12 +1302,23 @@ export default class OverlayExpress {
|
|
|
1233
1302
|
});
|
|
1234
1303
|
});
|
|
1235
1304
|
});
|
|
1305
|
+
// Compatibility alias used by Kubernetes probes and existing deployments.
|
|
1306
|
+
this.app.get('/healthz', (_, res) => {
|
|
1307
|
+
;
|
|
1308
|
+
(async () => {
|
|
1309
|
+
const report = await this.collectHealthReport('live');
|
|
1310
|
+
return res.status(report.live ? 200 : 503).json(report);
|
|
1311
|
+
})().catch(error => {
|
|
1312
|
+
this.logger.error({ operation: 'overlay.healthz', error });
|
|
1313
|
+
res.status(500).json({ status: 'error', message: 'Health report unavailable' });
|
|
1314
|
+
});
|
|
1315
|
+
});
|
|
1236
1316
|
this.app.get('/health/ready', (_, res) => {
|
|
1237
1317
|
;
|
|
1238
1318
|
(async () => {
|
|
1239
1319
|
const report = await this.collectHealthReport('ready');
|
|
1240
1320
|
return res.status(report.ready ? 200 : 503).json(report);
|
|
1241
|
-
})().catch(
|
|
1321
|
+
})().catch(error => {
|
|
1242
1322
|
this.logger.error({ operation: 'overlay.health_ready', error });
|
|
1243
1323
|
res.status(500).json({
|
|
1244
1324
|
status: 'error',
|
|
@@ -1251,7 +1331,7 @@ export default class OverlayExpress {
|
|
|
1251
1331
|
(async () => {
|
|
1252
1332
|
const report = await this.collectHealthReport('full');
|
|
1253
1333
|
return res.status(report.ready ? 200 : 503).json(report);
|
|
1254
|
-
})().catch(
|
|
1334
|
+
})().catch(error => {
|
|
1255
1335
|
this.logger.error({ operation: 'overlay.health_full', error });
|
|
1256
1336
|
res.status(500).json({
|
|
1257
1337
|
status: 'error',
|
|
@@ -1432,7 +1512,7 @@ export default class OverlayExpress {
|
|
|
1432
1512
|
// Write outputIndex
|
|
1433
1513
|
writer.writeVarIntNum(output.outputIndex);
|
|
1434
1514
|
// Write context length and data
|
|
1435
|
-
if (
|
|
1515
|
+
if (output.context != null && output.context.length > 0) {
|
|
1436
1516
|
writer.writeVarIntNum(output.context.length);
|
|
1437
1517
|
writer.write(output.context);
|
|
1438
1518
|
}
|
|
@@ -1576,12 +1656,23 @@ export default class OverlayExpress {
|
|
|
1576
1656
|
if (!Array.isArray(value) || !value.every(txid => typeof txid === 'string')) {
|
|
1577
1657
|
throw new PublicRequestError('txids must be an array of strings');
|
|
1578
1658
|
}
|
|
1659
|
+
if (maxBasmTxids !== -1 && value.length > maxBasmTxids) {
|
|
1660
|
+
throw new PublicRequestError(`txids must contain at most ${maxBasmTxids} entries`);
|
|
1661
|
+
}
|
|
1579
1662
|
return value;
|
|
1580
1663
|
};
|
|
1581
1664
|
registerJsonRoute('/requestTopicAnchorTip', async (req) => await basmEngine.provideTopicAnchorTip(readBasmTopic(req)));
|
|
1582
1665
|
registerJsonRoute('/requestTopicAnchorRange', async (req) => {
|
|
1583
1666
|
const { fromHeight, toHeight } = req.body;
|
|
1584
|
-
|
|
1667
|
+
const from = Number(fromHeight);
|
|
1668
|
+
const to = Number(toHeight);
|
|
1669
|
+
if (!Number.isSafeInteger(from) || !Number.isSafeInteger(to) || from < 0 || to < from) {
|
|
1670
|
+
throw new PublicRequestError('fromHeight and toHeight must define a valid ascending range');
|
|
1671
|
+
}
|
|
1672
|
+
if (maxBasmAnchorRange !== -1 && to - from + 1 > maxBasmAnchorRange) {
|
|
1673
|
+
throw new PublicRequestError(`topic anchor range must contain at most ${maxBasmAnchorRange} blocks`);
|
|
1674
|
+
}
|
|
1675
|
+
return await basmEngine.provideTopicAnchorRange(readBasmTopic(req), from, to);
|
|
1585
1676
|
});
|
|
1586
1677
|
registerJsonRoute('/requestAdmittedList', async (req) => {
|
|
1587
1678
|
const { blockHeight, blockHash } = req.body;
|
|
@@ -1641,7 +1732,10 @@ export default class OverlayExpress {
|
|
|
1641
1732
|
res.status(403).json({ status: 'error', message: 'Forbidden: Invalid credentials' });
|
|
1642
1733
|
return;
|
|
1643
1734
|
}
|
|
1644
|
-
res.status(401).json({
|
|
1735
|
+
res.status(401).json({
|
|
1736
|
+
status: 'error',
|
|
1737
|
+
message: 'Unauthorized: Provide a Bearer token or authenticate with your wallet'
|
|
1738
|
+
});
|
|
1645
1739
|
};
|
|
1646
1740
|
/**
|
|
1647
1741
|
* Public endpoint that returns the admin identity key (if configured).
|
|
@@ -1708,11 +1802,7 @@ export default class OverlayExpress {
|
|
|
1708
1802
|
const db = this.ensureMongo();
|
|
1709
1803
|
const collection = db.collection('shipRecords');
|
|
1710
1804
|
const search = typeof req.query.search === 'string' ? req.query.search : undefined;
|
|
1711
|
-
const
|
|
1712
|
-
const page = Math.max(1, Number.isNaN(rawPage) ? 1 : rawPage);
|
|
1713
|
-
const rawLimit = Number.parseInt(req.query.limit, 10);
|
|
1714
|
-
const limit = Math.min(200, Math.max(1, Number.isNaN(rawLimit) ? 50 : rawLimit));
|
|
1715
|
-
const skip = (page - 1) * limit;
|
|
1805
|
+
const { page, limit, skip } = parseAdminPage(req.query.page, req.query.limit);
|
|
1716
1806
|
const query = {};
|
|
1717
1807
|
if (typeof search === 'string' && search.length > 0) {
|
|
1718
1808
|
query.$or = [
|
|
@@ -1723,12 +1813,23 @@ export default class OverlayExpress {
|
|
|
1723
1813
|
];
|
|
1724
1814
|
}
|
|
1725
1815
|
const [records, total] = await Promise.all([
|
|
1726
|
-
|
|
1816
|
+
(() => {
|
|
1817
|
+
let cursor = collection.find(query).sort({ createdAt: -1 }).skip(skip);
|
|
1818
|
+
if (limit !== -1)
|
|
1819
|
+
cursor = cursor.limit(limit);
|
|
1820
|
+
return cursor.toArray();
|
|
1821
|
+
})(),
|
|
1727
1822
|
collection.countDocuments(query)
|
|
1728
1823
|
]);
|
|
1729
1824
|
return res.status(200).json({
|
|
1730
1825
|
status: 'success',
|
|
1731
|
-
data: {
|
|
1826
|
+
data: {
|
|
1827
|
+
records,
|
|
1828
|
+
total,
|
|
1829
|
+
page,
|
|
1830
|
+
limit,
|
|
1831
|
+
pages: limit === -1 ? 1 : Math.ceil(total / limit)
|
|
1832
|
+
}
|
|
1732
1833
|
});
|
|
1733
1834
|
}
|
|
1734
1835
|
catch (error) {
|
|
@@ -1751,11 +1852,7 @@ export default class OverlayExpress {
|
|
|
1751
1852
|
const db = this.ensureMongo();
|
|
1752
1853
|
const collection = db.collection('slapRecords');
|
|
1753
1854
|
const search = typeof req.query.search === 'string' ? req.query.search : undefined;
|
|
1754
|
-
const
|
|
1755
|
-
const page = Math.max(1, Number.isNaN(rawPage) ? 1 : rawPage);
|
|
1756
|
-
const rawLimit = Number.parseInt(req.query.limit, 10);
|
|
1757
|
-
const limit = Math.min(200, Math.max(1, Number.isNaN(rawLimit) ? 50 : rawLimit));
|
|
1758
|
-
const skip = (page - 1) * limit;
|
|
1855
|
+
const { page, limit, skip } = parseAdminPage(req.query.page, req.query.limit);
|
|
1759
1856
|
const query = {};
|
|
1760
1857
|
if (typeof search === 'string' && search.length > 0) {
|
|
1761
1858
|
query.$or = [
|
|
@@ -1766,12 +1863,23 @@ export default class OverlayExpress {
|
|
|
1766
1863
|
];
|
|
1767
1864
|
}
|
|
1768
1865
|
const [records, total] = await Promise.all([
|
|
1769
|
-
|
|
1866
|
+
(() => {
|
|
1867
|
+
let cursor = collection.find(query).sort({ createdAt: -1 }).skip(skip);
|
|
1868
|
+
if (limit !== -1)
|
|
1869
|
+
cursor = cursor.limit(limit);
|
|
1870
|
+
return cursor.toArray();
|
|
1871
|
+
})(),
|
|
1770
1872
|
collection.countDocuments(query)
|
|
1771
1873
|
]);
|
|
1772
1874
|
return res.status(200).json({
|
|
1773
1875
|
status: 'success',
|
|
1774
|
-
data: {
|
|
1876
|
+
data: {
|
|
1877
|
+
records,
|
|
1878
|
+
total,
|
|
1879
|
+
page,
|
|
1880
|
+
limit,
|
|
1881
|
+
pages: limit === -1 ? 1 : Math.ceil(total / limit)
|
|
1882
|
+
}
|
|
1775
1883
|
});
|
|
1776
1884
|
}
|
|
1777
1885
|
catch (error) {
|
|
@@ -1817,11 +1925,16 @@ export default class OverlayExpress {
|
|
|
1817
1925
|
(async () => {
|
|
1818
1926
|
try {
|
|
1819
1927
|
if (this.banService === undefined) {
|
|
1820
|
-
return res.status(400).json({
|
|
1928
|
+
return res.status(400).json({
|
|
1929
|
+
status: 'error',
|
|
1930
|
+
message: 'Ban service not available (MongoDB not configured)'
|
|
1931
|
+
});
|
|
1821
1932
|
}
|
|
1822
1933
|
const { type, value, reason } = req.body;
|
|
1823
1934
|
if (type !== 'domain' && type !== 'outpoint') {
|
|
1824
|
-
return res
|
|
1935
|
+
return res
|
|
1936
|
+
.status(400)
|
|
1937
|
+
.json({ status: 'error', message: 'type must be "domain" or "outpoint"' });
|
|
1825
1938
|
}
|
|
1826
1939
|
if (typeof value !== 'string' || value.length === 0) {
|
|
1827
1940
|
return res.status(400).json({ status: 'error', message: 'value is required' });
|
|
@@ -1853,13 +1966,17 @@ export default class OverlayExpress {
|
|
|
1853
1966
|
}
|
|
1854
1967
|
const { type, value } = req.body;
|
|
1855
1968
|
if (type !== 'domain' && type !== 'outpoint') {
|
|
1856
|
-
return res
|
|
1969
|
+
return res
|
|
1970
|
+
.status(400)
|
|
1971
|
+
.json({ status: 'error', message: 'type must be "domain" or "outpoint"' });
|
|
1857
1972
|
}
|
|
1858
1973
|
if (typeof value !== 'string' || value.length === 0) {
|
|
1859
1974
|
return res.status(400).json({ status: 'error', message: 'value is required' });
|
|
1860
1975
|
}
|
|
1861
1976
|
await this.banService.removeBan(type, value);
|
|
1862
|
-
return res
|
|
1977
|
+
return res
|
|
1978
|
+
.status(200)
|
|
1979
|
+
.json({ status: 'success', message: `${type} "${String(value)}" unbanned.` });
|
|
1863
1980
|
}
|
|
1864
1981
|
catch (error) {
|
|
1865
1982
|
return res.status(400).json({
|
|
@@ -1883,8 +2000,9 @@ export default class OverlayExpress {
|
|
|
1883
2000
|
}
|
|
1884
2001
|
const type = req.query.type;
|
|
1885
2002
|
const validType = type === 'domain' || type === 'outpoint' ? type : undefined;
|
|
1886
|
-
const
|
|
1887
|
-
|
|
2003
|
+
const { page, limit, skip } = parseAdminPage(req.query.page, req.query.limit);
|
|
2004
|
+
const bans = await this.banService.listBans(validType, limit, skip);
|
|
2005
|
+
return res.status(200).json({ status: 'success', data: { bans, page, limit } });
|
|
1888
2006
|
}
|
|
1889
2007
|
catch (error) {
|
|
1890
2008
|
return res.status(400).json({
|
|
@@ -1905,7 +2023,10 @@ export default class OverlayExpress {
|
|
|
1905
2023
|
try {
|
|
1906
2024
|
const { txid, outputIndex, service, ban, banDomain: shouldBanDomain } = req.body;
|
|
1907
2025
|
if (typeof txid !== 'string' || typeof outputIndex !== 'number') {
|
|
1908
|
-
return res.status(400).json({
|
|
2026
|
+
return res.status(400).json({
|
|
2027
|
+
status: 'error',
|
|
2028
|
+
message: 'txid (string) and outputIndex (number) are required'
|
|
2029
|
+
});
|
|
1909
2030
|
}
|
|
1910
2031
|
// Look up domain before eviction if needed for banning
|
|
1911
2032
|
let removedDomain;
|
|
@@ -1916,7 +2037,9 @@ export default class OverlayExpress {
|
|
|
1916
2037
|
if (ban === true && this.banService !== undefined) {
|
|
1917
2038
|
await this.banService.banOutpoint(txid, outputIndex, 'Manually removed by admin', removedDomain);
|
|
1918
2039
|
}
|
|
1919
|
-
if (shouldBanDomain === true &&
|
|
2040
|
+
if (shouldBanDomain === true &&
|
|
2041
|
+
typeof removedDomain === 'string' &&
|
|
2042
|
+
this.banService !== undefined) {
|
|
1920
2043
|
await this.banDomainAndRemoveRecords(removedDomain, 'Domain banned by admin via token removal');
|
|
1921
2044
|
}
|
|
1922
2045
|
const banMsg = ban === true ? ' Outpoint banned.' : '';
|
|
@@ -1946,7 +2069,9 @@ export default class OverlayExpress {
|
|
|
1946
2069
|
(async () => {
|
|
1947
2070
|
try {
|
|
1948
2071
|
await engine.syncAdvertisements();
|
|
1949
|
-
return res
|
|
2072
|
+
return res
|
|
2073
|
+
.status(200)
|
|
2074
|
+
.json({ status: 'success', message: 'Advertisements synced successfully' });
|
|
1950
2075
|
}
|
|
1951
2076
|
catch (error) {
|
|
1952
2077
|
console.error(chalk.red('Error in /admin/syncAdvertisements:'), error);
|
|
@@ -1970,7 +2095,9 @@ export default class OverlayExpress {
|
|
|
1970
2095
|
(async () => {
|
|
1971
2096
|
try {
|
|
1972
2097
|
await engine.startGASPSync();
|
|
1973
|
-
return res
|
|
2098
|
+
return res
|
|
2099
|
+
.status(200)
|
|
2100
|
+
.json({ status: 'success', message: 'GASP sync started and completed' });
|
|
1974
2101
|
}
|
|
1975
2102
|
catch (error) {
|
|
1976
2103
|
console.error(chalk.red('Error in /admin/startGASPSync:'), error);
|
|
@@ -2079,7 +2206,9 @@ export default class OverlayExpress {
|
|
|
2079
2206
|
try {
|
|
2080
2207
|
const janitor = this.createJanitor();
|
|
2081
2208
|
const report = await janitor.run();
|
|
2082
|
-
return res
|
|
2209
|
+
return res
|
|
2210
|
+
.status(200)
|
|
2211
|
+
.json({ status: 'success', message: 'Janitor run completed', data: report });
|
|
2083
2212
|
}
|
|
2084
2213
|
catch (error) {
|
|
2085
2214
|
console.error(chalk.red('Error in /admin/janitor:'), error);
|
|
@@ -2244,8 +2373,12 @@ export default class OverlayExpress {
|
|
|
2244
2373
|
const basmEngine = this.engine;
|
|
2245
2374
|
this.reorgAdapter = new ReorgSseAdapter({
|
|
2246
2375
|
url: reorgStreamUrl,
|
|
2247
|
-
onReorg: async (input) => {
|
|
2248
|
-
|
|
2376
|
+
onReorg: async (input) => {
|
|
2377
|
+
await basmEngine?.handleReorg(input);
|
|
2378
|
+
},
|
|
2379
|
+
onConnect: async () => {
|
|
2380
|
+
await basmEngine?.revalidateRecentAnchors(reorgScanDepth);
|
|
2381
|
+
},
|
|
2249
2382
|
logger: this.logger
|
|
2250
2383
|
});
|
|
2251
2384
|
this.reorgAdapter.start();
|