From 5b50dd02ecae982b86e7d0132de70f182615e45c Mon Sep 17 00:00:00 2001 From: zzzckck <152148891+zzzckck@users.noreply.github.com> Date: Tue, 5 Nov 2024 16:44:39 +0800 Subject: [PATCH] jsutil: put all js utils in one file (#2748) --- cmd/jsutils/README.md | 35 +--- cmd/jsutils/check_blobtx.js | 51 ------ cmd/jsutils/faucet_request.js | 49 ------ cmd/jsutils/get_perf.js | 70 -------- cmd/jsutils/getchainstatus.js | 294 ++++++++++++++++++++++++++++++++-- cmd/jsutils/getslashcount.js | 119 -------------- 6 files changed, 282 insertions(+), 336 deletions(-) delete mode 100644 cmd/jsutils/check_blobtx.js delete mode 100644 cmd/jsutils/faucet_request.js delete mode 100644 cmd/jsutils/get_perf.js delete mode 100644 cmd/jsutils/getslashcount.js diff --git a/cmd/jsutils/README.md b/cmd/jsutils/README.md index 95a9afee2d..d9e16c7f09 100644 --- a/cmd/jsutils/README.md +++ b/cmd/jsutils/README.md @@ -10,38 +10,9 @@ Install node.js dependency: ```shell script npm install ``` -## Run -### 1.Get Validator's Information: Version, MinGasPrice -mainnet validators version -```bash - npm run startMainnet -``` -testnet validators version -```bash - npm run startTestnet -``` - -### 2.Get Transaction Count -```bash -node gettxcount.js --rpc ${url} --startNum ${start} --endNum ${end} --miner ${miner} (optional) -``` -### 3. Get Performance -```bash -node get_perf.js --rpc ${url} --startNum ${start} --endNum ${end} -``` -output as following -```bash -Get the performance between [ 19470 , 19670 ) -txCountPerBlock = 3142.81 txCountTotal = 628562 BlockCount = 200 avgBlockTime = 3.005 inturnBlocksRatio = 0.975 justifiedBlocksRatio = 0.98 -txCountPerSecond = 1045.8602329450914 avgGasUsedPerBlock = 250.02062627 avgGasUsedPerSecond = 83.20153952412646 +## Run +Run according to the usage: ``` - -### 4. Get validators slash count -```bash -use the latest block -node getslashcount.js --Rpc ${ArchiveRpc} -use a block number -node getslashcount.js --Rpc ${ArchiveRpc} --Num ${blockNum} +node getchainstatus.js --help ``` - diff --git a/cmd/jsutils/check_blobtx.js b/cmd/jsutils/check_blobtx.js deleted file mode 100644 index 2e8fe1ed1e..0000000000 --- a/cmd/jsutils/check_blobtx.js +++ /dev/null @@ -1,51 +0,0 @@ -import { ethers } from "ethers"; -import program from "commander"; - -// depends on ethjs v6.11.0+ for 4844, https://github.com/ethers-io/ethers.js/releases/tag/v6.11.0 -// BSC testnet enabled 4844 on block: 39539137 -// Usage: -// nvm use 20 -// node check_blobtx.js --rpc https://data-seed-prebsc-1-s1.binance.org:8545 --startNum 39539137 -// node check_blobtx.js --rpc https://data-seed-prebsc-1-s1.binance.org:8545 --startNum 39539137 --endNum 40345994 -program.option("--rpc ", "Rpc Server URL"); -program.option("--startNum ", "start block", 0); -program.option("--endNum ", "end block", 0); -program.parse(process.argv); - -const provider = new ethers.JsonRpcProvider(program.rpc); -const main = async () => { - var startBlock = parseInt(program.startNum) - var endBlock = parseInt(program.endNum) - if (isNaN(endBlock) || isNaN(startBlock) || startBlock == 0) { - console.error("invalid input, --startNum", program.startNum, "--end", program.endNum) - return - } - // if --endNum is not specified, set it to the latest block number. - if (endBlock == 0) { - endBlock = await provider.getBlockNumber(); - } - if (startBlock > endBlock) { - console.error("invalid input, startBlock:",startBlock, " endBlock:", endBlock); - return - } - - for (let i = startBlock; i <= endBlock; i++) { - let blockData = await provider.getBlock(i); - console.log("startBlock:",startBlock, "endBlock:", endBlock, "curBlock", i, "blobGasUsed", blockData.blobGasUsed); - if (blockData.blobGasUsed == 0) { - continue - } - for (let txIndex = 0; txIndex<= blockData.transactions.length - 1; txIndex++) { - let txHash = blockData.transactions[txIndex] - let txData = await provider.getTransaction(txHash); - if (txData.type == 3) { - console.log("BlobTx in block:",i, " txIndex:", txIndex, " txHash:", txHash); - } - } - } -}; -main().then(() => process.exit(0)) - .catch((error) => { - console.error(error); - process.exit(1); - }); \ No newline at end of file diff --git a/cmd/jsutils/faucet_request.js b/cmd/jsutils/faucet_request.js deleted file mode 100644 index bd4179747b..0000000000 --- a/cmd/jsutils/faucet_request.js +++ /dev/null @@ -1,49 +0,0 @@ -import { ethers } from "ethers"; -import program from "commander"; - -// Usage: -// node faucet_request.js --rpc localhost:8545 --startNum 39539137 -// node faucet_request.js --rpc localhost:8545 --startNum 39539137 --endNum 40345994 - -// node faucet_request.js --rpc https://data-seed-prebsc-1-s1.bnbchain.org:8545 --startNum 39539137 --endNum 40345994 -program.option("--rpc ", "Rpc Server URL"); -program.option("--startNum ", "start block", 0); -program.option("--endNum ", "end block", 0); -program.parse(process.argv); - -const provider = new ethers.JsonRpcProvider(program.rpc); -const main = async () => { - var startBlock = parseInt(program.startNum) - var endBlock = parseInt(program.endNum) - if (isNaN(endBlock) || isNaN(startBlock) || startBlock == 0) { - console.error("invalid input, --startNum", program.startNum, "--end", program.endNum) - return - } - // if --endNum is not specified, set it to the latest block number. - if (endBlock == 0) { - endBlock = await provider.getBlockNumber(); - } - if (startBlock > endBlock) { - console.error("invalid input, startBlock:",startBlock, " endBlock:", endBlock); - return - } - - let startBalance = await provider.getBalance("0xaa25Aa7a19f9c426E07dee59b12f944f4d9f1DD3", startBlock) - let endBalance = await provider.getBalance("0xaa25Aa7a19f9c426E07dee59b12f944f4d9f1DD3", endBlock) - const faucetAmount = BigInt(0.3 * 10**18); // Convert 0.3 ether to wei as a BigInt - const numFaucetRequest = (startBalance - endBalance) / faucetAmount; - - // Convert BigInt to ether - const startBalanceEth = Number(startBalance) / 10**18; - const endBalanceEth = Number(endBalance) / 10**18; - - console.log(`Start Balance: ${startBalanceEth} ETH`); - console.log(`End Balance: ${endBalanceEth} ETH`); - - console.log("successful faucet request: ",numFaucetRequest); -}; -main().then(() => process.exit(0)) - .catch((error) => { - console.error(error); - process.exit(1); - }); diff --git a/cmd/jsutils/get_perf.js b/cmd/jsutils/get_perf.js deleted file mode 100644 index cec035f09f..0000000000 --- a/cmd/jsutils/get_perf.js +++ /dev/null @@ -1,70 +0,0 @@ -import { ethers } from "ethers"; -import program from "commander"; - -program.option("--rpc ", "Rpc"); -program.option("--startNum ", "start num") -program.option("--endNum ", "end num") -program.parse(process.argv); - -const provider = new ethers.JsonRpcProvider(program.rpc) - -const main = async () => { - let txCountTotal = 0; - let gasUsedTotal = 0; - let inturnBlocks = 0; - let justifiedBlocks = 0; - let turnLength = await provider.send("parlia_getTurnLength", [ - ethers.toQuantity(program.startNum)]); - for (let i = program.startNum; i < program.endNum; i++) { - let txCount = await provider.send("eth_getBlockTransactionCountByNumber", [ - ethers.toQuantity(i)]); - txCountTotal += ethers.toNumber(txCount) - - let header = await provider.send("eth_getHeaderByNumber", [ - ethers.toQuantity(i)]); - let gasUsed = eval(eval(header.gasUsed).toString(10)) - gasUsedTotal += gasUsed - let difficulty = eval(eval(header.difficulty).toString(10)) - if (difficulty == 2) { - inturnBlocks += 1 - } - let timestamp = eval(eval(header.timestamp).toString(10)) - - let justifiedNumber = await provider.send("parlia_getJustifiedNumber", [ - ethers.toQuantity(i)]); - if (justifiedNumber + 1 == i) { - justifiedBlocks += 1 - } else { - console.log("justified unexpected", "BlockNumber =", i,"justifiedNumber",justifiedNumber) - } - console.log("BlockNumber =", i, "mod =", i%turnLength, "miner =", header.miner , "difficulty =", difficulty, "txCount =", ethers.toNumber(txCount), "gasUsed", gasUsed, "timestamp", timestamp) - } - - let blockCount = program.endNum - program.startNum - let txCountPerBlock = txCountTotal/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 inturnBlocksRatio = inturnBlocks/blockCount - let justifiedBlocksRatio = justifiedBlocks/blockCount - let tps = txCountTotal/timeCost - let M = 1000000 - let avgGasUsedPerBlock = gasUsedTotal/blockCount/M - let avgGasUsedPerSecond = gasUsedTotal/timeCost/M - - console.log("Get the performance between [", program.startNum, ",", program.endNum, ")"); - console.log("txCountPerBlock =", txCountPerBlock, "txCountTotal =", txCountTotal, "BlockCount =", blockCount, "avgBlockTime =", avgBlockTime, "inturnBlocksRatio =", inturnBlocksRatio, "justifiedBlocksRatio =", justifiedBlocksRatio); - console.log("txCountPerSecond =", tps, "avgGasUsedPerBlock =", avgGasUsedPerBlock, "avgGasUsedPerSecond =", avgGasUsedPerSecond); -}; - -main().then(() => process.exit(0)) - .catch((error) => { - console.error(error); - process.exit(1); - }); \ No newline at end of file diff --git a/cmd/jsutils/getchainstatus.js b/cmd/jsutils/getchainstatus.js index db5e25cf48..4c93a57918 100644 --- a/cmd/jsutils/getchainstatus.js +++ b/cmd/jsutils/getchainstatus.js @@ -1,20 +1,14 @@ import { ethers } from "ethers"; import program from "commander"; -// Global Options: program.option("--rpc ", "Rpc"); -// GetTxCount Options: program.option("--startNum ", "start num") program.option("--endNum ", "end num") program.option("--miner ", "miner", "") -// GetVersion Options: program.option("--num ", "validator num", 21) -// GetTopAddr Options: program.option("--topNum ", "top num of address to be displayed", 20) - -program.parse(process.argv); - -const provider = new ethers.JsonRpcProvider(program.rpc) +program.option("--blockNum ", "block num", 0) +program.option("-h, --help", "") function printUsage() { console.log("Usage:"); @@ -23,21 +17,112 @@ function printUsage() { console.log("\nSubcommands:"); console.log(" GetTxCount: find the block with max tx size of a range"); console.log(" GetVersion: dump validators' binary version, based on Header.Extra"); - console.log(" GetTopAddr: get hottest $topNum target address within a block range"); + console.log(" GetTopAddr: get hottest $topNum target address of a block range"); + console.log(" GetSlashCount: get slash state at a specific block height"); + console.log(" GetPerformanceData: analyze the performance data of a block range"); + console.log(" GetBlobTxs: get BlobTxs of a block range"); + console.log(" GetFaucetStatus: get faucet status of BSC testnet"); console.log("\nOptions:"); console.log(" --rpc specify the url of RPC endpoint"); - console.log(" --startNum the start block number, for command GetTxCount"); - console.log(" --endNum the end block number, for command GetTxCount"); - console.log(" --miner the miner address, for command GetTxCount"); - console.log(" --num the number of blocks to be checked, for command GetVersion"); - console.log(" --topNum the topNum of blocks to be checked, for command GetVersion"); + console.log(" --startNum the start block number"); + console.log(" --endNum the end block number"); + console.log(" --miner the miner address"); + console.log(" --num the number of blocks to be checked"); + console.log(" --topNum the topNum of blocks to be checked"); + console.log(" --blockNum the block number to be checked"); console.log("\nExample:"); // mainnet https://bsc-mainnet.nodereal.io/v1/454e504917db4f82b756bd0cf6317dce console.log(" node getchainstatus.js GetTxCount --rpc https://bsc-testnet-dataseed.bnbchain.org --startNum 40000001 --endNum 40000005") console.log(" node getchainstatus.js GetVersion --rpc https://bsc-testnet-dataseed.bnbchain.org --num 21") console.log(" node getchainstatus.js GetTopAddr --rpc https://bsc-testnet-dataseed.bnbchain.org --startNum 40000001 --endNum 40000010 --topNum 10") + console.log(" node getchainstatus.js GetSlashCount --rpc https://bsc-testnet-dataseed.bnbchain.org --blockNum 40000001") // latest block if `--blockNum` is not specified + console.log(" node getchainstatus.js GetPerformanceData --rpc https://bsc-testnet-dataseed.bnbchain.org --startNum 40000001 --endNum 40000010") + console.log(" node getchainstatus.js GetBlobTxs --rpc https://bsc-testnet-dataseed.bnbchain.org --startNum 40000001 --endNum 40000010") + console.log(" node getchainstatus.js GetFaucetStatus --rpc https://bsc-testnet-dataseed.bnbchain.org --startNum 40000001 --endNum 40000010") } +program.usage = printUsage; +program.parse(process.argv); + +const provider = new ethers.JsonRpcProvider(program.rpc) + +const slashAbi = [ + "function getSlashIndicator(address validatorAddr) external view returns (uint256, uint256)" +] +const validatorSetAbi = [ + "function getLivingValidators() external view returns (address[], bytes[])" +] +const stakeHubAbi = [ + "function getValidatorDescription(address validatorAddr) external view returns (tuple(string, string, string, string))", + "function consensusToOperator(address consensusAddr) public view returns (address)" +] +const addrValidatorSet = '0x0000000000000000000000000000000000001000'; +const addrSlash = '0x0000000000000000000000000000000000001001'; +const addrStakeHub = '0x0000000000000000000000000000000000002002'; + +const validatorSet = new ethers.Contract(addrValidatorSet, validatorSetAbi, provider); +const slashIndicator = new ethers.Contract(addrSlash, slashAbi, provider) +const stakeHub = new ethers.Contract(addrStakeHub, stakeHubAbi, provider) + +const validatorMap = new Map([ + // BSC mainnet + ["0x37e9627A91DD13e453246856D58797Ad6583D762", "LegendII"], + ["0xB4647b856CB9C3856d559C885Bed8B43e0846a47", "CertiK"], + ["0x75B851a27D7101438F45fce31816501193239A83", "Figment"], + ["0x502aECFE253E6AA0e8D2A06E12438FFeD0Fe16a0", "BscScan"], + ["0xCa503a7eD99eca485da2E875aedf7758472c378C", "InfStones"], + ["0x5009317FD4F6F8FeEa9dAe41E5F0a4737BB7A7D5", "NodeReal"], + ["0x1cFDBd2dFf70C6e2e30df5012726F87731F38164", "Tranchess"], + ["0xF8de5e61322302b2c6e0a525cC842F10332811bf", "Namelix"], + ["0xCcB42A9b8d6C46468900527Bc741938E78AB4577", "Turing"], + ["0x9f1b7FAE54BE07F4FEE34Eb1aaCb39A1F7B6FC92", "TWStaking"], + ["0x7E1FdF03Eb3aC35BF0256694D7fBe6B6d7b3E0c8","LegendIII"], + ["0x7b501c7944185130DD4aD73293e8Aa84eFfDcee7","MathW"], + ["0x58567F7A51a58708C8B40ec592A38bA64C0697De","Legend"], + ["0x460A252B4fEEFA821d3351731220627D7B7d1F3d","Defibit"], + ["0x8A239732871AdC8829EA2f47e94087C5FBad47b6","The48Club"], + ["0xD3b0d838cCCEAe7ebF1781D11D1bB741DB7Fe1A7","BNBEve"], + ["0xF8B99643fAfC79d9404DE68E48C4D49a3936f787","Avengers"], + ["0x4e5acf9684652BEa56F2f01b7101a225Ee33d23f","HashKey"], + ["0x9bb56C2B4DBE5a06d79911C9899B6f817696ACFc","Feynman"], + ["0xbdcc079BBb23C1D9a6F36AA31309676C258aBAC7","Fuji"], + ["0x38944092685a336CB6B9ea58836436709a2adC89","Shannon"], + ["0xfC1004C0f296Ec3Df4F6762E9EabfcF20EB304a2","Aoraki"], + ["0xa0884bb00E5F23fE2427f0E5eC9E51F812848563","Coda"], + ["0xe7776De78740f28a96412eE5cbbB8f90896b11A5","Ankr"], + ["0xA2D969E82524001Cb6a2357dBF5922B04aD2FCD8","Pexmons"], + ["0x5cf810AB8C718ac065b45f892A5BAdAB2B2946B9","Zen"], + ["0x4d15D9BCd0c2f33E7510c0de8b42697CA558234a","LegendVII"], + ["0x1579ca96EBd49A0B173f86C372436ab1AD393380","LegendV"], + ["0xd1F72d433f362922f6565FC77c25e095B29141c8","LegendVI"], + ["0xf9814D93b4d904AaA855cBD4266D6Eb0Ec1Aa478","Legend8"], + ["0x025a4e09Ea947b8d695f53ddFDD48ddB8F9B06b7","Ciscox"], + ["0xE9436F6F30b4B01b57F2780B2898f3820EbD7B98","LegendIV"], + ["0xC2d534F079444E6E7Ff9DabB3FD8a26c607932c8","Axion"], + ["0x9F7110Ba7EdFda83Fc71BeA6BA3c0591117b440D","LegendIX"], + ["0xB997Bf1E3b96919fBA592c1F61CE507E165Ec030","Seoraksan"], + ["0x286C1b674d48cFF67b4096b6c1dc22e769581E91","Sigm8"], + ["0x73A26778ef9509a6E94b55310eE7233795a9EB25","Coinlix"], + ["0x18c44f4FBEde9826C7f257d500A65a3D5A8edebc","Nozti"], + ["0xA100FCd08cE722Dc68Ddc3b54237070Cb186f118","Tiollo"], + ["0x0F28847cfdbf7508B13Ebb9cEb94B2f1B32E9503","Raptas"], + ["0xfD85346c8C991baC16b9c9157e6bdfDACE1cD7d7","Glorin"], + ["0x978F05CED39A4EaFa6E8FD045Fe2dd6Da836c7DF","NovaX"], + ["0xd849d1dF66bFF1c2739B4399425755C2E0fAbbAb","Nexa"], + ["0xA015d9e9206859c13201BB3D6B324d6634276534","Star"], + ["0x5ADde0151BfAB27f329e5112c1AeDeed7f0D3692","Veri"], + // Chapel + ["0x08265dA01E1A65d62b903c7B34c08cB389bF3D99","Ararat"], + ["0x7f5f2cF1aec83bF0c74DF566a41aa7ed65EA84Ea","Kita"], + ["0x53387F3321FD69d1E030BB921230dFb188826AFF","Fuji"], + ["0x76D76ee8823dE52A1A431884c2ca930C5e72bff3","Seoraksan"], + ["0xd447b49CD040D20BC21e49ffEa6487F5638e4346","Everest"], + ["0x1a3d9D7A717D64e6088aC937d5aAcDD3E20ca963","Elbrus"], + ["0x40D3256EB0BaBE89f0ea54EDAa398513136612f5","Bloxroute"], + ["0xF9a1Db0d6f22Bd78ffAECCbc8F47c83Df9FBdbCf","Test"], + ["0xB4cd0dCF71381b452A92A359BbE7146e8825Ce46","BSCLista"] +]); + // 1.cmd: "GetTxCount", usage: // node getchainstatus.js GetTxCount --rpc https://bsc-testnet-dataseed.bnbchain.org \ // --startNum 40000001 --endNum 40000005 \ @@ -134,6 +219,177 @@ async function getTopAddr() { }); }; +// 4.cmd: "GetSlashCount", usage: +// node getchainstatus.js GetSlashCount \ +// --rpc https://bsc-testnet-dataseed.bnbchain.org \ +// --blockNum(optional): the block num which is based for the slash state, default: latest block +async function getSlashCount() { + let blockNum = ethers.getNumber(program.blockNum) + if (blockNum === 0) { + blockNum = await provider.getBlockNumber() + } + let block = await provider.getBlock(blockNum) + console.log("At block", blockNum, "time", block.date) + const data = await validatorSet.getLivingValidators({blockTag:blockNum}) + let totalSlash = 0 + for (let i = 0; i < data[0].length; i++) { + let addr = data[0][i]; + var val + if (!validatorMap.has(addr)) { + let opAddr = await stakeHub.consensusToOperator(addr, {blockTag:blockNum}) + let value = await stakeHub.getValidatorDescription(opAddr, {blockTag:blockNum}) + val = value[0] + console.log(addr, val) + } else { + val = validatorMap.get(addr) + } + let info = await slashIndicator.getSlashIndicator(addr, {blockTag:blockNum}) + let count = ethers.toNumber(info[1]) + totalSlash += count + console.log("Slash:", count, addr, val) + } + console.log("Total slash count", totalSlash) +}; + +// 5.cmd: "GetPerformanceData", usage: +// node getchainstatus.js GetPerformanceData \ +// --rpc https://bsc-testnet-dataseed.bnbchain.org \ +// --startNum 40000001 --endNum 40000005 +async function GetPerformanceData() { + let txCountTotal = 0; + let gasUsedTotal = 0; + let inturnBlocks = 0; + let justifiedBlocks = 0; + let turnLength = 1; + let parliaEnabled = true; + try { + turnLength = await provider.send("parlia_getTurnLength", [ethers.toQuantity(program.startNum)]); + } catch (error) { + // the "parlia" module was not enabled for RPC call + parliaEnabled = false + console.log("parlia RPC modudle is not enabled\n", error); + } + + for (let i = program.startNum; i < program.endNum; i++) { + let txCount = await provider.send("eth_getBlockTransactionCountByNumber", [ + ethers.toQuantity(i)]); + txCountTotal += ethers.toNumber(txCount) + + let header = await provider.send("eth_getHeaderByNumber", [ + ethers.toQuantity(i)]); + let gasUsed = eval(eval(header.gasUsed).toString(10)) + gasUsedTotal += gasUsed + let difficulty = eval(eval(header.difficulty).toString(10)) + if (difficulty == 2) { + inturnBlocks += 1 + } + let timestamp = eval(eval(header.timestamp).toString(10)) + if (parliaEnabled) { + let justifiedNumber = await provider.send("parlia_getJustifiedNumber", [ethers.toQuantity(i)]); + if (justifiedNumber + 1 == i) { + justifiedBlocks += 1 + } else { + console.log("justified unexpected", "BlockNumber =", i,"justifiedNumber",justifiedNumber) + } + } + console.log("BlockNumber =", i, "mod =", i%turnLength, "miner =", header.miner , "difficulty =", difficulty, "txCount =", ethers.toNumber(txCount), "gasUsed", gasUsed, "timestamp", timestamp) + } + let blockCount = program.endNum - program.startNum + let txCountPerBlock = txCountTotal/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 inturnBlocksRatio = inturnBlocks/blockCount + let justifiedBlocksRatio = justifiedBlocks/blockCount + let tps = txCountTotal/timeCost + let M = 1000000 + let avgGasUsedPerBlock = gasUsedTotal/blockCount/M + let avgGasUsedPerSecond = gasUsedTotal/timeCost/M + + console.log("Get the performance between [", program.startNum, ",", program.endNum, ")"); + console.log("txCountPerBlock =", txCountPerBlock, "txCountTotal =", txCountTotal, "BlockCount =", blockCount, "avgBlockTime =", avgBlockTime, "inturnBlocksRatio =", inturnBlocksRatio, "justifiedBlocksRatio =", justifiedBlocksRatio); + console.log("txCountPerSecond =", tps, "avgGasUsedPerBlock =", avgGasUsedPerBlock, "avgGasUsedPerSecond =", avgGasUsedPerSecond); +}; + +// 6.cmd: "GetBlobTxs", usage: +// node getchainstatus.js GetBlobTxs \ +// --rpc https://bsc-testnet-dataseed.bnbchain.org \ +// --startNum 40000001 --endNum 40000005 +// depends on ethjs v6.11.0+ for 4844, https://github.com/ethers-io/ethers.js/releases/tag/v6.11.0 +// BSC testnet enabled 4844 on block: 39539137 +async function GetBlobTxs() { + var startBlock = parseInt(program.startNum) + var endBlock = parseInt(program.endNum) + if (isNaN(endBlock) || isNaN(startBlock) || startBlock == 0) { + console.error("invalid input, --startNum", program.startNum, "--end", program.endNum) + return + } + // if --endNum is not specified, set it to the latest block number. + if (endBlock == 0) { + endBlock = await provider.getBlockNumber(); + } + if (startBlock > endBlock) { + console.error("invalid input, startBlock:",startBlock, " endBlock:", endBlock); + return + } + + for (let i = startBlock; i <= endBlock; i++) { + let blockData = await provider.getBlock(i); + console.log("startBlock:",startBlock, "endBlock:", endBlock, "curBlock", i, "blobGasUsed", blockData.blobGasUsed); + if (blockData.blobGasUsed == 0) { + continue + } + for (let txIndex = 0; txIndex<= blockData.transactions.length - 1; txIndex++) { + let txHash = blockData.transactions[txIndex] + let txData = await provider.getTransaction(txHash); + if (txData.type == 3) { + console.log("BlobTx in block:",i, " txIndex:", txIndex, " txHash:", txHash); + } + } + } +}; + +// 7.cmd: "GetFaucetStatus", usage: +// node getchainstatus.js GetFaucetStatus \ +// --rpc https://bsc-testnet-dataseed.bnbchain.org \ +// --startNum 40000001 --endNum 40000005 +async function GetFaucetStatus() { + var startBlock = parseInt(program.startNum) + var endBlock = parseInt(program.endNum) + if (isNaN(endBlock) || isNaN(startBlock) || startBlock == 0) { + console.error("invalid input, --startNum", program.startNum, "--end", program.endNum) + return + } + // if --endNum is not specified, set it to the latest block number. + if (endBlock == 0) { + endBlock = await provider.getBlockNumber(); + } + if (startBlock > endBlock) { + console.error("invalid input, startBlock:",startBlock, " endBlock:", endBlock); + return + } + + let startBalance = await provider.getBalance("0xaa25Aa7a19f9c426E07dee59b12f944f4d9f1DD3", startBlock) + let endBalance = await provider.getBalance("0xaa25Aa7a19f9c426E07dee59b12f944f4d9f1DD3", endBlock) + const faucetAmount = BigInt(0.3 * 10**18); // Convert 0.3 ether to wei as a BigInt + const numFaucetRequest = (startBalance - endBalance) / faucetAmount; + + // Convert BigInt to ether + const startBalanceEth = Number(startBalance) / 10**18; + const endBalanceEth = Number(endBalance) / 10**18; + + console.log(`Start Balance: ${startBalanceEth} ETH`); + console.log(`End Balance: ${endBalanceEth} ETH`); + + console.log("successful faucet request: ",numFaucetRequest); +}; + const main = async () => { if (process.argv.length <= 2) { console.error('invalid process.argv.length', process.argv.length); @@ -141,7 +397,7 @@ const main = async () => { return } const cmd = process.argv[2] - if (cmd === "--help") { + if (cmd == "-h" || cmd == "--help") { printUsage() return } @@ -151,6 +407,14 @@ const main = async () => { await getBinaryVersion() } else if (cmd === "GetTopAddr") { await getTopAddr() + } else if (cmd === "GetSlashCount") { + await getSlashCount() + } else if (cmd === "GetPerformanceData") { + await GetPerformanceData() + } else if (cmd === "GetBlobTxs") { + await GetBlobTxs() + } else if (cmd === "GetFaucetStatus") { + await GetFaucetStatus() } else { console.log("unsupported cmd", cmd); printUsage() diff --git a/cmd/jsutils/getslashcount.js b/cmd/jsutils/getslashcount.js deleted file mode 100644 index b45fad7d57..0000000000 --- a/cmd/jsutils/getslashcount.js +++ /dev/null @@ -1,119 +0,0 @@ -import { ethers } from "ethers"; -import program from "commander"; - -program.option("--Rpc ", "Rpc"); -program.option("--Num ", "num", 0) -program.parse(process.argv); - -const provider = new ethers.JsonRpcProvider(program.Rpc); - -const slashAbi = [ - "function getSlashIndicator(address validatorAddr) external view returns (uint256, uint256)" -] -const validatorSetAbi = [ - "function getLivingValidators() external view returns (address[], bytes[])" -] -const stakeHubAbi = [ - "function getValidatorDescription(address validatorAddr) external view returns (tuple(string, string, string, string))", - "function consensusToOperator(address consensusAddr) public view returns (address)" -] -const addrValidatorSet = '0x0000000000000000000000000000000000001000'; -const validatorSet = new ethers.Contract(addrValidatorSet, validatorSetAbi, provider); - -const addrSlash = '0x0000000000000000000000000000000000001001'; -const slashIndicator = new ethers.Contract(addrSlash, slashAbi, provider) - -const addrStakeHub = '0x0000000000000000000000000000000000002002'; -const stakeHub = new ethers.Contract(addrStakeHub, stakeHubAbi, provider) - -const validatorMap = new Map([ - //BSC - ["0x37e9627A91DD13e453246856D58797Ad6583D762", "LegendII"], - ["0xB4647b856CB9C3856d559C885Bed8B43e0846a47", "CertiK"], - ["0x75B851a27D7101438F45fce31816501193239A83", "Figment"], - ["0x502aECFE253E6AA0e8D2A06E12438FFeD0Fe16a0", "BscScan"], - ["0xCa503a7eD99eca485da2E875aedf7758472c378C", "InfStones"], - ["0x5009317FD4F6F8FeEa9dAe41E5F0a4737BB7A7D5", "NodeReal"], - ["0x1cFDBd2dFf70C6e2e30df5012726F87731F38164", "Tranchess"], - ["0xF8de5e61322302b2c6e0a525cC842F10332811bf", "Namelix"], - ["0xCcB42A9b8d6C46468900527Bc741938E78AB4577", "Turing"], - ["0x9f1b7FAE54BE07F4FEE34Eb1aaCb39A1F7B6FC92", "TWStaking"], - ["0x7E1FdF03Eb3aC35BF0256694D7fBe6B6d7b3E0c8","LegendIII"], - ["0x7b501c7944185130DD4aD73293e8Aa84eFfDcee7","MathW"], - ["0x58567F7A51a58708C8B40ec592A38bA64C0697De","Legend"], - ["0x460A252B4fEEFA821d3351731220627D7B7d1F3d","Defibit"], - ["0x8A239732871AdC8829EA2f47e94087C5FBad47b6","The48Club"], - ["0xD3b0d838cCCEAe7ebF1781D11D1bB741DB7Fe1A7","BNBEve"], - ["0xF8B99643fAfC79d9404DE68E48C4D49a3936f787","Avengers"], - ["0x4e5acf9684652BEa56F2f01b7101a225Ee33d23f","HashKey"], - ["0x9bb56C2B4DBE5a06d79911C9899B6f817696ACFc","Feynman"], - ["0xbdcc079BBb23C1D9a6F36AA31309676C258aBAC7","Fuji"], - ["0x38944092685a336CB6B9ea58836436709a2adC89","Shannon"], - ["0xfC1004C0f296Ec3Df4F6762E9EabfcF20EB304a2","Aoraki"], - ["0xa0884bb00E5F23fE2427f0E5eC9E51F812848563","Coda"], - ["0xe7776De78740f28a96412eE5cbbB8f90896b11A5","Ankr"], - ["0xA2D969E82524001Cb6a2357dBF5922B04aD2FCD8","Pexmons"], - ["0x5cf810AB8C718ac065b45f892A5BAdAB2B2946B9","Zen"], - ["0x4d15D9BCd0c2f33E7510c0de8b42697CA558234a","LegendVII"], - ["0x1579ca96EBd49A0B173f86C372436ab1AD393380","LegendV"], - ["0xd1F72d433f362922f6565FC77c25e095B29141c8","LegendVI"], - ["0xf9814D93b4d904AaA855cBD4266D6Eb0Ec1Aa478","Legend8"], - ["0x025a4e09Ea947b8d695f53ddFDD48ddB8F9B06b7","Ciscox"], - ["0xE9436F6F30b4B01b57F2780B2898f3820EbD7B98","LegendIV"], - ["0xC2d534F079444E6E7Ff9DabB3FD8a26c607932c8","Axion"], - ["0x9F7110Ba7EdFda83Fc71BeA6BA3c0591117b440D","LegendIX"], - ["0xB997Bf1E3b96919fBA592c1F61CE507E165Ec030","Seoraksan"], - ["0x286C1b674d48cFF67b4096b6c1dc22e769581E91","Sigm8"], - ["0x73A26778ef9509a6E94b55310eE7233795a9EB25","Coinlix"], - ["0x18c44f4FBEde9826C7f257d500A65a3D5A8edebc","Nozti"], - ["0xA100FCd08cE722Dc68Ddc3b54237070Cb186f118","Tiollo"], - ["0x0F28847cfdbf7508B13Ebb9cEb94B2f1B32E9503","Raptas"], - ["0xfD85346c8C991baC16b9c9157e6bdfDACE1cD7d7","Glorin"], - ["0x978F05CED39A4EaFa6E8FD045Fe2dd6Da836c7DF","NovaX"], - ["0xd849d1dF66bFF1c2739B4399425755C2E0fAbbAb","Nexa"], - ["0xA015d9e9206859c13201BB3D6B324d6634276534","Star"], - ["0x5ADde0151BfAB27f329e5112c1AeDeed7f0D3692","Veri"], - //Chapel - ["0x08265dA01E1A65d62b903c7B34c08cB389bF3D99","Ararat"], - ["0x7f5f2cF1aec83bF0c74DF566a41aa7ed65EA84Ea","Kita"], - ["0x53387F3321FD69d1E030BB921230dFb188826AFF","Fuji"], - ["0x76D76ee8823dE52A1A431884c2ca930C5e72bff3","Seoraksan"], - ["0xd447b49CD040D20BC21e49ffEa6487F5638e4346","Everest"], - ["0x1a3d9D7A717D64e6088aC937d5aAcDD3E20ca963","Elbrus"], - ["0x40D3256EB0BaBE89f0ea54EDAa398513136612f5","Bloxroute"], - ["0xF9a1Db0d6f22Bd78ffAECCbc8F47c83Df9FBdbCf","Test"] -]); - - -const main = async () => { - let blockNum = ethers.getNumber(program.Num) - if (blockNum === 0) { - blockNum = await provider.getBlockNumber() - } - let block = await provider.getBlock(blockNum) - console.log("At block", blockNum, "time", block.date) - const data = await validatorSet.getLivingValidators({blockTag:blockNum}) - let totalSlash = 0 - for (let i = 0; i < data[0].length; i++) { - let addr = data[0][i]; - var val - if (!validatorMap.has(addr)) { - let opAddr = await stakeHub.consensusToOperator(addr, {blockTag:blockNum}) - let value = await stakeHub.getValidatorDescription(opAddr, {blockTag:blockNum}) - val = value[0] - console.log(addr, val) - } else { - val = validatorMap.get(addr) - } - let info = await slashIndicator.getSlashIndicator(addr, {blockTag:blockNum}) - let count = ethers.toNumber(info[1]) - totalSlash += count - console.log("Slash:", count, addr, val) - } - console.log("Total slash count", totalSlash) -}; -main().then(() => process.exit(0)) - .catch((error) => { - console.error(error); - process.exit(1); - }); \ No newline at end of file