From 1fe2d22e29b990337c52d668350167ccd583ddb0 Mon Sep 17 00:00:00 2001 From: Zhang Zhuo Date: Fri, 3 Feb 2023 14:24:15 +0800 Subject: [PATCH] feat: make eip2718 & eip1559 configurable in txpool (#206) * txpool only supports legacy tx * configurable tx pool EIP-2718 && EIP-1559 * try fix CI * fix CI * fix metamask incompatibility * fix comments * fix CI * set basefee as 0 when disable eip2718 or eip1559 * fix typo --------- Co-authored-by: colinlyguo --- core/tx_pool.go | 4 ++-- internal/ethapi/api.go | 8 ++++---- miner/worker.go | 9 ++++++++- params/config.go | 12 +++++++++--- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/core/tx_pool.go b/core/tx_pool.go index 292026efebfe..506526561da0 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -1320,8 +1320,8 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) { // Update all fork indicator by next pending block number. next := new(big.Int).Add(newHead.Number, big.NewInt(1)) pool.istanbul = pool.chainconfig.IsIstanbul(next) - pool.eip2718 = pool.chainconfig.IsBerlin(next) - pool.eip1559 = pool.chainconfig.IsLondon(next) + pool.eip2718 = pool.chainconfig.EnableEIP2718 && pool.chainconfig.IsBerlin(next) + pool.eip1559 = pool.chainconfig.EnableEIP1559 && pool.chainconfig.IsLondon(next) } // promoteExecutables moves transactions that have become processable from the diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index fe1ddd319bb2..f478ebfd7c85 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1121,7 +1121,7 @@ func (s *PublicBlockChainAPI) EstimateGas(ctx context.Context, args TransactionA } // RPCMarshalHeader converts the given header to the RPC output . -func RPCMarshalHeader(head *types.Header) map[string]interface{} { +func RPCMarshalHeader(head *types.Header, enableBaseFee bool) map[string]interface{} { result := map[string]interface{}{ "number": (*hexutil.Big)(head.Number), "hash": head.Hash(), @@ -1142,7 +1142,7 @@ func RPCMarshalHeader(head *types.Header) map[string]interface{} { "receiptsRoot": head.ReceiptHash, } - if head.BaseFee != nil { + if enableBaseFee && head.BaseFee != nil { result["baseFeePerGas"] = (*hexutil.Big)(head.BaseFee) } @@ -1153,7 +1153,7 @@ func RPCMarshalHeader(head *types.Header) map[string]interface{} { // returned. When fullTx is true the returned block contains full transaction details, otherwise it will only contain // transaction hashes. func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *params.ChainConfig) (map[string]interface{}, error) { - fields := RPCMarshalHeader(block.Header()) + fields := RPCMarshalHeader(block.Header(), config.EnableEIP2718 && config.EnableEIP1559) fields["size"] = hexutil.Uint64(block.Size()) if inclTx { @@ -1188,7 +1188,7 @@ func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *param // rpcMarshalHeader uses the generalized output filler, then adds the total difficulty field, which requires // a `PublicBlockchainAPI`. func (s *PublicBlockChainAPI) rpcMarshalHeader(ctx context.Context, header *types.Header) map[string]interface{} { - fields := RPCMarshalHeader(header) + fields := RPCMarshalHeader(header, s.b.ChainConfig().EnableEIP2718 && s.b.ChainConfig().EnableEIP1559) fields["totalDifficulty"] = (*hexutil.Big)(s.b.GetTd(ctx, header.Hash())) return fields } diff --git a/miner/worker.go b/miner/worker.go index 7933195d9269..08b13c0d5d1e 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -924,7 +924,14 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64) } // Set baseFee and GasLimit if we are on an EIP-1559 chain if w.chainConfig.IsLondon(header.Number) { - header.BaseFee = misc.CalcBaseFee(w.chainConfig, parent.Header()) + if w.chainConfig.EnableEIP2718 && w.chainConfig.EnableEIP1559 { + header.BaseFee = misc.CalcBaseFee(w.chainConfig, parent.Header()) + } else { + // When disabling EIP-2718 or EIP-1559, we do not set baseFeePerGas in RPC response. + // Setting BaseFee as 0 here can help outside SDK calculates l2geth's RLP encoding, + // otherwise the l2geth's BaseFee is not known from the outside. + header.BaseFee = big.NewInt(0) + } if !w.chainConfig.IsLondon(parent.Number()) { parentGasLimit := parent.GasLimit() * params.ElasticityMultiplier header.GasLimit = core.CalcGasLimit(parentGasLimit, w.config.GasCeil) diff --git a/params/config.go b/params/config.go index e059631afa35..ce9b3f533e2d 100644 --- a/params/config.go +++ b/params/config.go @@ -258,16 +258,16 @@ var ( // // This configuration is intentionally not using keyed fields to force anyone // adding flags to the config to also have to set these fields. - AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil, false, nil} + AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil, false, nil, true, true} // AllCliqueProtocolChanges contains every protocol change (EIPs) introduced // and accepted by the Ethereum core developers into the Clique consensus. // // This configuration is intentionally not using keyed fields to force anyone // adding flags to the config to also have to set these fields. - AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}, false, nil} + AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}, false, nil, true, true} - TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil, false, &common.Address{123}} + TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil, false, &common.Address{123}, true, true} TestRules = TestChainConfig.Rules(new(big.Int)) ) @@ -361,6 +361,12 @@ type ChainConfig struct { // Scroll genesis extension: Transaction fee vault address [optional] FeeVaultAddress *common.Address `json:"feeVaultAddress,omitempty"` + + // Scroll genesis extension: enable EIP-2718 in tx pool. + EnableEIP2718 bool `json:"enableEIP2718,omitempty"` + + // Scroll genesis extension: enable EIP-1559 in tx pool, EnableEIP2718 should be true too. + EnableEIP1559 bool `json:"enableEIP1559,omitempty"` } // EthashConfig is the consensus engine configs for proof-of-work based sealing.