From bb759450e9c4963027aa726bce22b262c03e74fa Mon Sep 17 00:00:00 2001 From: NathanBSC Date: Thu, 13 Jun 2024 18:26:05 +0800 Subject: [PATCH] cmd/jsutils: get mean number of block txs --- cmd/jsutils/gettxcount.js | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/cmd/jsutils/gettxcount.js b/cmd/jsutils/gettxcount.js index 8bc7f2bdd9..cf4b8cec91 100644 --- a/cmd/jsutils/gettxcount.js +++ b/cmd/jsutils/gettxcount.js @@ -13,9 +13,11 @@ program.parse(process.argv); const provider = new ethers.JsonRpcProvider(program.rpc) const main = async () => { - let txCount = 0; + let txCountTotal = 0; + let gasUsedTotal = 0; + let txCountMax = 0; let num = 0; - console.log("Find the max txs count between", program.startNum, "and", program.endNum); + console.log("Find the max and mean txs count between", program.startNum, "and", program.endNum); for (let i = program.startNum; i < program.endNum; i++) { if (program.miner !== "") { let blockData = await provider.getBlock(Number(i)) @@ -26,12 +28,36 @@ const main = async () => { let x = await provider.send("eth_getBlockTransactionCountByNumber", [ ethers.toQuantity(i)]); let a = ethers.toNumber(x) - if (a > txCount) { + txCountTotal += a + if (a > txCountMax) { num = i; - txCount = a; + txCountMax = a; } + + let header = await provider.send("eth_getHeaderByNumber", [ + ethers.toQuantity(i)]); + let gasUsed = eval(eval(header.gasUsed).toString(10)) + gasUsedTotal += gasUsed } - console.log("BlockNum = ", num, "TxCount =", txCount); + console.log("txCountMax =", txCountMax, "BlockNumber = ", num); + + let blockCount = program.endNum - program.startNum + let txCountPerBlock = txCountTotal/blockCount + console.log("txCountPerBlock =", txCountPerBlock, "txCountTotal =", txCountTotal, "BlockCount = ", blockCount); + + let startHeader = await provider.send("eth_getHeaderByNumber", [ + ethers.toQuantity(program.startNum)]); + let startTime = eval(eval(startHeader.timestamp).toString(10)) + let endHeader = await provider.send("eth_getHeaderByNumber", [ + ethers.toQuantity(program.endNum)]); + let endTime = eval(eval(endHeader.timestamp).toString(10)) + let timeCost = endTime - startTime + let avgBlockTime = timeCost/blockCount + let tps = txCountTotal/timeCost + let avgBlockGasUsed = gasUsedTotal/blockCount + console.log("txCountPerSecond =", tps, "avgBlockTime = ", avgBlockTime, "avgBlockGasUsed = ", avgBlockGasUsed); + + }; main().then(() => process.exit(0))