mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-01-22 08:29:23 +00:00
Refactor get_spec
This commit is contained in:
parent
5a0d84ed01
commit
3a49d6225e
29
setup.py
29
setup.py
@ -158,10 +158,10 @@ def _load_kzg_trusted_setups(preset_name):
|
|||||||
|
|
||||||
return trusted_setup_G1, trusted_setup_G2, trusted_setup_G1_lagrange, roots_of_unity
|
return trusted_setup_G1, trusted_setup_G2, trusted_setup_G1_lagrange, roots_of_unity
|
||||||
|
|
||||||
|
ALL_KZG_SETUPS = {
|
||||||
MINIMAL_KZG_SETUPS = _load_kzg_trusted_setups('minimal')
|
'minimal': _load_kzg_trusted_setups('minimal'),
|
||||||
MAINNET_KZG_SETUPS = _load_kzg_trusted_setups('mainnet')
|
'mainnet': _load_kzg_trusted_setups('mainnet')
|
||||||
|
}
|
||||||
|
|
||||||
ETH2_SPEC_COMMENT_PREFIX = "eth2spec:"
|
ETH2_SPEC_COMMENT_PREFIX = "eth2spec:"
|
||||||
|
|
||||||
@ -190,6 +190,15 @@ def _parse_value(name: str, typed_value: str, type_hint: Optional[str]=None) ->
|
|||||||
return VariableDefinition(type_name=type_name, value=typed_value[i+1:-1], comment=comment, type_hint=type_hint)
|
return VariableDefinition(type_name=type_name, value=typed_value[i+1:-1], comment=comment, type_hint=type_hint)
|
||||||
|
|
||||||
|
|
||||||
|
def _update_constant_vars_with_kzg_setups(constant_vars, preset_name):
|
||||||
|
comment = "noqa: E501"
|
||||||
|
kzg_setups = ALL_KZG_SETUPS[preset_name]
|
||||||
|
constant_vars['KZG_SETUP_G1'] = VariableDefinition(constant_vars['KZG_SETUP_G1'].value, str(kzg_setups[0]), comment, None)
|
||||||
|
constant_vars['KZG_SETUP_G2'] = VariableDefinition(constant_vars['KZG_SETUP_G2'].value, str(kzg_setups[1]), comment, None)
|
||||||
|
constant_vars['KZG_SETUP_LAGRANGE'] = VariableDefinition(constant_vars['KZG_SETUP_LAGRANGE'].value, str(kzg_setups[2]), comment, None)
|
||||||
|
constant_vars['ROOTS_OF_UNITY'] = VariableDefinition(constant_vars['ROOTS_OF_UNITY'].value, str(kzg_setups[3]), comment, None)
|
||||||
|
|
||||||
|
|
||||||
def get_spec(file_name: Path, preset: Dict[str, str], config: Dict[str, str], preset_name=str) -> SpecObject:
|
def get_spec(file_name: Path, preset: Dict[str, str], config: Dict[str, str], preset_name=str) -> SpecObject:
|
||||||
functions: Dict[str, str] = {}
|
functions: Dict[str, str] = {}
|
||||||
protocols: Dict[str, ProtocolDefinition] = {}
|
protocols: Dict[str, ProtocolDefinition] = {}
|
||||||
@ -281,17 +290,7 @@ def get_spec(file_name: Path, preset: Dict[str, str], config: Dict[str, str], pr
|
|||||||
|
|
||||||
# Load KZG trusted setup from files
|
# Load KZG trusted setup from files
|
||||||
if any('KZG_SETUP' in name for name in constant_vars):
|
if any('KZG_SETUP' in name for name in constant_vars):
|
||||||
comment = "noqa: E501"
|
_update_constant_vars_with_kzg_setups(constant_vars, preset_name)
|
||||||
if preset_name == 'mainnet':
|
|
||||||
constant_vars['KZG_SETUP_G1'] = VariableDefinition(constant_vars['KZG_SETUP_G1'].value, str(MAINNET_KZG_SETUPS[0]), comment, None)
|
|
||||||
constant_vars['KZG_SETUP_G2'] = VariableDefinition(constant_vars['KZG_SETUP_G2'].value, str(MAINNET_KZG_SETUPS[1]), comment, None)
|
|
||||||
constant_vars['KZG_SETUP_LAGRANGE'] = VariableDefinition(constant_vars['KZG_SETUP_LAGRANGE'].value, str(MAINNET_KZG_SETUPS[2]), comment, None)
|
|
||||||
constant_vars['ROOTS_OF_UNITY'] = VariableDefinition(constant_vars['ROOTS_OF_UNITY'].value, str(MAINNET_KZG_SETUPS[3]), comment, None)
|
|
||||||
elif preset_name == 'minimal':
|
|
||||||
constant_vars['KZG_SETUP_G1'] = VariableDefinition(constant_vars['KZG_SETUP_G1'].value, str(MINIMAL_KZG_SETUPS[0]), comment, None)
|
|
||||||
constant_vars['KZG_SETUP_G2'] = VariableDefinition(constant_vars['KZG_SETUP_G2'].value, str(MINIMAL_KZG_SETUPS[1]), comment, None)
|
|
||||||
constant_vars['KZG_SETUP_LAGRANGE'] = VariableDefinition(constant_vars['KZG_SETUP_LAGRANGE'].value, str(MINIMAL_KZG_SETUPS[2]), comment, None)
|
|
||||||
constant_vars['ROOTS_OF_UNITY'] = VariableDefinition(constant_vars['ROOTS_OF_UNITY'].value, str(MINIMAL_KZG_SETUPS[3]), comment, None)
|
|
||||||
|
|
||||||
return SpecObject(
|
return SpecObject(
|
||||||
functions=functions,
|
functions=functions,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user