beignet 0.11.0 → 0.11.1

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.
@@ -67,6 +67,7 @@ const funding_selection_1 = require("./funding-selection");
67
67
  const validation_3 = require("../validation");
68
68
  const bitcoin = __importStar(require("bitcoinjs-lib"));
69
69
  const ecc = __importStar(require("@bitcoinerlab/secp256k1"));
70
+ const transaction_1 = require("../storage/transaction");
70
71
  const recovery_1 = require("../recovery");
71
72
  const flags_1 = require("../features/flags");
72
73
  const chain_watcher_1 = require("../chain/chain-watcher");
@@ -1030,6 +1031,7 @@ class LightningNode extends events_1.EventEmitter {
1030
1031
  }
1031
1032
  const gossipRestoreCutoff = Math.floor(Date.now() / 1000) - types_2.DEFAULT_PRUNE_MAX_AGE;
1032
1033
  const diskChannelEndpoints = new Set();
1034
+ const staleRowDeletes = [];
1033
1035
  for (const channel of this.storage.loadAllGossipChannels()) {
1034
1036
  const ts1 = channel.update1 &&
1035
1037
  !(0, types_2.gossipTimestampTooFarFuture)(channel.update1.timestamp)
@@ -1042,7 +1044,7 @@ class LightningNode extends events_1.EventEmitter {
1042
1044
  if (Math.max(ts1, ts2) < gossipRestoreCutoff) {
1043
1045
  if (typeof this.storage.deleteGossipChannel === 'function') {
1044
1046
  const scidHex = channel.shortChannelId.toString('hex');
1045
- this.safeStorage(() => this.storage.deleteGossipChannel(scidHex), 'deleteGossipChannel');
1047
+ staleRowDeletes.push(() => this.storage.deleteGossipChannel(scidHex));
1046
1048
  }
1047
1049
  continue;
1048
1050
  }
@@ -1055,12 +1057,13 @@ class LightningNode extends events_1.EventEmitter {
1055
1057
  const nodeIdHex = node.nodeId.toString('hex');
1056
1058
  if (!diskChannelEndpoints.has(nodeIdHex) &&
1057
1059
  typeof this.storage.deleteGossipNode === 'function') {
1058
- this.safeStorage(() => this.storage.deleteGossipNode(nodeIdHex), 'deleteGossipNode');
1060
+ staleRowDeletes.push(() => this.storage.deleteGossipNode(nodeIdHex));
1059
1061
  }
1060
1062
  continue;
1061
1063
  }
1062
1064
  this.graph.restoreNode(node);
1063
1065
  }
1066
+ this.batchStorageDeletes(staleRowDeletes, 'gossipRestoreCleanup');
1064
1067
  this.pruneStaleGossipWithStorage();
1065
1068
  this.jitReceiveManager?.restore();
1066
1069
  this.restoreDirectFundingPolicy();
@@ -1427,6 +1430,38 @@ class LightningNode extends events_1.EventEmitter {
1427
1430
  return false;
1428
1431
  }
1429
1432
  }
1433
+ batchStorageDeletes(deletes, operation) {
1434
+ if (!this.storage || deletes.length === 0)
1435
+ return;
1436
+ let failed = 0;
1437
+ let lastError = '';
1438
+ const run = () => {
1439
+ failed = 0;
1440
+ for (const del of deletes) {
1441
+ try {
1442
+ del();
1443
+ }
1444
+ catch (err) {
1445
+ failed++;
1446
+ lastError = err.message;
1447
+ }
1448
+ }
1449
+ };
1450
+ try {
1451
+ (0, transaction_1.withStorageTransaction)(this.storage, run);
1452
+ }
1453
+ catch (err) {
1454
+ lastError = err.message;
1455
+ run();
1456
+ }
1457
+ if (failed > 0) {
1458
+ this.emit('node:error', {
1459
+ code: 'PERSISTENCE_ERROR',
1460
+ message: `${operation}: ${failed} of ${deletes.length} deletes failed (${lastError})`,
1461
+ timestamp: Date.now()
1462
+ });
1463
+ }
1464
+ }
1430
1465
  wireChannelManagerEvents() {
1431
1466
  this.channelManager.on('watchtower:backup', (channelId, _peerPubkey, perCommitmentSecret, revokedTx) => {
1432
1467
  this.backupRevokedStateToTowers(channelId, perCommitmentSecret, revokedTx);
@@ -11491,13 +11526,7 @@ class LightningNode extends events_1.EventEmitter {
11491
11526
  this.graph.pruneStaleChannels(now);
11492
11527
  if (this.storage &&
11493
11528
  typeof this.storage.deleteGossipChannel === 'function') {
11494
- for (const scidHex of staleScids) {
11495
- try {
11496
- this.storage.deleteGossipChannel(scidHex);
11497
- }
11498
- catch {
11499
- }
11500
- }
11529
+ this.batchStorageDeletes(staleScids.map((scidHex) => () => this.storage.deleteGossipChannel(scidHex)), 'pruneStaleGossip');
11501
11530
  }
11502
11531
  }
11503
11532
  emitStructuredLog(category, action, data) {