Skip to content

Commit

Permalink
Merge pull request #50 from nguyenphuminh/big-fix
Browse files Browse the repository at this point in the history
Big fix
  • Loading branch information
nguyenphuminh authored Oct 26, 2022
2 parents 36b17a3 + ee0d0e0 commit f5302f1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 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.19.0",
"version": "0.20.0",
"description": "Node for JeChain - an experimental smart contract blockchain network",
"main": "./index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"BLOCK_REWARD": "202977000000000000",
"BLOCK_TIME": 30000,
"BLOCK_GAS_LIMIT": "500000000000000",
"BLOCK_GAS_LIMIT": "50000000000000",
"INITIAL_SUPPLY": "100000000000000000000000000"
}
10 changes: 5 additions & 5 deletions src/consensus/consensus.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { log16 } = require("../utils/utils");
const generateMerkleRoot = require("../core/merkle");
const { BLOCK_REWARD, BLOCK_TIME } = require("../config.json");

async function verifyBlock(newBlock, chainInfo, stateDB) {
async function verifyBlock(newBlock, chainInfo, stateDB, enableLogging = false) {
// Check if the block is valid or not, if yes, we will push it to the chain, update the difficulty, chain state and the transaction pool.

// A block is valid under these factors:
Expand Down Expand Up @@ -33,9 +33,6 @@ async function verifyBlock(newBlock, chainInfo, stateDB) {
newBlock.hash.startsWith("00000" + Array(Math.floor(log16(chainInfo.difficulty)) + 1).join("0")) &&
newBlock.difficulty === chainInfo.difficulty &&

// Check transactions
await Block.hasValidTransactions(newBlock, stateDB) &&

// Check transactions ordering
await Block.hasValidTxOrder(newBlock, stateDB) &&

Expand All @@ -50,7 +47,10 @@ async function verifyBlock(newBlock, chainInfo, stateDB) {
generateMerkleRoot(newBlock.transactions) === newBlock.txRoot &&

// Check gas limit
Block.hasValidGasLimit(newBlock)
Block.hasValidGasLimit(newBlock) &&

// Check transactions and transit state rih
await Block.verifyTxAndTransit(newBlock, stateDB, enableLogging)
)
}

Expand Down
12 changes: 11 additions & 1 deletion src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ function isNumber(str) {
return str.split("").every(char => "0123456789".includes(char));
}

function bigIntable(str) {
try {
BigInt(str);

return true;
} catch (e) {
return false;
}
}

function parseJSON(value) {
let parsed;

Expand All @@ -20,4 +30,4 @@ function parseJSON(value) {
return parsed;
}

module.exports = { log16, isNumber, parseJSON };
module.exports = { log16, isNumber, parseJSON, bigIntable };

0 comments on commit f5302f1

Please sign in to comment.