From 2a0a4cc60e4fb0d6af97352f53daef7ae7407f9e Mon Sep 17 00:00:00 2001 From: "Phu Minh (Catto)" <53084840+nguyenphuminh@users.noreply.github.com> Date: Fri, 12 Jan 2024 19:45:50 -0800 Subject: [PATCH 1/2] Fixed a problem with nonce - Fixed a problem with nonce in transaction pool: Nonce starts at 0 when checking, it's supposed to be the current nonce of the sender, not 0. - Add more info to logs. --- src/core/txPool.js | 10 +++++----- src/node/server.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/txPool.js b/src/core/txPool.js index d03417d..eb2f13e 100644 --- a/src/core/txPool.js +++ b/src/core/txPool.js @@ -13,7 +13,7 @@ async function addTransaction(transaction, chainInfo, stateDB) { try { transaction = Transaction.deserialize(transaction); } catch (e) { - console.log(`\x1b[31mERROR\x1b[0m [${(new Date()).toISOString()}] Failed to add one transaction to pool.`); + console.log(`\x1b[31mERROR\x1b[0m [${(new Date()).toISOString()}] Failed to add one transaction to pool: Can not deserialize transaction.`); // If transaction can not be deserialized, it's faulty return; @@ -24,7 +24,7 @@ async function addTransaction(transaction, chainInfo, stateDB) { await Transaction.isValid(transaction, stateDB)) || BigInt(transaction.additionalData.contractGas || 0) > BigInt(BLOCK_GAS_LIMIT) ) { - console.log(`\x1b[31mERROR\x1b[0m [${(new Date()).toISOString()}] Failed to add one transaction to pool.`); + console.log(`\x1b[31mERROR\x1b[0m [${(new Date()).toISOString()}] Failed to add one transaction to pool: Transaction is invalid.`); return; } @@ -36,13 +36,13 @@ async function addTransaction(transaction, chainInfo, stateDB) { const txSenderAddress = SHA256(txSenderPubkey); if (!(await stateDB.keys().all()).includes(txSenderAddress)) { - console.log(`\x1b[31mERROR\x1b[0m [${(new Date()).toISOString()}] Failed to add one transaction to pool.`); + console.log(`\x1b[31mERROR\x1b[0m [${(new Date()).toISOString()}] Failed to add one transaction to pool: Sender does not exist.`); return; } // Check nonce - let maxNonce = 0; + let maxNonce = deserializeState(await stateDB.get(txSenderAddress)).nonce; for (const tx of txPool) { const poolTxSenderPubkey = Transaction.getPubKey(transaction); @@ -54,7 +54,7 @@ async function addTransaction(transaction, chainInfo, stateDB) { } if (maxNonce + 1 !== transaction.nonce) { - console.log(`\x1b[31mERROR\x1b[0m [${(new Date()).toISOString()}] Failed to add one transaction to pool.`); + console.log(`\x1b[31mERROR\x1b[0m [${(new Date()).toISOString()}] Failed to add one transaction to pool: Transaction has nonce lower than nonce in pool.`); return; } diff --git a/src/node/server.js b/src/node/server.js index 67a6951..07f9754 100644 --- a/src/node/server.js +++ b/src/node/server.js @@ -178,7 +178,7 @@ async function startServer(options) { // This is pretty much the same as addTransaction, but we will send the transaction to other connected nodes if it's valid. // Check nonce - let maxNonce = 0; + let maxNonce = deserializeState(await stateDB.get(txSenderAddress)).nonce; for (const tx of chainInfo.transactionPool) { const poolTxSenderPubkey = Transaction.getPubKey(transaction); From 4188fef8392f63dd5914162580fc9c98037d1afd Mon Sep 17 00:00:00 2001 From: "Phu Minh (Catto)" <53084840+nguyenphuminh@users.noreply.github.com> Date: Fri, 12 Jan 2024 19:46:58 -0800 Subject: [PATCH 2/2] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 589ea23..a1d5105 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jechain", - "version": "0.29.0", + "version": "0.30.0", "description": "Node for JeChain - an experimental smart contract blockchain network", "main": "./index.js", "scripts": {