您好,登錄后才能下訂單哦!
Eth的區塊是如何打包的,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。
一個區塊最多打包多少筆交易是由塊的gas limit決定的,注意,這里的gas limit是塊的gas limit,不是交易的gas limit。可以近似理解為,塊的gas limit是這個塊的所有交易的實際使用的gas 之和。
一個區塊中,交易的打包順序是按照gas price的順序打包。當然,曠工自己的交易通常都是排在最前面。
可能是曠工的挖礦軟件的原因,存在很多空塊。
每個交易的gas limit與該交易實際使用的gas 可能存在很大不同。
問題:
當多筆交易的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=12473572 block=11372139 blockGasLimit=12493807 totalGas=42940607 totalUsed=12476950 block=11372140 blockGasLimit=12481608 totalGas=25078349 totalUsed=12043096 block=11372141 blockGasLimit=12493796 totalGas=27022444 totalUsed=12487147 block=11372142 blockGasLimit=12500000 totalGas=22645996 totalUsed=12493723 block=11372143 blockGasLimit=12506095 totalGas=22893218 totalUsed=12496704 block=11372144 blockGasLimit=12500000 totalGas=31048160 totalUsed=12480116 block=11372145 blockGasLimit=12487794 totalGas=22559614 totalUsed=12309872 block=11372146 blockGasLimit=12499988 totalGas=24119898 totalUsed=12492163 block=11372147 blockGasLimit=12506081 totalGas=21924202 totalUsed=12496671 block=11372148 blockGasLimit=12493870 totalGas=24220866 totalUsed=12485457 block=11372149 blockGasLimit=12481670 totalGas=30033765 totalUsed=12427012 block=11372150 blockGasLimit=12493858 totalGas=28686643 totalUsed=12483406 block=11372151 blockGasLimit=12500000 totalGas=31961412 totalUsed=12497551 block=11372152 blockGasLimit=12487794 totalGas=33613986 totalUsed=12458057 block=11372153 blockGasLimit=12499988 totalGas=24284337 totalUsed=12491038 block=11372154 blockGasLimit=12506079 totalGas=26059761 totalUsed=12506039 block=11372155 blockGasLimit=12493868 totalGas=32729299 totalUsed=12492179 block=11372156 blockGasLimit=12499967 totalGas=23658650 totalUsed=12486884 block=11372157 blockGasLimit=12487762 totalGas=21961423 totalUsed=12474256 block=11372158 blockGasLimit=12499956 totalGas=33268172 totalUsed=12483959 block=11372159 blockGasLimit=12506038 totalGas=0 totalUsed=0 block=11372160 blockGasLimit=12493827 totalGas=39459443 totalUsed=12492541 block=11372161 blockGasLimit=12500000 totalGas=31209609 totalUsed=12498393 block=11372162 blockGasLimit=12506102 totalGas=27257576 totalUsed=12503912 block=11372163 blockGasLimit=12518284 totalGas=50218838 totalUsed=12503856 block=11372164 blockGasLimit=12506061 totalGas=27976755 totalUsed=12505035 block=11372165 blockGasLimit=12493850 totalGas=54951578 totalUsed=12477118 block=11372166 blockGasLimit=12500000 totalGas=30783166 totalUsed=12484261 block=11372167 blockGasLimit=12506081 totalGas=27590667 totalUsed=12500771 block=11372168 blockGasLimit=12493870 totalGas=32379572 totalUsed=12473748 block=11372169 blockGasLimit=12481670 totalGas=27596013 totalUsed=12472659 block=11372170 blockGasLimit=12469482 totalGas=25644061 totalUsed=12449695 block=11372171 blockGasLimit=12481658 totalGas=27973875 totalUsed=12473614 block=11372172 blockGasLimit=12493846 totalGas=28867697 totalUsed=12335617 block=11372173 blockGasLimit=12500000 totalGas=24431156 totalUsed=12489721 block=11372174 blockGasLimit=12512206 totalGas=27373387 totalUsed=12492328 block=11372175 blockGasLimit=12518288 totalGas=21555614 totalUsed=12501095 block=11372176 blockGasLimit=12506065 totalGas=56709220 totalUsed=12497070 block=11372177 blockGasLimit=12512160 totalGas=24697457 totalUsed=12505347 block=11372178 blockGasLimit=12499943 totalGas=19120028 totalUsed=12479333 block=11372179 blockGasLimit=12506018 totalGas=25932080 totalUsed=12496731 block=11372180 blockGasLimit=12493807 totalGas=41795302 totalUsed=12481165 block=11372181 blockGasLimit=12481608 totalGas=25959547 totalUsed=12469426 block=11372182 blockGasLimit=12469420 totalGas=52977503 totalUsed=12464632 block=11372183 blockGasLimit=12481596 totalGas=25338396 totalUsed=12472763 block=11372184 blockGasLimit=12493784 totalGas=35134413 totalUsed=12487281 block=11372185 blockGasLimit=12500000 totalGas=36800994 totalUsed=12498440 block=11372186 blockGasLimit=12487794 totalGas=20094351 totalUsed=12475535 block=11372187 blockGasLimit=12499988 totalGas=20561891 totalUsed=12487291
看完上述內容是否對您有幫助呢?如果還想對相關知識有進一步的了解或閱讀更多相關文章,請關注億速云行業資訊頻道,感謝您對億速云的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。