Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport v0.8.2 to dev #1355

Merged
merged 67 commits into from
Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
1644ae6
Clarify the illegal types
hwwhww Jul 10, 2019
25ec084
To fit in `MAX_TRANSFERS=0` case
hwwhww Jul 10, 2019
01af304
Found by Cem Özer: Ignore older latest messages in attesting balance …
protolambda Jul 20, 2019
43a0ca4
check bit lengths
djrtwo Jul 22, 2019
a90d273
fix minor var typo
djrtwo Jul 22, 2019
5efdbb4
Merge pull request #1308 from ethereum/val-fix
djrtwo Jul 22, 2019
f229d21
Bump `py-ssz` to `0.1.0a11` and update the fuzzing tests
hwwhww Jul 11, 2019
b08ecb0
Apply suggestions from code review
hwwhww Jul 13, 2019
db9091f
Add `AttestationDataAndCustodyBit` back
hwwhww Jul 13, 2019
82e2c55
ssz==0.1.3
hwwhww Jul 15, 2019
f9f722c
Merge pull request #1306 from ethereum/old_latest_message
djrtwo Jul 25, 2019
c019954
Merge branch 'v08x' into n_zero
hwwhww Jul 25, 2019
62138fe
Update Illegal types
hwwhww Jul 25, 2019
f336e7f
Rename `is_empty` to `is_zero`
hwwhww Jul 25, 2019
47714cb
Add hash_tree_root tests against py-ssz
hwwhww Jul 24, 2019
62772c9
Refactor
hwwhww Jul 25, 2019
bd69dc7
add tests for bit lengths
djrtwo Jul 25, 2019
3f75f1e
Update 0_beacon-chain.md
JustinDrake Jul 25, 2019
1ec20f6
do not reset start_shard until after processing compact root
djrtwo Jul 25, 2019
e20f5eb
Merge pull request #1317 from ethereum/attestation-bit-lengths
protolambda Jul 25, 2019
f1db318
Merge pull request #1289 from ethereum/update_ssz_fuzzing
hwwhww Jul 25, 2019
d791e9f
Merge pull request #1319 from ethereum/compact_committees-shard
protolambda Jul 25, 2019
b73625f
update test generation code (work in progress), improve the simplicit…
protolambda Jul 25, 2019
69052ac
Update testgen code, and if force is not on, test generation won't ru…
protolambda Jul 26, 2019
e8b3f99
update testgen, make epoch proc work
protolambda Jul 26, 2019
8a83fce
fixes to decorator order, and make functions fully yield, with pytest…
protolambda Jul 26, 2019
d7728e6
handle meta tags passed from inner testgen decorator
protolambda Jul 26, 2019
77484c3
make sure new config loader change is working
protolambda Jul 26, 2019
62c917a
update shuffling test gen
protolambda Jul 27, 2019
badd325
update BLS suite to split test cases
protolambda Jul 27, 2019
08a52c1
update genesis test gen
protolambda Jul 27, 2019
156dcfe
update sanity test gen
protolambda Jul 27, 2019
c628c81
SSZ static format updated to per-case outputs
protolambda Jul 27, 2019
5b956b3
implement new ssz generic tests
protolambda Jul 27, 2019
aea8237
update tests, implement main call, add basic vector tests
protolambda Jul 27, 2019
88dbd18
fix imports, new container tests, update randomization logic
protolambda Jul 27, 2019
adb6bff
make random value generator respect byte list type limit
protolambda Jul 27, 2019
ab156f3
Merge pull request #1283 from ethereum/n_zero
dankrad Jul 29, 2019
eb7c3b9
make test gen output SSZ in addition to yaml files for SSZ objects
protolambda Jul 29, 2019
c329a00
improve test gen logging
protolambda Jul 29, 2019
2dcad9a
add config filtering option
protolambda Jul 30, 2019
f5e4042
update test generator documentation
protolambda Jul 30, 2019
bdebfe3
organize test-case-part explanation better
protolambda Jul 30, 2019
c91cefc
move bls tests to general config dir
protolambda Jul 30, 2019
2ba3cc9
update test format doc and SSZ-static format docs
protolambda Jul 30, 2019
eba4730
update makefile to support generators outputting to same config, or e…
protolambda Jul 30, 2019
79f6ab5
fix imports in genesis generator
protolambda Jul 30, 2019
ccf472a
remove old requirements from generators
protolambda Jul 30, 2019
7165932
output list-type parts correctly
protolambda Jul 30, 2019
ff2b533
update test format docs with new test structure
protolambda Jul 30, 2019
5ec941e
more documentation updates
protolambda Jul 30, 2019
5bdcd26
new ssz generic format + typo fix in shuffling format doc
protolambda Jul 30, 2019
0c5153d
add coment about test generation config filtering to makefile
protolambda Jul 30, 2019
5f33560
Merge branch 'v08x' into testgen-reorg
protolambda Jul 30, 2019
9f0a601
Apply suggestions from code review
protolambda Jul 31, 2019
d0985db
Apply suggestions from code review
protolambda Jul 31, 2019
18fc4ed
reword to 'also available as <name>.ssz'
protolambda Jul 31, 2019
8563dbf
make ssz_static output roots to roots.yaml instead of meta
protolambda Aug 1, 2019
12900b2
handle empty test ouputs, and split out output format functions
protolambda Aug 1, 2019
63e2915
update SSZ static doc to reflect options in test conditions
protolambda Aug 2, 2019
73a9e86
Merge pull request #1320 from ethereum/testgen-reorg
djrtwo Aug 3, 2019
32a43ac
Clarify length bit for Bitlist merklization
paulhauner Jul 25, 2019
67a6b98
Merge pull request #1334 from ethereum/dev-ports
djrtwo Aug 4, 2019
3e45bf4
Merge pull request #1333 from ethereum/v08x
djrtwo Aug 4, 2019
01d58eb
Merge branch 'dev' into v082_backport
hwwhww Aug 11, 2019
40fbcd3
Merge branch 'dev' into v082_backport
hwwhww Aug 11, 2019
d84c902
Merge branch 'dev' into v082_backport
hwwhww Aug 11, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ commands:
description: "Restore the cache with pyspec keys"
steps:
- restore_cached_venv:
venv_name: v3-pyspec-bump2
venv_name: v4-pyspec
reqs_checksum: cache-{{ checksum "test_libs/pyspec/requirements.txt" }}-{{ checksum "test_libs/pyspec/requirements-testing.txt" }}
save_pyspec_cached_venv:
description: Save a venv into a cache with pyspec keys"
steps:
- save_cached_venv:
venv_name: v3-pyspec-bump2
venv_name: v4-pyspec
reqs_checksum: cache-{{ checksum "test_libs/pyspec/requirements.txt" }}-{{ checksum "test_libs/pyspec/requirements-testing.txt" }}
venv_path: ./test_libs/pyspec/venv
restore_deposit_contract_cached_venv:
Expand Down
46 changes: 25 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ SPEC_DIR = ./specs
SCRIPT_DIR = ./scripts
TEST_LIBS_DIR = ./test_libs
PY_SPEC_DIR = $(TEST_LIBS_DIR)/pyspec
YAML_TEST_DIR = ./eth2.0-spec-tests/tests
TEST_VECTOR_DIR = ./eth2.0-spec-tests/tests
GENERATOR_DIR = ./test_generators
DEPOSIT_CONTRACT_DIR = ./deposit_contract
CONFIGS_DIR = ./configs

