diff --git a/package.json b/package.json index d18d0d9..f1f2bf2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jechain", - "version": "0.17.3", + "version": "0.17.4", "description": "Node for JeChain - an experimental smart contract blockchain network", "main": "./index.js", "scripts": { diff --git a/src/node/server.js b/src/node/server.js index af01c37..178b8ea 100644 --- a/src/node/server.js +++ b/src/node/server.js @@ -340,27 +340,22 @@ function mine(publicKey, ENABLE_LOGGING) { }); } - let gas = BigInt(0); // We will collect all the gas fee and add it to the mint transaction, along with the fixed mining reward. - - chainInfo.transactionPool.forEach(transaction => { gas += BigInt(transaction.gas) + BigInt(transaction.additionalData.contractGas || 0) }); - - // Mint transaction for miner's reward. - const rewardTransaction = new Transaction(SHA256(publicKey), (BigInt(BLOCK_REWARD) + gas).toString()); - Transaction.sign(rewardTransaction, MINT_KEY_PAIR); - + // Collect a list of transactions to mine const transactionsToMine = []; let totalGas = 0n; for (const tx of chainInfo.transactionPool) { - if (totalGas + BigInt(tx.additionalData.contractGas || 0) >= BigInt(BLOCK_GAS_LIMIT)) { - break; - } + if (totalGas + BigInt(tx.additionalData.contractGas || 0) >= BigInt(BLOCK_GAS_LIMIT)) break; transactionsToMine.push(tx); totalGas += BigInt(tx.additionalData.contractGas || 0); } + // Mint transaction for miner's reward. + const rewardTransaction = new Transaction(SHA256(publicKey), (BigInt(BLOCK_REWARD) + totalGas).toString()); + Transaction.sign(rewardTransaction, MINT_KEY_PAIR); + // Create a new block. const block = new Block( chainInfo.latestBlock.blockNumber + 1,