千家信息网

Eth的区块是如何打包的

发表于:2025-01-23 作者:千家信息网编辑
千家信息网最后更新 2025年01月23日,Eth的区块是如何打包的,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。一个区块最多打包多少笔交易是由块的gas limi
千家信息网最后更新 2025年01月23日Eth的区块是如何打包的

Eth的区块是如何打包的,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

  1. 一个区块最多打包多少笔交易是由块的gas limit决定的,注意,这里的gas limit是块的gas limit,不是交易的gas limit。可以近似理解为,块的gas limit是这个块的所有交易的实际使用的gas 之和。

  2. 一个区块中,交易的打包顺序是按照gas price的顺序打包。当然,旷工自己的交易通常都是排在最前面。

  3. 可能是旷工的挖矿软件的原因,存在很多空块。

  4. 每个交易的gas limit与该交易实际使用的gas 可能存在很大不同。

问题:

  1. 当多笔交易的gas price相同时,在区块中的顺序是怎样决定的?

import {JsonRpcProvider} from "@ethersproject/providers";import { ethers } from "ethers"// 获取交易区块信息及该块的交易列表// 交易列表中的交易没有gasUsed字段, 如果需要获取gasUsed, 需要调用getTransactionReceipt接口来查询async function getBlockTxs(provider: JsonRpcProvider, block: number | string) {    return provider.getBlockWithTransactions(block)};(async() => {    let localProvider = new ethers.providers.JsonRpcProvider({url: ''}, 'mainnet')    let block = 11372138    for (let i = 0; i < 50; i ++) {        let txs = await getBlockTxs(localProvider, block+i)        let gasLimit = txs.gasLimit.toNumber()        // console.log('block gas limit:', gasLimit)        let transactions = txs.transactions            , totalGas = 0            , totalUsed = 0        // console.log(transactions[0])        for (let i = 0; i < transactions.length; i++) {            let tx = transactions[i]            totalGas += tx.gasLimit.toNumber()            let rTx = await localProvider.getTransactionReceipt(tx.hash)            totalUsed += rTx.gasUsed.toNumber()            // console.info('block=%d index=%d gasPrice=%d gasLimit=%d usedRatio=%d totalGas=%d totalUsed=%d', block,            //     i, tx.gasPrice.div(GWei).toNumber(), tx.gasLimit.toNumber(), rTx.gasUsed.mul(100).div(tx.gasLimit).toNumber(), totalGas, totalUsed)        }        console.info('block=%d blockGasLimit=%d totalGas=%d totalUsed=%d', block+i, gasLimit, totalGas, totalUsed)    }})()
block=11372138 blockGasLimit=12481619 totalGas=25997923 totalUsed=12473572block=11372139 blockGasLimit=12493807 totalGas=42940607 totalUsed=12476950block=11372140 blockGasLimit=12481608 totalGas=25078349 totalUsed=12043096block=11372141 blockGasLimit=12493796 totalGas=27022444 totalUsed=12487147block=11372142 blockGasLimit=12500000 totalGas=22645996 totalUsed=12493723block=11372143 blockGasLimit=12506095 totalGas=22893218 totalUsed=12496704block=11372144 blockGasLimit=12500000 totalGas=31048160 totalUsed=12480116block=11372145 blockGasLimit=12487794 totalGas=22559614 totalUsed=12309872block=11372146 blockGasLimit=12499988 totalGas=24119898 totalUsed=12492163block=11372147 blockGasLimit=12506081 totalGas=21924202 totalUsed=12496671block=11372148 blockGasLimit=12493870 totalGas=24220866 totalUsed=12485457block=11372149 blockGasLimit=12481670 totalGas=30033765 totalUsed=12427012block=11372150 blockGasLimit=12493858 totalGas=28686643 totalUsed=12483406block=11372151 blockGasLimit=12500000 totalGas=31961412 totalUsed=12497551block=11372152 blockGasLimit=12487794 totalGas=33613986 totalUsed=12458057block=11372153 blockGasLimit=12499988 totalGas=24284337 totalUsed=12491038block=11372154 blockGasLimit=12506079 totalGas=26059761 totalUsed=12506039block=11372155 blockGasLimit=12493868 totalGas=32729299 totalUsed=12492179block=11372156 blockGasLimit=12499967 totalGas=23658650 totalUsed=12486884block=11372157 blockGasLimit=12487762 totalGas=21961423 totalUsed=12474256block=11372158 blockGasLimit=12499956 totalGas=33268172 totalUsed=12483959block=11372159 blockGasLimit=12506038 totalGas=0 totalUsed=0block=11372160 blockGasLimit=12493827 totalGas=39459443 totalUsed=12492541block=11372161 blockGasLimit=12500000 totalGas=31209609 totalUsed=12498393block=11372162 blockGasLimit=12506102 totalGas=27257576 totalUsed=12503912block=11372163 blockGasLimit=12518284 totalGas=50218838 totalUsed=12503856block=11372164 blockGasLimit=12506061 totalGas=27976755 totalUsed=12505035block=11372165 blockGasLimit=12493850 totalGas=54951578 totalUsed=12477118block=11372166 blockGasLimit=12500000 totalGas=30783166 totalUsed=12484261block=11372167 blockGasLimit=12506081 totalGas=27590667 totalUsed=12500771block=11372168 blockGasLimit=12493870 totalGas=32379572 totalUsed=12473748block=11372169 blockGasLimit=12481670 totalGas=27596013 totalUsed=12472659block=11372170 blockGasLimit=12469482 totalGas=25644061 totalUsed=12449695block=11372171 blockGasLimit=12481658 totalGas=27973875 totalUsed=12473614block=11372172 blockGasLimit=12493846 totalGas=28867697 totalUsed=12335617block=11372173 blockGasLimit=12500000 totalGas=24431156 totalUsed=12489721block=11372174 blockGasLimit=12512206 totalGas=27373387 totalUsed=12492328block=11372175 blockGasLimit=12518288 totalGas=21555614 totalUsed=12501095block=11372176 blockGasLimit=12506065 totalGas=56709220 totalUsed=12497070block=11372177 blockGasLimit=12512160 totalGas=24697457 totalUsed=12505347block=11372178 blockGasLimit=12499943 totalGas=19120028 totalUsed=12479333block=11372179 blockGasLimit=12506018 totalGas=25932080 totalUsed=12496731block=11372180 blockGasLimit=12493807 totalGas=41795302 totalUsed=12481165block=11372181 blockGasLimit=12481608 totalGas=25959547 totalUsed=12469426block=11372182 blockGasLimit=12469420 totalGas=52977503 totalUsed=12464632block=11372183 blockGasLimit=12481596 totalGas=25338396 totalUsed=12472763block=11372184 blockGasLimit=12493784 totalGas=35134413 totalUsed=12487281block=11372185 blockGasLimit=12500000 totalGas=36800994 totalUsed=12498440block=11372186 blockGasLimit=12487794 totalGas=20094351 totalUsed=12475535block=11372187 blockGasLimit=12499988 totalGas=20561891 totalUsed=12487291

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注行业资讯频道,感谢您对的支持。

0