# Collect a list of generator names
GENERATORS = $(sort $(dir $(wildcard $(GENERATOR_DIR)/*/)))
# Map this list of generator paths to a list of test output paths
YAML_TEST_TARGETS = $(patsubst $(GENERATOR_DIR)/%, $(YAML_TEST_DIR)/%, $(GENERATORS))
GENERATORS = $(sort $(dir $(wildcard $(GENERATOR_DIR)/*/.)))
# Map this list of generator paths to "gen_{generator name}" entries
GENERATOR_TARGETS = $(patsubst $(GENERATOR_DIR)/%/, gen_%, $(GENERATORS))
GENERATOR_VENVS = $(patsubst $(GENERATOR_DIR)/%, $(GENERATOR_DIR)/%venv, $(GENERATORS))

# To check generator matching:
#$(info $$GENERATOR_TARGETS is [${GENERATOR_TARGETS}])

PY_SPEC_PHASE_0_TARGETS = $(PY_SPEC_DIR)/eth2spec/phase0/spec.py
PY_SPEC_PHASE_0_DEPS = $(SPEC_DIR)/core/0_*.md

Expand All @@ -24,14 +27,14 @@ PY_SPEC_ALL_TARGETS = $(PY_SPEC_PHASE_0_TARGETS) $(PY_SPEC_PHASE_1_TARGETS)
COV_HTML_OUT=.htmlcov
COV_INDEX_FILE=$(PY_SPEC_DIR)/$(COV_HTML_OUT)/index.html

