Skip to content

Commit 34fc0a5

Browse files
committed
Merge branch 'dev'
2 parents 0347c52 + a553e3b commit 34fc0a5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1324
-551
lines changed

Makefile

+4-2
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,15 @@ pyspec:
9494
install_test:
9595
python3 -m venv venv; . venv/bin/activate; python3 -m pip install -e .[lint]; python3 -m pip install -e .[test]
9696

97+
# Testing against `minimal` config by default
9798
test: pyspec
9899
. venv/bin/activate; cd $(PY_SPEC_DIR); \
99-
python3 -m pytest -n 4 --disable-bls --cov=eth2spec.phase0.mainnet --cov=eth2spec.altair.mainnet --cov-report="html:$(COV_HTML_OUT)" --cov-branch eth2spec
100+
python3 -m pytest -n 4 --disable-bls --cov=eth2spec.phase0.minimal --cov=eth2spec.altair.minimal --cov-report="html:$(COV_HTML_OUT)" --cov-branch eth2spec
100101

102+
# Testing against `minimal` config by default
101103
find_test: pyspec
102104
. venv/bin/activate; cd $(PY_SPEC_DIR); \
103-
python3 -m pytest -k=$(K) --disable-bls --cov=eth2spec.phase0.mainnet --cov=eth2spec.altair.mainnet --cov-report="html:$(COV_HTML_OUT)" --cov-branch eth2spec
105+
python3 -m pytest -k=$(K) --disable-bls --cov=eth2spec.phase0.minimal --cov=eth2spec.altair.minimal --cov-report="html:$(COV_HTML_OUT)" --cov-branch eth2spec
104106

