@leofcoin/chain 1.5.58 → 1.5.60

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.
@@ -4933,14 +4933,18 @@ class Chain extends VersionControl {
4933
4933
  }
4934
4934
  }
4935
4935
  async #addBlock(block) {
4936
+ console.log({ block });
4936
4937
  const blockMessage = await new BlockMessage(block);
4937
4938
  await Promise.all(blockMessage.decoded.transactions
4938
4939
  // @ts-ignore
4939
4940
  .map(async (transaction) => {
4940
4941
  let hash = transaction.hash;
4941
- if (!hash)
4942
- await new TransactionMessage(transaction).hash();
4942
+ if (!hash) {
4943
+ hash = await new TransactionMessage(transaction).hash();
4944
+ transaction.hash = hash;
4945
+ }
4943
4946
  (await transactionPoolStore.has(hash)) && (await transactionPoolStore.delete(hash));
4947
+ return transaction;
4944
4948
  }));
4945
4949
  const hash = await blockMessage.hash();
4946
4950
  await globalThis.blockStore.put(hash, blockMessage.encoded);
@@ -4951,13 +4955,11 @@ class Chain extends VersionControl {
4951
4955
  let contracts = [];
4952
4956
  for (let transaction of blockMessage.decoded.transactions) {
4953
4957
  // await transactionStore.put(transaction.hash, transaction.encoded)
4954
- // @ts-ignore
4955
- const index = contracts.indexOf(transaction.to);
4956
- // @ts-ignore
4957
- if (index === -1)
4958
+ if (!contracts.includes(transaction.to)) {
4958
4959
  contracts.push(transaction.to);
4960
+ }
4959
4961
  // Todo: go trough all accounts
4960
- // @ts-ignore
4962
+ //@ts-ignore
4961
4963
  promises.push(this.#executeTransaction(transaction));
4962
4964
  }
4963
4965
  try {
@@ -147,15 +147,14 @@ _.init = async (message) => {
147
147
 
148
148
  // }
149
149
  for (const block of blocks) {
150
- // we only revalidate the latest 128 blocks
151
- // every 128 blocks a snapshot is taken and stored in state
150
+ // we only revalidate the latest 24 blocks
151
+ // every 24 blocks a snapshot is taken and stored in state
152
152
  // this means contracts will be restored from this state
153
153
  // this also means devs NEED to make sure the state can be restored
154
154
  // on contract deploy an error will be thrown if state wasn't recoverable
155
- if (block.index > 128) {
156
- for (const transaction of blocks[block.index - 2].transactions) {
157
- latestTransactions.splice(transaction, 1);
158
- }
155
+ if (block.index > 24) {
156
+ const transactionCount = blocks[block.index - 1].transactions.length;
157
+ latestTransactions.splice(-(transactionCount - 1), latestTransactions.length);
159
158
  }
160
159
  await Promise.all(
161
160
  block.transactions.map(async (transaction) => {
package/exports/chain.js CHANGED
@@ -1344,14 +1344,18 @@ class Chain extends VersionControl {
1344
1344
  }
1345
1345
  }
1346
1346
  async #addBlock(block) {
1347
+ console.log({ block });
1347
1348
  const blockMessage = await new BlockMessage(block);
1348
1349
  await Promise.all(blockMessage.decoded.transactions
1349
1350
  // @ts-ignore
1350
1351
  .map(async (transaction) => {
1351
1352
  let hash = transaction.hash;
1352
- if (!hash)
1353
- await new TransactionMessage(transaction).hash();
1353
+ if (!hash) {
1354
+ hash = await new TransactionMessage(transaction).hash();
1355
+ transaction.hash = hash;
1356
+ }
1354
1357
  (await transactionPoolStore.has(hash)) && (await transactionPoolStore.delete(hash));
1358
+ return transaction;
1355
1359
  }));
1356
1360
  const hash = await blockMessage.hash();
1357
1361
  await globalThis.blockStore.put(hash, blockMessage.encoded);
@@ -1362,13 +1366,11 @@ class Chain extends VersionControl {
1362
1366
  let contracts = [];
1363
1367
  for (let transaction of blockMessage.decoded.transactions) {
1364
1368
  // await transactionStore.put(transaction.hash, transaction.encoded)
1365
- // @ts-ignore
1366
- const index = contracts.indexOf(transaction.to);
1367
- // @ts-ignore
1368
- if (index === -1)
1369
+ if (!contracts.includes(transaction.to)) {
1369
1370
  contracts.push(transaction.to);
1371
+ }
1370
1372
  // Todo: go trough all accounts
1371
- // @ts-ignore
1373
+ //@ts-ignore
1372
1374
  promises.push(this.#executeTransaction(transaction));
1373
1375
  }
1374
1376
  try {
@@ -147,15 +147,14 @@ _.init = async (message) => {
147
147
 
148
148
  // }
149
149
  for (const block of blocks) {
150
- // we only revalidate the latest 128 blocks
151
- // every 128 blocks a snapshot is taken and stored in state
150
+ // we only revalidate the latest 24 blocks
151
+ // every 24 blocks a snapshot is taken and stored in state
152
152
  // this means contracts will be restored from this state
153
153
  // this also means devs NEED to make sure the state can be restored
154
154
  // on contract deploy an error will be thrown if state wasn't recoverable
155
- if (block.index > 128) {
156
- for (const transaction of blocks[block.index - 2].transactions) {
157
- latestTransactions.splice(transaction, 1);
158
- }
155
+ if (block.index > 24) {
156
+ const transactionCount = blocks[block.index - 1].transactions.length;
157
+ latestTransactions.splice(-(transactionCount - 1), latestTransactions.length);
159
158
  }
160
159
  await Promise.all(
161
160
  block.transactions.map(async (transaction) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.5.58",
3
+ "version": "1.5.60",
4
4
  "description": "Official javascript implementation",
5
5
  "exports": {
6
6
  "./node": {