.PHONY: clean all test citest lint gen_yaml_tests pyspec phase0 phase1 install_test open_cov \
.PHONY: clean partial_clean all test citest lint generate_tests pyspec phase0 phase1 install_test open_cov \
install_deposit_contract_test test_deposit_contract compile_deposit_contract

all: $(PY_SPEC_ALL_TARGETS) $(YAML_TEST_DIR) $(YAML_TEST_TARGETS)
all: $(PY_SPEC_ALL_TARGETS)

# deletes everything except the venvs
partial_clean:
rm -rf $(YAML_TEST_DIR)
rm -rf $(TEST_VECTOR_DIR)
rm -rf $(GENERATOR_VENVS)
rm -rf $(PY_SPEC_DIR)/.pytest_cache
rm -rf $(PY_SPEC_ALL_TARGETS)
Expand All @@ -44,8 +47,8 @@ clean: partial_clean
rm -rf $(PY_SPEC_DIR)/venv
rm -rf $(DEPOSIT_CONTRACT_DIR)/venv

# "make gen_yaml_tests" to run generators
gen_yaml_tests: $(PY_SPEC_ALL_TARGETS) $(YAML_TEST_TARGETS)
# "make generate_tests" to run all generators
generate_tests: $(PY_SPEC_ALL_TARGETS) $(GENERATOR_TARGETS)

# installs the packages to run pyspec tests
install_test:
Expand Down Expand Up @@ -90,8 +93,8 @@ $(PY_SPEC_DIR)/eth2spec/phase1/spec.py: $(PY_SPEC_PHASE_1_DEPS)

CURRENT_DIR = ${CURDIR}

# The function that builds a set of suite files, by calling a generator for the given type (param 1)
define build_yaml_tests
# Runs a generator, identified by param 1
define run_generator
# Started!
# Create output directory
# Navigate to the generator
Expand All @@ -100,24 +103,25 @@ define build_yaml_tests
# Install all the necessary requirements
# Run the generator. The generator is assumed to have an "main.py" file.
# We output to the tests dir (generator program should accept a "-o <filepath>" argument.
# `-l minimal general` can be added to the generator call to filter to smaller configs, when testing.
echo "generator $(1) started"; \
mkdir -p $(YAML_TEST_DIR)$(1); \
cd $(GENERATOR_DIR)$(1); \
mkdir -p $(TEST_VECTOR_DIR); \
cd $(GENERATOR_DIR)/$(1); \
if ! test -d venv; then python3 -m venv venv; fi; \
. venv/bin/activate; \
pip3 install -r requirements.txt; \
python3 main.py -o $(CURRENT_DIR)/$(YAML_TEST_DIR)$(1) -c $(CURRENT_DIR)/$(CONFIGS_DIR); \
python3 main.py -o $(CURRENT_DIR)/$(TEST_VECTOR_DIR) -c $(CURRENT_DIR)/$(CONFIGS_DIR); \
echo "generator $(1) finished"
endef

