Skip to content

Commit

Permalink
Merge pull request #85 from nguyenphuminh/nonce-fix
Browse files Browse the repository at this point in the history
Nonce fix
  • Loading branch information
nguyenphuminh authored Jan 13, 2024
2 parents 065827e + 4188fef commit b7487e3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
10 changes: 5 additions & 5 deletions src/core/txPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/node/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b7487e3

Please sign in to comment.