@leofcoin/chain 1.6.6 → 1.6.8
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/exports/browser/chain.js +21 -10
- package/exports/chain.js +21 -10
- package/package.json +1 -1
package/exports/browser/chain.js
CHANGED
|
@@ -3939,7 +3939,7 @@ class Machine {
|
|
|
3939
3939
|
console.error(`init error: ${data.message}`);
|
|
3940
3940
|
break;
|
|
3941
3941
|
}
|
|
3942
|
-
case '
|
|
3942
|
+
case 'executeError': {
|
|
3943
3943
|
// console.warn(`error executing transaction ${data.message}`);
|
|
3944
3944
|
pubsub.publish(data.id, { error: data.message });
|
|
3945
3945
|
break;
|
|
@@ -4979,6 +4979,7 @@ class Chain extends VersionControl {
|
|
|
4979
4979
|
return this;
|
|
4980
4980
|
}
|
|
4981
4981
|
async #invalidTransaction(hash) {
|
|
4982
|
+
hash = new TextDecoder().decode(hash);
|
|
4982
4983
|
await globalThis.transactionPoolStore.delete(hash);
|
|
4983
4984
|
console.log(`removed invalid transaction: ${hash}`);
|
|
4984
4985
|
}
|
|
@@ -5072,6 +5073,9 @@ class Chain extends VersionControl {
|
|
|
5072
5073
|
// @ts-ignore
|
|
5073
5074
|
transaction.hash = hash;
|
|
5074
5075
|
}
|
|
5076
|
+
if (!(await transactionStore.has(hash))) {
|
|
5077
|
+
transactionStore.put(hash, await blockMessage.hash());
|
|
5078
|
+
}
|
|
5075
5079
|
(await transactionPoolStore.has(hash)) && (await transactionPoolStore.delete(hash));
|
|
5076
5080
|
return transaction;
|
|
5077
5081
|
}));
|
|
@@ -5090,12 +5094,16 @@ class Chain extends VersionControl {
|
|
|
5090
5094
|
}
|
|
5091
5095
|
try {
|
|
5092
5096
|
promises = await Promise.allSettled(promises);
|
|
5097
|
+
const noncesByAddress = {};
|
|
5093
5098
|
for (let transaction of blockMessage.decoded.transactions) {
|
|
5094
5099
|
globalThis.pubsub.publish('transaction-processed', transaction);
|
|
5095
5100
|
if (transaction.to === globalThis.peernet.selectedAccount)
|
|
5096
5101
|
globalThis.pubsub.publish('account-transaction-processed', transaction);
|
|
5097
|
-
|
|
5102
|
+
if (!noncesByAddress[transaction.from] || noncesByAddress?.[transaction.from] < transaction.nonce) {
|
|
5103
|
+
noncesByAddress[transaction.from] = transaction.nonce;
|
|
5104
|
+
}
|
|
5098
5105
|
}
|
|
5106
|
+
await Promise.all(Object.entries(noncesByAddress).map(([from, nonce]) => globalThis.accountsStore.put(from, String(nonce))));
|
|
5099
5107
|
if ((await this.lastBlock).index < Number(blockMessage.decoded.index)) {
|
|
5100
5108
|
await this.machine.addLoadedBlock({ ...blockMessage.decoded, loaded: true, hash: await blockMessage.hash() });
|
|
5101
5109
|
await this.updateState(blockMessage);
|
|
@@ -5183,15 +5191,18 @@ class Chain extends VersionControl {
|
|
|
5183
5191
|
console.log({ latestTransactions });
|
|
5184
5192
|
// exclude failing tx
|
|
5185
5193
|
transactions = await this.promiseTransactions(transactions);
|
|
5186
|
-
const
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5194
|
+
const normalTransactions = [];
|
|
5195
|
+
const priorityransactions = [];
|
|
5196
|
+
for (const transaction of transactions) {
|
|
5197
|
+
if (transaction.decoded.priority)
|
|
5198
|
+
priorityransactions.push(transaction);
|
|
5199
|
+
else
|
|
5200
|
+
normalTransactions.push(transaction);
|
|
5201
|
+
}
|
|
5202
|
+
for (const transaction of priorityransactions.sort((a, b) => a.decoded.nonce - b.decoded.nonce)) {
|
|
5190
5203
|
await this.#handleTransaction(transaction, latestTransactions, block);
|
|
5191
5204
|
}
|
|
5192
|
-
await Promise.all(
|
|
5193
|
-
.filter((transaction) => !transaction.decoded.priority)
|
|
5194
|
-
.map((transaction) => this.#handleTransaction(transaction, latestTransactions, block)));
|
|
5205
|
+
await Promise.all(normalTransactions.map((transaction) => this.#handleTransaction(transaction, latestTransactions, block)));
|
|
5195
5206
|
// don't add empty block
|
|
5196
5207
|
if (block.transactions.length === 0)
|
|
5197
5208
|
return;
|
|
@@ -5271,7 +5282,7 @@ class Chain extends VersionControl {
|
|
|
5271
5282
|
const hash = await transaction.hash();
|
|
5272
5283
|
try {
|
|
5273
5284
|
const has = await globalThis.transactionPoolStore.has(hash);
|
|
5274
|
-
if (!has) {
|
|
5285
|
+
if (!has && !(await transactionStore.has(hash))) {
|
|
5275
5286
|
await globalThis.transactionPoolStore.put(hash, transaction.encoded);
|
|
5276
5287
|
}
|
|
5277
5288
|
if (this.#participating && !this.#runningEpoch)
|
package/exports/chain.js
CHANGED
|
@@ -307,7 +307,7 @@ class Machine {
|
|
|
307
307
|
console.error(`init error: ${data.message}`);
|
|
308
308
|
break;
|
|
309
309
|
}
|
|
310
|
-
case '
|
|
310
|
+
case 'executeError': {
|
|
311
311
|
// console.warn(`error executing transaction ${data.message}`);
|
|
312
312
|
pubsub.publish(data.id, { error: data.message });
|
|
313
313
|
break;
|
|
@@ -1347,6 +1347,7 @@ class Chain extends VersionControl {
|
|
|
1347
1347
|
return this;
|
|
1348
1348
|
}
|
|
1349
1349
|
async #invalidTransaction(hash) {
|
|
1350
|
+
hash = new TextDecoder().decode(hash);
|
|
1350
1351
|
await globalThis.transactionPoolStore.delete(hash);
|
|
1351
1352
|
console.log(`removed invalid transaction: ${hash}`);
|
|
1352
1353
|
}
|
|
@@ -1440,6 +1441,9 @@ class Chain extends VersionControl {
|
|
|
1440
1441
|
// @ts-ignore
|
|
1441
1442
|
transaction.hash = hash;
|
|
1442
1443
|
}
|
|
1444
|
+
if (!(await transactionStore.has(hash))) {
|
|
1445
|
+
transactionStore.put(hash, await blockMessage.hash());
|
|
1446
|
+
}
|
|
1443
1447
|
(await transactionPoolStore.has(hash)) && (await transactionPoolStore.delete(hash));
|
|
1444
1448
|
return transaction;
|
|
1445
1449
|
}));
|
|
@@ -1458,12 +1462,16 @@ class Chain extends VersionControl {
|
|
|
1458
1462
|
}
|
|
1459
1463
|
try {
|
|
1460
1464
|
promises = await Promise.allSettled(promises);
|
|
1465
|
+
const noncesByAddress = {};
|
|
1461
1466
|
for (let transaction of blockMessage.decoded.transactions) {
|
|
1462
1467
|
globalThis.pubsub.publish('transaction-processed', transaction);
|
|
1463
1468
|
if (transaction.to === globalThis.peernet.selectedAccount)
|
|
1464
1469
|
globalThis.pubsub.publish('account-transaction-processed', transaction);
|
|
1465
|
-
|
|
1470
|
+
if (!noncesByAddress[transaction.from] || noncesByAddress?.[transaction.from] < transaction.nonce) {
|
|
1471
|
+
noncesByAddress[transaction.from] = transaction.nonce;
|
|
1472
|
+
}
|
|
1466
1473
|
}
|
|
1474
|
+
await Promise.all(Object.entries(noncesByAddress).map(([from, nonce]) => globalThis.accountsStore.put(from, String(nonce))));
|
|
1467
1475
|
if ((await this.lastBlock).index < Number(blockMessage.decoded.index)) {
|
|
1468
1476
|
await this.machine.addLoadedBlock({ ...blockMessage.decoded, loaded: true, hash: await blockMessage.hash() });
|
|
1469
1477
|
await this.updateState(blockMessage);
|
|
@@ -1551,15 +1559,18 @@ class Chain extends VersionControl {
|
|
|
1551
1559
|
console.log({ latestTransactions });
|
|
1552
1560
|
// exclude failing tx
|
|
1553
1561
|
transactions = await this.promiseTransactions(transactions);
|
|
1554
|
-
const
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1562
|
+
const normalTransactions = [];
|
|
1563
|
+
const priorityransactions = [];
|
|
1564
|
+
for (const transaction of transactions) {
|
|
1565
|
+
if (transaction.decoded.priority)
|
|
1566
|
+
priorityransactions.push(transaction);
|
|
1567
|
+
else
|
|
1568
|
+
normalTransactions.push(transaction);
|
|
1569
|
+
}
|
|
1570
|
+
for (const transaction of priorityransactions.sort((a, b) => a.decoded.nonce - b.decoded.nonce)) {
|
|
1558
1571
|
await this.#handleTransaction(transaction, latestTransactions, block);
|
|
1559
1572
|
}
|
|
1560
|
-
await Promise.all(
|
|
1561
|
-
.filter((transaction) => !transaction.decoded.priority)
|
|
1562
|
-
.map((transaction) => this.#handleTransaction(transaction, latestTransactions, block)));
|
|
1573
|
+
await Promise.all(normalTransactions.map((transaction) => this.#handleTransaction(transaction, latestTransactions, block)));
|
|
1563
1574
|
// don't add empty block
|
|
1564
1575
|
if (block.transactions.length === 0)
|
|
1565
1576
|
return;
|
|
@@ -1639,7 +1650,7 @@ class Chain extends VersionControl {
|
|
|
1639
1650
|
const hash = await transaction.hash();
|
|
1640
1651
|
try {
|
|
1641
1652
|
const has = await globalThis.transactionPoolStore.has(hash);
|
|
1642
|
-
if (!has) {
|
|
1653
|
+
if (!has && !(await transactionStore.has(hash))) {
|
|
1643
1654
|
await globalThis.transactionPoolStore.put(hash, transaction.encoded);
|
|
1644
1655
|
}
|
|
1645
1656
|
if (this.#participating && !this.#runningEpoch)
|