# The tests dir itself is simply build by creating the directory (recursively creating deeper directories if necessary)
$(YAML_TEST_DIR):
$(info creating directory, to output yaml targets to: ${YAML_TEST_TARGETS})
$(TEST_VECTOR_DIR):
$(info creating test output directory, for generators: ${GENERATOR_TARGETS})
mkdir -p $@
$(YAML_TEST_DIR)/:
$(info ignoring duplicate yaml tests dir)
$(TEST_VECTOR_DIR)/:
$(info ignoring duplicate tests dir)

# For any target within the tests dir, build it using the build_yaml_tests function.
# For any generator, build it using the run_generator function.
# (creation of output dir is a dependency)
$(YAML_TEST_DIR)%: $(PY_SPEC_ALL_TARGETS) $(YAML_TEST_DIR)
$(call build_yaml_tests,$*)
gen_%: $(PY_SPEC_ALL_TARGETS) $(TEST_VECTOR_DIR)
$(call run_generator,$*)
36 changes: 36 additions & 0 deletions configs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Configs

This directory contains a set of constants presets used for testing, testnets, and mainnet.

A preset file contains all the constants known for its target.
Later-fork constants can be ignored, e.g. ignore phase1 constants as a client that only supports phase 0 currently.


## Forking

Configs are not replaced, but extended with forks. This is to support syncing from one state to the other over a fork boundary, without hot-swapping a config.
Instead, for forks that introduce changes in a constant, the constant name is prefixed with a short abbreviation of the fork.

Over time, the need to sync an older state may be deprecated.
In this case, the prefix on the new constant may be removed, and the old constant will keep a special name before completely being removed.

A previous iteration of forking made use of "timelines", but this collides with the definitions used in the spec (constants for special forking slots etc.),
and was not integrated sufficiently in any of the spec tools or implementations.
Instead, the config essentially doubles as fork definition now, changing the value for e.g. `PHASE_1_GENESIS_SLOT` changes the fork.

Another reason to prefer forking through constants is the ability to program a forking moment based on context, instead of being limited to a static slot number.


## Format

Each preset is a key-value mapping.

**Key**: an `UPPER_SNAKE_CASE` (a.k.a. "macro case") formatted string, name of the constant.

**Value** can be either:
- an unsigned integer number, can be up to 64 bits (incl.)
- a hexadecimal string, prefixed with `0x`

Presets may contain comments to describe the values.

See [`mainnet.yaml`](./mainnet.yaml) for a complete example.
20 changes: 0 additions & 20 deletions configs/constant_presets/README.md

This file was deleted.

19 changes: 0 additions & 19 deletions configs/fork_timelines/README.md

This file was deleted.

12 changes: 0 additions & 12 deletions configs/fork_timelines/mainnet.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions configs/fork_timelines/testing.yaml

This file was deleted.

