Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/jsutils/getchainstatus.js: add GetEip7623 #2862

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion cmd/jsutils/getchainstatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function printUsage() {
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")
console.log(" node getchainstatus.js GetKeyParameters --rpc https://bsc-testnet-dataseed.bnbchain.org") // default: latest block
console.log(" node getchainstatus.js GetEip7623 --rpc https://bsc-testnet-dataseed.bnbchain.org --startNum 40000001 --endNum 40000010")
}

program.usage = printUsage;
Expand Down Expand Up @@ -493,7 +494,58 @@ async function getKeyParameters() {
}
validatorTable.sort((a, b) => b.votingPower - a.votingPower);
console.table(validatorTable)
};
}

// 9.cmd: "getEip7623", usage:
// node getEip7623.js GetEip7736 \
// --rpc https://bsc-testnet-dataseed.bnbchain.org \
// --startNum 40000001 --endNum 40000005
async function getEip7623() {
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
}

const startTime = Date.now();

const TOTAL_COST_FLOOR_PER_TOKEN = 10
const intrinsicGas = 21000
for (let blockNumber = startBlock; blockNumber <= endBlock; blockNumber++) {
const block = await provider.getBlock(blockNumber, true);

for (let txHash of block.transactions) {
let tx = block.getPrefetchedTransaction(txHash)
const receipt = await provider.getTransactionReceipt(tx.hash);
let tokens_in_calldata = -4; // means '0x'
let calldata = tx.data;
for (let i = 0; i < calldata.length; i += 2) {
const byte = parseInt(calldata.substr(i, 2), 16);
if (byte === 0) {
tokens_in_calldata++;
} else {
tokens_in_calldata = tokens_in_calldata + 4;
}
}
let want = TOTAL_COST_FLOOR_PER_TOKEN * tokens_in_calldata + intrinsicGas
if (want > receipt.gasUsed) {
console.log("Cost more gas, blockNum:", tx.blockNumber, "txHash", tx.hash, " gasUsed", receipt.gasUsed.toString(), " New GasUsed", want)
}
}
}
const endTime = Date.now();
const duration = (endTime - startTime) / 1000;
console.log(`Script executed in: ${duration} seconds`);
}

const main = async () => {
if (process.argv.length <= 2) {
Expand Down Expand Up @@ -522,6 +574,8 @@ const main = async () => {
await getFaucetStatus()
} else if (cmd === "GetKeyParameters") {
await getKeyParameters()
} else if (cmd === "GetEip7623"){
await getEip7623()
} else {
console.log("unsupported cmd", cmd);
printUsage()
Expand Down
Loading