Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
djrtwo committed Oct 4, 2021
2 parents 67fd797 + fea3702 commit ceb17a7
Show file tree
Hide file tree
Showing 16 changed files with 196 additions and 53 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ The merge is still actively in development. The exact specification has not been
* [Fork Choice changes](specs/merge/fork-choice.md)
* [Validator additions](specs/merge/validator.md)
* [Client settings](specs/merge/client-settings.md)
* [P2P Networking](specs/merge/p2p-interface.md)

### Sharding

Expand Down
2 changes: 1 addition & 1 deletion specs/altair/beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ def initialize_beacon_state_from_eth1(eth1_block_hash: Bytes32,
eth1_timestamp: uint64,
deposits: Sequence[Deposit]) -> BeaconState:
fork = Fork(
previous_version=GENESIS_FORK_VERSION,
previous_version=ALTAIR_FORK_VERSION, # [Modified in Altair] for testing only
current_version=ALTAIR_FORK_VERSION, # [Modified in Altair]
epoch=GENESIS_EPOCH,
)
Expand Down
35 changes: 14 additions & 21 deletions specs/merge/beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
- [Constants](#constants)
- [Execution](#execution)
- [Configuration](#configuration)
- [Genesis testing settings](#genesis-testing-settings)
- [Transition settings](#transition-settings)
- [Containers](#containers)
- [Extended containers](#extended-containers)
Expand Down Expand Up @@ -71,15 +70,6 @@ This patch adds transaction execution to the beacon chain as part of the Merge f

## Configuration

### Genesis testing settings

*Note*: These configuration settings do not apply to the mainnet and are utilized only by pure Merge testing.

| Name | Value |
| - | - |
| `GENESIS_GAS_LIMIT` | `uint64(30000000)` (= 30,000,000) |
| `GENESIS_BASE_FEE_PER_GAS` | `Bytes32('0x00ca9a3b00000000000000000000000000000000000000000000000000000000')` (= 1,000,000,000) |

### Transition settings

| Name | Value |
Expand Down Expand Up @@ -257,7 +247,7 @@ The Engine API may be used to implement them with an external execution engine.
```python
def execute_payload(self: ExecutionEngine, execution_payload: ExecutionPayload) -> bool:
"""
Returns ``True`` iff ``execution_payload`` is valid with respect to ``self.execution_state``.
Return ``True`` if and only if ``execution_payload`` is valid with respect to ``self.execution_state``.
"""
...
```
Expand Down Expand Up @@ -354,15 +344,21 @@ def process_execution_payload(state: BeaconState, payload: ExecutionPayload, exe
## Testing

*Note*: The function `initialize_beacon_state_from_eth1` is modified for pure Merge testing only.

*Note*: The function `initialize_beacon_state_from_eth1` is modified: (1) using `MERGE_FORK_VERSION` as the current fork version, (2) utilizing the Merge `BeaconBlockBody` when constructing the initial `latest_block_header`, and (3) initialize `latest_execution_payload_header`.
Modifications include:
1. Use `MERGE_FORK_VERSION` as the current fork version.
2. Utilize the Merge `BeaconBlockBody` when constructing the initial `latest_block_header`.
3. Initialize `latest_execution_payload_header`.
If `execution_payload_header == ExecutionPayloadHeader()`, then the Merge has not yet occurred.
Else, the Merge starts from genesis and the transition is incomplete.

```python
def initialize_beacon_state_from_eth1(eth1_block_hash: Bytes32,
eth1_timestamp: uint64,
deposits: Sequence[Deposit]) -> BeaconState:
deposits: Sequence[Deposit],
execution_payload_header: ExecutionPayloadHeader=ExecutionPayloadHeader()
) -> BeaconState:
fork = Fork(
previous_version=GENESIS_FORK_VERSION,
previous_version=MERGE_FORK_VERSION, # [Modified in Merge] for testing only
current_version=MERGE_FORK_VERSION, # [Modified in Merge]
epoch=GENESIS_EPOCH,
)
Expand Down Expand Up @@ -397,12 +393,9 @@ def initialize_beacon_state_from_eth1(eth1_block_hash: Bytes32,
state.current_sync_committee = get_next_sync_committee(state)
state.next_sync_committee = get_next_sync_committee(state)

# [New in Merge] Initialize the execution payload header (with block number set to 0)
state.latest_execution_payload_header.block_hash = eth1_block_hash
state.latest_execution_payload_header.timestamp = eth1_timestamp
state.latest_execution_payload_header.random = eth1_block_hash
state.latest_execution_payload_header.gas_limit = GENESIS_GAS_LIMIT
state.latest_execution_payload_header.base_fee_per_gas = GENESIS_BASE_FEE_PER_GAS
# [New in Merge] Initialize the execution payload header
# If empty, will initialize a chain that has not yet gone through the Merge transition
state.latest_execution_payload_header = execution_payload_header

return state
```
2 changes: 1 addition & 1 deletion tests/core/pyspec/eth2spec/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.0
1.1.1
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from eth2spec.test.context import (
spec_state_test,
with_phases,
with_altair_and_later,
)
from eth2spec.test.helpers.constants import ALTAIR
from eth2spec.test.helpers.merkle import build_proof


@with_phases([ALTAIR])
@with_altair_and_later
@spec_state_test
def test_next_sync_committee_merkle_proof(spec, state):
yield "state", state
Expand All @@ -25,7 +24,7 @@ def test_next_sync_committee_merkle_proof(spec, state):
)


@with_phases([ALTAIR])
@with_altair_and_later
@spec_state_test
def test_finality_root_merkle_proof(spec, state):
yield "state", state
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from eth2spec.test.context import (
with_altair_and_later,
spec_state_test,
with_altair_and_later,
)
from eth2spec.test.helpers.state import (
transition_to,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from eth2spec.test.context import (
spec_state_test,
with_phases,
with_altair_and_later,
)
from eth2spec.test.helpers.constants import ALTAIR


@with_phases([ALTAIR])
@with_altair_and_later
@spec_state_test
def test_weight_denominator(spec, state):
assert (
Expand All @@ -17,7 +16,7 @@ def test_weight_denominator(spec, state):
) == spec.WEIGHT_DENOMINATOR


@with_phases([ALTAIR])
@with_altair_and_later
@spec_state_test
def test_inactivity_score(spec, state):
assert spec.config.INACTIVITY_SCORE_BIAS <= spec.config.INACTIVITY_SCORE_RECOVERY_RATE
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
from eth2spec.test.context import (
spec_state_test,
with_presets,
with_phases,
with_altair_and_later,
)
from eth2spec.test.helpers.attestations import next_epoch_with_attestations
from eth2spec.test.helpers.block import (
build_empty_block,
build_empty_block_for_next_slot,
)
from eth2spec.test.helpers.constants import (
ALTAIR,
MINIMAL,
)
from eth2spec.test.helpers.constants import MINIMAL
from eth2spec.test.helpers.state import (
next_slots,
state_transition_and_sign_block,
Expand All @@ -22,7 +19,7 @@
from eth2spec.test.helpers.merkle import build_proof


@with_phases([ALTAIR])
@with_altair_and_later
@spec_state_test
def test_process_light_client_update_not_updated(spec, state):
pre_snapshot = spec.LightClientSnapshot(
Expand Down Expand Up @@ -81,7 +78,7 @@ def test_process_light_client_update_not_updated(spec, state):
assert store.snapshot == pre_snapshot


@with_phases([ALTAIR])
@with_altair_and_later
@spec_state_test
@with_presets([MINIMAL], reason="too slow")
def test_process_light_client_update_timeout(spec, state):
Expand Down Expand Up @@ -147,7 +144,7 @@ def test_process_light_client_update_timeout(spec, state):
assert store.snapshot.header == update.header


@with_phases([ALTAIR])
@with_altair_and_later
@spec_state_test
@with_presets([MINIMAL], reason="too slow")
def test_process_light_client_update_finality_updated(spec, state):
Expand Down
4 changes: 2 additions & 2 deletions tests/core/pyspec/eth2spec/test/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ def is_post_merge(spec):
return spec.fork not in FORKS_BEFORE_MERGE


with_altair_and_later = with_phases([ALTAIR, MERGE])
with_merge_and_later = with_phases([MERGE]) # TODO: include sharding when spec stabilizes.
with_altair_and_later = with_all_phases_except([PHASE0])
with_merge_and_later = with_all_phases_except([PHASE0, ALTAIR])


def only_generator(reason):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def build_empty_execution_payload(spec, state, randao_mix=None):
Assuming a pre-state of the same slot, build a valid ExecutionPayload without any transactions.
"""
latest = state.latest_execution_payload_header
timestamp = spec.compute_time_at_slot(state, state.slot)
timestamp = spec.compute_timestamp_at_slot(state, state.slot)
empty_txs = spec.List[spec.Transaction, spec.MAX_TRANSACTIONS_PER_PAYLOAD]()

if randao_mix is None:
Expand Down
27 changes: 23 additions & 4 deletions tests/core/pyspec/eth2spec/test/helpers/genesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ def build_mock_validator(spec, i: int, balance: int):
)


def get_sample_genesis_execution_payload_header(spec,
eth1_block_hash=None):
if eth1_block_hash is None:
eth1_block_hash = b'\x55' * 32
return spec.ExecutionPayloadHeader(
parent_hash=b'\x30' * 32,
coinbase=b'\x42' * 20,
state_root=b'\x20' * 32,
receipt_root=b'\x20' * 32,
logs_bloom=b'\x35' * spec.BYTES_PER_LOGS_BLOOM,
random=eth1_block_hash,
block_number=0,
gas_limit=30000000,
base_fee_per_gas=spec.Bytes32('0x00ca9a3b00000000000000000000000000000000000000000000000000000000'),
block_hash=eth1_block_hash,
transactions_root=spec.Root(b'\x56' * 32),
)


def create_genesis_state(spec, validator_balances, activation_threshold):
deposit_root = b'\x42' * 32

Expand Down Expand Up @@ -76,9 +95,9 @@ def create_genesis_state(spec, validator_balances, activation_threshold):

if spec.fork not in FORKS_BEFORE_MERGE:
# Initialize the execution payload header (with block number and genesis time set to 0)
state.latest_execution_payload_header.block_hash = eth1_block_hash
state.latest_execution_payload_header.random = eth1_block_hash
state.latest_execution_payload_header.gas_limit = spec.GENESIS_GAS_LIMIT
state.latest_execution_payload_header.base_fee_per_gas = spec.GENESIS_BASE_FEE_PER_GAS
state.latest_execution_payload_header = get_sample_genesis_execution_payload_header(
spec,
eth1_block_hash=eth1_block_hash,
)

return state
Empty file.
122 changes: 122 additions & 0 deletions tests/core/pyspec/eth2spec/test/merge/genesis/test_initialization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
from eth2spec.test.context import (
MERGE,
single_phase,
spec_test,
with_presets,
with_phases,
with_merge_and_later,
)
from eth2spec.test.helpers.constants import MINIMAL
from eth2spec.test.helpers.deposits import (
prepare_full_genesis_deposits,
)
from eth2spec.test.helpers.genesis import (
get_sample_genesis_execution_payload_header,
)


def eth1_init_data(eth1_block_hash, eth1_timestamp):
yield 'eth1', {
'eth1_block_hash': '0x' + eth1_block_hash.hex(),
'eth1_timestamp': int(eth1_timestamp),
}


@with_phases([MERGE])
@spec_test
@single_phase
@with_presets([MINIMAL], reason="too slow")
def test_initialize_pre_transition_no_param(spec):
deposit_count = spec.config.MIN_GENESIS_ACTIVE_VALIDATOR_COUNT
deposits, deposit_root, _ = prepare_full_genesis_deposits(
spec,
spec.MAX_EFFECTIVE_BALANCE,
deposit_count,
signed=True,
)

eth1_block_hash = b'\x12' * 32
eth1_timestamp = spec.config.MIN_GENESIS_TIME

yield from eth1_init_data(eth1_block_hash, eth1_timestamp)
yield 'deposits', deposits

# initialize beacon_state *without* an execution_payload_header
yield 'execution_payload_header', 'meta', False
state = spec.initialize_beacon_state_from_eth1(eth1_block_hash, eth1_timestamp, deposits)

assert not spec.is_merge_complete(state)

yield 'state', state


@with_merge_and_later
@spec_test
@single_phase
@with_presets([MINIMAL], reason="too slow")
def test_initialize_pre_transition_empty_payload(spec):
deposit_count = spec.config.MIN_GENESIS_ACTIVE_VALIDATOR_COUNT
deposits, deposit_root, _ = prepare_full_genesis_deposits(
spec,
spec.MAX_EFFECTIVE_BALANCE,
deposit_count,
signed=True,
)

eth1_block_hash = b'\x12' * 32
eth1_timestamp = spec.config.MIN_GENESIS_TIME

yield from eth1_init_data(eth1_block_hash, eth1_timestamp)
yield 'deposits', deposits

# initialize beacon_state *with* an *empty* execution_payload_header
yield 'execution_payload_header', 'meta', True
execution_payload_header = spec.ExecutionPayloadHeader()
state = spec.initialize_beacon_state_from_eth1(
eth1_block_hash,
eth1_timestamp,
deposits,
execution_payload_header=execution_payload_header,
)

assert not spec.is_merge_complete(state)

yield 'execution_payload_header', execution_payload_header

yield 'state', state


@with_merge_and_later
@spec_test
@single_phase
@with_presets([MINIMAL], reason="too slow")
def test_initialize_post_transition(spec):
deposit_count = spec.config.MIN_GENESIS_ACTIVE_VALIDATOR_COUNT
deposits, deposit_root, _ = prepare_full_genesis_deposits(
spec,
spec.MAX_EFFECTIVE_BALANCE,
deposit_count,
signed=True,
)

eth1_block_hash = b'\x12' * 32
eth1_timestamp = spec.config.MIN_GENESIS_TIME

yield from eth1_init_data(eth1_block_hash, eth1_timestamp)
yield 'deposits', deposits

# initialize beacon_state *with* an execution_payload_header
yield 'execution_payload_header', 'meta', True
genesis_execution_payload_header = get_sample_genesis_execution_payload_header(spec)
state = spec.initialize_beacon_state_from_eth1(
eth1_block_hash,
eth1_timestamp,
deposits,
execution_payload_header=genesis_execution_payload_header,
)

yield 'execution_payload_header', genesis_execution_payload_header

assert spec.is_merge_complete(state)

yield 'state', state
Loading

0 comments on commit ceb17a7

Please sign in to comment.