EIP-1559: miner changes (#22896)
* core/types, miner: create TxWithMinerFee wrapper, add EIP-1559 support to TransactionsByMinerFeeAndNonce miner: set base fee when creating a new header, handle gas limit, log miner fees * all: rename to NewTransactionsByPriceAndNonce * core/types, miner: rename to NewTransactionsByPriceAndNonce + EffectiveTip miner: activate 1559 for testGenerateBlockAndImport tests * core,miner: revert naming to TransactionsByPriceAndTime * core/types/transaction: update effective tip calculation logic * miner: update aleut to london * core/types/transaction_test: use correct signer for 1559 txs + add back sender check * miner/worker: calculate gas target from gas limit * core, miner: fix block gas limits for 1559 Co-authored-by: Ansgar Dietrichs <adietrichs@gmail.com> Co-authored-by: lightclient@protonmail.com <lightclient@protonmail.com>
This commit is contained in:
committed by
GitHub
parent
16bc57438b
commit
a6c462781f
@@ -106,12 +106,12 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD
|
||||
// to keep the baseline gas above the provided floor, and increase it towards the
|
||||
// ceil if the blocks are full. If the ceil is exceeded, it will always decrease
|
||||
// the gas allowance.
|
||||
func CalcGasLimit(parent *types.Block, gasFloor, gasCeil uint64) uint64 {
|
||||
func CalcGasLimit(parentGasUsed, parentGasLimit, gasFloor, gasCeil uint64) uint64 {
|
||||
// contrib = (parentGasUsed * 3 / 2) / 1024
|
||||
contrib := (parent.GasUsed() + parent.GasUsed()/2) / params.GasLimitBoundDivisor
|
||||
contrib := (parentGasUsed + parentGasUsed/2) / params.GasLimitBoundDivisor
|
||||
|
||||
// decay = parentGasLimit / 1024 -1
|
||||
decay := parent.GasLimit()/params.GasLimitBoundDivisor - 1
|
||||
decay := parentGasLimit/params.GasLimitBoundDivisor - 1
|
||||
|
||||
/*
|
||||
strategy: gasLimit of block-to-mine is set based on parent's
|
||||
@@ -120,21 +120,45 @@ func CalcGasLimit(parent *types.Block, gasFloor, gasCeil uint64) uint64 {
|
||||
at that usage) the amount increased/decreased depends on how far away
|
||||
from parentGasLimit * (2/3) parentGasUsed is.
|
||||
*/
|
||||
limit := parent.GasLimit() - decay + contrib
|
||||
limit := parentGasLimit - decay + contrib
|
||||
if limit < params.MinGasLimit {
|
||||
limit = params.MinGasLimit
|
||||
}
|
||||
// If we're outside our allowed gas range, we try to hone towards them
|
||||
if limit < gasFloor {
|
||||
limit = parent.GasLimit() + decay
|
||||
limit = parentGasLimit + decay
|
||||
if limit > gasFloor {
|
||||
limit = gasFloor
|
||||
}
|
||||
} else if limit > gasCeil {
|
||||
limit = parent.GasLimit() - decay
|
||||
limit = parentGasLimit - decay
|
||||
if limit < gasCeil {
|
||||
limit = gasCeil
|
||||
}
|
||||
}
|
||||
return limit
|
||||
}
|
||||
|
||||
// CalcGasLimit1559 calculates the next block gas limit under 1559 rules.
|
||||
func CalcGasLimit1559(parentGasLimit, desiredLimit uint64) uint64 {
|
||||
delta := parentGasLimit/params.GasLimitBoundDivisor - 1
|
||||
limit := parentGasLimit
|
||||
if desiredLimit < params.MinGasLimit {
|
||||
desiredLimit = params.MinGasLimit
|
||||
}
|
||||
// If we're outside our allowed gas range, we try to hone towards them
|
||||
if limit < desiredLimit {
|
||||
limit = parentGasLimit + delta
|
||||
if limit > desiredLimit {
|
||||
limit = desiredLimit
|
||||
}
|
||||
return limit
|
||||
}
|
||||
if limit > desiredLimit {
|
||||
limit = parentGasLimit - delta
|
||||
if limit < desiredLimit {
|
||||
limit = desiredLimit
|
||||
}
|
||||
}
|
||||
return limit
|
||||
}
|
||||
|
Reference in New Issue
Block a user