bsc basefee的影响参数

1. 参数配置

params/protocol_params.go
DefaultBaseFeeChangeDenominator = 8            // Bounds the amount the base fee can change between blocks.
	DefaultElasticityMultiplier     = 2            // Bounds the maximum gas limit an EIP-1559 block may have.
	InitialBaseFee                  = 1000000000   // Initial base fee for EIP-1559 blocks.
	InitialBaseFeeForBSC            = 100000000000 // Initial base fee for EIP-1559 blocks on bsc Mainnet

配置的默认的InitialBaseFeeForBSC,影响范围:影响200个区块(epoch)以后

2. 创世区块配置

{
  "config": {
    "chainId": 15656,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "petersburgBlock": 0,
    "istanbulBlock": 0,
    "muirGlacierBlock": 0,
    "ramanujanBlock": 0,
    "nielsBlock": 0,
    "mirrorSyncBlock":1,
    "brunoBlock": 1,
    "eulerBlock": 2,
    "nanoBlock": 3,
    "moranBlock": 3,
    "gibbsBlock": 4,
    "planckBlock": 5,
    "lubanBlock": 6,
    "platoBlock": 7,
    "berlinBlock": 8,
    "londonBlock": 8,
    "hertzBlock": 8,
    "hertzfixBlock": 8,
    "shanghaiTime": 0,
    "keplerTime": 0,
    "feynmanTime": 0,
    "parlia": {
      "period": 3,
      "epoch": 200
    }
  },
  "nonce": "0x0",
  "timestamp": "0x5e9da7ce",
  "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000b17a1bd545b45a918bf6b0450e88b9cafc0914a9a0754ecdd8c0867986e462ddc97089bd21a3cc1eb6cb6ecb011c7a72b1926ed3bf4ed04e6e2e67e30000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "gasLimit": "0x2625a00",
  "difficulty": "0x1",
  "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE",
  "baseFeePerGas": "0x174876e800",

baseFeePerGas配置了100gwei,影响范围:影响从0-200个区块(epoch)

3. 获取gasprice的逻辑

tipcap就是配置文件里面的gasprice

func (api *EthereumAPI) GasPrice(ctx context.Context) (*hexutil.Big, error) {
	tipcap, err := api.b.SuggestGasTipCap(ctx)
	if err != nil {
		return nil, err
	}
	head := api.b.CurrentHeader()
	if head.BaseFee != nil {
		tipcap.Add(tipcap, head.BaseFee)
	}
	return (*hexutil.Big)(tipcap), err
}

当前的header是从创世区块的header + 当前的区块的header一起作用的:

func NewHeaderChain(chainDb ethdb.Database, config *params.ChainConfig, engine consensus.Engine, procInterrupt func() bool) (*HeaderChain, error) {
	hc := &HeaderChain{
		config:        config,
		chainDb:       chainDb,
		headerCache:   lru.NewCache[common.Hash, *types.Header](headerCacheLimit),
		tdCache:       lru.NewCache[common.Hash, *big.Int](tdCacheLimit),
		numberCache:   lru.NewCache[common.Hash, uint64](numberCacheLimit),
		procInterrupt: procInterrupt,
		engine:        engine,
	}
	hc.genesisHeader = hc.GetHeaderByNumber(0)
	if hc.genesisHeader == nil {
		return nil, ErrNoGenesis
	}
	hc.currentHeader.Store(hc.genesisHeader)
	if head := rawdb.ReadHeadBlockHash(chainDb); head != (common.Hash{}) {
		if chead := hc.GetHeaderByHash(head); chead != nil {
			hc.currentHeader.Store(chead)
		}
	}

所以header.basefee 在前200个区块的时候是有创世区块决定的,200个epoch以后就可以根据InitialBaseFeeForBSC进行更新了

所以如果要配置basefee,需要配置2个地方:

1. 创世区块文件baseFeePerGas

2.InitialBaseFeeForBSC

posted @ 2025-08-06 17:50  若-飞  阅读(30)  评论(0)    收藏  举报