105107
citest: pyspec
106108
mkdir -p tests/core/pyspec/test-reports/eth2spec; . venv/bin/activate; cd $(PY_SPEC_DIR); \

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ while the details are in review and may change.
4343
* [ethereum.org](https://ethereum.org) high-level description of the merge [here](https://ethereum.org/en/eth2/docking/)
4444
* Specifications:
4545
* [Beacon Chain changes](specs/merge/beacon-chain.md)
46+
* [Merge fork](specs/merge/fork.md)
4647
* [Fork Choice changes](specs/merge/fork-choice.md)
4748
* [Validator additions](specs/merge/validator.md)
4849

configs/mainnet.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ SHARDING_FORK_VERSION: 0x03000000
3232
SHARDING_FORK_EPOCH: 18446744073709551615
3333

3434
# TBD, 2**32 is a placeholder. Merge transition approach is in active R&D.
35-
TRANSITION_TOTAL_DIFFICULTY: 4294967296
35+
MIN_ANCHOR_POW_BLOCK_DIFFICULTY: 4294967296
3636

3737

3838
# Time parameters

configs/minimal.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ SHARDING_FORK_VERSION: 0x03000001
3131
SHARDING_FORK_EPOCH: 18446744073709551615
3232

3333
# TBD, 2**32 is a placeholder. Merge transition approach is in active R&D.
34-
TRANSITION_TOTAL_DIFFICULTY: 4294967296
34+
MIN_ANCHOR_POW_BLOCK_DIFFICULTY: 4294967296
3535

3636

3737
# Time parameters

presets/mainnet/altair.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR: 2
1414
# ---------------------------------------------------------------
1515
# 2**9 (= 512)
1616
SYNC_COMMITTEE_SIZE: 512
17-
# 2**9 (= 512)
18-
EPOCHS_PER_SYNC_COMMITTEE_PERIOD: 512
17+
# 2**8 (= 256)
18+
EPOCHS_PER_SYNC_COMMITTEE_PERIOD: 256
1919

2020

2121
# Sync protocol

presets/mainnet/sharding.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ MAX_SHARD_PROPOSER_SLASHINGS: 16
1515
# Shard block configs
1616
# ---------------------------------------------------------------
1717
MAX_SHARD_HEADERS_PER_SHARD: 4
18+
# 2**8 (= 256)
19+
SHARD_STATE_MEMORY_SLOTS: 256
1820
# 2**11 (= 2,048)
1921
MAX_SAMPLES_PER_BLOCK: 2048
2022
# 2**10 (= 1,1024)

presets/minimal/sharding.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ MAX_SHARD_PROPOSER_SLASHINGS: 4
1515
# Shard block configs
1616
# ---------------------------------------------------------------
1717
MAX_SHARD_HEADERS_PER_SHARD: 4
18+
# 2**8 (= 256)
19+
SHARD_STATE_MEMORY_SLOTS: 256
1820
# 2**11 (= 2,048)
1921
MAX_SAMPLES_PER_BLOCK: 2048
2022
# 2**10 (= 1,1024)

setup.py

+24-20
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ def floorlog2(x: int) -> uint64:
5555
'''
5656

5757

58+
OPTIMIZED_BLS_AGGREGATE_PUBKEYS = '''
59+
def eth2_aggregate_pubkeys(pubkeys: Sequence[BLSPubkey]) -> BLSPubkey:
60+
return bls.AggregatePKs(pubkeys)
61+
'''
62+
63+
5864
class ProtocolDefinition(NamedTuple):
5965
# just function definitions currently. May expand with configuration vars in future.
6066
functions: Dict[str, str]
@@ -299,10 +305,7 @@ def hardcoded_custom_type_dep_constants(cls) -> Dict[str, str]: # TODO
299305

300306
@classmethod
301307
@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]:
306309
raise NotImplementedError()
307310

308311
@classmethod
@@ -426,8 +429,8 @@ def hardcoded_custom_type_dep_constants(cls) -> Dict[str, str]:
426429
return {}
427430

428431
@classmethod
429-
def invariant_checks(cls) -> str:
430-
return ''
432+
def implement_optimizations(cls, functions: Dict[str, str]) -> Dict[str, str]:
433+
return functions
431434

432435
@classmethod
433436
def build_spec(cls, preset_name: str,
@@ -476,12 +479,10 @@ def hardcoded_ssz_dep_constants(cls) -> Dict[str, str]:
476479
return {**super().hardcoded_ssz_dep_constants(), **constants}
477480

478481
@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)
485486

486487
#
487488
# MergeSpecBuilder
@@ -509,7 +510,7 @@ def sundry_functions(cls) -> str:
509510
510511
def get_pow_block(hash: Bytes32) -> PowBlock:
511512
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))
513514
514515
515516
def get_execution_state(execution_state_root: Bytes32) -> ExecutionState:
@@ -588,15 +589,16 @@ def format_protocol(protocol_name: str, protocol_def: ProtocolDefinition) -> str
588589
for k in list(spec_object.functions):
589590
if "ceillog2" in k or "floorlog2" in k:
590591
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())
592594

593595
# Access global dict of config vars for runtime configurables
594596
for name in spec_object.config_vars.keys():
595597
functions_spec = functions_spec.replace(name, 'config.' + name)
596598

597599
def format_config_var(name: str, vardef: VariableDefinition) -> str:
598600
if vardef.type_name is None:
599-
out = f'{name}={vardef.value}'
601+
out = f'{name}={vardef.value},'
600602
else:
601603
out = f'{name}={vardef.type_name}({vardef.value}),'
602604
if vardef.comment is not None:
@@ -647,7 +649,6 @@ def format_constant(name: str, vardef: VariableDefinition) -> str:
647649
# Since some constants are hardcoded in setup.py, the following assertions verify that the hardcoded constants are
648650
# as same as the spec definition.
649651
+ ('\n\n\n' + ssz_dep_constants_verification if ssz_dep_constants_verification != '' else '')
650-
+ ('\n' + builder.invariant_checks() if builder.invariant_checks() != '' else '')
651652
+ '\n'
652653
)
653654
return spec
@@ -831,7 +832,7 @@ def initialize_options(self):
831832
self.out_dir = 'pyspec_output'
832833
self.build_targets = """
833834
minimal:presets/minimal:configs/minimal.yaml
834-
mainnet:presets/mainnet:configs/mainnet.yaml
835+
mainnet:presets/mainnet:configs/mainnet.yaml
835836
"""
836837

837838
def finalize_options(self):
@@ -853,6 +854,7 @@ def finalize_options(self):
853854
specs/phase0/validator.md
854855
specs/phase0/weak-subjectivity.md
855856
specs/altair/beacon-chain.md
857+
specs/altair/bls.md
856858
specs/altair/fork.md
857859
specs/altair/validator.md
858860
specs/altair/p2p-interface.md
@@ -865,6 +867,7 @@ def finalize_options(self):
865867
specs/phase0/validator.md
866868
specs/phase0/weak-subjectivity.md
867869
specs/merge/beacon-chain.md
870+
specs/merge/fork.md
868871
specs/merge/fork-choice.md
869872
specs/merge/validator.md
870873
"""
@@ -912,7 +915,8 @@ def run(self):
912915

913916
if not self.dry_run:
914917
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")
916920

917921

918922
class BuildPyCommand(build_py):
@@ -1006,7 +1010,7 @@ def run(self):
10061010
python_requires=">=3.8, <4",
10071011
extras_require={
10081012
"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"],
10101014
"generator": ["python-snappy==0.5.4"],
10111015
},
10121016
install_requires=[
@@ -1016,7 +1020,7 @@ def run(self):
10161020
"py_ecc==5.2.0",
10171021
"milagro_bls_binding==1.6.3",
10181022
"dataclasses==0.6",
1019-
"remerkleable==0.1.19",
1023+
"remerkleable==0.1.20",
10201024
RUAMEL_YAML_VERSION,
10211025
"lru-dict==1.1.6",
10221026
MARKO_VERSION,

0 commit comments

Comments
 (0)