Merge branch 'master' into vbuterin-patch-2
This commit is contained in:
commit
ef72b7ec20
|
@ -60,15 +60,15 @@ jobs:
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
key: v1-specs-repo-{{ .Branch }}-{{ .Revision }}
|
key: v1-specs-repo-{{ .Branch }}-{{ .Revision }}
|
||||||
- restore_cached_venv:
|
- restore_cached_venv:
|
||||||
venv_name: v1-test_libs
|
venv_name: v1-pyspec
|
||||||
reqs_checksum: '{{ checksum "test_libs/pyspec/setup.py" }}'
|
reqs_checksum: '{{ checksum "test_libs/pyspec/requirements.txt" }}-{{ checksum "test_libs/pyspec/requirements-testing.txt" }}'
|
||||||
- run:
|
- run:
|
||||||
name: Install pyspec requirements
|
name: Install pyspec requirements
|
||||||
command: make install_test
|
command: make install_test
|
||||||
- save_cached_venv:
|
- save_cached_venv:
|
||||||
venv_name: v1-test_libs
|
venv_name: v1-pyspec
|
||||||
reqs_checksum: '{{ checksum "test_libs/pyspec/setup.py" }}'
|
reqs_checksum: '{{ checksum "test_libs/pyspec/requirements.txt" }}-{{ checksum "test_libs/pyspec/requirements-testing.txt" }}'
|
||||||
venv_path: ./test_libs/venv
|
venv_path: ./test_libs/pyspec/venv
|
||||||
test:
|
test:
|
||||||
docker:
|
docker:
|
||||||
- image: circleci/python:3.6
|
- image: circleci/python:3.6
|
||||||
|
@ -77,8 +77,8 @@ jobs:
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
key: v1-specs-repo-{{ .Branch }}-{{ .Revision }}
|
key: v1-specs-repo-{{ .Branch }}-{{ .Revision }}
|
||||||
- restore_cached_venv:
|
- restore_cached_venv:
|
||||||
venv_name: v1-test_libs
|
venv_name: v1-pyspec
|
||||||
reqs_checksum: '{{ checksum "test_libs/pyspec/setup.py" }}'
|
reqs_checksum: '{{ checksum "test_libs/pyspec/requirements.txt" }}-{{ checksum "test_libs/pyspec/requirements-testing.txt" }}'
|
||||||
- run:
|
- run:
|
||||||
name: Run py-tests
|
name: Run py-tests
|
||||||
command: make citest
|
command: make citest
|
||||||
|
|
|
@ -4,10 +4,6 @@ venv
|
||||||
.venvs
|
.venvs
|
||||||
.venv
|
.venv
|
||||||
/.pytest_cache
|
/.pytest_cache
|
||||||
*.egg
|
|
||||||
*.egg-info
|
|
||||||
eggs
|
|
||||||
.eggs
|
|
||||||
|
|
||||||
build/
|
build/
|
||||||
output/
|
output/
|
||||||
|
@ -17,6 +13,3 @@ eth2.0-spec-tests/
|
||||||
|
|
||||||
# Dynamically built from Markdown spec
|
# Dynamically built from Markdown spec
|
||||||
test_libs/pyspec/eth2spec/phase0/spec.py
|
test_libs/pyspec/eth2spec/phase0/spec.py
|
||||||
|
|
||||||
# vscode
|
|
||||||
.vscode/**
|
|
||||||
|
|
14
Makefile
14
Makefile
|
@ -2,7 +2,6 @@ SPEC_DIR = ./specs
|
||||||
SCRIPT_DIR = ./scripts
|
SCRIPT_DIR = ./scripts
|
||||||
TEST_LIBS_DIR = ./test_libs
|
TEST_LIBS_DIR = ./test_libs
|
||||||
PY_SPEC_DIR = $(TEST_LIBS_DIR)/pyspec
|
PY_SPEC_DIR = $(TEST_LIBS_DIR)/pyspec
|
||||||
CONFIG_HELPERS_DIR = $(TEST_LIBS_DIR)/config_helpers
|
|
||||||
YAML_TEST_DIR = ./eth2.0-spec-tests/tests
|
YAML_TEST_DIR = ./eth2.0-spec-tests/tests
|
||||||
GENERATOR_DIR = ./test_generators
|
GENERATOR_DIR = ./test_generators
|
||||||
CONFIGS_DIR = ./configs
|
CONFIGS_DIR = ./configs
|
||||||
|
@ -24,8 +23,7 @@ all: $(PY_SPEC_ALL_TARGETS) $(YAML_TEST_DIR) $(YAML_TEST_TARGETS)
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(YAML_TEST_DIR)
|
rm -rf $(YAML_TEST_DIR)
|
||||||
rm -rf $(GENERATOR_VENVS)
|
rm -rf $(GENERATOR_VENVS)
|
||||||
rm -rf $(TEST_LIBS_DIR)/venv
|
rm -rf $(PY_SPEC_DIR)/venv $(PY_SPEC_DIR)/.pytest_cache
|
||||||
rm -rf $(PY_SPEC_DIR)/.pytest_cache
|
|
||||||
rm -rf $(PY_SPEC_ALL_TARGETS)
|
rm -rf $(PY_SPEC_ALL_TARGETS)
|
||||||
|
|
||||||
# "make gen_yaml_tests" to run generators
|
# "make gen_yaml_tests" to run generators
|
||||||
|
@ -33,17 +31,13 @@ gen_yaml_tests: $(PY_SPEC_ALL_TARGETS) $(YAML_TEST_TARGETS)
|
||||||
|
|
||||||
# installs the packages to run pyspec tests
|
# installs the packages to run pyspec tests
|
||||||
install_test:
|
install_test:
|
||||||
cd $(TEST_LIBS_DIR); python3 -m venv venv; . venv/bin/activate; \
|
cd $(PY_SPEC_DIR); python3 -m venv venv; . venv/bin/activate; pip3 install -r requirements-testing.txt;
|
||||||
cd ..; cd $(CONFIG_HELPERS_DIR); pip3 install -e .; \
|
|
||||||
cd ../..; cd $(PY_SPEC_DIR); pip3 install -e .[dev];
|
|
||||||
|
|
||||||
test: $(PY_SPEC_ALL_TARGETS)
|
test: $(PY_SPEC_ALL_TARGETS)
|
||||||
cd $(TEST_LIBS_DIR); . venv/bin/activate; \
|
cd $(PY_SPEC_DIR); . venv/bin/activate; python -m pytest .
|
||||||
cd ..; cd $(PY_SPEC_DIR); python -m pytest .;
|
|
||||||
|
|
||||||
citest: $(PY_SPEC_ALL_TARGETS)
|
citest: $(PY_SPEC_ALL_TARGETS)
|
||||||
cd $(TEST_LIBS_DIR); . venv/bin/activate; \
|
cd $(PY_SPEC_DIR); mkdir -p test-reports/eth2spec; . venv/bin/activate; python -m pytest --junitxml=test-reports/eth2spec/test_results.xml .
|
||||||
cd ..; cd $(PY_SPEC_DIR); mkdir -p test-reports/eth2spec; python -m pytest --junitxml=test-reports/eth2spec/test_results.xml .
|
|
||||||
|
|
||||||
# "make pyspec" to create the pyspec for all phases.
|
# "make pyspec" to create the pyspec for all phases.
|
||||||
pyspec: $(PY_SPEC_ALL_TARGETS)
|
pyspec: $(PY_SPEC_ALL_TARGETS)
|
||||||
|
|
|
@ -15,6 +15,8 @@ MAX_INDICES_PER_ATTESTATION: 4096
|
||||||
MIN_PER_EPOCH_CHURN_LIMIT: 4
|
MIN_PER_EPOCH_CHURN_LIMIT: 4
|
||||||
# 2**16 (= 65,536)
|
# 2**16 (= 65,536)
|
||||||
CHURN_LIMIT_QUOTIENT: 65536
|
CHURN_LIMIT_QUOTIENT: 65536
|
||||||
|
# Normalizes base rewards
|
||||||
|
BASE_REWARDS_PER_EPOCH: 5
|
||||||
# See issue 563
|
# See issue 563
|
||||||
SHUFFLE_ROUND_COUNT: 90
|
SHUFFLE_ROUND_COUNT: 90
|
||||||
|
|
||||||
|
@ -36,7 +38,7 @@ MAX_EFFECTIVE_BALANCE: 32000000000
|
||||||
# 2**4 * 10**9 (= 16,000,000,000) Gwei
|
# 2**4 * 10**9 (= 16,000,000,000) Gwei
|
||||||
EJECTION_BALANCE: 16000000000
|
EJECTION_BALANCE: 16000000000
|
||||||
# 2**0 * 10**9 (= 1,000,000,000) Gwei
|
# 2**0 * 10**9 (= 1,000,000,000) Gwei
|
||||||
HIGH_BALANCE_INCREMENT: 1000000000
|
EFFECTIVE_BALANCE_INCREMENT: 1000000000
|
||||||
|
|
||||||
|
|
||||||
# Initial values
|
# Initial values
|
||||||
|
@ -71,6 +73,8 @@ MIN_VALIDATOR_WITHDRAWABILITY_DELAY: 256
|
||||||
PERSISTENT_COMMITTEE_PERIOD: 2048
|
PERSISTENT_COMMITTEE_PERIOD: 2048
|
||||||
# 2**6 (= 64) epochs ~7 hours
|
# 2**6 (= 64) epochs ~7 hours
|
||||||
MAX_CROSSLINK_EPOCHS: 64
|
MAX_CROSSLINK_EPOCHS: 64
|
||||||
|
# 2**2 (= 4) epochs 25.6 minutes
|
||||||
|
MIN_EPOCHS_TO_INACTIVITY_PENALTY: 4
|
||||||
|
|
||||||
|
|
||||||
# State list lengths
|
# State list lengths
|
||||||
|
@ -91,14 +95,14 @@ BASE_REWARD_QUOTIENT: 32
|
||||||
WHISTLEBLOWING_REWARD_QUOTIENT: 512
|
WHISTLEBLOWING_REWARD_QUOTIENT: 512
|
||||||
# 2**3 (= 8)
|
# 2**3 (= 8)
|
||||||
PROPOSER_REWARD_QUOTIENT: 8
|
PROPOSER_REWARD_QUOTIENT: 8
|
||||||
# 2**24 (= 16,777,216)
|
# 2**25 (= 33,554,432)
|
||||||
INACTIVITY_PENALTY_QUOTIENT: 16777216
|
INACTIVITY_PENALTY_QUOTIENT: 33554432
|
||||||
|
# 2**5 (= 32)
|
||||||
|
MIN_SLASHING_PENALTY_QUOTIENT: 32
|
||||||
|
|
||||||
|
|
||||||
# Max operations per block
|
# Max operations per block
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# 2**5 (= 32)
|
|
||||||
MIN_PENALTY_QUOTIENT: 32
|
|
||||||
# 2**4 (= 16)
|
# 2**4 (= 16)
|
||||||
MAX_PROPOSER_SLASHINGS: 16
|
MAX_PROPOSER_SLASHINGS: 16
|
||||||
# 2**0 (= 1)
|
# 2**0 (= 1)
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
# [customized] Just 8 shards for testing purposes
|
# [customized] Just 8 shards for testing purposes
|
||||||
SHARD_COUNT: 8
|
SHARD_COUNT: 8
|
||||||
|
|
||||||
# [customized] unsecure, but fast
|
# [customized] unsecure, but fast
|
||||||
TARGET_COMMITTEE_SIZE: 4
|
TARGET_COMMITTEE_SIZE: 4
|
||||||
# 2**12 (= 4,096)
|
# 2**12 (= 4,096)
|
||||||
|
@ -15,6 +14,8 @@ MAX_INDICES_PER_ATTESTATION: 4096
|
||||||
MIN_PER_EPOCH_CHURN_LIMIT: 4
|
MIN_PER_EPOCH_CHURN_LIMIT: 4
|
||||||
# 2**16 (= 65,536)
|
# 2**16 (= 65,536)
|
||||||
CHURN_LIMIT_QUOTIENT: 65536
|
CHURN_LIMIT_QUOTIENT: 65536
|
||||||
|
# Normalizes base rewards
|
||||||
|
BASE_REWARDS_PER_EPOCH: 5
|
||||||
# [customized] Faster, but unsecure.
|
# [customized] Faster, but unsecure.
|
||||||
SHUFFLE_ROUND_COUNT: 10
|
SHUFFLE_ROUND_COUNT: 10
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ MAX_EFFECTIVE_BALANCE: 32000000000
|
||||||
# 2**4 * 10**9 (= 16,000,000,000) Gwei
|
# 2**4 * 10**9 (= 16,000,000,000) Gwei
|
||||||
EJECTION_BALANCE: 16000000000
|
EJECTION_BALANCE: 16000000000
|
||||||
# 2**0 * 10**9 (= 1,000,000,000) Gwei
|
# 2**0 * 10**9 (= 1,000,000,000) Gwei
|
||||||
HIGH_BALANCE_INCREMENT: 1000000000
|
EFFECTIVE_BALANCE_INCREMENT: 1000000000
|
||||||
|
|
||||||
|
|
||||||
# Initial values
|
# Initial values
|
||||||
|
@ -71,6 +72,8 @@ MIN_VALIDATOR_WITHDRAWABILITY_DELAY: 256
|
||||||
PERSISTENT_COMMITTEE_PERIOD: 2048
|
PERSISTENT_COMMITTEE_PERIOD: 2048
|
||||||
# 2**6 (= 64) epochs ~7 hours
|
# 2**6 (= 64) epochs ~7 hours
|
||||||
MAX_CROSSLINK_EPOCHS: 64
|
MAX_CROSSLINK_EPOCHS: 64
|
||||||
|
# 2**2 (= 4) epochs 25.6 minutes
|
||||||
|
MIN_EPOCHS_TO_INACTIVITY_PENALTY: 4
|
||||||
|
|
||||||
|
|
||||||
# State list lengths
|
# State list lengths
|
||||||
|
@ -91,14 +94,14 @@ BASE_REWARD_QUOTIENT: 32
|
||||||
WHISTLEBLOWING_REWARD_QUOTIENT: 512
|
WHISTLEBLOWING_REWARD_QUOTIENT: 512
|
||||||
# 2**3 (= 8)
|
# 2**3 (= 8)
|
||||||
PROPOSER_REWARD_QUOTIENT: 8
|
PROPOSER_REWARD_QUOTIENT: 8
|
||||||
# 2**24 (= 16,777,216)
|
# 2**25 (= 33,554,432)
|
||||||
INACTIVITY_PENALTY_QUOTIENT: 16777216
|
INACTIVITY_PENALTY_QUOTIENT: 33554432
|
||||||
|
# 2**5 (= 32)
|
||||||
|
MIN_SLASHING_PENALTY_QUOTIENT: 32
|
||||||
|
|
||||||
|
|
||||||
# Max operations per block
|
# Max operations per block
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# 2**5 (= 32)
|
|
||||||
MIN_PENALTY_QUOTIENT: 32
|
|
||||||
# 2**4 (= 16)
|
# 2**4 (= 16)
|
||||||
MAX_PROPOSER_SLASHINGS: 16
|
MAX_PROPOSER_SLASHINGS: 16
|
||||||
# 2**0 (= 1)
|
# 2**0 (= 1)
|
||||||
|
|
|
@ -5,10 +5,8 @@ import function_puller
|
||||||
def build_phase0_spec(sourcefile, outfile):
|
def build_phase0_spec(sourcefile, outfile):
|
||||||
code_lines = []
|
code_lines = []
|
||||||
code_lines.append("""
|
code_lines.append("""
|
||||||
|
|
||||||
from typing import (
|
from typing import (
|
||||||
Any,
|
Any,
|
||||||
Callable,
|
|
||||||
Dict,
|
Dict,
|
||||||
List,
|
List,
|
||||||
NewType,
|
NewType,
|
||||||
|
@ -17,19 +15,16 @@ from typing import (
|
||||||
from eth2spec.utils.minimal_ssz import *
|
from eth2spec.utils.minimal_ssz import *
|
||||||
from eth2spec.utils.bls_stub import *
|
from eth2spec.utils.bls_stub import *
|
||||||
|
|
||||||
|
""")
|
||||||
""")
|
|
||||||
for i in (1, 2, 3, 4, 8, 32, 48, 96):
|
for i in (1, 2, 3, 4, 8, 32, 48, 96):
|
||||||
code_lines.append("def int_to_bytes%d(x): return x.to_bytes(%d, 'little')" % (i, i))
|
code_lines.append("def int_to_bytes%d(x): return x.to_bytes(%d, 'little')" % (i, i))
|
||||||
|
|
||||||
code_lines.append("""
|
code_lines.append("""
|
||||||
|
|
||||||
# stub, will get overwritten by real var
|
# stub, will get overwritten by real var
|
||||||
SLOTS_PER_EPOCH = 64
|
SLOTS_PER_EPOCH = 64
|
||||||
|
|
||||||
|
|
||||||
def slot_to_epoch(x): return x // SLOTS_PER_EPOCH
|
|
||||||
|
|
||||||
|
|
||||||
Slot = NewType('Slot', int) # uint64
|
Slot = NewType('Slot', int) # uint64
|
||||||
Epoch = NewType('Epoch', int) # uint64
|
Epoch = NewType('Epoch', int) # uint64
|
||||||
Shard = NewType('Shard', int) # uint64
|
Shard = NewType('Shard', int) # uint64
|
||||||
|
@ -38,9 +33,8 @@ Gwei = NewType('Gwei', int) # uint64
|
||||||
Bytes32 = NewType('Bytes32', bytes) # bytes32
|
Bytes32 = NewType('Bytes32', bytes) # bytes32
|
||||||
BLSPubkey = NewType('BLSPubkey', bytes) # bytes48
|
BLSPubkey = NewType('BLSPubkey', bytes) # bytes48
|
||||||
BLSSignature = NewType('BLSSignature', bytes) # bytes96
|
BLSSignature = NewType('BLSSignature', bytes) # bytes96
|
||||||
Any = None
|
|
||||||
Store = None
|
Store = None
|
||||||
""")
|
""")
|
||||||
|
|
||||||
code_lines += function_puller.get_spec(sourcefile)
|
code_lines += function_puller.get_spec(sourcefile)
|
||||||
|
|
||||||
|
@ -84,7 +78,7 @@ def apply_constants_preset(preset: Dict[str, Any]):
|
||||||
|
|
||||||
# Deal with derived constants
|
# Deal with derived constants
|
||||||
global_vars['GENESIS_EPOCH'] = slot_to_epoch(GENESIS_SLOT)
|
global_vars['GENESIS_EPOCH'] = slot_to_epoch(GENESIS_SLOT)
|
||||||
|
|
||||||
# Initialize SSZ types again, to account for changed lengths
|
# Initialize SSZ types again, to account for changed lengths
|
||||||
init_SSZ_types()
|
init_SSZ_types()
|
||||||
""")
|
""")
|
||||||
|
|
|
@ -62,9 +62,10 @@ def get_spec(file_name: str) -> List[str]:
|
||||||
code_lines.append('')
|
code_lines.append('')
|
||||||
for type_line in ssz_type:
|
for type_line in ssz_type:
|
||||||
code_lines.append(' ' + type_line)
|
code_lines.append(' ' + type_line)
|
||||||
code_lines.append('')
|
code_lines.append('\n')
|
||||||
code_lines.append('ssz_types = [' + ', '.join([f'\'{ssz_type_name}\'' for (ssz_type_name, _) in type_defs]) + ']')
|
code_lines.append('ssz_types = [' + ', '.join([f'\'{ssz_type_name}\'' for (ssz_type_name, _) in type_defs]) + ']')
|
||||||
code_lines.append('')
|
code_lines.append('\n')
|
||||||
code_lines.append('def get_ssz_type_by_name(name: str) -> SSZType: return globals()[name]')
|
code_lines.append('def get_ssz_type_by_name(name: str) -> SSZType:')
|
||||||
|
code_lines.append(' return globals()[name]')
|
||||||
code_lines.append('')
|
code_lines.append('')
|
||||||
return code_lines
|
return code_lines
|
||||||
|
|
|
@ -687,7 +687,6 @@ def is_slashable_validator(validator: Validator, epoch: Epoch) -> bool:
|
||||||
Check if ``validator`` is slashable.
|
Check if ``validator`` is slashable.
|
||||||
"""
|
"""
|
||||||
return validator.slashed is False and (validator.activation_epoch <= epoch < validator.withdrawable_epoch)
|
return validator.slashed is False and (validator.activation_epoch <= epoch < validator.withdrawable_epoch)
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### `get_active_validator_indices`
|
### `get_active_validator_indices`
|
||||||
|
@ -857,10 +856,11 @@ def get_beacon_proposer_index(state: BeaconState) -> ValidatorIndex:
|
||||||
shard = (get_epoch_start_shard(state, epoch) + offset) % SHARD_COUNT
|
shard = (get_epoch_start_shard(state, epoch) + offset) % SHARD_COUNT
|
||||||
first_committee = get_crosslink_committee(state, epoch, shard)
|
first_committee = get_crosslink_committee(state, epoch, shard)
|
||||||
MAX_RANDOM_BYTE = 2**8 - 1
|
MAX_RANDOM_BYTE = 2**8 - 1
|
||||||
|
seed = generate_seed(state, epoch)
|
||||||
i = 0
|
i = 0
|
||||||
while True:
|
while True:
|
||||||
candidate_index = first_committee[(epoch + i) % len(first_committee)]
|
candidate_index = first_committee[(epoch + i) % len(first_committee)]
|
||||||
random_byte = hash(generate_seed(state, epoch) + int_to_bytes8(i // 32))[i % 32]
|
random_byte = hash(seed + int_to_bytes8(i // 32))[i % 32]
|
||||||
effective_balance = state.validator_registry[candidate_index].effective_balance
|
effective_balance = state.validator_registry[candidate_index].effective_balance
|
||||||
if effective_balance * MAX_RANDOM_BYTE >= MAX_EFFECTIVE_BALANCE * random_byte:
|
if effective_balance * MAX_RANDOM_BYTE >= MAX_EFFECTIVE_BALANCE * random_byte:
|
||||||
return candidate_index
|
return candidate_index
|
||||||
|
@ -1206,7 +1206,7 @@ def get_genesis_beacon_state(genesis_validator_deposits: List[Deposit],
|
||||||
process_deposit(state, deposit)
|
process_deposit(state, deposit)
|
||||||
|
|
||||||
# Process genesis activations
|
# Process genesis activations
|
||||||
for index, validator in enumerate(state.validator_registry):
|
for validator in state.validator_registry:
|
||||||
if validator.effective_balance >= MAX_EFFECTIVE_BALANCE:
|
if validator.effective_balance >= MAX_EFFECTIVE_BALANCE:
|
||||||
validator.activation_eligibility_epoch = GENESIS_EPOCH
|
validator.activation_eligibility_epoch = GENESIS_EPOCH
|
||||||
validator.activation_epoch = GENESIS_EPOCH
|
validator.activation_epoch = GENESIS_EPOCH
|
||||||
|
@ -1409,15 +1409,14 @@ def get_base_reward(state: BeaconState, index: ValidatorIndex) -> Gwei:
|
||||||
if adjusted_quotient == 0:
|
if adjusted_quotient == 0:
|
||||||
return 0
|
return 0
|
||||||
return state.validator_registry[index].effective_balance // adjusted_quotient // BASE_REWARDS_PER_EPOCH
|
return state.validator_registry[index].effective_balance // adjusted_quotient // BASE_REWARDS_PER_EPOCH
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def get_attestation_deltas(state: BeaconState) -> Tuple[List[Gwei], List[Gwei]]:
|
def get_attestation_deltas(state: BeaconState) -> Tuple[List[Gwei], List[Gwei]]:
|
||||||
previous_epoch = get_previous_epoch(state)
|
previous_epoch = get_previous_epoch(state)
|
||||||
total_balance = get_total_active_balance(state)
|
total_balance = get_total_active_balance(state)
|
||||||
rewards = [0 for index in range(len(state.validator_registry))]
|
rewards = [0 for _ in range(len(state.validator_registry))]
|
||||||
penalties = [0 for index in range(len(state.validator_registry))]
|
penalties = [0 for _ in range(len(state.validator_registry))]
|
||||||
eligible_validator_indices = [
|
eligible_validator_indices = [
|
||||||
index for index, v in enumerate(state.validator_registry)
|
index for index, v in enumerate(state.validator_registry)
|
||||||
if is_active_validator(v, previous_epoch) or (v.slashed and previous_epoch + 1 < v.withdrawable_epoch)
|
if is_active_validator(v, previous_epoch) or (v.slashed and previous_epoch + 1 < v.withdrawable_epoch)
|
||||||
|
@ -1453,7 +1452,7 @@ def get_attestation_deltas(state: BeaconState) -> Tuple[List[Gwei], List[Gwei]]:
|
||||||
if index not in matching_target_attesting_indices:
|
if index not in matching_target_attesting_indices:
|
||||||
penalties[index] += state.validator_registry[index].effective_balance * finality_delay // INACTIVITY_PENALTY_QUOTIENT
|
penalties[index] += state.validator_registry[index].effective_balance * finality_delay // INACTIVITY_PENALTY_QUOTIENT
|
||||||
|
|
||||||
return [rewards, penalties]
|
return rewards, penalties
|
||||||
```
|
```
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
@ -1473,7 +1472,7 @@ def get_crosslink_deltas(state: BeaconState) -> Tuple[List[Gwei], List[Gwei]]:
|
||||||
rewards[index] += base_reward * attesting_balance // committee_balance
|
rewards[index] += base_reward * attesting_balance // committee_balance
|
||||||
else:
|
else:
|
||||||
penalties[index] += base_reward
|
penalties[index] += base_reward
|
||||||
return [rewards, penalties]
|
return rewards, penalties
|
||||||
```
|
```
|
||||||
|
|
||||||
Run the following function:
|
Run the following function:
|
||||||
|
@ -1512,6 +1511,7 @@ def process_registry_updates(state: BeaconState) -> None:
|
||||||
], key=lambda index: state.validator_registry[index].activation_eligibility_epoch)
|
], key=lambda index: state.validator_registry[index].activation_eligibility_epoch)
|
||||||
# Dequeued validators for activation up to churn limit (without resetting activation epoch)
|
# Dequeued validators for activation up to churn limit (without resetting activation epoch)
|
||||||
for index in activation_queue[:get_churn_limit(state)]:
|
for index in activation_queue[:get_churn_limit(state)]:
|
||||||
|
validator = state.validator_registry[index]
|
||||||
if validator.activation_epoch == FAR_FUTURE_EPOCH:
|
if validator.activation_epoch == FAR_FUTURE_EPOCH:
|
||||||
validator.activation_epoch = get_delayed_activation_exit_epoch(get_current_epoch(state))
|
validator.activation_epoch = get_delayed_activation_exit_epoch(get_current_epoch(state))
|
||||||
```
|
```
|
||||||
|
@ -1553,10 +1553,10 @@ def process_final_updates(state: BeaconState) -> None:
|
||||||
state.eth1_data_votes = []
|
state.eth1_data_votes = []
|
||||||
# Update effective balances with hysteresis
|
# Update effective balances with hysteresis
|
||||||
for index, validator in enumerate(state.validator_registry):
|
for index, validator in enumerate(state.validator_registry):
|
||||||
balance = min(state.balances[index], MAX_EFFECTIVE_BALANCE)
|
balance = state.balances[index]
|
||||||
HALF_INCREMENT = EFFECTIVE_BALANCE_INCREMENT // 2
|
HALF_INCREMENT = EFFECTIVE_BALANCE_INCREMENT // 2
|
||||||
if balance < validator.effective_balance or validator.effective_balance + 3 * HALF_INCREMENT < balance:
|
if balance < validator.effective_balance or validator.effective_balance + 3 * HALF_INCREMENT < balance:
|
||||||
validator.effective_balance = balance - balance % EFFECTIVE_BALANCE_INCREMENT
|
validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE)
|
||||||
# Update start shard
|
# Update start shard
|
||||||
state.latest_start_shard = (state.latest_start_shard + get_shard_delta(state, current_epoch)) % SHARD_COUNT
|
state.latest_start_shard = (state.latest_start_shard + get_shard_delta(state, current_epoch)) % SHARD_COUNT
|
||||||
# Set active index root
|
# Set active index root
|
||||||
|
@ -1778,7 +1778,7 @@ def process_deposit(state: BeaconState, deposit: Deposit) -> None:
|
||||||
activation_epoch=FAR_FUTURE_EPOCH,
|
activation_epoch=FAR_FUTURE_EPOCH,
|
||||||
exit_epoch=FAR_FUTURE_EPOCH,
|
exit_epoch=FAR_FUTURE_EPOCH,
|
||||||
withdrawable_epoch=FAR_FUTURE_EPOCH,
|
withdrawable_epoch=FAR_FUTURE_EPOCH,
|
||||||
effective_balance=amount - amount % EFFECTIVE_BALANCE_INCREMENT
|
effective_balance=min(amount - amount % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE)
|
||||||
))
|
))
|
||||||
state.balances.append(amount)
|
state.balances.append(amount)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -9,13 +9,16 @@
|
||||||
- [Table of contents](#table-of-contents)
|
- [Table of contents](#table-of-contents)
|
||||||
- [Introduction](#introduction)
|
- [Introduction](#introduction)
|
||||||
- [Constants](#constants)
|
- [Constants](#constants)
|
||||||
- [Deposit contract](#time-parameters)
|
- [Gwei values](#gwei-values)
|
||||||
|
- [Contract](#contract)
|
||||||
- [Ethereum 1.0 deposit contract](#ethereum-10-deposit-contract)
|
- [Ethereum 1.0 deposit contract](#ethereum-10-deposit-contract)
|
||||||
- [Deposit arguments](#deposit-arguments)
|
- [Arguments](#arguments)
|
||||||
- [Withdrawal credentials](#withdrawal-credentials)
|
- [Withdrawal credentials](#withdrawal-credentials)
|
||||||
|
- [Amount](#amount)
|
||||||
|
- [Event logs](#event-logs)
|
||||||
- [`Deposit` logs](#deposit-logs)
|
- [`Deposit` logs](#deposit-logs)
|
||||||
- [`Eth2Genesis` log](#eth2genesis-log)
|
- [`Eth2Genesis` log](#eth2genesis-log)
|
||||||
- [Vyper code](#vyper-code)
|
- [Vyper code](#vyper-code)
|
||||||
|
|
||||||
<!-- /TOC -->
|
<!-- /TOC -->
|
||||||
|
|
||||||
|
@ -25,22 +28,29 @@ This document represents is the specification for the beacon chain deposit contr
|
||||||
|
|
||||||
## Constants
|
## Constants
|
||||||
|
|
||||||
### Deposit contract
|
### Gwei values
|
||||||
|
|
||||||
|
| Name | Value | Unit |
|
||||||
|
| - | - | - |
|
||||||
|
| `FULL_DEPOSIT_AMOUNT` | `32 * 10**9` | Gwei |
|
||||||
|
|
||||||
|
### Contract
|
||||||
|
|
||||||
| Name | Value |
|
| Name | Value |
|
||||||
| - | - |
|
| - | - |
|
||||||
| `DEPOSIT_CONTRACT_ADDRESS` | **TBD** |
|
| `DEPOSIT_CONTRACT_ADDRESS` | **TBD** |
|
||||||
| `DEPOSIT_CONTRACT_TREE_DEPTH` | `2**5` (= 32) |
|
| `DEPOSIT_CONTRACT_TREE_DEPTH` | `2**5` (= 32) |
|
||||||
|
| `CHAIN_START_FULL_DEPOSIT_THRESHOLD` | `2**16` (=65,536) |
|
||||||
|
|
||||||
## Ethereum 1.0 deposit contract
|
## Ethereum 1.0 deposit contract
|
||||||
|
|
||||||
The initial deployment phases of Ethereum 2.0 are implemented without consensus changes to Ethereum 1.0. A deposit contract at address `DEPOSIT_CONTRACT_ADDRESS` is added to Ethereum 1.0 for deposits of ETH to the beacon chain. Validator balances will be withdrawable to the shards in phase 2, i.e. when the EVM2.0 is deployed and the shards have state.
|
The initial deployment phases of Ethereum 2.0 are implemented without consensus changes to Ethereum 1.0. A deposit contract at address `DEPOSIT_CONTRACT_ADDRESS` is added to Ethereum 1.0 for deposits of ETH to the beacon chain. Validator balances will be withdrawable to the shards in phase 2, i.e. when the EVM2.0 is deployed and the shards have state.
|
||||||
|
|
||||||
### Deposit arguments
|
### Arguments
|
||||||
|
|
||||||
The deposit contract has a single `deposit` function which takes as argument a SimpleSerialize'd `DepositData`.
|
The deposit contract has a `deposit` function which takes the amount in Ethereum 1.0 transaction, and arguments `pubkey: bytes[48], withdrawal_credentials: bytes[32], signature: bytes[96]` corresponding to `DepositData`.
|
||||||
|
|
||||||
### Withdrawal credentials
|
#### Withdrawal credentials
|
||||||
|
|
||||||
One of the `DepositData` fields is `withdrawal_credentials`. It is a commitment to credentials for withdrawals to shards. The first byte of `withdrawal_credentials` is a version number. As of now the only expected format is as follows:
|
One of the `DepositData` fields is `withdrawal_credentials`. It is a commitment to credentials for withdrawals to shards. The first byte of `withdrawal_credentials` is a version number. As of now the only expected format is as follows:
|
||||||
|
|
||||||
|
@ -49,13 +59,20 @@ One of the `DepositData` fields is `withdrawal_credentials`. It is a commitment
|
||||||
|
|
||||||
The private key corresponding to `withdrawal_pubkey` will be required to initiate a withdrawal. It can be stored separately until a withdrawal is required, e.g. in cold storage.
|
The private key corresponding to `withdrawal_pubkey` will be required to initiate a withdrawal. It can be stored separately until a withdrawal is required, e.g. in cold storage.
|
||||||
|
|
||||||
|
#### Amount
|
||||||
|
|
||||||
|
* A valid deposit amount should be at least `MIN_DEPOSIT_AMOUNT` in Gwei.
|
||||||
|
* A deposit with an amount greater than or equal to `FULL_DEPOSIT_AMOUNT` in Gwei is considered as a full deposit.
|
||||||
|
|
||||||
|
## Event logs
|
||||||
|
|
||||||
### `Deposit` logs
|
### `Deposit` logs
|
||||||
|
|
||||||
Every Ethereum 1.0 deposit, of size between `MIN_DEPOSIT_AMOUNT` and `MAX_DEPOSIT_AMOUNT`, emits a `Deposit` log for consumption by the beacon chain. The deposit contract does little validation, pushing most of the validator onboarding logic to the beacon chain. In particular, the proof of possession (a BLS12 signature) is not verified by the deposit contract.
|
Every Ethereum 1.0 deposit, of size at least `MIN_DEPOSIT_AMOUNT`, emits a `Deposit` log for consumption by the beacon chain. The deposit contract does little validation, pushing most of the validator onboarding logic to the beacon chain. In particular, the proof of possession (a BLS12-381 signature) is not verified by the deposit contract.
|
||||||
|
|
||||||
### `Eth2Genesis` log
|
### `Eth2Genesis` log
|
||||||
|
|
||||||
When a sufficient amount of full deposits have been made, the deposit contract emits the `Eth2Genesis` log. The beacon chain state may then be initialized by calling the `get_genesis_beacon_state` function (defined below) where:
|
When `CHAIN_START_FULL_DEPOSIT_THRESHOLD` of full deposits have been made, the deposit contract emits the `Eth2Genesis` log. The beacon chain state may then be initialized by calling the `get_genesis_beacon_state` function (defined below) where:
|
||||||
|
|
||||||
* `genesis_time` equals `time` in the `Eth2Genesis` log
|
* `genesis_time` equals `time` in the `Eth2Genesis` log
|
||||||
* `latest_eth1_data.deposit_root` equals `deposit_root` in the `Eth2Genesis` log
|
* `latest_eth1_data.deposit_root` equals `deposit_root` in the `Eth2Genesis` log
|
||||||
|
@ -63,7 +80,7 @@ When a sufficient amount of full deposits have been made, the deposit contract e
|
||||||
* `latest_eth1_data.block_hash` equals the hash of the block that included the log
|
* `latest_eth1_data.block_hash` equals the hash of the block that included the log
|
||||||
* `genesis_validator_deposits` is a list of `Deposit` objects built according to the `Deposit` logs up to the deposit that triggered the `Eth2Genesis` log, processed in the order in which they were emitted (oldest to newest)
|
* `genesis_validator_deposits` is a list of `Deposit` objects built according to the `Deposit` logs up to the deposit that triggered the `Eth2Genesis` log, processed in the order in which they were emitted (oldest to newest)
|
||||||
|
|
||||||
### Vyper code
|
## Vyper code
|
||||||
|
|
||||||
The source for the Vyper contract lives in a [separate repository](https://github.com/ethereum/deposit_contract) at [https://github.com/ethereum/deposit_contract/blob/master/deposit_contract/contracts/validator_registration.v.py](https://github.com/ethereum/deposit_contract/blob/master/deposit_contract/contracts/validator_registration.v.py).
|
The source for the Vyper contract lives in a [separate repository](https://github.com/ethereum/deposit_contract) at [https://github.com/ethereum/deposit_contract/blob/master/deposit_contract/contracts/validator_registration.v.py](https://github.com/ethereum/deposit_contract/blob/master/deposit_contract/contracts/validator_registration.v.py).
|
||||||
|
|
||||||
|
@ -73,4 +90,4 @@ For convenience, we provide the interface to the contract here:
|
||||||
|
|
||||||
* `__init__()`: initializes the contract
|
* `__init__()`: initializes the contract
|
||||||
* `get_deposit_root() -> bytes32`: returns the current root of the deposit tree
|
* `get_deposit_root() -> bytes32`: returns the current root of the deposit tree
|
||||||
* `deposit(bytes[512])`: adds a deposit instance to the deposit tree, incorporating the input argument and the value transferred in the given call. Note: the amount of value transferred *must* be within `MIN_DEPOSIT_AMOUNT` and `MAX_DEPOSIT_AMOUNT`, inclusive. Each of these constants are specified in units of Gwei.
|
* `deposit(pubkey: bytes[48], withdrawal_credentials: bytes[32], signature: bytes[96])`: adds a deposit instance to the deposit tree, incorporating the input arguments and the value transferred in the given call. Note: the amount of value transferred *must* be at least `MIN_DEPOSIT_AMOUNT`. Each of these constants are specified in units of Gwei.
|
||||||
|
|
|
@ -46,9 +46,9 @@ Note: Nodes needs to have a clock that is roughly (i.e. within `SECONDS_PER_SLOT
|
||||||
|
|
||||||
### Beacon chain fork choice rule
|
### Beacon chain fork choice rule
|
||||||
|
|
||||||
The beacon chain fork choice rule is a hybrid that combines justification and finality with Latest Message Driven (LMD) Greediest Heaviest Observed SubTree (GHOST). At any point in time a [validator](#dfn-validator) `v` subjectively calculates the beacon chain head as follows.
|
The beacon chain fork choice rule is a hybrid that combines justification and finality with Latest Message Driven (LMD) Greediest Heaviest Observed SubTree (GHOST). At any point in time a validator `v` subjectively calculates the beacon chain head as follows.
|
||||||
|
|
||||||
* Abstractly define `Store` as the type of storage object for the chain data and `store` be the set of attestations and blocks that the [validator](#dfn-validator) `v` has observed and verified (in particular, block ancestors must be recursively verified). Attestations not yet included in any chain are still included in `store`.
|
* Abstractly define `Store` as the type of storage object for the chain data and `store` be the set of attestations and blocks that the validator `v` has observed and verified (in particular, block ancestors must be recursively verified). Attestations not yet included in any chain are still included in `store`.
|
||||||
* Let `finalized_head` be the finalized block with the highest epoch. (A block `B` is finalized if there is a descendant of `B` in `store` the processing of which sets `B` as finalized.)
|
* Let `finalized_head` be the finalized block with the highest epoch. (A block `B` is finalized if there is a descendant of `B` in `store` the processing of which sets `B` as finalized.)
|
||||||
* Let `justified_head` be the descendant of `finalized_head` with the highest epoch that has been justified for at least 1 epoch. (A block `B` is justified if there is a descendant of `B` in `store` the processing of which sets `B` as justified.) If no such descendant exists set `justified_head` to `finalized_head`.
|
* Let `justified_head` be the descendant of `finalized_head` with the highest epoch that has been justified for at least 1 epoch. (A block `B` is justified if there is a descendant of `B` in `store` the processing of which sets `B` as justified.) If no such descendant exists set `justified_head` to `finalized_head`.
|
||||||
* Let `get_ancestor(store: Store, block: BeaconBlock, slot: Slot) -> BeaconBlock` be the ancestor of `block` with slot number `slot`. The `get_ancestor` function can be defined recursively as:
|
* Let `get_ancestor(store: Store, block: BeaconBlock, slot: Slot) -> BeaconBlock` be the ancestor of `block` with slot number `slot`. The `get_ancestor` function can be defined recursively as:
|
||||||
|
@ -66,7 +66,7 @@ def get_ancestor(store: Store, block: BeaconBlock, slot: Slot) -> BeaconBlock:
|
||||||
return get_ancestor(store, store.get_parent(block), slot)
|
return get_ancestor(store, store.get_parent(block), slot)
|
||||||
```
|
```
|
||||||
|
|
||||||
* Let `get_latest_attestation(store: Store, index: ValidatorIndex) -> Attestation` be the attestation with the highest slot number in `store` from the validator with the given `index`. If several such attestations exist, use the one the [validator](#dfn-validator) `v` observed first.
|
* Let `get_latest_attestation(store: Store, index: ValidatorIndex) -> Attestation` be the attestation with the highest slot number in `store` from the validator with the given `index`. If several such attestations exist, use the one the validator `v` observed first.
|
||||||
* Let `get_latest_attestation_target(store: Store, index: ValidatorIndex) -> BeaconBlock` be the target block in the attestation `get_latest_attestation(store, index)`.
|
* Let `get_latest_attestation_target(store: Store, index: ValidatorIndex) -> BeaconBlock` be the target block in the attestation `get_latest_attestation(store, index)`.
|
||||||
* Let `get_children(store: Store, block: BeaconBlock) -> List[BeaconBlock]` returns the child blocks of the given `block`.
|
* Let `get_children(store: Store, block: BeaconBlock) -> List[BeaconBlock]` returns the child blocks of the given `block`.
|
||||||
* Let `justified_head_state` be the resulting `BeaconState` object from processing the chain up to the `justified_head`.
|
* Let `justified_head_state` be the resulting `BeaconState` object from processing the chain up to the `justified_head`.
|
||||||
|
|
|
@ -224,7 +224,7 @@ Up to `MAX_ATTESTATIONS` aggregate attestations can be included in the `block`.
|
||||||
|
|
||||||
##### Deposits
|
##### Deposits
|
||||||
|
|
||||||
If there are any unprocessed deposits for the existing `state.latest_eth1_data` (i.e. `state.latest_eth1_data.deposit_count > state.deposit_index`), then pending deposits _must_ be added to the block. The expected number of deposits is exactly `min(MAX_DEPOSITS, latest_eth1_data.deposit_count - state.deposit_index)`. These [`deposits`](../core/0_beacon-chain.md#deposit) are constructed from the `Deposit` logs from the [Eth1.0 deposit contract](../core/0_deposit-contract.md) and must be processed in sequential order. The deposits included in the `block` must satisfy the verification conditions found in [deposits processing](../core/0_beacon-chain.md#deposits).
|
If there are any unprocessed deposits for the existing `state.latest_eth1_data` (i.e. `state.latest_eth1_data.deposit_count > state.deposit_index`), then pending deposits _must_ be added to the block. The expected number of deposits is exactly `min(MAX_DEPOSITS, latest_eth1_data.deposit_count - state.deposit_index)`. These [`deposits`](../core/0_beacon-chain.md#deposit) are constructed from the `Deposit` logs from the [Eth1.0 deposit contract](../core/0_deposit-contract) and must be processed in sequential order. The deposits included in the `block` must satisfy the verification conditions found in [deposits processing](../core/0_beacon-chain.md#deposits).
|
||||||
|
|
||||||
The `proof` for each deposit must be constructed against the deposit root contained in `state.latest_eth1_data` rather than the deposit root at the time the deposit was initially logged from the 1.0 chain. This entails storing a full deposit merkle tree locally and computing updated proofs against the `latest_eth1_data.deposit_root` as needed. See [`minimal_merkle.py`](https://github.com/ethereum/research/blob/master/spec_pythonizer/utils/merkle_minimal.py) for a sample implementation.
|
The `proof` for each deposit must be constructed against the deposit root contained in `state.latest_eth1_data` rather than the deposit root at the time the deposit was initially logged from the 1.0 chain. This entails storing a full deposit merkle tree locally and computing updated proofs against the `latest_eth1_data.deposit_root` as needed. See [`minimal_merkle.py`](https://github.com/ethereum/research/blob/master/spec_pythonizer/utils/merkle_minimal.py) for a sample implementation.
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,22 @@
|
||||||
# Eth2.0 Test Generators
|
# Eth 2.0 Test Generators
|
||||||
|
|
||||||
This directory contains all the generators for YAML tests, consumed by Eth 2.0 client implementations.
|
This directory contains all the generators for YAML tests, consumed by Eth 2.0 client implementations.
|
||||||
|
|
||||||
Any issues with the generators and/or generated tests should be filed
|
Any issues with the generators and/or generated tests should be filed in the repository that hosts the generator outputs, here: [ethereum/eth2.0-tests](https://github.com/ethereum/eth2.0-tests).
|
||||||
in the repository that hosts the generator outputs, here: [ethereum/eth2.0-tests](https://github.com/ethereum/eth2.0-tests/).
|
|
||||||
|
|
||||||
Whenever a release is made, the new tests are automatically built and
|
Whenever a release is made, the new tests are automatically built, and
|
||||||
[eth2TestGenBot](https://github.com/eth2TestGenBot) commits the changes to the test repository.
|
[eth2TestGenBot](https://github.com/eth2TestGenBot) commits the changes to the test repository.
|
||||||
|
|
||||||
## How to run generators
|
## How to run generators
|
||||||
|
|
||||||
pre-requisites:
|
Prerequisites:
|
||||||
- Python 3 installed
|
- Python 3 installed
|
||||||
- PIP 3
|
- PIP 3
|
||||||
- GNU make
|
- GNU make
|
||||||
|
|
||||||
### Cleaning
|
### Cleaning
|
||||||
|
|
||||||
This removes the existing virtual environments (`/test_generators/<generator>/venv`), and generated tests (`/yaml_tests/`).
|
This removes the existing virtual environments (`/test_generators/<generator>/venv`) and generated tests (`/yaml_tests/`).
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
make clean
|
make clean
|
||||||
|
@ -25,7 +24,7 @@ make clean
|
||||||
|
|
||||||
### Running all test generators
|
### Running all test generators
|
||||||
|
|
||||||
This runs all the generators.
|
This runs all of the generators.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
make -j 4 gen_yaml_tests
|
make -j 4 gen_yaml_tests
|
||||||
|
@ -36,8 +35,7 @@ The `-j N` flag makes the generators run in parallel, with `N` being the amount
|
||||||
|
|
||||||
### Running a single generator
|
### Running a single generator
|
||||||
|
|
||||||
The make file auto-detects generators in the `test_generators/` directory,
|
The makefile auto-detects generators in the `test_generators` directory and provides a tests-gen target for each generator. See example:
|
||||||
and provides a tests-gen target for each generator, see example.
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
make ./yaml_tests/shuffling/
|
make ./yaml_tests/shuffling/
|
||||||
|
@ -45,7 +43,7 @@ make ./yaml_tests/shuffling/
|
||||||
|
|
||||||
## Developing a generator
|
## Developing a generator
|
||||||
|
|
||||||
Simply open up the generator (not all at once) of choice in your favorite IDE/editor, and run:
|
Simply open up the generator (not all at once) of choice in your favorite IDE/editor and run:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# From the root of the generator directory:
|
# From the root of the generator directory:
|
||||||
|
@ -65,19 +63,19 @@ eth-utils==1.4.1
|
||||||
../../test_libs/config_helpers
|
../../test_libs/config_helpers
|
||||||
../../test_libs/pyspec
|
../../test_libs/pyspec
|
||||||
```
|
```
|
||||||
The config helper and pyspec is optional, but preferred. We encourage generators to derive tests from the spec itself, to prevent code duplication and outdated tests.
|
The config helper and pyspec is optional, but preferred. We encourage generators to derive tests from the spec itself in order to prevent code duplication and outdated tests.
|
||||||
Applying configurations to the spec is simple, and enables you to create test suites with different contexts.
|
Applying configurations to the spec is simple and enables you to create test suites with different contexts.
|
||||||
|
|
||||||
Note: make sure to run `make pyspec` from the root of the specs repository, to build the pyspec requirement.
|
Note: make sure to run `make pyspec` from the root of the specs repository in order to build the pyspec requirement.
|
||||||
|
|
||||||
Install all the necessary requirements (re-run when you add more):
|
Install all the necessary requirements (re-run when you add more):
|
||||||
```bash
|
```bash
|
||||||
pip3 install -e .[pyspec]
|
pip3 install -r requirements.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
And write your initial test generator, extending the base generator:
|
And write your initial test generator, extending the base generator:
|
||||||
|
|
||||||
Write a `main.py` file, here's an example:
|
Write a `main.py` file. See example:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from gen_base import gen_runner, gen_suite, gen_typing
|
from gen_base import gen_runner, gen_suite, gen_typing
|
||||||
|
@ -134,26 +132,26 @@ if __name__ == "__main__":
|
||||||
```
|
```
|
||||||
|
|
||||||
Recommendations:
|
Recommendations:
|
||||||
- you can have more than just 1 suite creator, e.g. ` gen_runner.run_generator("foo", [bar_test_suite, abc_test_suite, example_test_suite])`
|
- You can have more than just one suite creator, e.g. ` gen_runner.run_generator("foo", [bar_test_suite, abc_test_suite, example_test_suite])`.
|
||||||
- you can concatenate lists of test cases, if you don't want to split it up in suites, however make sure they could be run with one handler.
|
- You can concatenate lists of test cases if you don't want to split it up in suites, however, make sure they can be run with one handler.
|
||||||
- you can split your suite creators into different python files/packages, good for code organization.
|
- You can split your suite creators into different python files/packages; this is good for code organization.
|
||||||
- use config "minimal" for performance. But also implement a suite with the default config where necessary.
|
- Use config "minimal" for performance, but also implement a suite with the default config where necessary.
|
||||||
- you may be able to write your test suite creator in a way where it does not make assumptions on constants.
|
- You may be able to write your test suite creator in a way where it does not make assumptions on constants.
|
||||||
If so, you can generate test suites with different configurations for the same scenario (see example).
|
If so, you can generate test suites with different configurations for the same scenario (see example).
|
||||||
- the test-generator accepts `--output` and `--force` (overwrite output)
|
- The test-generator accepts `--output` and `--force` (overwrite output).
|
||||||
|
|
||||||
## How to add a new test generator
|
## How to add a new test generator
|
||||||
|
|
||||||
In order to add a new test generator that builds `New Tests`:
|
To add a new test generator that builds `New Tests`:
|
||||||
|
|
||||||
1. Create a new directory `new_tests`, within the `test_generators` directory.
|
1. Create a new directory `new_tests` within the `test_generators` directory.
|
||||||
Note that `new_tests` is also the name of the directory in which the tests will appear in the tests repository later.
|
Note that `new_tests` is also the name of the directory in which the tests will appear in the tests repository later.
|
||||||
2. Your generator is assumed to have a `requirements.txt` file,
|
2. Your generator is assumed to have a `requirements.txt` file,
|
||||||
with any dependencies it may need. Leave it empty if your generator has none.
|
with any dependencies it may need. Leave it empty if your generator has none.
|
||||||
3. Your generator is assumed to have a `main.py` file in its root.
|
3. Your generator is assumed to have a `main.py` file in its root.
|
||||||
By adding the base generator to your requirements, you can make a generator really easily. See docs below.
|
By adding the base generator to your requirements, you can make a generator really easily. See docs below.
|
||||||
4. Your generator is called with `-o some/file/path/for_testing/can/be_anything -c some/other/path/to_configs/`.
|
4. Your generator is called with `-o some/file/path/for_testing/can/be_anything -c some/other/path/to_configs/`.
|
||||||
The base generator helps you handle this; you only have to define suite headers,
|
The base generator helps you handle this; you only have to define suite headers
|
||||||
and a list of tests for each suite you generate.
|
and a list of tests for each suite you generate.
|
||||||
5. Finally, add any linting or testing commands to the
|
5. Finally, add any linting or testing commands to the
|
||||||
[circleci config file](https://github.com/ethereum/eth2.0-test-generators/blob/master/.circleci/config.yml)
|
[circleci config file](https://github.com/ethereum/eth2.0-test-generators/blob/master/.circleci/config.yml)
|
||||||
|
@ -168,6 +166,6 @@ Do note that generators should be easy to maintain, lean, and based on the spec.
|
||||||
|
|
||||||
If a test generator is not needed anymore, undo the steps described above and make a new release:
|
If a test generator is not needed anymore, undo the steps described above and make a new release:
|
||||||
|
|
||||||
1. remove the generator directory
|
1. Remove the generator directory.
|
||||||
2. remove the generated tests in the `eth2.0-tests` repository by opening a PR there.
|
2. Remove the generated tests in the [`eth2.0-tests`](https://github.com/ethereum/eth2.0-tests) repository by opening a PR there.
|
||||||
3. make a new release
|
3. Make a new release.
|
||||||
|
|
|
@ -77,7 +77,7 @@ def build_deposit_for_index(initial_validator_count: int, index: int) -> Tuple[s
|
||||||
keys.pubkeys[index],
|
keys.pubkeys[index],
|
||||||
keys.withdrawal_creds[index],
|
keys.withdrawal_creds[index],
|
||||||
keys.privkeys[index],
|
keys.privkeys[index],
|
||||||
spec.MAX_DEPOSIT_AMOUNT,
|
spec.MAX_EFFECTIVE_BALANCE,
|
||||||
)
|
)
|
||||||
|
|
||||||
state.latest_eth1_data.deposit_root = get_merkle_root(tuple(deposit_data_leaves))
|
state.latest_eth1_data.deposit_root = get_merkle_root(tuple(deposit_data_leaves))
|
||||||
|
|
|
@ -26,7 +26,7 @@ def create_deposits(pubkeys: List[spec.BLSPubkey], withdrawal_cred: List[spec.By
|
||||||
spec.DepositData(
|
spec.DepositData(
|
||||||
pubkey=pubkeys[i],
|
pubkey=pubkeys[i],
|
||||||
withdrawal_credentials=spec.BLS_WITHDRAWAL_PREFIX_BYTE + withdrawal_cred[i][1:],
|
withdrawal_credentials=spec.BLS_WITHDRAWAL_PREFIX_BYTE + withdrawal_cred[i][1:],
|
||||||
amount=spec.MAX_DEPOSIT_AMOUNT,
|
amount=spec.MAX_EFFECTIVE_BALANCE,
|
||||||
proof_of_possession=proof_of_possession,
|
proof_of_possession=proof_of_possession,
|
||||||
) for i in range(len(pubkeys))
|
) for i in range(len(pubkeys))
|
||||||
]
|
]
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
ruamel.yaml==0.15.87
|
|
@ -1,20 +1,9 @@
|
||||||
from setuptools import setup, find_packages
|
from distutils.core import setup
|
||||||
|
|
||||||
|
|
||||||
deps = {
|
|
||||||
'preset_loader': [
|
|
||||||
"ruamel.yaml==0.15.87",
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
deps['dev'] = (
|
|
||||||
deps['preset_loader']
|
|
||||||
)
|
|
||||||
|
|
||||||
install_requires = deps['preset_loader']
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='config_helpers',
|
name='config_helpers',
|
||||||
packages=find_packages(exclude=["tests", "tests.*"]),
|
packages=['preset_loader'],
|
||||||
install_requires=install_requires,
|
install_requires=[
|
||||||
|
"ruamel.yaml==0.15.87"
|
||||||
|
]
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
from typing import Callable, Dict, Tuple, Any
|
from typing import (
|
||||||
|
Any,
|
||||||
|
Callable,
|
||||||
|
Dict,
|
||||||
|
Tuple,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
TestCase = Dict[str, Any]
|
TestCase = Dict[str, Any]
|
||||||
TestSuite = Dict[str, Any]
|
TestSuite = Dict[str, Any]
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
ruamel.yaml==0.15.87
|
||||||
|
eth-utils==1.4.1
|
|
@ -1,21 +1,10 @@
|
||||||
from setuptools import setup, find_packages
|
from distutils.core import setup
|
||||||
|
|
||||||
|
|
||||||
deps = {
|
|
||||||
'gen_base': [
|
|
||||||
"ruamel.yaml==0.15.87",
|
|
||||||
"eth-utils==1.4.1",
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
deps['dev'] = (
|
|
||||||
deps['gen_base']
|
|
||||||
)
|
|
||||||
|
|
||||||
install_requires = deps['gen_base']
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='gen_helpers',
|
name='gen_helpers',
|
||||||
packages=find_packages(exclude=["tests", "tests.*"]),
|
packages=['gen_base'],
|
||||||
install_requires=install_requires,
|
install_requires=[
|
||||||
|
"ruamel.yaml==0.15.87",
|
||||||
|
"eth-utils==1.4.1"
|
||||||
|
]
|
||||||
)
|
)
|
||||||
|
|
|
@ -38,7 +38,7 @@ Install dependencies:
|
||||||
```bash
|
```bash
|
||||||
python3 -m venv venv
|
python3 -m venv venv
|
||||||
. venv/bin/activate
|
. venv/bin/activate
|
||||||
pip3 install -e .[dev]
|
pip3 install -r requirements-testing.txt
|
||||||
```
|
```
|
||||||
Note: make sure to run `make -B pyspec` from the root of the specs repository,
|
Note: make sure to run `make -B pyspec` from the root of the specs repository,
|
||||||
to build the parts of the pyspec module derived from the markdown specs.
|
to build the parts of the pyspec module derived from the markdown specs.
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
-r requirements.txt
|
||||||
|
pytest>=3.6,<3.7
|
||||||
|
../config_helpers
|
|
@ -0,0 +1,4 @@
|
||||||
|
eth-utils>=1.3.0,<2
|
||||||
|
eth-typing>=2.1.0,<3.0.0
|
||||||
|
pycryptodome==3.7.3
|
||||||
|
py_ecc>=1.6.0
|
|
@ -1,28 +1,13 @@
|
||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
|
setup(
|
||||||
deps = {
|
name='pyspec',
|
||||||
'pyspec': [
|
packages=find_packages(),
|
||||||
|
tests_require=["pytest"],
|
||||||
|
install_requires=[
|
||||||
"eth-utils>=1.3.0,<2",
|
"eth-utils>=1.3.0,<2",
|
||||||
"eth-typing>=2.1.0,<3.0.0",
|
"eth-typing>=2.1.0,<3.0.0",
|
||||||
"pycryptodome==3.7.3",
|
"pycryptodome==3.7.3",
|
||||||
"py_ecc>=1.6.0",
|
"py_ecc>=1.6.0",
|
||||||
],
|
]
|
||||||
'test': [
|
|
||||||
"pytest>=3.6,<3.7",
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
deps['dev'] = (
|
|
||||||
deps['pyspec'] +
|
|
||||||
deps['test']
|
|
||||||
)
|
|
||||||
|
|
||||||
install_requires = deps['pyspec']
|
|
||||||
|
|
||||||
setup(
|
|
||||||
name='pyspec',
|
|
||||||
packages=find_packages(exclude=["tests", "tests.*"]),
|
|
||||||
install_requires=install_requires,
|
|
||||||
extras_require=deps,
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
from copy import deepcopy
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
import eth2spec.phase0.spec as spec
|
||||||
|
|
||||||
|
from eth2spec.phase0.spec import (
|
||||||
|
get_current_epoch,
|
||||||
|
is_active_validator,
|
||||||
|
)
|
||||||
|
from tests.helpers import (
|
||||||
|
next_epoch,
|
||||||
|
)
|
||||||
|
|
||||||
|
# mark entire file as 'state'
|
||||||
|
pytestmark = pytest.mark.state
|
||||||
|
|
||||||
|
|
||||||
|
def test_activation(state):
|
||||||
|
index = 0
|
||||||
|
assert is_active_validator(state.validator_registry[index], get_current_epoch(state))
|
||||||
|
|
||||||
|
# Mock a new deposit
|
||||||
|
state.validator_registry[index].activation_eligibility_epoch = spec.FAR_FUTURE_EPOCH
|
||||||
|
state.validator_registry[index].activation_epoch = spec.FAR_FUTURE_EPOCH
|
||||||
|
state.validator_registry[index].effective_balance = spec.MAX_EFFECTIVE_BALANCE
|
||||||
|
assert not is_active_validator(state.validator_registry[index], get_current_epoch(state))
|
||||||
|
|
||||||
|
pre_state = deepcopy(state)
|
||||||
|
|
||||||
|
blocks = []
|
||||||
|
for _ in range(spec.ACTIVATION_EXIT_DELAY + 1):
|
||||||
|
block = next_epoch(state)
|
||||||
|
blocks.append(block)
|
||||||
|
|
||||||
|
assert state.validator_registry[index].activation_eligibility_epoch != spec.FAR_FUTURE_EPOCH
|
||||||
|
assert state.validator_registry[index].activation_epoch != spec.FAR_FUTURE_EPOCH
|
||||||
|
assert is_active_validator(
|
||||||
|
state.validator_registry[index],
|
||||||
|
get_current_epoch(state),
|
||||||
|
)
|
||||||
|
|
||||||
|
return pre_state, blocks, state
|
||||||
|
|
||||||
|
|
||||||
|
def test_ejection(state):
|
||||||
|
index = 0
|
||||||
|
assert is_active_validator(state.validator_registry[index], get_current_epoch(state))
|
||||||
|
assert state.validator_registry[index].exit_epoch == spec.FAR_FUTURE_EPOCH
|
||||||
|
|
||||||
|
# Mock an ejection
|
||||||
|
state.validator_registry[index].effective_balance = spec.EJECTION_BALANCE
|
||||||
|
|
||||||
|
pre_state = deepcopy(state)
|
||||||
|
|
||||||
|
blocks = []
|
||||||
|
for _ in range(spec.ACTIVATION_EXIT_DELAY + 1):
|
||||||
|
block = next_epoch(state)
|
||||||
|
blocks.append(block)
|
||||||
|
|
||||||
|
assert state.validator_registry[index].exit_epoch != spec.FAR_FUTURE_EPOCH
|
||||||
|
assert not is_active_validator(
|
||||||
|
state.validator_registry[index],
|
||||||
|
get_current_epoch(state),
|
||||||
|
)
|
||||||
|
|
||||||
|
return pre_state, blocks, state
|
|
@ -394,11 +394,21 @@ def add_attestation_to_state(state, attestation, slot):
|
||||||
|
|
||||||
|
|
||||||
def next_slot(state):
|
def next_slot(state):
|
||||||
|
"""
|
||||||
|
Transition to the next slot via an empty block.
|
||||||
|
Return the empty block that triggered the transition.
|
||||||
|
"""
|
||||||
block = build_empty_block_for_next_slot(state)
|
block = build_empty_block_for_next_slot(state)
|
||||||
state_transition(state, block)
|
state_transition(state, block)
|
||||||
|
return block
|
||||||
|
|
||||||
|
|
||||||
def next_epoch(state):
|
def next_epoch(state):
|
||||||
|
"""
|
||||||
|
Transition to the start slot of the next epoch via an empty block.
|
||||||
|
Return the empty block that triggered the transition.
|
||||||
|
"""
|
||||||
block = build_empty_block_for_next_slot(state)
|
block = build_empty_block_for_next_slot(state)
|
||||||
block.slot += spec.SLOTS_PER_EPOCH - (state.slot % spec.SLOTS_PER_EPOCH)
|
block.slot += spec.SLOTS_PER_EPOCH - (state.slot % spec.SLOTS_PER_EPOCH)
|
||||||
state_transition(state, block)
|
state_transition(state, block)
|
||||||
|
return block
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
from setuptools import setup, find_packages
|
|
||||||
|
|
||||||
|
|
||||||
deps = {
|
|
||||||
'pyspec': [
|
|
||||||
"eth-utils>=1.3.0,<2",
|
|
||||||
"eth-typing>=2.1.0,<3.0.0",
|
|
||||||
"pycryptodome==3.7.3",
|
|
||||||
"py_ecc>=1.6.0",
|
|
||||||
],
|
|
||||||
'test': [
|
|
||||||
"pytest>=3.6,<3.7",
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
deps['dev'] = (
|
|
||||||
deps['pyspec'] +
|
|
||||||
deps['test']
|
|
||||||
)
|
|
||||||
|
|
||||||
install_requires = deps['pyspec']
|
|
||||||
|
|
||||||
|
|
||||||
setup(
|
|
||||||
name='pyspec',
|
|
||||||
packages=find_packages(exclude=["tests", "tests.*"]),
|
|
||||||
install_requires=install_requires,
|
|
||||||
extras_require=deps,
|
|
||||||
)
|
|
Loading…
Reference in New Issue