@leofcoin/chain 1.7.84 → 1.7.86

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.
@@ -4567,9 +4567,11 @@ class Machine {
4567
4567
  return this.#askWorker('block', index);
4568
4568
  }
4569
4569
  async addLoadedBlock(block) {
4570
+ debug$2(`adding loaded block: ${block.index}@${block.hash}`);
4571
+ debug$2(JSON.stringify(block, jsonStringifyBigInt));
4570
4572
  if (block.decoded)
4571
4573
  block = { ...block.decoded, hash: await block.hash() };
4572
- return this.#askWorker('addLoadedBlock', block);
4574
+ return this.#askWorker('addLoadedBlock', JSON.stringify(block, jsonStringifyBigInt));
4573
4575
  }
4574
4576
  async latestTransactions() {
4575
4577
  return this.#askWorker('latestTransactions');
@@ -5124,11 +5126,15 @@ class State extends Contract {
5124
5126
  async #loadBlocks(blocks) {
5125
5127
  this.#chainState = 'loading';
5126
5128
  let poolTransactionKeys = await globalThis.transactionPoolStore.keys();
5129
+ debug$1(`pool transactions: ${poolTransactionKeys.length}`);
5130
+ debug$1(`loading ${blocks.length} blocks`);
5127
5131
  for (const block of blocks) {
5128
5132
  if (block && !block.loaded) {
5129
5133
  try {
5134
+ debug$1(`loading block: ${Number(block.index)} ${block.hash}`);
5130
5135
  let transactions = await this.#loadBlockTransactions([...block.transactions] || []);
5131
5136
  // const lastTransactions = await this.#getLastTransactions()
5137
+ debug$1(`loading transactions: ${transactions.length} for block ${block.index}`);
5132
5138
  let priority = [];
5133
5139
  for (const transaction of transactions) {
5134
5140
  const hash = await transaction.hash();
@@ -5145,14 +5151,17 @@ class State extends Contract {
5145
5151
  }
5146
5152
  // prority blocks execution from the rest so result in higher fees.
5147
5153
  if (priority.length > 0) {
5154
+ debug$1(`executing ${priority.length} priority transactions for block ${block.index}`);
5148
5155
  priority = priority.sort((a, b) => a.nonce - b.nonce);
5149
5156
  for (const transaction of priority) {
5150
5157
  await this.#_executeTransaction(transaction);
5151
5158
  }
5152
5159
  }
5153
5160
  transactions = transactions.filter((transaction) => !transaction.decoded.priority);
5161
+ debug$1(`executing ${transactions.length} transactions for block ${block.index}`);
5154
5162
  await Promise.all(transactions.map((transaction) => this.#_executeTransaction(transaction)));
5155
5163
  this.#blocks[block.index].loaded = true;
5164
+ debug$1(`executed transactions for block ${block.index}`);
5156
5165
  if (Number(block.index) === 0)
5157
5166
  this.#loaded = true;
5158
5167
  await this.#machine.addLoadedBlock(block);
@@ -488,9 +488,20 @@ const _ = {
488
488
  worker.postMessage({ type: 'machine-ready', lastBlock });
489
489
  },
490
490
  addLoadedBlock: (block) => {
491
- blocks[block.index - 1] = block;
491
+ formatBytes(JSON.stringify(block).length);
492
+ block = JSON.parse(block, jsonParseBigInt);
493
+ // if (block.decoded) block = { ...block.decoded, hash: await new BlockMessage(block).hash() }
494
+ // if (blocks[block.index - 1]) {
495
+ // console.warn(`block ${block.index} already loaded, skipping`)
496
+ // return false
497
+ // }
498
+ blocks[Number(block.index) - 1] = block;
492
499
  lastBlock = blocks[blocks.length - 1];
493
500
  totalBlocks = totalBlocks += 1n;
501
+ worker.postMessage({
502
+ type: 'debug',
503
+ message: `added block: ${block.index} @${block.hash} size: ${formatBytes(JSON.stringify(block).length)}`
504
+ });
494
505
  return true;
495
506
  },
496
507
  loadBlock: (block) => {
package/exports/chain.js CHANGED
@@ -713,9 +713,11 @@ class Machine {
713
713
  return this.#askWorker('block', index);
714
714
  }
715
715
  async addLoadedBlock(block) {
716
+ debug$2(`adding loaded block: ${block.index}@${block.hash}`);
717
+ debug$2(JSON.stringify(block, jsonStringifyBigInt));
716
718
  if (block.decoded)
717
719
  block = { ...block.decoded, hash: await block.hash() };
718
- return this.#askWorker('addLoadedBlock', block);
720
+ return this.#askWorker('addLoadedBlock', JSON.stringify(block, jsonStringifyBigInt));
719
721
  }
720
722
  async latestTransactions() {
721
723
  return this.#askWorker('latestTransactions');
@@ -1270,11 +1272,15 @@ class State extends Contract {
1270
1272
  async #loadBlocks(blocks) {
1271
1273
  this.#chainState = 'loading';
1272
1274
  let poolTransactionKeys = await globalThis.transactionPoolStore.keys();
1275
+ debug$1(`pool transactions: ${poolTransactionKeys.length}`);
1276
+ debug$1(`loading ${blocks.length} blocks`);
1273
1277
  for (const block of blocks) {
1274
1278
  if (block && !block.loaded) {
1275
1279
  try {
1280
+ debug$1(`loading block: ${Number(block.index)} ${block.hash}`);
1276
1281
  let transactions = await this.#loadBlockTransactions([...block.transactions] || []);
1277
1282
  // const lastTransactions = await this.#getLastTransactions()
1283
+ debug$1(`loading transactions: ${transactions.length} for block ${block.index}`);
1278
1284
  let priority = [];
1279
1285
  for (const transaction of transactions) {
1280
1286
  const hash = await transaction.hash();
@@ -1291,14 +1297,17 @@ class State extends Contract {
1291
1297
  }
1292
1298
  // prority blocks execution from the rest so result in higher fees.
1293
1299
  if (priority.length > 0) {
1300
+ debug$1(`executing ${priority.length} priority transactions for block ${block.index}`);
1294
1301
  priority = priority.sort((a, b) => a.nonce - b.nonce);
1295
1302
  for (const transaction of priority) {
1296
1303
  await this.#_executeTransaction(transaction);
1297
1304
  }
1298
1305
  }
1299
1306
  transactions = transactions.filter((transaction) => !transaction.decoded.priority);
1307
+ debug$1(`executing ${transactions.length} transactions for block ${block.index}`);
1300
1308
  await Promise.all(transactions.map((transaction) => this.#_executeTransaction(transaction)));
1301
1309
  this.#blocks[block.index].loaded = true;
1310
+ debug$1(`executed transactions for block ${block.index}`);
1302
1311
  if (Number(block.index) === 0)
1303
1312
  this.#loaded = true;
1304
1313
  await this.#machine.addLoadedBlock(block);
@@ -488,9 +488,20 @@ const _ = {
488
488
  worker.postMessage({ type: 'machine-ready', lastBlock });
489
489
  },
490
490
  addLoadedBlock: (block) => {
491
- blocks[block.index - 1] = block;
491
+ formatBytes(JSON.stringify(block).length);
492
+ block = JSON.parse(block, jsonParseBigInt);
493
+ // if (block.decoded) block = { ...block.decoded, hash: await new BlockMessage(block).hash() }
494
+ // if (blocks[block.index - 1]) {
495
+ // console.warn(`block ${block.index} already loaded, skipping`)
496
+ // return false
497
+ // }
498
+ blocks[Number(block.index) - 1] = block;
492
499
  lastBlock = blocks[blocks.length - 1];
493
500
  totalBlocks = totalBlocks += 1n;
501
+ worker.postMessage({
502
+ type: 'debug',
503
+ message: `added block: ${block.index} @${block.hash} size: ${formatBytes(JSON.stringify(block).length)}`
504
+ });
494
505
  return true;
495
506
  },
496
507
  loadBlock: (block) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.7.84",
3
+ "version": "1.7.86",
4
4
  "description": "Official javascript implementation",
5
5
  "private": false,
6
6
  "exports": {