File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion scripts/build_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
from eth2spec.utils.ssz.ssz_impl import (
hash_tree_root,
signing_root,
is_empty,
is_zero,
)
from eth2spec.utils.ssz.ssz_typing import (
uint64, bit, boolean, Container, List, Vector, Bytes, BytesN,
Expand Down
7 changes: 5 additions & 2 deletions specs/core/0_beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -1504,8 +1504,6 @@ def process_final_updates(state: BeaconState) -> None:
HALF_INCREMENT = EFFECTIVE_BALANCE_INCREMENT // 2
if balance < validator.effective_balance or validator.effective_balance + 3 * HALF_INCREMENT < balance:
validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE)
# Update start shard
state.start_shard = Shard((state.start_shard + get_shard_delta(state, current_epoch)) % SHARD_COUNT)
# Set active index root
index_epoch = Epoch(next_epoch + ACTIVATION_EXIT_DELAY)
index_root_position = index_epoch % EPOCHS_PER_HISTORICAL_VECTOR
Expand All @@ -1522,6 +1520,8 @@ def process_final_updates(state: BeaconState) -> None:
if next_epoch % (SLOTS_PER_HISTORICAL_ROOT // SLOTS_PER_EPOCH) == 0:
historical_batch = HistoricalBatch(block_roots=state.block_roots, state_roots=state.state_roots)
state.historical_roots.append(hash_tree_root(historical_batch))
# Update start shard
state.start_shard = Shard((state.start_shard + get_shard_delta(state, current_epoch)) % SHARD_COUNT)
# Rotate current/previous epoch attestations
state.previous_epoch_attestations = state.current_epoch_attestations
state.current_epoch_attestations = []
Expand Down Expand Up @@ -1654,6 +1654,9 @@ def process_attestation(state: BeaconState, attestation: Attestation) -> None:
attestation_slot = get_attestation_data_slot(state, data)
assert attestation_slot + MIN_ATTESTATION_INCLUSION_DELAY <= state.slot <= attestation_slot + SLOTS_PER_EPOCH

committee = get_crosslink_committee(state, data.target.epoch, data.crosslink.shard)
assert len(attestation.aggregation_bits) == len(attestation.custody_bits) == len(committee)

pending_attestation = PendingAttestation(
data=data,
aggregation_bits=attestation.aggregation_bits,
Expand Down
8 changes: 6 additions & 2 deletions specs/core/0_fork-choice.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ def get_genesis_store(genesis_state: BeaconState) -> Store:
```python
def get_ancestor(store: Store, root: Hash, slot: Slot) -> Hash:
block = store.blocks[root]
assert block.slot >= slot
return root if block.slot == slot else get_ancestor(store, block.parent_root, slot)
if block.slot > slot:
return get_ancestor(store, block.parent_root, slot)
elif block.slot == slot:
return root
else:
return Bytes32() # root is older than queried slot: no results.
```

#### `get_latest_attesting_balance`
Expand Down
2 changes: 1 addition & 1 deletion specs/core/1_custody-game.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def get_custody_period_for_validator(state: BeaconState, validator_index: Valida
```python
def replace_empty_or_append(list: MutableSequence[Any], new_element: Any) -> int:
for i in range(len(list)):
if is_empty(list[i]):
if is_zero(list[i]):
list[i] = new_element
return i
list.append(new_element)
Expand Down
12 changes: 7 additions & 5 deletions specs/simple-serialize.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
- [Variable-size and fixed-size](#variable-size-and-fixed-size)
- [Aliases](#aliases)
- [Default values](#default-values)
- [`is_empty`](#is_empty)
- [`is_zero`](#is_zero)
- [Illegal types](#illegal-types)
- [Serialization](#serialization)
- [`uintN`](#uintn)
Expand Down Expand Up @@ -75,19 +75,21 @@ For convenience we alias:
* `bit` to `boolean`
* `byte` to `uint8` (this is a basic type)
* `BytesN` to `Vector[byte, N]` (this is *not* a basic type)
* `null`: `{}`, i.e. the empty container
* `null`: `{}`

### Default values

The default value of a type upon initialization is recursively defined using `0` for `uintN`, `False` for `boolean` and the elements of `Bitvector`, and `[]` for lists and `Bitlist`. Unions default to the first type in the union (with type index zero), which is `null` if present in the union.

#### `is_empty`
#### `is_zero`

An SSZ object is called empty (and thus, `is_empty(object)` returns true) if it is equal to the default value for that type.
An SSZ object is called zeroed (and thus, `is_zero(object)` returns true) if it is equal to the default value for that type.

### Illegal types

Empty vector types (i.e. `[subtype, 0]` for some `subtype`) are not legal. The `null` type is only legal as the first type in a union subtype (i.e. with type index zero).
- Empty vector types (`Vector[type, 0]`, `Bitvector[0]`) are illegal.
- Containers with no fields are illegal.
- The `null` type is only legal as the first type in a union subtype (i.e. with type index zero).

## Serialization

Expand Down
Loading