mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
set BaseFee to nil (#222)
* set BaseFee to nil * fix lint * comment fix * update genesis.go
This commit is contained in:
parent
ec9254b0b1
commit
310c870c6a
11 changed files with 64 additions and 25 deletions
|
|
@ -611,7 +611,11 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallM
|
||||||
// Backfill the legacy gasPrice for EVM execution, unless we're all zeroes
|
// Backfill the legacy gasPrice for EVM execution, unless we're all zeroes
|
||||||
call.GasPrice = new(big.Int)
|
call.GasPrice = new(big.Int)
|
||||||
if call.GasFeeCap.BitLen() > 0 || call.GasTipCap.BitLen() > 0 {
|
if call.GasFeeCap.BitLen() > 0 || call.GasTipCap.BitLen() > 0 {
|
||||||
|
if head.BaseFee != nil {
|
||||||
call.GasPrice = math.BigMin(new(big.Int).Add(call.GasTipCap, head.BaseFee), call.GasFeeCap)
|
call.GasPrice = math.BigMin(new(big.Int).Add(call.GasTipCap, head.BaseFee), call.GasFeeCap)
|
||||||
|
} else {
|
||||||
|
call.GasPrice = math.BigMin(call.GasTipCap, call.GasFeeCap)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -249,10 +249,14 @@ func (c *BoundContract) createDynamicTx(opts *TransactOpts, contract *common.Add
|
||||||
// Estimate FeeCap
|
// Estimate FeeCap
|
||||||
gasFeeCap := opts.GasFeeCap
|
gasFeeCap := opts.GasFeeCap
|
||||||
if gasFeeCap == nil {
|
if gasFeeCap == nil {
|
||||||
|
if head.BaseFee != nil {
|
||||||
gasFeeCap = new(big.Int).Add(
|
gasFeeCap = new(big.Int).Add(
|
||||||
gasTipCap,
|
gasTipCap,
|
||||||
new(big.Int).Mul(head.BaseFee, big.NewInt(2)),
|
new(big.Int).Mul(head.BaseFee, big.NewInt(2)),
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
gasFeeCap = new(big.Int).Set(gasTipCap)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if gasFeeCap.Cmp(gasTipCap) < 0 {
|
if gasFeeCap.Cmp(gasTipCap) < 0 {
|
||||||
return nil, fmt.Errorf("maxFeePerGas (%v) < maxPriorityFeePerGas (%v)", gasFeeCap, gasTipCap)
|
return nil, fmt.Errorf("maxFeePerGas (%v) < maxPriorityFeePerGas (%v)", gasFeeCap, gasTipCap)
|
||||||
|
|
|
||||||
|
|
@ -248,7 +248,7 @@ func Transition(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
// Sanity check, to not `panic` in state_transition
|
// Sanity check, to not `panic` in state_transition
|
||||||
if chainConfig.IsLondon(big.NewInt(int64(prestate.Env.Number))) {
|
if chainConfig.IsLondon(big.NewInt(int64(prestate.Env.Number))) {
|
||||||
if prestate.Env.BaseFee == nil {
|
if prestate.Env.BaseFee == nil && chainConfig.EnableEIP2718 && chainConfig.EnableEIP1559 {
|
||||||
return NewError(ErrorConfig, errors.New("EIP-1559 config but missing 'currentBaseFee' in env section"))
|
return NewError(ErrorConfig, errors.New("EIP-1559 config but missing 'currentBaseFee' in env section"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,13 @@ func VerifyEip1559Header(config *params.ChainConfig, parent, header *types.Heade
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Verify the header is not malformed
|
// Verify the header is not malformed
|
||||||
if header.BaseFee == nil {
|
if header.BaseFee == nil && (config.EnableEIP2718 && config.EnableEIP1559) {
|
||||||
return fmt.Errorf("header is missing baseFee")
|
return fmt.Errorf("header is missing baseFee")
|
||||||
}
|
}
|
||||||
|
// Now BaseFee can be nil, because !(config.EnableEIP2718 && config.EnableEIP1559)
|
||||||
|
if header.BaseFee == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
// Verify the baseFee is correct based on the parent header.
|
// Verify the baseFee is correct based on the parent header.
|
||||||
|
|
||||||
var expectedBaseFee *big.Int
|
var expectedBaseFee *big.Int
|
||||||
|
|
@ -72,6 +76,9 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
|
||||||
parentGasTargetBig = new(big.Int).SetUint64(parentGasTarget)
|
parentGasTargetBig = new(big.Int).SetUint64(parentGasTarget)
|
||||||
baseFeeChangeDenominator = new(big.Int).SetUint64(params.BaseFeeChangeDenominator)
|
baseFeeChangeDenominator = new(big.Int).SetUint64(params.BaseFeeChangeDenominator)
|
||||||
)
|
)
|
||||||
|
if !config.EnableEIP2718 || !config.EnableEIP1559 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
// If the parent gasUsed is the same as the target, the baseFee remains unchanged.
|
// If the parent gasUsed is the same as the target, the baseFee remains unchanged.
|
||||||
if parent.GasUsed == parentGasTarget {
|
if parent.GasUsed == parentGasTarget {
|
||||||
return new(big.Int).Set(parent.BaseFee)
|
return new(big.Int).Set(parent.BaseFee)
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,11 @@ func (b *BlockGen) Number() *big.Int {
|
||||||
|
|
||||||
// BaseFee returns the EIP-1559 base fee of the block being generated.
|
// BaseFee returns the EIP-1559 base fee of the block being generated.
|
||||||
func (b *BlockGen) BaseFee() *big.Int {
|
func (b *BlockGen) BaseFee() *big.Int {
|
||||||
|
if b.header.BaseFee != nil {
|
||||||
return new(big.Int).Set(b.header.BaseFee)
|
return new(big.Int).Set(b.header.BaseFee)
|
||||||
|
} else {
|
||||||
|
return big.NewInt(0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddUncheckedReceipt forcefully adds a receipts to the block without a
|
// AddUncheckedReceipt forcefully adds a receipts to the block without a
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,9 @@ func (g Genesis) MarshalJSON() ([]byte, error) {
|
||||||
enc.Number = math.HexOrDecimal64(g.Number)
|
enc.Number = math.HexOrDecimal64(g.Number)
|
||||||
enc.GasUsed = math.HexOrDecimal64(g.GasUsed)
|
enc.GasUsed = math.HexOrDecimal64(g.GasUsed)
|
||||||
enc.ParentHash = g.ParentHash
|
enc.ParentHash = g.ParentHash
|
||||||
|
if g.BaseFee != nil {
|
||||||
enc.BaseFee = (*math.HexOrDecimal256)(g.BaseFee)
|
enc.BaseFee = (*math.HexOrDecimal256)(g.BaseFee)
|
||||||
|
}
|
||||||
return json.Marshal(&enc)
|
return json.Marshal(&enc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -315,8 +315,10 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
|
||||||
if g.Config != nil && g.Config.IsLondon(common.Big0) {
|
if g.Config != nil && g.Config.IsLondon(common.Big0) {
|
||||||
if g.BaseFee != nil {
|
if g.BaseFee != nil {
|
||||||
head.BaseFee = g.BaseFee
|
head.BaseFee = g.BaseFee
|
||||||
} else {
|
} else if g.Config.EnableEIP2718 && g.Config.EnableEIP1559 {
|
||||||
head.BaseFee = new(big.Int).SetUint64(params.InitialBaseFee)
|
head.BaseFee = new(big.Int).SetUint64(params.InitialBaseFee)
|
||||||
|
} else {
|
||||||
|
head.BaseFee = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
statedb.Commit(false)
|
statedb.Commit(false)
|
||||||
|
|
|
||||||
|
|
@ -156,12 +156,12 @@ func TestStateProcessorErrors(t *testing.T) {
|
||||||
},
|
},
|
||||||
want: "could not apply tx 0 [0xbd49d8dadfd47fb846986695f7d4da3f7b2c48c8da82dbc211a26eb124883de9]: gas limit reached",
|
want: "could not apply tx 0 [0xbd49d8dadfd47fb846986695f7d4da3f7b2c48c8da82dbc211a26eb124883de9]: gas limit reached",
|
||||||
},
|
},
|
||||||
{ // ErrFeeCapTooLow
|
// { // ErrFeeCapTooLow
|
||||||
txs: []*types.Transaction{
|
// txs: []*types.Transaction{
|
||||||
mkDynamicTx(0, common.Address{}, params.TxGas, big.NewInt(0), big.NewInt(0)),
|
// mkDynamicTx(0, common.Address{}, params.TxGas, big.NewInt(0), big.NewInt(0)),
|
||||||
},
|
// },
|
||||||
want: "could not apply tx 0 [0xc4ab868fef0c82ae0387b742aee87907f2d0fc528fc6ea0a021459fb0fc4a4a8]: max fee per gas less than block base fee: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxFeePerGas: 0 baseFee: 875000000",
|
// want: "could not apply tx 0 [0xc4ab868fef0c82ae0387b742aee87907f2d0fc528fc6ea0a021459fb0fc4a4a8]: max fee per gas less than block base fee: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxFeePerGas: 0 baseFee: 875000000",
|
||||||
},
|
// },
|
||||||
{ // ErrTipVeryHigh
|
{ // ErrTipVeryHigh
|
||||||
txs: []*types.Transaction{
|
txs: []*types.Transaction{
|
||||||
mkDynamicTx(0, common.Address{}, params.TxGas, tooBigNumber, big.NewInt(1)),
|
mkDynamicTx(0, common.Address{}, params.TxGas, tooBigNumber, big.NewInt(1)),
|
||||||
|
|
|
||||||
|
|
@ -268,7 +268,11 @@ func (st *StateTransition) preCheck() error {
|
||||||
}
|
}
|
||||||
// This will panic if baseFee is nil, but basefee presence is verified
|
// This will panic if baseFee is nil, but basefee presence is verified
|
||||||
// as part of header validation.
|
// as part of header validation.
|
||||||
if st.gasFeeCap.Cmp(st.evm.Context.BaseFee) < 0 {
|
if st.evm.Context.BaseFee != nil && st.gasFeeCap.Cmp(st.evm.Context.BaseFee) < 0 {
|
||||||
|
return fmt.Errorf("%w: address %v, maxFeePerGas: %s baseFee: %s", ErrFeeCapTooLow,
|
||||||
|
st.msg.From().Hex(), st.gasFeeCap, st.evm.Context.BaseFee)
|
||||||
|
}
|
||||||
|
if st.evm.Context.BaseFee == nil && st.gasFeeCap.Cmp(big.NewInt(0)) < 0 {
|
||||||
return fmt.Errorf("%w: address %v, maxFeePerGas: %s baseFee: %s", ErrFeeCapTooLow,
|
return fmt.Errorf("%w: address %v, maxFeePerGas: %s baseFee: %s", ErrFeeCapTooLow,
|
||||||
st.msg.From().Hex(), st.gasFeeCap, st.evm.Context.BaseFee)
|
st.msg.From().Hex(), st.gasFeeCap, st.evm.Context.BaseFee)
|
||||||
}
|
}
|
||||||
|
|
@ -352,7 +356,11 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
|
||||||
}
|
}
|
||||||
effectiveTip := st.gasPrice
|
effectiveTip := st.gasPrice
|
||||||
if london {
|
if london {
|
||||||
|
if st.evm.Context.BaseFee != nil {
|
||||||
effectiveTip = cmath.BigMin(st.gasTipCap, new(big.Int).Sub(st.gasFeeCap, st.evm.Context.BaseFee))
|
effectiveTip = cmath.BigMin(st.gasTipCap, new(big.Int).Sub(st.gasFeeCap, st.evm.Context.BaseFee))
|
||||||
|
} else {
|
||||||
|
effectiveTip = cmath.BigMin(st.gasTipCap, st.gasFeeCap)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if st.evm.ChainConfig().UsingScroll {
|
if st.evm.ChainConfig().UsingScroll {
|
||||||
|
|
|
||||||
|
|
@ -93,10 +93,16 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
|
||||||
args.MaxPriorityFeePerGas = (*hexutil.Big)(tip)
|
args.MaxPriorityFeePerGas = (*hexutil.Big)(tip)
|
||||||
}
|
}
|
||||||
if args.MaxFeePerGas == nil {
|
if args.MaxFeePerGas == nil {
|
||||||
gasFeeCap := new(big.Int).Add(
|
var gasFeeCap *big.Int
|
||||||
|
if head.BaseFee != nil {
|
||||||
|
gasFeeCap = new(big.Int).Add(
|
||||||
(*big.Int)(args.MaxPriorityFeePerGas),
|
(*big.Int)(args.MaxPriorityFeePerGas),
|
||||||
new(big.Int).Mul(head.BaseFee, big.NewInt(2)),
|
new(big.Int).Mul(head.BaseFee, big.NewInt(2)),
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
gasFeeCap = new(big.Int).Set(
|
||||||
|
(*big.Int)(args.MaxPriorityFeePerGas))
|
||||||
|
}
|
||||||
args.MaxFeePerGas = (*hexutil.Big)(gasFeeCap)
|
args.MaxFeePerGas = (*hexutil.Big)(gasFeeCap)
|
||||||
}
|
}
|
||||||
if args.MaxFeePerGas.ToInt().Cmp(args.MaxPriorityFeePerGas.ToInt()) < 0 {
|
if args.MaxFeePerGas.ToInt().Cmp(args.MaxPriorityFeePerGas.ToInt()) < 0 {
|
||||||
|
|
@ -115,8 +121,10 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
|
||||||
// The legacy tx gas price suggestion should not add 2x base fee
|
// The legacy tx gas price suggestion should not add 2x base fee
|
||||||
// because all fees are consumed, so it would result in a spiral
|
// because all fees are consumed, so it would result in a spiral
|
||||||
// upwards.
|
// upwards.
|
||||||
|
if head.BaseFee != nil {
|
||||||
price.Add(price, head.BaseFee)
|
price.Add(price, head.BaseFee)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
args.GasPrice = (*hexutil.Big)(price)
|
args.GasPrice = (*hexutil.Big)(price)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -933,9 +933,9 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
|
||||||
header.BaseFee = misc.CalcBaseFee(w.chainConfig, parent.Header())
|
header.BaseFee = misc.CalcBaseFee(w.chainConfig, parent.Header())
|
||||||
} else {
|
} else {
|
||||||
// When disabling EIP-2718 or EIP-1559, we do not set baseFeePerGas in RPC response.
|
// 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,
|
// Setting BaseFee as nil here can help outside SDK calculates l2geth's RLP encoding,
|
||||||
// otherwise the l2geth's BaseFee is not known from the outside.
|
// otherwise the l2geth's BaseFee is not known from the outside.
|
||||||
header.BaseFee = big.NewInt(0)
|
header.BaseFee = nil
|
||||||
}
|
}
|
||||||
if !w.chainConfig.IsLondon(parent.Number()) {
|
if !w.chainConfig.IsLondon(parent.Number()) {
|
||||||
parentGasLimit := parent.GasLimit() * params.ElasticityMultiplier
|
parentGasLimit := parent.GasLimit() * params.ElasticityMultiplier
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue