手续费由三部分组成:基础燃烧费用(BaseFeeBurn)、矿工费(MinerTip)、溢出部分燃烧费用(OverEstimationBurn)
交易费用不超过:GasFeeCap * gasLimit
基础燃烧 = GasUsage * BaseFee
矿工费 = gasLimit * GasPremium
溢出燃烧:OverEstimationBurn * BaseFee
其中GasLimit、GasFeeCap、GasPremium通过JsonRpc API “Filecoin.GasEstimateMessageGas”获得,GasUsage通过“Filecoin.StateSearchMsg”获得,BaseFee 通过“Filecoin.ChainHead”获取。
OverEstimationBurn 参考如下计算公式获得:https://github.com/filecoin-project/lotus/blob/v0.10.0/chain/vm/burn.go#L38
以主网“bafy2bzaceaczht5a54irqdpydkqxsyciog2gzx5obca4cea7fcdbimfxwn6mi”交易为例:
gasUsed : 493168
gasLimit: 613210
baseFee:1503992198 attoFIL(从最新区块中获取)
基础燃烧 493168 * 1503992198 attoFIL = 741,720,824,303,264 attoFIL
矿工费 613,210 * 100500 = 61,627,605,000 attoFIL
over := gasLimit - (gasOveruseNumgasUsed)/gasOveruseDenom
= 613,210 - (11493168)/10
= 613,210 - 5,424,848/10
= 613,210 - 5,424,84.8
= 70,725.2
over < 0 false
over > gasUsed 70,725.2 > 493168 false
over = 70,725.2
gasToBurn := newInt(gasLimit-gasUsed) = newInt(613210-493168) = 120,042
gasToBurn = gasToBurn * newInt(over) = 120,042 * newInt(70,725.2) = 8,489,970,450
gasToBurn = gasToBurn / newInt(gasUsed) = 8,489,970,450 / newInt(493168) = 17,215.16896878954027836355967946
退还部分 = 613210 - 493168 - gasToBurn.Int64 = 613210 - 493168 - 17,215 = 102,827
溢出部分燃烧费用 = gasToBurn.Int64 = 17,215
OverEstimationBurn = 溢出部分燃烧费用 * baseFeeToPay =17,215 * 1503992198 = 25,891,225,688,570
最终GasFee = 741,720,824,303,264 + 61,627,605,000 + 25,891,225,688,570 = 767,673,677,596,834 attoFIL
FileCoin资料收集:
Filscan-Filecoin区块链浏览器: https://filscan.io/#/home
Filecoin区块链浏览器: https://filfox.info/zh
全节点API文档: https://github.com/filecoin-project/lotus/blob/master/documentation/en/api-methods.md
网络状态 | Filecoin:https://network.filecoin.io/
节点的搭建:https://docs.filecoin.io/build/#running-your-own-remote-network
开放节点API:https://docs.filecoin.io/build/hosted-lotus/
Lotus API方法| Filecoin文件:https://docs.filecoin.io/reference/lotus-api/#features
Calibration水龙头:https://faucet.calibration.fildev.network/
filecoin.js开发文档:https://filecoin-shipyard.github.io/filecoin.js/docs/introduction
filecoin.js 签名机:https://github.com/filecoin-shipyard/filecoin.js
费用经济治理模型:https://docs.filecoin.io/about-filecoin/how-filecoin-works/#proofs
手续费优化:https://starli.medium.com/filecoin-gas-calculation-4352536e287c
溢出燃烧部分手续费计算:https://github.com/filecoin-project/lotus/blob/v0.10.0/chain/vm/burn.go#L38
参考:
https://filscan.io/tipset/message-detail?cid=bafy2bzaceaczht5a54irqdpydkqxsyciog2gzx5obca4cea7fcdbimfxwn6mi
https://www.filscout.com/en/message/bafy2bzaceaczht5a54irqdpydkqxsyciog2gzx5obca4cea7fcdbimfxwn6mi
https://github.com/filecoin-project/lotus/blob/v0.10.0/chain/vm/burn.go#L38