Skip to content

Commit

Permalink
Merge pull request #43 from nguyenphuminh/fix-transaction-packing
Browse files Browse the repository at this point in the history
Fix transaction packing
  • Loading branch information
nguyenphuminh authored Aug 31, 2022
2 parents 5965696 + 25d2baf commit e55192a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 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.17.3",
"version": "0.17.4",
"description": "Node for JeChain - an experimental smart contract blockchain network",
"main": "./index.js",
"scripts": {
Expand Down
17 changes: 6 additions & 11 deletions src/node/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e55192a

Please sign in to comment.