Skip to content

Commit ebfc9c0

Browse files
committed
Allow configuring the base fee in genesis header
1 parent d55a2d3 commit ebfc9c0

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

eth/vm/forks/london/headers.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,25 @@ def create_header_from_parent(difficulty_fn: Callable[[BlockHeaderAPI, int], int
108108
header_params['timestamp'],
109109
)
110110

111+
# The general fill function doesn't recognize this custom field, so remove it
112+
configured_fee_per_gas = header_params.pop('base_fee_per_gas', None)
113+
111114
all_fields = fill_header_params_from_parent(parent_header, **header_params)
112115

113-
# must add the new field *after* filling, because the general fill function doesn't recognize it
114-
base_fee_per_gas = calculate_expected_base_fee_per_gas(parent_header)
115-
if 'base_fee_per_gas' in header_params and all_fields['base_fee_per_gas'] != base_fee_per_gas:
116-
raise ValidationError(
117-
f"Cannot select an invalid base_fee_per_gas of:"
118-
f" {all_fields['base_fee_per_gas']!r}, expected: {base_fee_per_gas}"
119-
)
116+
calculated_fee_per_gas = calculate_expected_base_fee_per_gas(parent_header)
117+
if configured_fee_per_gas is None:
118+
all_fields['base_fee_per_gas'] = calculated_fee_per_gas
120119
else:
121-
all_fields['base_fee_per_gas'] = base_fee_per_gas
120+
# Must not configure an invalid base fee. So verify that either:
121+
# 1. This is the genesis header, or
122+
# 2. The configured value matches the calculated value from the parent
123+
if parent_header is None or configured_fee_per_gas == calculated_fee_per_gas:
124+
all_fields['base_fee_per_gas'] = configured_fee_per_gas
125+
else:
126+
raise ValidationError(
127+
f"Cannot select an invalid base_fee_per_gas of:"
128+
f" {all_fields['base_fee_per_gas']!r}, expected: {base_fee_per_gas}"
129+
)
122130

123131
new_header = LondonBlockHeader(**all_fields) # type:ignore
124132
return new_header

0 commit comments

Comments
 (0)