Add deprecation helpers in spec builder

This commit is contained in:
Hsiao-Wei Wang 2024-07-03 20:48:56 +08:00 committed by Potuz
parent a11ffb5278
commit b230a42584
3 changed files with 33 additions and 4 deletions

View File

@ -124,13 +124,22 @@ def objects_to_spec(preset_name: str,
# Keep engine from the most recent fork
execution_engine_cls = reduce(lambda txt, builder: builder.execution_engine_cls() or txt, builders, "")
# Remove deprecated constants
deprecate_constants = reduce(lambda obj, builder: obj.union(builder.deprecate_constants()), builders, set())
# constant_vars = {k: v for k, v in spec_object.constant_vars.items() if k not in deprecate_constants}
filtered_ssz_dep_constants = {k: v for k, v in hardcoded_ssz_dep_constants.items() if k not in deprecate_constants}
# Remove deprecated presets
deprecate_presets = reduce(lambda obj, builder: obj.union(builder.deprecate_presets()), builders, set())
# preset_vars = {k: v for k, v in spec_object.constant_vars.items() if k not in deprecate_constants}
filtered_hardcoded_func_dep_presets = {k: v for k, v in hardcoded_func_dep_presets.items() if k not in deprecate_presets}
constant_vars_spec = '# Constant vars\n' + '\n'.join(format_constant(k, v) for k, v in spec_object.constant_vars.items())
preset_vars_spec = '# Preset vars\n' + '\n'.join(format_constant(k, v) for k, v in spec_object.preset_vars.items())
ordered_class_objects_spec = '\n\n\n'.join(ordered_class_objects.values())
ssz_dep_constants = '\n'.join(map(lambda x: '%s = %s' % (x, hardcoded_ssz_dep_constants[x]), hardcoded_ssz_dep_constants))
ssz_dep_constants_verification = '\n'.join(map(lambda x: 'assert %s == %s' % (x, spec_object.ssz_dep_constants[x]), hardcoded_ssz_dep_constants))
ssz_dep_constants_verification = '\n'.join(map(lambda x: 'assert %s == %s' % (x, spec_object.ssz_dep_constants[x]), filtered_ssz_dep_constants))
custom_type_dep_constants = '\n'.join(map(lambda x: '%s = %s' % (x, hardcoded_custom_type_dep_constants[x]), hardcoded_custom_type_dep_constants))
func_dep_presets_verification = '\n'.join(map(lambda x: 'assert %s == %s # noqa: E501' % (x, spec_object.func_dep_presets[x]), hardcoded_func_dep_presets))
func_dep_presets_verification = '\n'.join(map(lambda x: 'assert %s == %s # noqa: E501' % (x, spec_object.func_dep_presets[x]), filtered_hardcoded_func_dep_presets))
spec_strs = [
imports,
preparations,

View File

@ -1,5 +1,5 @@
from abc import ABC, abstractmethod
from typing import Sequence, Dict
from typing import Sequence, Dict, Set
from pathlib import Path
class BaseSpecBuilder(ABC):
@ -54,3 +54,11 @@ class BaseSpecBuilder(ABC):
@classmethod
def implement_optimizations(cls, functions: Dict[str, str]) -> Dict[str, str]:
return functions
@classmethod
def deprecate_constants(cls) -> Set[str]:
return set()
@classmethod
def deprecate_presets(cls) -> Set[str]:
return set()

View File

@ -1,4 +1,4 @@
from typing import Dict
from typing import Dict, Set
from .base import BaseSpecBuilder
from ..constants import EIP7732
@ -19,3 +19,15 @@ from eth2spec.electra import {preset_name} as electra
'PTC_SIZE': spec_object.preset_vars['PTC_SIZE'].value,
'MAX_PAYLOAD_ATTESTATIONS': spec_object.preset_vars['MAX_PAYLOAD_ATTESTATIONS'].value,
}
@classmethod
def deprecate_constants(cls) -> Set[str]:
return set([
'EXECUTION_PAYLOAD_GINDEX',
])
@classmethod
def deprecate_presets(cls) -> Set[str]:
return set([
'KZG_COMMITMENT_INCLUSION_PROOF_DEPTH',
])