Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
djrtwo committed Jun 8, 2021
2 parents 0347c52 + a553e3b commit 34fc0a5
Show file tree
Hide file tree
Showing 54 changed files with 1,324 additions and 551 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ pyspec:
install_test:
python3 -m venv venv; . venv/bin/activate; python3 -m pip install -e .[lint]; python3 -m pip install -e .[test]

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

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

citest: pyspec
mkdir -p tests/core/pyspec/test-reports/eth2spec; . venv/bin/activate; cd $(PY_SPEC_DIR); \
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ while the details are in review and may change.
* [ethereum.org](https://ethereum.org) high-level description of the merge [here](https://ethereum.org/en/eth2/docking/)
* Specifications:
* [Beacon Chain changes](specs/merge/beacon-chain.md)
* [Merge fork](specs/merge/fork.md)
* [Fork Choice changes](specs/merge/fork-choice.md)
* [Validator additions](specs/merge/validator.md)

Expand Down
2 changes: 1 addition & 1 deletion configs/mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ SHARDING_FORK_VERSION: 0x03000000
SHARDING_FORK_EPOCH: 18446744073709551615

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


# Time parameters
Expand Down
2 changes: 1 addition & 1 deletion configs/minimal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ SHARDING_FORK_VERSION: 0x03000001
SHARDING_FORK_EPOCH: 18446744073709551615

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


# Time parameters
Expand Down
4 changes: 2 additions & 2 deletions presets/mainnet/altair.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR: 2
# ---------------------------------------------------------------
# 2**9 (= 512)
SYNC_COMMITTEE_SIZE: 512
# 2**9 (= 512)
EPOCHS_PER_SYNC_COMMITTEE_PERIOD: 512
# 2**8 (= 256)
EPOCHS_PER_SYNC_COMMITTEE_PERIOD: 256


# Sync protocol
Expand Down
2 changes: 2 additions & 0 deletions presets/mainnet/sharding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ MAX_SHARD_PROPOSER_SLASHINGS: 16
# Shard block configs
# ---------------------------------------------------------------
MAX_SHARD_HEADERS_PER_SHARD: 4
# 2**8 (= 256)
SHARD_STATE_MEMORY_SLOTS: 256
# 2**11 (= 2,048)
MAX_SAMPLES_PER_BLOCK: 2048
# 2**10 (= 1,1024)
Expand Down
2 changes: 2 additions & 0 deletions presets/minimal/sharding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ MAX_SHARD_PROPOSER_SLASHINGS: 4
# Shard block configs
# ---------------------------------------------------------------
MAX_SHARD_HEADERS_PER_SHARD: 4
# 2**8 (= 256)
SHARD_STATE_MEMORY_SLOTS: 256
# 2**11 (= 2,048)
MAX_SAMPLES_PER_BLOCK: 2048
# 2**10 (= 1,1024)
Expand Down
44 changes: 24 additions & 20 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ def floorlog2(x: int) -> uint64:
'''


OPTIMIZED_BLS_AGGREGATE_PUBKEYS = '''
def eth2_aggregate_pubkeys(pubkeys: Sequence[BLSPubkey]) -> BLSPubkey:
return bls.AggregatePKs(pubkeys)
'''


class ProtocolDefinition(NamedTuple):
# just function definitions currently. May expand with configuration vars in future.
functions: Dict[str, str]
Expand Down Expand Up @@ -299,10 +305,7 @@ def hardcoded_custom_type_dep_constants(cls) -> Dict[str, str]: # TODO

@classmethod
@abstractmethod
def invariant_checks(cls) -> str:
"""
The invariant checks
"""
def implement_optimizations(cls, functions: Dict[str, str]) -> Dict[str, str]:
raise NotImplementedError()

@classmethod
Expand Down Expand Up @@ -426,8 +429,8 @@ def hardcoded_custom_type_dep_constants(cls) -> Dict[str, str]:
return {}

@classmethod
def invariant_checks(cls) -> str:
return ''
def implement_optimizations(cls, functions: Dict[str, str]) -> Dict[str, str]:
return functions

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

@classmethod
def invariant_checks(cls) -> str:
return '''
assert (
TIMELY_HEAD_WEIGHT + TIMELY_SOURCE_WEIGHT + TIMELY_TARGET_WEIGHT + SYNC_REWARD_WEIGHT + PROPOSER_WEIGHT
) == WEIGHT_DENOMINATOR'''

def implement_optimizations(cls, functions: Dict[str, str]) -> Dict[str, str]:
if "eth2_aggregate_pubkeys" in functions:
functions["eth2_aggregate_pubkeys"] = OPTIMIZED_BLS_AGGREGATE_PUBKEYS.strip()
return super().implement_optimizations(functions)

#
# MergeSpecBuilder
Expand Down Expand Up @@ -509,7 +510,7 @@ def sundry_functions(cls) -> str:
def get_pow_block(hash: Bytes32) -> PowBlock:
return PowBlock(block_hash=hash, is_valid=True, is_processed=True,
total_difficulty=config.TRANSITION_TOTAL_DIFFICULTY)
total_difficulty=uint256(0), difficulty=uint256(0))
def get_execution_state(execution_state_root: Bytes32) -> ExecutionState:
Expand Down Expand Up @@ -588,15 +589,16 @@ def format_protocol(protocol_name: str, protocol_def: ProtocolDefinition) -> str
for k in list(spec_object.functions):
if "ceillog2" in k or "floorlog2" in k:
del spec_object.functions[k]
functions_spec = '\n\n\n'.join(spec_object.functions.values())
functions = builder.implement_optimizations(spec_object.functions)
functions_spec = '\n\n\n'.join(functions.values())

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

def format_config_var(name: str, vardef: VariableDefinition) -> str:
if vardef.type_name is None:
out = f'{name}={vardef.value}'
out = f'{name}={vardef.value},'
else:
out = f'{name}={vardef.type_name}({vardef.value}),'
if vardef.comment is not None:
Expand Down Expand Up @@ -647,7 +649,6 @@ def format_constant(name: str, vardef: VariableDefinition) -> str:
# Since some constants are hardcoded in setup.py, the following assertions verify that the hardcoded constants are
# as same as the spec definition.
+ ('\n\n\n' + ssz_dep_constants_verification if ssz_dep_constants_verification != '' else '')
+ ('\n' + builder.invariant_checks() if builder.invariant_checks() != '' else '')
+ '\n'
)
return spec
Expand Down Expand Up @@ -831,7 +832,7 @@ def initialize_options(self):
self.out_dir = 'pyspec_output'
self.build_targets = """
minimal:presets/minimal:configs/minimal.yaml
mainnet:presets/mainnet:configs/mainnet.yaml
mainnet:presets/mainnet:configs/mainnet.yaml
"""

def finalize_options(self):
Expand All @@ -853,6 +854,7 @@ def finalize_options(self):
specs/phase0/validator.md
specs/phase0/weak-subjectivity.md
specs/altair/beacon-chain.md
specs/altair/bls.md
specs/altair/fork.md
specs/altair/validator.md
specs/altair/p2p-interface.md
Expand All @@ -865,6 +867,7 @@ def finalize_options(self):
specs/phase0/validator.md
specs/phase0/weak-subjectivity.md
specs/merge/beacon-chain.md
specs/merge/fork.md
specs/merge/fork-choice.md
specs/merge/validator.md
"""
Expand Down Expand Up @@ -912,7 +915,8 @@ def run(self):

if not self.dry_run:
with open(os.path.join(self.out_dir, '__init__.py'), 'w') as out:
out.write("")
# `mainnet` is the default spec.
out.write("from . import mainnet as spec # noqa:F401\n")


class BuildPyCommand(build_py):
Expand Down Expand Up @@ -1006,7 +1010,7 @@ def run(self):
python_requires=">=3.8, <4",
extras_require={
"test": ["pytest>=4.4", "pytest-cov", "pytest-xdist"],
"lint": ["flake8==3.7.7", "mypy==0.750"],
"lint": ["flake8==3.7.7", "mypy==0.812"],
"generator": ["python-snappy==0.5.4"],
},
install_requires=[
Expand All @@ -1016,7 +1020,7 @@ def run(self):
"py_ecc==5.2.0",
"milagro_bls_binding==1.6.3",
"dataclasses==0.6",
"remerkleable==0.1.19",
"remerkleable==0.1.20",
RUAMEL_YAML_VERSION,
"lru-dict==1.1.6",
MARKO_VERSION,
Expand Down
Loading

0 comments on commit 34fc0a5

Please sign in to comment.