Skip to content

Commit

Permalink
feat: make eip2718 & eip1559 configurable in txpool (ethereum#206)
Browse files Browse the repository at this point in the history
* 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 <colinlyguo@gmail.com>
  • Loading branch information
lispc and colinlyguo authored Feb 3, 2023
1 parent 08ba436 commit 1fe2d22
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
4 changes: 2 additions & 2 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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)
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
9 changes: 8 additions & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
)

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 1fe2d22

Please sign in to comment.