@@ -55,6 +55,12 @@ def floorlog2(x: int) -> uint64:
55
55
'''
56
56
57
57
58
+ OPTIMIZED_BLS_AGGREGATE_PUBKEYS = '''
59
+ def eth2_aggregate_pubkeys(pubkeys: Sequence[BLSPubkey]) -> BLSPubkey:
60
+ return bls.AggregatePKs(pubkeys)
61
+ '''
62
+
63
+
58
64
class ProtocolDefinition (NamedTuple ):
59
65
# just function definitions currently. May expand with configuration vars in future.
60
66
functions : Dict [str , str ]
@@ -299,10 +305,7 @@ def hardcoded_custom_type_dep_constants(cls) -> Dict[str, str]: # TODO
299
305
300
306
@classmethod
301
307
@abstractmethod
302
- def invariant_checks (cls ) -> str :
303
- """
304
- The invariant checks
305
- """
308
+ def implement_optimizations (cls , functions : Dict [str , str ]) -> Dict [str , str ]:
306
309
raise NotImplementedError ()
307
310
308
311
@classmethod
@@ -426,8 +429,8 @@ def hardcoded_custom_type_dep_constants(cls) -> Dict[str, str]:
426
429
return {}
427
430
428
431
@classmethod
429
- def invariant_checks (cls ) -> str :
430
- return ''
432
+ def implement_optimizations (cls , functions : Dict [ str , str ] ) -> Dict [ str , str ] :
433
+ return functions
431
434
432
435
@classmethod
433
436
def build_spec (cls , preset_name : str ,
@@ -476,12 +479,10 @@ def hardcoded_ssz_dep_constants(cls) -> Dict[str, str]:
476
479
return {** super ().hardcoded_ssz_dep_constants (), ** constants }
477
480
478
481
@classmethod
479
- def invariant_checks (cls ) -> str :
480
- return '''
481
- assert (
482
- TIMELY_HEAD_WEIGHT + TIMELY_SOURCE_WEIGHT + TIMELY_TARGET_WEIGHT + SYNC_REWARD_WEIGHT + PROPOSER_WEIGHT
483
- ) == WEIGHT_DENOMINATOR'''
484
-
482
+ def implement_optimizations (cls , functions : Dict [str , str ]) -> Dict [str , str ]:
483
+ if "eth2_aggregate_pubkeys" in functions :
484
+ functions ["eth2_aggregate_pubkeys" ] = OPTIMIZED_BLS_AGGREGATE_PUBKEYS .strip ()
485
+ return super ().implement_optimizations (functions )
485
486
486
487
#
487
488
# MergeSpecBuilder
@@ -509,7 +510,7 @@ def sundry_functions(cls) -> str:
509
510
510
511
def get_pow_block(hash: Bytes32) -> PowBlock:
511
512
return PowBlock(block_hash=hash, is_valid=True, is_processed=True,
512
- total_difficulty=config.TRANSITION_TOTAL_DIFFICULTY )
513
+ total_difficulty=uint256(0), difficulty=uint256(0) )
513
514
514
515
515
516
def get_execution_state(execution_state_root: Bytes32) -> ExecutionState:
@@ -588,15 +589,16 @@ def format_protocol(protocol_name: str, protocol_def: ProtocolDefinition) -> str
588
589
for k in list (spec_object .functions ):
589
590
if "ceillog2" in k or "floorlog2" in k :
590
591
del spec_object .functions [k ]
591
- functions_spec = '\n \n \n ' .join (spec_object .functions .values ())
592
+ functions = builder .implement_optimizations (spec_object .functions )
593
+ functions_spec = '\n \n \n ' .join (functions .values ())
592
594
593
595
# Access global dict of config vars for runtime configurables
594
596
for name in spec_object .config_vars .keys ():
595
597
functions_spec = functions_spec .replace (name , 'config.' + name )
596
598
597
599
def format_config_var (name : str , vardef : VariableDefinition ) -> str :
598
600
if vardef .type_name is None :
599
- out = f'{ name } ={ vardef .value } '
601
+ out = f'{ name } ={ vardef .value } , '
600
602
else :
601
603
out = f'{ name } ={ vardef .type_name } ({ vardef .value } ),'
602
604
if vardef .comment is not None :
@@ -647,7 +649,6 @@ def format_constant(name: str, vardef: VariableDefinition) -> str:
647
649
# Since some constants are hardcoded in setup.py, the following assertions verify that the hardcoded constants are
648
650
# as same as the spec definition.
649
651
+ ('\n \n \n ' + ssz_dep_constants_verification if ssz_dep_constants_verification != '' else '' )
650
- + ('\n ' + builder .invariant_checks () if builder .invariant_checks () != '' else '' )
651
652
+ '\n '
652
653
)
653
654
return spec
@@ -831,7 +832,7 @@ def initialize_options(self):
831
832
self .out_dir = 'pyspec_output'
832
833
self .build_targets = """
833
834
minimal:presets/minimal:configs/minimal.yaml
834
- mainnet:presets/mainnet:configs/mainnet.yaml
835
+ mainnet:presets/mainnet:configs/mainnet.yaml
835
836
"""
836
837
837
838
def finalize_options (self ):
@@ -853,6 +854,7 @@ def finalize_options(self):
853
854
specs/phase0/validator.md
854
855
specs/phase0/weak-subjectivity.md
855
856
specs/altair/beacon-chain.md
857
+ specs/altair/bls.md
856
858
specs/altair/fork.md
857
859
specs/altair/validator.md
858
860
specs/altair/p2p-interface.md
@@ -865,6 +867,7 @@ def finalize_options(self):
865
867
specs/phase0/validator.md
866
868
specs/phase0/weak-subjectivity.md
867
869
specs/merge/beacon-chain.md
870
+ specs/merge/fork.md
868
871
specs/merge/fork-choice.md
869
872
specs/merge/validator.md
870
873
"""
@@ -912,7 +915,8 @@ def run(self):
912
915
913
916
if not self .dry_run :
914
917
with open (os .path .join (self .out_dir , '__init__.py' ), 'w' ) as out :
915
- out .write ("" )
918
+ # `mainnet` is the default spec.
919
+ out .write ("from . import mainnet as spec # noqa:F401\n " )
916
920
917
921
918
922
class BuildPyCommand (build_py ):
@@ -1006,7 +1010,7 @@ def run(self):
1006
1010
python_requires = ">=3.8, <4" ,
1007
1011
extras_require = {
1008
1012
"test" : ["pytest>=4.4" , "pytest-cov" , "pytest-xdist" ],
1009
- "lint" : ["flake8==3.7.7" , "mypy==0.750 " ],
1013
+ "lint" : ["flake8==3.7.7" , "mypy==0.812 " ],
1010
1014
"generator" : ["python-snappy==0.5.4" ],
1011
1015
},
1012
1016
install_requires = [
@@ -1016,7 +1020,7 @@ def run(self):
1016
1020
"py_ecc==5.2.0" ,
1017
1021
"milagro_bls_binding==1.6.3" ,
1018
1022
"dataclasses==0.6" ,
1019
- "remerkleable==0.1.19 " ,
1023
+ "remerkleable==0.1.20 " ,
1020
1024
RUAMEL_YAML_VERSION ,
1021
1025
"lru-dict==1.1.6" ,
1022
1026
MARKO_VERSION ,
0 commit comments