Skip to content

Commit

Permalink
Remove gas_target from block structure (#3552)
Browse files Browse the repository at this point in the history
* remove gas_target from block structure

* missed block.gas_target

* avoid undue gas_target halving on 1559 fork block

* fix spelling error
  • Loading branch information
lightclient authored May 7, 2021
1 parent d12ddc7 commit 67d0d75
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions EIPS/eip-1559.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ A transaction pricing mechanism that includes fixed-per-block network fee that i
## Abstract
We introduce a new [EIP-2718](./eip-2718.md) transaction type, with the format `0x02 || rlp([chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, access_list, signatureYParity, signatureR, signatureS])`.

There is a base fee per gas in protocol, which can move up or down each block according to a formula which is a function of gas used in parent block and gas target (formerly known as gas limit) of parent block.
There is a base fee per gas in protocol, which can move up or down each block according to a formula which is a function of gas used in parent block and gas target (block gas limit divided by elasticity multiplier) of parent block.
The algorithm results in the base fee per gas increasing when blocks are above the gas target, and decreasing when blocks are below the gas target.
The base fee per gas is burned.
Transactions specify the maximum fee per gas they are willing to give to miners to incentivize them to include their transaction (aka: priority fee).
Expand Down Expand Up @@ -133,7 +133,7 @@ class Block:
logs_bloom: int = 0
difficulty: int = 0
number: int = 0
gas_target: int = 0 # note the name change to gas_target from gas_limit
gas_limit: int = 0 # note the gas_limit is the gas_target * ELASTICITY_MULTIPLIER
gas_used: int = 0
timestamp: int = 0
extra_data: bytes = bytes()
Expand All @@ -155,17 +155,24 @@ ELASTICITY_MULTIPLIER = 2

class World(ABC):
def validate_block(self, block: Block) -> None:
parent_gas_target = self.parent(block).gas_limit // ELASTICITY_MULTIPLIER

# On the fork block, don't account for the ELASTICITY_MULTIPLIER to avoid
# unduly halving the gas target.
if INITIAL_FORK_BLOCK_NUMBER == block.number:
parent_gas_target = self.parent(block).gas_limit

parent_base_fee_per_gas = self.parent(block).base_fee_per_gas
parent_gas_used = self.parent(block).gas_used
parent_gas_target = self.parent(block).gas_target
gas_target = block.gas_limit // ELASTICITY_MULTIPLIER
transactions = self.transactions(block)

# check if the block used too much gas
assert block.gas_used <= block.gas_target * ELASTICITY_MULTIPLIER, 'invalid block: too much gas used'
assert block.gas_used <= block.gas_limit, 'invalid block: too much gas used'

# check if the block changed the gas target too much
assert block.gas_target <= parent_gas_target + parent_gas_target // 1024, 'invalid block: gas target increased too much'
assert block.gas_target >= parent_gas_target - parent_gas_target // 1024, 'invalid block: gas target decreased too much'
assert gas_target <= parent_gas_target + parent_gas_target // 1024, 'invalid block: gas target increased too much'
assert gas_target >= parent_gas_target - parent_gas_target // 1024, 'invalid block: gas target decreased too much'

# check if the base fee is correct
if parent_gas_used == parent_gas_target:
Expand Down

0 comments on commit 67d0d75

Please sign in to comment.