@@ -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} { 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} { base_fee_per_gas }  
129+             )
122130
123131    new_header  =  LondonBlockHeader (** all_fields )  # type:ignore 
124132    return  new_header 
0 commit comments