initialization => activation; calcGasLimitAndBaseFee doesn't need gasFloor and gasCeil
This commit is contained in:
@@ -265,7 +265,7 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent *
|
||||
return fmt.Errorf("invalid difficulty: have %v, want %v", header.Difficulty, expected)
|
||||
}
|
||||
|
||||
// If we have not reached the EIP1559 finalization block we need to verify that the GasLimit field is valid
|
||||
// If we have not reached the EIP1559 activation block we need to verify that the GasLimit field is valid
|
||||
if !chain.Config().IsEIP1559Finalized(header.Number) {
|
||||
// Verify that the gas limit is <= 2^63-1
|
||||
cap := uint64(0x7fffffffffffffff)
|
||||
|
||||
@@ -61,7 +61,7 @@ func VerifyEIP1559BaseFee(config *params.ChainConfig, header, parent *types.Head
|
||||
}
|
||||
return nil
|
||||
}
|
||||
// Verify the BaseFee is valid if we are past the EIP1559 initialization block
|
||||
// Verify the BaseFee is valid if we are past the EIP1559 activation block
|
||||
if config.IsEIP1559(header.Number) {
|
||||
// A valid BASEFEE is one such that abs(BASEFEE - PARENT_BASEFEE) <= max(1, PARENT_BASEFEE // BASEFEE_MAX_CHANGE_DENOMINATOR)
|
||||
if parent.BaseFee == nil {
|
||||
@@ -83,7 +83,7 @@ func VerifyEIP1559BaseFee(config *params.ChainConfig, header, parent *types.Head
|
||||
}
|
||||
return nil
|
||||
}
|
||||
// If we are before the EIP1559 initialization block the current and parent BaseFees should be nil
|
||||
// If we are before the EIP1559 activation block the current and parent BaseFees should be nil
|
||||
if header.BaseFee != nil || parent.BaseFee != nil {
|
||||
return errHaveBaseFee
|
||||
}
|
||||
|
||||
@@ -145,20 +145,20 @@ func CalcGasLimitAndBaseFee(config *params.ChainConfig, parent *types.Block, gas
|
||||
if !config.IsEIP1559(new(big.Int).Add(parent.Number(), common.Big1)) {
|
||||
return CalcGasLimit(parent, gasFloor, gasCeil), nil
|
||||
}
|
||||
return calcGasLimitAndBaseFee(config, parent, gasFloor, gasCeil)
|
||||
return calcGasLimitAndBaseFee(config, parent)
|
||||
}
|
||||
|
||||
// start at 50 : 50 and then shift to 0 : 100
|
||||
// calcGasLimitAndBaseFee returns the EIP1559GasLimit and the BaseFee
|
||||
// The GasLimit for the legacy pool is (params.MaxGasEIP1559 - EIP1559GasLimit)
|
||||
func calcGasLimitAndBaseFee(config *params.ChainConfig, parent *types.Block, gasFloor, gasCeil uint64) (uint64, *big.Int) {
|
||||
// panic if we do not have a block number set for the EIP1559 initialization fork
|
||||
func calcGasLimitAndBaseFee(config *params.ChainConfig, parent *types.Block) (uint64, *big.Int) {
|
||||
// panic if we do not have a block number set for EIP1559 activation
|
||||
if config.EIP1559Block == nil {
|
||||
panic("chain config is missing EIP1559Block")
|
||||
}
|
||||
height := new(big.Int).Add(parent.Number(), common.Big1)
|
||||
|
||||
// If we are at the block of EIP1559 initialization then the BaseFee is set to the initial value
|
||||
// If we are at the block of EIP1559 activation then the BaseFee is set to the initial value
|
||||
// and the GasLimit is split evenly between the two pools
|
||||
if config.EIP1559Block.Cmp(height) == 0 {
|
||||
return params.MaxGasEIP1559 / 2, new(big.Int).SetUint64(params.EIP1559InitialBaseFee)
|
||||
|
||||
@@ -66,7 +66,7 @@ func (b *BlockGen) SetCoinbase(addr common.Address) {
|
||||
if b.config.IsEIP1559(b.header.Number) {
|
||||
b.gasPool = new(GasPool).AddGas(params.MaxGasEIP1559 - b.header.GasLimit)
|
||||
b.gasPool1559 = new(GasPool).AddGas(b.header.GasLimit)
|
||||
} else { // If we are before EIP1559 initialization then we use header.GasLimit for the legacy pool
|
||||
} else { // If we are before EIP1559 activation then we use header.GasLimit for the legacy pool
|
||||
b.gasPool = new(GasPool).AddGas(b.header.GasLimit)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ func (p *statePrefetcher) Prefetch(block *types.Block, statedb *state.StateDB, c
|
||||
if p.config.IsEIP1559(block.Number()) {
|
||||
gaspool = new(GasPool).AddGas(params.MaxGasEIP1559 - block.GasLimit())
|
||||
gp1559 = new(GasPool).AddGas(block.GasLimit())
|
||||
} else { // If we are before EIP1559 initialization then we use header.GasLimit for the legacy pool
|
||||
} else { // If we are before EIP1559 activation then we use header.GasLimit for the legacy pool
|
||||
gaspool = new(GasPool).AddGas(block.GasLimit())
|
||||
}
|
||||
// Iterate over and process the individual transactions
|
||||
|
||||
@@ -69,7 +69,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
|
||||
if p.config.IsEIP1559(block.Number()) {
|
||||
gp = new(GasPool).AddGas(params.MaxGasEIP1559 - block.GasLimit())
|
||||
gp1559 = new(GasPool).AddGas(block.GasLimit())
|
||||
} else { // If we are before EIP1559 initialization then we use header.GasLimit for the legacy pool
|
||||
} else { // If we are before EIP1559 activation then we use header.GasLimit for the legacy pool
|
||||
gp = new(GasPool).AddGas(block.GasLimit())
|
||||
}
|
||||
|
||||
|
||||
@@ -246,7 +246,7 @@ func (st *StateTransition) preCheck() error {
|
||||
if st.evm.ChainConfig().IsEIP1559Finalized(st.evm.BlockNumber) && !st.isEIP1559 {
|
||||
return ErrTxNotEIP1559
|
||||
}
|
||||
// If we are before the EIP1559 initialization block, throw an error if we have EIP1559 fields or do not have a GasPrice
|
||||
// If we are before the EIP1559 activation block, throw an error if we have EIP1559 fields or do not have a GasPrice
|
||||
if !st.evm.ChainConfig().IsEIP1559(st.evm.BlockNumber) && (st.msg.GasPremium() != nil || st.msg.FeeCap() != nil || st.gp1559 != nil || st.evm.BaseFee != nil || st.msg.GasPrice() == nil) {
|
||||
return ErrTxIsEIP1559
|
||||
}
|
||||
@@ -254,7 +254,7 @@ func (st *StateTransition) preCheck() error {
|
||||
if (st.msg.GasPremium() != nil || st.msg.FeeCap() != nil) && st.msg.GasPrice() != nil {
|
||||
return ErrTxSetsLegacyAndEIP1559Fields
|
||||
}
|
||||
// We need a BaseFee if we are past EIP1559 initialization
|
||||
// We need a BaseFee if we are past EIP1559 activation
|
||||
if st.evm.ChainConfig().IsEIP1559(st.evm.BlockNumber) && st.evm.BaseFee == nil {
|
||||
return ErrNoBaseFee
|
||||
}
|
||||
|
||||
+2
-2
@@ -84,7 +84,7 @@ var (
|
||||
// and the input transaction does not conform to with EIP1559
|
||||
ErrTxNotEIP1559 = fmt.Errorf("after block %d EIP1559 is finalized and transactions must contain a GasPremium and FeeCap and not contain a GasPrice", params.EIP1559ForkFinalizedBlockNumber)
|
||||
|
||||
// ErrTxIsEIP1559 is returned if we have not reached the EIP1559 initialization block height
|
||||
// ErrTxIsEIP1559 is returned if we have not reached the EIP1559 activation block height
|
||||
// and the input transaction is not of the legacy type
|
||||
ErrTxIsEIP1559 = fmt.Errorf("before block %d EIP1559 is not activated and transactions must contain a GasPrice and not contain a GasPremium or FeeCap", params.EIP1559ForkBlockNumber)
|
||||
|
||||
@@ -92,7 +92,7 @@ var (
|
||||
// both legacy (GasPrice) and EIP1559 (GasPremium and FeeCap) fields
|
||||
ErrTxSetsLegacyAndEIP1559Fields = errors.New("transaction sets both legacy and EIP1559 fields")
|
||||
|
||||
// ErrNoBaseFee is returned if we are past the EIP1559 initialization block but
|
||||
// ErrNoBaseFee is returned if we are past the EIP1559 activation block but
|
||||
// the current header does not provide a BaseFee
|
||||
ErrNoBaseFee = errors.New("current header does not provide the BaseFee needed to process EIP1559 transactions")
|
||||
|
||||
|
||||
+2
-2
@@ -487,7 +487,7 @@ func (w *worker) mainLoop() {
|
||||
if !w.chainConfig.IsEIP1559(w.chain.CurrentBlock().Number()) && legacyGasPool != nil && legacyGasPool.Gas() < params.TxGas {
|
||||
continue
|
||||
}
|
||||
// When we are between EIP1559 initialization and finalization we can received transactions of both types
|
||||
// When we are between EIP1559 activation and finalization we can received transactions of both types
|
||||
// and one pool could be exhausted while the other is not
|
||||
// If both pools are exhausted we know the block is full but if only one is we could still accept transactions
|
||||
// of the other type so we need to proceed into commitTransactions()
|
||||
@@ -764,7 +764,7 @@ func (w *worker) commitTransactions(txs *types.TransactionsByPriceAndNonce, coin
|
||||
eip1559GasLimit = w.current.header.GasLimit
|
||||
w.current.gasPool = new(core.GasPool).AddGas(eip1559GasLimit)
|
||||
}
|
||||
} else if w.current.gasPool == nil { // If we are before EIP1559 initialization then we use header.GasLimit for the legacy pool
|
||||
} else if w.current.gasPool == nil { // If we are before EIP1559 activation then we use header.GasLimit for the legacy pool
|
||||
legacyGasLimit = w.current.header.GasLimit
|
||||
w.current.gasPool = new(core.GasPool).AddGas(legacyGasLimit)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user