Skip to content

Commit

Permalink
polish merge/beacon-chain.md (#2472)
Browse files Browse the repository at this point in the history
Polish `merge/beacon-chain.md` with mostly non-substantive changes.

**Non-substantive changes**

* rename `MAX_EXECUTION_TRANSACTIONS` to `MAX_TRANSACTIONS_PER_PAYLOAD`
	- rename "execution transaction" to just "transaction" as per discussion with Danny
* rename `compute_time_at_slot` to `compute_timestamp_at_slot`
	- the function returns a Unix timestamp
	- "timestamp" matches `execution_payload.timestamp`
* be explicit about `ExecutionEngine.execution_state` for clarity
* rename `ExecutionPayload.number` to `ExecutionPayload.block_number`
	- more specific ("number" is pretty vague)
	- consistent with `ExecutionPayload.block_hash`
* rename `new_block` to `on_payload`
	- the `on_` prefix is consistent with other event handlers (e.g. see `on_tick`, `on_block`, `on_attestation` [here](https://github.com/ethereum/eth2.0-specs/blob/dev/specs/phase0/fork-choice.md#handlers))
	- the `_payload` suffix is more to the point given the function accepts an `execution_payload`
	- avoids conflict with `on_block` which is already used in the fork choice
* rework the table of contents for consistency
* order `is_execution_enabled` after `is_transition_completed` and `is_transition_block`
	- `is_execution_enabled` refers to `is_transition_completed` and `is_transition_block`
* rename "transition" to "merge"
	- "transition" is a bit vague—we will have other transitions at future hard forks
	- there is no need for two words to refer to the same concept
* add a bunch of inline comments, e.g. in `process_execution_payload`
* make the `process_execution_payload` signature consistent with the other `process_` functions in `process_block` which take as arguments `state` and `block.body`
* remove `TRANSITION_TOTAL_DIFFICULTY`
	- to be put in `merge/fork-choice.md` where it is used 
* various misc cleanups

**Substantive changes**

* reorder `ExecutionPayload` fields
	- for consistency with yellow paper and Eth1
	- same for `ExecutionPayloadHeader`
	- added comments separating out the execution block header fields from the extra fields (cosmetic)
  • Loading branch information
JustinDrake authored Jun 18, 2021
1 parent 903b363 commit 878b15d
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 143 deletions.
18 changes: 11 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def get_spec(file_name: Path, preset: Dict[str, str], config: Dict[str, str]) ->

if not _is_constant_id(name):
# Check for short type declarations
if value.startswith("uint") or value.startswith("Bytes") or value.startswith("ByteList"):
if value.startswith("uint") or value.startswith("Bytes") or value.startswith("ByteList") or value.startswith("Union"):
custom_types[name] = value
continue

Expand Down Expand Up @@ -495,7 +495,7 @@ def imports(cls, preset_name: str):
return super().imports(preset_name) + f'''
from typing import Protocol
from eth2spec.phase0 import {preset_name} as phase0
from eth2spec.utils.ssz.ssz_typing import Bytes20, ByteList, ByteVector, uint256
from eth2spec.utils.ssz.ssz_typing import Bytes20, ByteList, ByteVector, uint256, Union
'''

@classmethod
Expand Down Expand Up @@ -523,7 +523,7 @@ def get_pow_chain_head() -> PowBlock:
class NoopExecutionEngine(ExecutionEngine):
def new_block(self, execution_payload: ExecutionPayload) -> bool:
def on_payload(self, execution_payload: ExecutionPayload) -> bool:
return True
def set_head(self, block_hash: Hash32) -> bool:
Expand Down Expand Up @@ -553,6 +553,10 @@ def hardcoded_custom_type_dep_constants(cls) -> str:
}


def is_spec_defined_type(value: str) -> bool:
return value.startswith('ByteList') or value.startswith('Union')


def objects_to_spec(preset_name: str,
spec_object: SpecObject,
builder: SpecBuilder,
Expand All @@ -565,15 +569,15 @@ def objects_to_spec(preset_name: str,
[
f"class {key}({value}):\n pass\n"
for key, value in spec_object.custom_types.items()
if not value.startswith('ByteList')
if not is_spec_defined_type(value)
]
)
+ ('\n\n' if len([key for key, value in spec_object.custom_types.items() if value.startswith('ByteList')]) > 0 else '')
+ ('\n\n' if len([key for key, value in spec_object.custom_types.items() if is_spec_defined_type(value)]) > 0 else '')
+ '\n\n'.join(
[
f"{key} = {value}\n"
for key, value in spec_object.custom_types.items()
if value.startswith('ByteList')
if is_spec_defined_type(value)
]
)
)
Expand Down Expand Up @@ -1020,7 +1024,7 @@ def run(self):
"py_ecc==5.2.0",
"milagro_bls_binding==1.6.3",
"dataclasses==0.6",
"remerkleable==0.1.20",
"remerkleable==0.1.21",
RUAMEL_YAML_VERSION,
"lru-dict==1.1.6",
MARKO_VERSION,
Expand Down
Loading

0 comments on commit 878b15d

Please sign in to comment.