@leofcoin/chain 1.9.10 → 1.9.12

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.
@@ -1,4 +1,4 @@
1
- import { t as toBase58, T as TransactionMessage, C as ContractMessage, R as RawTransactionMessage, B as BlockMessage, L as LastBlockMessage, P as PROTOCOL_VERSION, a as REACHED_ONE_ZERO_ZERO, b as PrevoteMessage, c as PrecommitMessage, d as ProposalMessage, e as BWMessage, S as StateMessage, f as BWRequestMessage } from './constants-BCaq9RBn.js';
1
+ import { t as toBase58, T as TransactionMessage, C as ContractMessage, f as RawTransactionMessage, b as BlockMessage, L as LastBlockMessage, P as PROTOCOL_VERSION, R as REACHED_ONE_ZERO_ZERO, d as PrevoteMessage, c as PrecommitMessage, e as ProposalMessage, B as BWMessage, S as StateMessage, a as BWRequestMessage } from './constants-V2VjIc2r.js';
2
2
 
3
3
  const getTargets = () => Array.from([]);
4
4
  const isEnabled = (target) => {
@@ -932,7 +932,7 @@ var hasRequiredRe;
932
932
  function requireRe () {
933
933
  if (hasRequiredRe) return re.exports;
934
934
  hasRequiredRe = 1;
935
- (function (module, exports$1) {
935
+ (function (module, exports) {
936
936
 
937
937
  const {
938
938
  MAX_SAFE_COMPONENT_LENGTH,
@@ -940,14 +940,14 @@ function requireRe () {
940
940
  MAX_LENGTH,
941
941
  } = requireConstants();
942
942
  const debug = requireDebug();
943
- exports$1 = module.exports = {};
943
+ exports = module.exports = {};
944
944
 
945
945
  // The actual regexps go on exports.re
946
- const re = exports$1.re = [];
947
- const safeRe = exports$1.safeRe = [];
948
- const src = exports$1.src = [];
949
- const safeSrc = exports$1.safeSrc = [];
950
- const t = exports$1.t = {};
946
+ const re = exports.re = [];
947
+ const safeRe = exports.safeRe = [];
948
+ const src = exports.src = [];
949
+ const safeSrc = exports.safeSrc = [];
950
+ const t = exports.t = {};
951
951
  let R = 0;
952
952
 
953
953
  const LETTERDASHNUMBER = '[a-zA-Z0-9-]';
@@ -1070,7 +1070,7 @@ function requireRe () {
1070
1070
  createToken('GTLT', '((?:<|>)?=?)');
1071
1071
 
1072
1072
  // Something like "2.*" or "1.2.x".
1073
- // Note that "x.x" is a valid xRange identifer, meaning "any version"
1073
+ // Note that "x.x" is a valid xRange identifier, meaning "any version"
1074
1074
  // Only the first item is strictly required.
1075
1075
  createToken('XRANGEIDENTIFIERLOOSE', `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);
1076
1076
  createToken('XRANGEIDENTIFIER', `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`);
@@ -1111,7 +1111,7 @@ function requireRe () {
1111
1111
  createToken('LONETILDE', '(?:~>?)');
1112
1112
 
1113
1113
  createToken('TILDETRIM', `(\\s*)${src[t.LONETILDE]}\\s+`, true);
1114
- exports$1.tildeTrimReplace = '$1~';
1114
+ exports.tildeTrimReplace = '$1~';
1115
1115
 
1116
1116
  createToken('TILDE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`);
1117
1117
  createToken('TILDELOOSE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`);
@@ -1121,7 +1121,7 @@ function requireRe () {
1121
1121
  createToken('LONECARET', '(?:\\^)');
1122
1122
 
1123
1123
  createToken('CARETTRIM', `(\\s*)${src[t.LONECARET]}\\s+`, true);
1124
- exports$1.caretTrimReplace = '$1^';
1124
+ exports.caretTrimReplace = '$1^';
1125
1125
 
1126
1126
  createToken('CARET', `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`);
1127
1127
  createToken('CARETLOOSE', `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`);
@@ -1134,7 +1134,7 @@ function requireRe () {
1134
1134
  // it modifies, so that `> 1.2.3` ==> `>1.2.3`
1135
1135
  createToken('COMPARATORTRIM', `(\\s*)${src[t.GTLT]
1136
1136
  }\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true);
1137
- exports$1.comparatorTrimReplace = '$1$2$3';
1137
+ exports.comparatorTrimReplace = '$1$2$3';
1138
1138
 
1139
1139
  // Something like `1.2.3 - 1.2.4`
1140
1140
  // Note that these all use the loose form, because they'll be
@@ -2066,6 +2066,62 @@ function requireCoerce () {
2066
2066
  return coerce_1;
2067
2067
  }
2068
2068
 
2069
+ var truncate_1;
2070
+ var hasRequiredTruncate;
2071
+
2072
+ function requireTruncate () {
2073
+ if (hasRequiredTruncate) return truncate_1;
2074
+ hasRequiredTruncate = 1;
2075
+
2076
+ const parse = requireParse();
2077
+ const constants = requireConstants();
2078
+ const SemVer = requireSemver$1();
2079
+
2080
+ const truncate = (version, truncation, options) => {
2081
+ if (!constants.RELEASE_TYPES.includes(truncation)) {
2082
+ return null
2083
+ }
2084
+
2085
+ const clonedVersion = cloneInputVersion(version, options);
2086
+ return clonedVersion && doTruncation(clonedVersion, truncation)
2087
+ };
2088
+
2089
+ const cloneInputVersion = (version, options) => {
2090
+ const versionStringToParse = (
2091
+ version instanceof SemVer ? version.version : version
2092
+ );
2093
+
2094
+ return parse(versionStringToParse, options)
2095
+ };
2096
+
2097
+ const doTruncation = (version, truncation) => {
2098
+ if (isPrerelease(truncation)) {
2099
+ return version.version
2100
+ }
2101
+
2102
+ version.prerelease = [];
2103
+
2104
+ switch (truncation) {
2105
+ case 'major':
2106
+ version.minor = 0;
2107
+ version.patch = 0;
2108
+ break
2109
+ case 'minor':
2110
+ version.patch = 0;
2111
+ break
2112
+ }
2113
+
2114
+ return version.format()
2115
+ };
2116
+
2117
+ const isPrerelease = (type) => {
2118
+ return type.startsWith('pre')
2119
+ };
2120
+
2121
+ truncate_1 = truncate;
2122
+ return truncate_1;
2123
+ }
2124
+
2069
2125
  var lrucache;
2070
2126
  var hasRequiredLrucache;
2071
2127
 
@@ -2221,6 +2277,9 @@ function requireRange () {
2221
2277
  }
2222
2278
 
2223
2279
  parseRange (range) {
2280
+ // strip build metadata so it can't bleed into the version
2281
+ range = range.replace(BUILDSTRIPRE, '');
2282
+
2224
2283
  // memoize range parsing for performance.
2225
2284
  // this is a very hot path, and fully deterministic.
2226
2285
  const memoOpts =
@@ -2346,6 +2405,7 @@ function requireRange () {
2346
2405
  const SemVer = requireSemver$1();
2347
2406
  const {
2348
2407
  safeRe: re,
2408
+ src,
2349
2409
  t,
2350
2410
  comparatorTrimReplace,
2351
2411
  tildeTrimReplace,
@@ -2353,6 +2413,9 @@ function requireRange () {
2353
2413
  } = requireRe();
2354
2414
  const { FLAG_INCLUDE_PRERELEASE, FLAG_LOOSE } = requireConstants();
2355
2415
 
2416
+ // unbounded global build-metadata stripper used by parseRange
2417
+ const BUILDSTRIPRE = new RegExp(src[t.BUILD], 'g');
2418
+
2356
2419
  const isNullSet = c => c.value === '<0.0.0-0';
2357
2420
  const isAny = c => c.value === '';
2358
2421
 
@@ -3404,7 +3467,7 @@ function requireSubset () {
3404
3467
  if (higher === c && higher !== gt) {
3405
3468
  return false
3406
3469
  }
3407
- } else if (gt.operator === '>=' && !satisfies(gt.semver, String(c), options)) {
3470
+ } else if (gt.operator === '>=' && !c.test(gt.semver)) {
3408
3471
  return false
3409
3472
  }
3410
3473
  }
@@ -3422,7 +3485,7 @@ function requireSubset () {
3422
3485
  if (lower === c && lower !== lt) {
3423
3486
  return false
3424
3487
  }
3425
- } else if (lt.operator === '<=' && !satisfies(lt.semver, String(c), options)) {
3488
+ } else if (lt.operator === '<=' && !c.test(lt.semver)) {
3426
3489
  return false
3427
3490
  }
3428
3491
  }
@@ -3515,6 +3578,7 @@ function requireSemver () {
3515
3578
  const lte = requireLte();
3516
3579
  const cmp = requireCmp();
3517
3580
  const coerce = requireCoerce();
3581
+ const truncate = requireTruncate();
3518
3582
  const Comparator = requireComparator();
3519
3583
  const Range = requireRange();
3520
3584
  const satisfies = requireSatisfies();
@@ -3553,6 +3617,7 @@ function requireSemver () {
3553
3617
  lte,
3554
3618
  cmp,
3555
3619
  coerce,
3620
+ truncate,
3556
3621
  Comparator,
3557
3622
  Range,
3558
3623
  satisfies,
@@ -5733,7 +5798,7 @@ class ConnectionMonitor {
5733
5798
  try {
5734
5799
  const networkName = globalThis.peernet?.network;
5735
5800
  if (networkName && typeof networkName === "string") {
5736
- const { default: networks } = await import('./constants-BCaq9RBn.js').then(function (n) { return n.n; });
5801
+ const { default: networks } = await import('./constants-V2VjIc2r.js').then(function (n) { return n.n; });
5737
5802
  const [mainKey, subKey] = networkName.split(":");
5738
5803
  const networkConfig = networks?.[mainKey]?.[subKey];
5739
5804
  if (networkConfig?.stars && Array.isArray(networkConfig.stars)) {
@@ -6051,22 +6116,22 @@ class Chain extends VersionControl {
6051
6116
  #sleep(ms) {
6052
6117
  return new Promise((resolve) => setTimeout(resolve, ms));
6053
6118
  }
6054
- async #recordPeerFailure(peerId, reason) {
6055
- if (!this.#peerReputations.has(peerId)) {
6056
- this.#peerReputations.set(peerId, { score: 0, failures: [] });
6119
+ async #recordPeerFailure(peerId2, reason) {
6120
+ if (!this.#peerReputations.has(peerId2)) {
6121
+ this.#peerReputations.set(peerId2, { score: 0, failures: [] });
6057
6122
  }
6058
- const rep = this.#peerReputations.get(peerId);
6123
+ const rep = this.#peerReputations.get(peerId2);
6059
6124
  rep.score -= 1;
6060
6125
  rep.failures.push(`${Date.now()}: ${reason}`);
6061
6126
  if (rep.failures.length > this.#maxPeerFailures) {
6062
6127
  rep.failures.shift();
6063
6128
  }
6064
6129
  if (rep.score < this.#minPeerScore) {
6065
- console.warn(`[peer-ban] Peer ${peerId} banned after ${rep.failures.length} failures`);
6130
+ console.warn(`[peer-ban] Peer ${peerId2} banned after ${rep.failures.length} failures`);
6066
6131
  try {
6067
- await globalThis.peernet.disconnect(peerId);
6132
+ await globalThis.peernet.disconnect(peerId2);
6068
6133
  } catch (e) {
6069
- debug(`Failed to disconnect peer ${peerId}`);
6134
+ debug(`Failed to disconnect peer ${peerId2}`);
6070
6135
  }
6071
6136
  }
6072
6137
  }
@@ -6186,8 +6251,8 @@ class Chain extends VersionControl {
6186
6251
  const start = Date.now();
6187
6252
  try {
6188
6253
  await this.#createBlock();
6189
- } catch (error) {
6190
- console.error(error);
6254
+ } catch (error2) {
6255
+ console.error(error2);
6191
6256
  }
6192
6257
  const end = Date.now();
6193
6258
  console.log((end - start) / 1e3 + " s");
@@ -6302,30 +6367,57 @@ class Chain extends VersionControl {
6302
6367
  console.warn(`Deprecated: ${response.decoded.response} is not an Uint8Array`);
6303
6368
  }
6304
6369
  return response.decoded.response;
6305
- } catch (error) {
6306
- const peerId = peer?.peerId || peer?.id || peer?.address || "unknown";
6307
- debug(`peernet request failed: ${request} -> ${peerId}:`, error?.message ?? error);
6308
- throw error;
6370
+ } catch (error2) {
6371
+ const peerId2 = peer?.peerId || peer?.id || peer?.address || "unknown";
6372
+ debug(`peernet request failed: ${request} -> ${peerId2}:`, error2?.message ?? error2);
6373
+ throw error2;
6309
6374
  }
6310
6375
  }
6311
6376
  async #decodeKnownBlocksResponse(response) {
6312
6377
  if (!response) return null;
6378
+ if (Array.isArray(response)) {
6379
+ return { blocks: response };
6380
+ }
6313
6381
  if (Array.isArray(response.blocks)) {
6314
6382
  return { blocks: response.blocks };
6315
6383
  }
6384
+ if (response.response && Array.isArray(response.response.blocks)) {
6385
+ return { blocks: response.response.blocks };
6386
+ }
6387
+ if (typeof response === "string") {
6388
+ try {
6389
+ const parsed = JSON.parse(response);
6390
+ if (Array.isArray(parsed)) return { blocks: parsed };
6391
+ if (parsed && Array.isArray(parsed.blocks)) return { blocks: parsed.blocks };
6392
+ if (parsed?.response && Array.isArray(parsed.response.blocks)) return { blocks: parsed.response.blocks };
6393
+ } catch {
6394
+ return null;
6395
+ }
6396
+ return null;
6397
+ }
6316
6398
  if (!(response instanceof Uint8Array)) return null;
6317
6399
  let payload = response;
6318
- for (let i = 0; i < 2; i++) {
6400
+ for (let i = 0; i < 3; i++) {
6319
6401
  if (!(payload instanceof Uint8Array)) break;
6320
6402
  try {
6321
6403
  const nestedResponse = await new globalThis.peernet.protos["peernet-response"](payload);
6322
6404
  payload = nestedResponse?.decoded?.response;
6323
6405
  } catch {
6324
- return null;
6406
+ break;
6325
6407
  }
6326
6408
  }
6327
6409
  if (Array.isArray(payload)) return { blocks: payload };
6328
6410
  if (payload && Array.isArray(payload.blocks)) return { blocks: payload.blocks };
6411
+ if (payload?.response && Array.isArray(payload.response.blocks)) return { blocks: payload.response.blocks };
6412
+ try {
6413
+ const decoded = new TextDecoder().decode(response);
6414
+ const parsed = JSON.parse(decoded);
6415
+ if (Array.isArray(parsed)) return { blocks: parsed };
6416
+ if (parsed && Array.isArray(parsed.blocks)) return { blocks: parsed.blocks };
6417
+ if (parsed?.response && Array.isArray(parsed.response.blocks)) return { blocks: parsed.response.blocks };
6418
+ } catch {
6419
+ return null;
6420
+ }
6329
6421
  return null;
6330
6422
  }
6331
6423
  async getPeerTransactionPool(peer) {
@@ -6342,8 +6434,8 @@ class Chain extends VersionControl {
6342
6434
  let txData;
6343
6435
  try {
6344
6436
  txData = await globalThis.peernet.get(key, "transaction");
6345
- } catch (error) {
6346
- debug(`Failed to get transaction ${key}:`, error?.message ?? error);
6437
+ } catch (error2) {
6438
+ debug(`Failed to get transaction ${key}:`, error2?.message ?? error2);
6347
6439
  }
6348
6440
  if (txData !== void 0) {
6349
6441
  transactionsToGet.push(transactionPoolStore.put(key, txData));
@@ -6352,11 +6444,11 @@ class Chain extends VersionControl {
6352
6444
  }
6353
6445
  return Promise.all(transactionsToGet);
6354
6446
  }
6355
- async #peerConnected(peerId) {
6356
- debug(`peer connected: ${peerId}`);
6357
- const peer = peernet.getConnection(peerId);
6447
+ async #peerConnected(peerId2) {
6448
+ debug(`peer connected: ${peerId2}`);
6449
+ const peer = peernet.getConnection(peerId2);
6358
6450
  if (!peer) {
6359
- debug(`peer not found: ${peerId}`);
6451
+ debug(`peer not found: ${peerId2}`);
6360
6452
  return;
6361
6453
  }
6362
6454
  if (!peer.version) {
@@ -6371,13 +6463,13 @@ class Chain extends VersionControl {
6371
6463
  peer.version = versionResponse.version;
6372
6464
  }
6373
6465
  if (!peer.version || typeof peer.version !== "string") {
6374
- const reason = `invalid version response from peer ${peerId}`;
6466
+ const reason = `invalid version response from peer ${peerId2}`;
6375
6467
  debug(reason);
6376
- await this.#recordPeerFailure(peerId, reason);
6468
+ await this.#recordPeerFailure(peerId2, reason);
6377
6469
  return;
6378
6470
  }
6379
- } catch (error) {
6380
- debug(`failed to request version from peer ${peerId}:`, error?.message ?? error);
6471
+ } catch (error2) {
6472
+ debug(`failed to request version from peer ${peerId2}:`, error2?.message ?? error2);
6381
6473
  return;
6382
6474
  }
6383
6475
  }
@@ -6385,31 +6477,32 @@ class Chain extends VersionControl {
6385
6477
  if (!this.isVersionCompatible(peer.version)) {
6386
6478
  const mismatchReason = `incompatible peer version ${peer.version} (local: ${this.version})`;
6387
6479
  console.error(`[chain] ${mismatchReason}`);
6388
- await this.#recordPeerFailure(peerId, mismatchReason);
6480
+ await this.#recordPeerFailure(peerId2, mismatchReason);
6389
6481
  return;
6390
6482
  }
6391
6483
  let lastBlock;
6392
6484
  try {
6393
6485
  console.log("requesting last block from peer...");
6394
6486
  console.log(await this.lastBlock);
6395
- console.log(new LastBlockMessage(await this.#makeRequest(peer, "lastBlock")));
6396
- lastBlock = new LastBlockMessage(await this.#makeRequest(peer, "lastBlock")).decoded;
6397
- } catch (error) {
6398
- const peerName = peer?.peerId || peer?.id || peer?.address || peerId || "unknown";
6399
- debug(`lastBlock request failed: ${peerName}:`, error?.message ?? error);
6400
- await this.#recordPeerFailure(peerId, `lastBlock request failed: ${error?.message ?? error}`);
6487
+ const lastBlockRaw = await this.#makeRequest(peer, "lastBlock");
6488
+ console.log(new LastBlockMessage(lastBlockRaw));
6489
+ lastBlock = new LastBlockMessage(lastBlockRaw).decoded;
6490
+ } catch (error2) {
6491
+ const peerName2 = peer?.peerId || peer?.id || peer?.address || peerId2 || "unknown";
6492
+ debug(`lastBlock request failed: ${peerName2}:`, error2?.message ?? error2);
6493
+ await this.#recordPeerFailure(peerId2, `lastBlock request failed: ${error2?.message ?? error2}`);
6401
6494
  return;
6402
6495
  }
6403
6496
  const localBlock = await this.lastBlock;
6404
6497
  const MAX_SYNC_AHEAD = 1e5;
6405
6498
  if (lastBlock?.index > BigInt(localBlock?.index ?? 0) + BigInt(MAX_SYNC_AHEAD)) {
6406
- const peerName = peer?.peerId || peer?.id || peer?.address || peerId || "unknown";
6407
- debug(`Peer ${peerName} claims unreasonable block height ${lastBlock.index} (local: ${localBlock?.index ?? 0})`);
6408
- await this.#recordPeerFailure(peerId, `unreasonable lastBlock index: ${lastBlock.index}`);
6499
+ const peerName2 = peer?.peerId || peer?.id || peer?.address || peerId2 || "unknown";
6500
+ debug(`Peer ${peerName2} claims unreasonable block height ${lastBlock.index} (local: ${localBlock?.index ?? 0})`);
6501
+ await this.#recordPeerFailure(peerId2, `unreasonable lastBlock index: ${lastBlock.index}`);
6409
6502
  return;
6410
6503
  }
6411
6504
  if (!lastBlock || !lastBlock.hash || lastBlock.hash === "0x0") {
6412
- debug(`peer has no lastBlock: ${peerId}`);
6505
+ debug(`peer has no lastBlock: ${peerId2}`);
6413
6506
  return;
6414
6507
  }
6415
6508
  const higherThenCurrentLocal = !localBlock?.index ? true : lastBlock.index > localBlock.index;
@@ -6419,23 +6512,24 @@ class Chain extends VersionControl {
6419
6512
  const knownBlocksRaw = await this.#makeRequest(peer, "knownBlocks");
6420
6513
  const knownBlocksResponse = await this.#decodeKnownBlocksResponse(knownBlocksRaw);
6421
6514
  if (!knownBlocksResponse) {
6422
- const reason = `knownBlocks decode failed for peer ${peerId}`;
6423
- debug(reason);
6424
- await this.#recordPeerFailure(peerId, reason);
6425
- return;
6426
- }
6427
- const MAX_WANTLIST_SIZE = 1e3;
6428
- const remaining = MAX_WANTLIST_SIZE - this.wantList.length;
6429
- if (remaining > 0) {
6430
- for (const hash of knownBlocksResponse.blocks.slice(0, remaining)) {
6431
- this.wantList.push(hash);
6515
+ debug(
6516
+ `knownBlocks decode failed for peer ${peerId2} (non-fatal), continuing sync without prefilled wantList`
6517
+ );
6518
+ } else {
6519
+ const MAX_WANTLIST_SIZE = 1e3;
6520
+ const remaining = MAX_WANTLIST_SIZE - this.wantList.length;
6521
+ if (remaining > 0) {
6522
+ for (const hash of knownBlocksResponse.blocks.slice(0, remaining)) {
6523
+ this.wantList.push(hash);
6524
+ }
6432
6525
  }
6433
6526
  }
6434
- } catch (error) {
6435
- const peerName = peer?.peerId || peer?.id || peer?.address || peerId || "unknown";
6436
- debug(`knownBlocks request failed: ${peerName}:`, error?.message ?? error);
6437
- await this.#recordPeerFailure(peerId, `knownBlocks request failed: ${error?.message ?? error}`);
6438
- return;
6527
+ } catch (error2) {
6528
+ const peerName2 = peer?.peerId || peer?.id || peer?.address || peerId2 || "unknown";
6529
+ debug(
6530
+ `knownBlocks request failed: ${peerName2} (non-fatal), continuing sync without prefilled wantList:`,
6531
+ error2?.message ?? error2
6532
+ );
6439
6533
  }
6440
6534
  }
6441
6535
  }
@@ -6451,9 +6545,9 @@ class Chain extends VersionControl {
6451
6545
  try {
6452
6546
  const peerTransactionPool = higherThenCurrentLocal && await this.getPeerTransactionPool(peer) || [];
6453
6547
  if (this.#participating && peerTransactionPool.length > 0) return this.#runEpoch();
6454
- } catch (error) {
6455
- const peerName = peer?.peerId || peer?.id || peer?.address || peerId || "unknown";
6456
- debug(`transactionPool request failed: ${peerName}:`, error?.message ?? error);
6548
+ } catch (error2) {
6549
+ const peerName2 = peer?.peerId || peer?.id || peer?.address || peerId2 || "unknown";
6550
+ debug(`transactionPool request failed: ${peerName2}:`, error2?.message ?? error2);
6457
6551
  }
6458
6552
  }, 3e3);
6459
6553
  try {
@@ -6461,12 +6555,18 @@ class Chain extends VersionControl {
6461
6555
  if (stateInfo instanceof Uint8Array) {
6462
6556
  stateInfo = new StateMessage(stateInfo).decoded;
6463
6557
  }
6558
+ debug(
6559
+ `sync start with peer ${peerId2}: local=${localBlock?.index ?? -1} remote=${lastBlock?.index ?? -1} hash=${lastBlock?.hash}`
6560
+ );
6464
6561
  await this.syncChain(lastBlock);
6562
+ debug(
6563
+ `sync finished with peer ${peerId2}: state=${this.syncState} localNow=${(await this.lastBlock)?.index ?? -1}`
6564
+ );
6465
6565
  this.machine.states.info = stateInfo;
6466
- } catch (error) {
6467
- const peerName = peer?.peerId || peer?.id || peer?.address || peerId || "unknown";
6468
- debug(`stateInfo/syncChain failed: ${peerName}:`, error?.message ?? error);
6469
- await this.#recordPeerFailure(peerId, `stateInfo/syncChain failed: ${error?.message ?? error}`);
6566
+ } catch (error2) {
6567
+ const peerName2 = peer?.peerId || peer?.id || peer?.address || peerId2 || "unknown";
6568
+ debug(`stateInfo/syncChain failed: ${peerName2}:`, error2?.message ?? error2);
6569
+ await this.#recordPeerFailure(peerId2, `stateInfo/syncChain failed: ${error2?.message ?? error2}`);
6470
6570
  return;
6471
6571
  }
6472
6572
  }
@@ -6482,16 +6582,19 @@ class Chain extends VersionControl {
6482
6582
  try {
6483
6583
  let result = await this.machine.execute(to, method, params);
6484
6584
  globalThis.pubsub.publish(`transaction.completed.${hash}`, { status: "fulfilled", hash });
6485
- return result || "no state change";
6486
- } catch (error) {
6585
+ debug(
6586
+ `lastBlock request failed: ${peerName} (non-fatal), continuing sync without prefilled wantList:`,
6587
+ error?.message ?? error
6588
+ );
6589
+ } catch (error2) {
6487
6590
  await transactionPoolStore.delete(hash);
6488
6591
  try {
6489
6592
  globalThis.peernet.publish("invalid-transaction", hash);
6490
6593
  } catch (publishError) {
6491
6594
  debug("peernet publish failed: invalid-transaction", publishError?.message ?? publishError);
6492
6595
  }
6493
- globalThis.pubsub.publish(`transaction.completed.${hash}`, { status: "fail", hash, error });
6494
- throw { error, hash, from, to, params, nonce };
6596
+ globalThis.pubsub.publish(`transaction.completed.${hash}`, { status: "fail", hash, error: error2 });
6597
+ throw { error: error2, hash, from, to, params, nonce };
6495
6598
  }
6496
6599
  }
6497
6600
  async #addBlock(block) {
@@ -6502,7 +6605,7 @@ class Chain extends VersionControl {
6502
6605
  const existingBlockAtHeight = this.#blocks[blockIndex];
6503
6606
  if (existingBlockAtHeight) {
6504
6607
  if (existingBlockAtHeight.hash !== hash) {
6505
- console.error(`[CONSENSUS ALERT] Conflicting blocks at height ${blockIndex}:`);
6608
+ debug(`knownBlocks decode failed for peer ${peerId} (non-fatal), continuing sync without prefilled wantList`);
6506
6609
  console.error(` Local: ${existingBlockAtHeight.hash}`);
6507
6610
  console.error(` Remote: ${hash}`);
6508
6611
  throw new Error(`Block conflict detected at index ${blockIndex}`);
@@ -6610,10 +6713,10 @@ class Chain extends VersionControl {
6610
6713
  await this.updateState(blockMessage);
6611
6714
  }
6612
6715
  globalThis.pubsub.publish("block-processed", blockMessage.decoded);
6613
- } catch (error) {
6614
- console.log(error.hash);
6716
+ } catch (error2) {
6717
+ console.log(error2.hash);
6615
6718
  console.log("errrrr");
6616
- await transactionPoolStore.delete(error.hash);
6719
+ await transactionPoolStore.delete(error2.hash);
6617
6720
  }
6618
6721
  }
6619
6722
  async participate(address) {
@@ -6631,12 +6734,12 @@ class Chain extends VersionControl {
6631
6734
  const transaction = await signTransaction(rawTransaction, globalThis.peernet.identity);
6632
6735
  try {
6633
6736
  await this.sendTransaction(transaction);
6634
- } catch (error) {
6635
- console.error(error);
6737
+ } catch (error2) {
6738
+ console.error(error2);
6636
6739
  }
6637
6740
  }
6638
- } catch (error) {
6639
- debug("Error in participate:", error.message);
6741
+ } catch (error2) {
6742
+ debug("Error in participate:", error2.message);
6640
6743
  }
6641
6744
  if (await this.hasTransactionToHandle() && !this.#runningEpoch && this.#participating) await this.#runEpoch();
6642
6745
  }
@@ -6733,9 +6836,9 @@ class Chain extends VersionControl {
6733
6836
  address: validator,
6734
6837
  bw: bw.up + bw.down
6735
6838
  };
6736
- } catch (error) {
6737
- const peerId = peer?.peerId || peer?.id || peer?.address || "unknown";
6738
- debug(`bw request failed: ${peerId}:`, error?.message ?? error);
6839
+ } catch (error2) {
6840
+ const peerId2 = peer?.peerId || peer?.id || peer?.address || "unknown";
6841
+ debug(`bw request failed: ${peerId2}:`, error2?.message ?? error2);
6739
6842
  return null;
6740
6843
  }
6741
6844
  } else if (globalThis.peernet.selectedAccount === validator) {
@@ -6753,8 +6856,8 @@ class Chain extends VersionControl {
6753
6856
  }
6754
6857
  }
6755
6858
  };
6756
- finalizeBWAndBroadcast().catch((error) => {
6757
- debug(`background BW finalization failed:`, error?.message ?? error);
6859
+ finalizeBWAndBroadcast().catch((error2) => {
6860
+ debug(`background BW finalization failed:`, error2?.message ?? error2);
6758
6861
  });
6759
6862
  block.validators = block.validators.map((validator) => {
6760
6863
  validator.reward = block.fees;
@@ -6819,8 +6922,8 @@ class Chain extends VersionControl {
6819
6922
  debug("peernet publish failed: consensus:propose", publishError?.message ?? publishError);
6820
6923
  }
6821
6924
  await this.#castVote("prevote", hash, block.index, this.#consensusRound);
6822
- } catch (error) {
6823
- console.log(error);
6925
+ } catch (error2) {
6926
+ console.log(error2);
6824
6927
  throw new Error(`invalid block ${block}`);
6825
6928
  }
6826
6929
  }
@@ -6951,8 +7054,8 @@ class Chain extends VersionControl {
6951
7054
  if (globalThis.peernet && globalThis.peernet.start) {
6952
7055
  await globalThis.peernet.start();
6953
7056
  }
6954
- } catch (error) {
6955
- console.warn("Failed to reconnect to peers:", error.message);
7057
+ } catch (error2) {
7058
+ console.warn("Failed to reconnect to peers:", error2.message);
6956
7059
  }
6957
7060
  }
6958
7061
  }