Skip to content

Commit 29457ba

Browse files
committed
base_fee from None to exception pre-1559
1 parent 207cbdc commit 29457ba

File tree

5 files changed

+37
-25
lines changed

5 files changed

+37
-25
lines changed

eth/rlp/headers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from typing import (
2-
Optional,
32
cast,
43
overload,
54
)
@@ -177,5 +176,5 @@ def is_genesis(self) -> bool:
177176
return self.parent_hash == GENESIS_PARENT_HASH and self.block_number == 0
178177

179178
@property
180-
def base_fee_per_gas(self) -> Optional[int]:
181-
return None
179+
def base_fee_per_gas(self) -> int:
180+
raise AttributeError("Base fee per gas not available until London fork")

eth/vm/base.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,29 @@ def create_execution_context(cls,
173173
prev_hashes: Iterable[Hash32],
174174
chain_context: ChainContextAPI) -> ExecutionContextAPI:
175175
fee_recipient = cls.consensus_class.get_fee_recipient(header)
176-
return ExecutionContext(
177-
coinbase=fee_recipient,
178-
timestamp=header.timestamp,
179-
block_number=header.block_number,
180-
difficulty=header.difficulty,
181-
gas_limit=header.gas_limit,
182-
prev_hashes=prev_hashes,
183-
chain_id=chain_context.chain_id,
184-
base_fee_per_gas=header.base_fee_per_gas,
185-
)
176+
try:
177+
base_fee = header.base_fee_per_gas
178+
except AttributeError:
179+
return ExecutionContext(
180+
coinbase=fee_recipient,
181+
timestamp=header.timestamp,
182+
block_number=header.block_number,
183+
difficulty=header.difficulty,
184+
gas_limit=header.gas_limit,
185+
prev_hashes=prev_hashes,
186+
chain_id=chain_context.chain_id,
187+
)
188+
else:
189+
return ExecutionContext(
190+
coinbase=fee_recipient,
191+
timestamp=header.timestamp,
192+
block_number=header.block_number,
193+
difficulty=header.difficulty,
194+
gas_limit=header.gas_limit,
195+
prev_hashes=prev_hashes,
196+
chain_id=chain_context.chain_id,
197+
base_fee_per_gas=base_fee,
198+
)
186199

187200
def execute_bytecode(self,
188201
origin: Address,
@@ -673,10 +686,10 @@ def in_costless_state(self) -> Iterator[StateAPI]:
673686
temp_block = self.generate_block_from_parent_header_and_coinbase(header, header.coinbase)
674687
prev_hashes = itertools.chain((header.hash,), self.previous_hashes)
675688

676-
if temp_block.header.base_fee_per_gas is None:
677-
free_header = temp_block.header
678-
else:
689+
if hasattr(temp_block.header, 'base_fee_per_gas'):
679690
free_header = temp_block.header.copy(base_fee_per_gas=0)
691+
else:
692+
free_header = temp_block.header
680693

681694
state = self.build_state(self.chaindb.db,
682695
free_header,

eth/vm/execution_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(
3333
gas_limit: int,
3434
prev_hashes: Iterable[Hash32],
3535
chain_id: int,
36-
base_fee_per_gas: Optional[int]) -> None:
36+
base_fee_per_gas: Optional[int] = None) -> None:
3737
self._coinbase = coinbase
3838
self._timestamp = timestamp
3939
self._block_number = block_number

eth/vm/forks/london/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def validate_gas(
4242
header: BlockHeaderAPI,
4343
parent_header: BlockHeaderAPI) -> None:
4444

45-
if parent_header.base_fee_per_gas is not None:
45+
if hasattr(parent_header, 'base_fee_per_gas'):
4646
# Follow normal gas limit rules if the previous block had a base fee
4747
parent_gas_limit = parent_header.gas_limit
4848
else:

eth/vm/forks/london/headers.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434
def calculate_expected_base_fee_per_gas(parent_header: BlockHeaderAPI) -> int:
3535
if parent_header is None:
3636
# Parent is empty when making the genesis header
37-
parent_base_fee_per_gas = None
38-
else:
39-
parent_base_fee_per_gas = parent_header.base_fee_per_gas
40-
41-
if parent_base_fee_per_gas is None:
42-
# Parent is a non-London header or this is a genesis header
4337
return INITIAL_BASE_FEE
38+
else:
39+
try:
40+
parent_base_fee_per_gas = parent_header.base_fee_per_gas
41+
except AttributeError:
42+
# Parent is a non-London header
43+
return INITIAL_BASE_FEE
4444

4545
parent_gas_target = parent_header.gas_limit
4646
parent_gas_used = parent_header.gas_used
@@ -72,7 +72,7 @@ def create_header_from_parent(difficulty_fn: Callable[[BlockHeaderAPI, int], int
7272
**header_params: Any) -> BlockHeaderAPI:
7373

7474
if 'gas_limit' not in header_params:
75-
if parent_header is not None and parent_header.base_fee_per_gas is None:
75+
if parent_header is not None and not hasattr(parent_header, 'base_fee_per_gas'):
7676
# If the previous block was not a London block,
7777
# double the gas limit, so the new target is the old gas limit
7878
header_params['gas_limit'] = parent_header.gas_limit * ELASTICITY_MULTIPLIER

0 commit comments

Comments
 (0)