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

SSZ implementation for exec. spec - Support for Python 3 typing. #1077

Merged
merged 52 commits into from
Jun 4, 2019
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
761c9e5
SSZ impl. rework started, see issue 1064
protolambda May 12, 2019
08faa86
POC ssz types spec build + update spec defs, typing still needs work
protolambda May 12, 2019
ed4416b
update SSZ implementation
protolambda May 24, 2019
81cb4a2
update some common usage of SSZ types, as a start
protolambda May 24, 2019
5b6a98b
Some updates
vbuterin May 25, 2019
3b4d9b7
Class-ified the type definitions
vbuterin May 25, 2019
e14f789
Presentation edits
vbuterin May 27, 2019
d5eab25
improve impl, box less used integer types, use uint64 as default
protolambda May 27, 2019
f308888
Minor adjustments + getting the beacon spec doc ready
protolambda May 27, 2019
132d3c9
fix spec builder
protolambda May 27, 2019
d63b553
efficiency bugfix in bytes encoding, improve typing doc + bugfix
protolambda May 27, 2019
87b3466
update encoder and decoder for reading from parsed data
protolambda May 27, 2019
c68944b
separate type (direct) from kinds (alias incl)
protolambda May 27, 2019
0f79ed7
update yaml encoder/decoder and obj randomizer for typed ssz usage
protolambda May 27, 2019
d023d2d
lots of bugfixes
protolambda May 27, 2019
b4c4df6
bugfix in sss_types global building in script
protolambda May 27, 2019
54b14b5
update ssz-static generator
protolambda May 27, 2019
0e9a047
Merge branch 'dev' into ssz-impl-rework
protolambda May 27, 2019
9e61cc2
bugfix: typing edge-case: python bool is subclass of int.
protolambda May 27, 2019
5e28adf
bugfix: don't forget about var-length bytes getting a length mixin
protolambda May 27, 2019
00ffaf4
Fix ssz path
hwwhww May 28, 2019
f0ceefc
Make `test_libs/pyspec/tests` pass
hwwhww May 28, 2019
19601df
Starting work on partials
vbuterin May 28, 2019
4955c40
merge
vbuterin May 28, 2019
053d6e7
Simplified hash tree root
vbuterin May 28, 2019
ebdf74c
kick the CI
hwwhww May 30, 2019
8fae0f8
Added support for SSZ partials
vbuterin May 30, 2019
3630b2e
Merge branch 'ssz-impl-rework' of github.com:ethereum/eth2.0-specs in…
vbuterin May 30, 2019
e044305
Merge branch 'dev' into ssz-impl-rework
protolambda May 31, 2019
3cb43fc
fix ssz infer type decorator, one None argument too many
protolambda May 31, 2019
1c734d3
fix utils init
protolambda May 31, 2019
33233c9
fix ssz imports
protolambda May 31, 2019
77d4f0b
update generator type hinting to use new type syntax
protolambda May 31, 2019
df25f22
get rid of scope-problem inducing init trick
protolambda May 31, 2019
7df788c
resolve linting problems, except ssz-partials
protolambda Jun 1, 2019
f3a517b
fix minor lint problems
protolambda Jun 1, 2019
b79f01e
update flake8 to support type annotation in linting, ignore operator …
protolambda Jun 1, 2019
fae1e92
resolve some new lint issues detected by newer version, and a few loo…
protolambda Jun 1, 2019
8e8ef2d
Fix forgotten setup.py change, make generators using ssz work again
protolambda Jun 1, 2019
a557605
Fix `ssz_partials.py` linter errors
hwwhww Jun 3, 2019
6cd9811
Delete extra newline
hwwhww Jun 3, 2019
fb584bc
fix linting dependency + caching issue
protolambda Jun 3, 2019
a7ee6f1
Refactor
hwwhww Jun 4, 2019
e2eab66
Refactor
hwwhww Jun 4, 2019
6d55ba9
minor refactor
hwwhww Jun 4, 2019
8631cad
Apply suggestions from code review
protolambda Jun 4, 2019
fe9c708
Fix whitespace
protolambda Jun 4, 2019
59137fd
fix get_zero_value exception raise + fix up type checks
protolambda Jun 4, 2019
578328b
call comments: remove partials from ssz rework PR, review that sepera…
protolambda Jun 4, 2019
6168a90
speed and simplicity improvement for next_power_of_two function
protolambda Jun 4, 2019
4bf3a26
fix formatting
protolambda Jun 4, 2019
9bdb182
remove tautological type definition
protolambda Jun 4, 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
10 changes: 5 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ jobs:
- restore_cache:
key: v1-specs-repo-{{ .Branch }}-{{ .Revision }}
- restore_cached_venv:
venv_name: v1-pyspec-03
venv_name: v2-pyspec
reqs_checksum: '{{ checksum "test_libs/pyspec/requirements.txt" }}-{{ checksum "test_libs/pyspec/requirements-testing.txt" }}'
- run:
name: Install pyspec requirements
command: make install_test && make install_lint
command: make install_test
- save_cached_venv:
venv_name: v1-pyspec-03
venv_name: v2-pyspec
reqs_checksum: '{{ checksum "test_libs/pyspec/requirements.txt" }}-{{ checksum "test_libs/pyspec/requirements-testing.txt" }}'
venv_path: ./test_libs/pyspec/venv
test:
Expand All @@ -77,7 +77,7 @@ jobs:
- restore_cache:
key: v1-specs-repo-{{ .Branch }}-{{ .Revision }}
- restore_cached_venv:
venv_name: v1-pyspec-03
venv_name: v2-pyspec
reqs_checksum: '{{ checksum "test_libs/pyspec/requirements.txt" }}-{{ checksum "test_libs/pyspec/requirements-testing.txt" }}'
- run:
name: Run py-tests
Expand All @@ -92,7 +92,7 @@ jobs:
- restore_cache:
key: v1-specs-repo-{{ .Branch }}-{{ .Revision }}
- restore_cached_venv:
venv_name: v1-pyspec-03
venv_name: v2-pyspec
reqs_checksum: '{{ checksum "test_libs/pyspec/requirements.txt" }}-{{ checksum "test_libs/pyspec/requirements-testing.txt" }}'
- run:
name: Run linter
Expand Down
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,9 @@ test: $(PY_SPEC_ALL_TARGETS)
citest: $(PY_SPEC_ALL_TARGETS)
cd $(PY_SPEC_DIR); mkdir -p test-reports/eth2spec; . venv/bin/activate; python -m pytest --junitxml=test-reports/eth2spec/test_results.xml .

install_lint:
cd $(PY_SPEC_DIR); python3 -m venv venv; . venv/bin/activate; pip3 install flake8==3.5.0

lint: $(PY_SPEC_ALL_TARGETS)
cd $(PY_SPEC_DIR); . venv/bin/activate; \
flake8 --max-line-length=120 ./eth2spec;
flake8 --ignore=E252,W504 --max-line-length=120 ./eth2spec;

# "make pyspec" to create the pyspec for all phases.
pyspec: $(PY_SPEC_ALL_TARGETS)
Expand Down
22 changes: 12 additions & 10 deletions scripts/phase0/build_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,33 @@ def build_phase0_spec(sourcefile, outfile):
NewType,
Tuple,
)
from eth2spec.utils.minimal_ssz import (
SSZType,
from eth2spec.utils.ssz.ssz_impl import (
hash_tree_root,
signing_root,
)
from eth2spec.utils.ssz.ssz_typing import (
# unused: uint8, uint16, uint32, uint128, uint256,
uint64, Container, Vector, BytesN
)
from eth2spec.utils.hash_function import hash
from eth2spec.utils.bls import (
bls_aggregate_pubkeys,
bls_verify,
bls_verify_multiple,
)


# stub, will get overwritten by real var
SLOTS_PER_EPOCH = 64

# Note: 'int' type defaults to being interpreted as a uint64 by SSZ implementation.
Slot = NewType('Slot', int) # uint64
Epoch = NewType('Epoch', int) # uint64
Shard = NewType('Shard', int) # uint64
ValidatorIndex = NewType('ValidatorIndex', int) # uint64
Gwei = NewType('Gwei', int) # uint64
Bytes32 = NewType('Bytes32', bytes) # bytes32
BLSPubkey = NewType('BLSPubkey', bytes) # bytes48
BLSSignature = NewType('BLSSignature', bytes) # bytes96
Store = None

Bytes4 = BytesN[4]
Bytes32 = BytesN[32]
Bytes48 = BytesN[48]
Bytes96 = BytesN[96]

""")

code_lines += function_puller.get_spec(sourcefile)
Expand Down
44 changes: 25 additions & 19 deletions scripts/phase0/function_puller.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import sys
from typing import List


def get_spec(file_name: str) -> List[str]:
code_lines = []
pulling_from = None
current_name = None
# list of current type definition being parsed, or None otherwise
current_typedef = None
# list of (name, definition lines list) tuples.
type_defs = []
for linenum, line in enumerate(open(sys.argv[1]).readlines()):
for linenum, line in enumerate(open(file_name).readlines()):
line = line.rstrip()
if pulling_from is None and len(line) > 0 and line[0] == '#' and line[-1] == '`':
current_name = line[line[:-1].rfind('`') + 1: -1]
Expand All @@ -19,26 +20,25 @@ def get_spec(file_name: str) -> List[str]:
if pulling_from is None:
pulling_from = linenum
else:
pulling_from = None
if current_typedef is not None:
assert code_lines[-1] == '}'
code_lines[-1] = '})'
current_typedef[-1] = '})'
type_defs.append((current_name, current_typedef))
pulling_from = None
current_typedef = None
current_typedef = None
else:
if pulling_from == linenum and line == '{':
code_lines.append('%s = SSZType({' % current_name)
current_typedef = ['global_vars["%s"] = SSZType({' % current_name]
elif pulling_from is not None:
if pulling_from is not None:
# Add some whitespace between functions
if line[:3] == 'def':
if line[:3] == 'def' or line[:5] == 'class':
code_lines.append('')
code_lines.append('')
code_lines.append(line)
# Remember type def lines
# Check for SSZ type definitions
if len(line) > 18 and line[:6] == 'class ' and line[-12:] == '(Container):':
name = line[6:-12]
# Check consistency with markdown header
assert name == current_name
current_typedef = []
if current_typedef is not None:
current_typedef.append(line)
code_lines.append(line)
elif pulling_from is None and len(line) > 0 and line[0] == '|':
row = line[1:].split('|')
if len(row) >= 2:
Expand All @@ -56,20 +56,26 @@ def get_spec(file_name: str) -> List[str]:
code_lines.append(row[0] + ' = ' + (row[1].replace('**TBD**', '0x1234567890123456789012345678901234567890')))
# Build type-def re-initialization
code_lines.append('\n')
code_lines.append('ssz_types = [\n')
for (ssz_type_name, _) in type_defs:
code_lines.append(f' {ssz_type_name},')
code_lines.append(']')
code_lines.append('\n')
code_lines.append('def init_SSZ_types():')
code_lines.append(' global_vars = globals()')
for ssz_type_name, ssz_type in type_defs:
code_lines.append('')
for type_line in ssz_type:
if len(type_line) > 0:
code_lines.append(' ' + type_line)
code_lines.append('\n')
code_lines.append('ssz_types = [\n')
for (ssz_type_name, _) in type_defs:
code_lines.append(f' "{ssz_type_name}",\n')
code_lines.append(']')
code_lines.append(f' global_vars["{ssz_type_name}"] = {ssz_type_name}')
code_lines.append(' global_vars["ssz_types"] = [')
for (ssz_type_name, _) in type_defs:
code_lines.append(f' "{ssz_type_name}",')
code_lines.append(' ]')
code_lines.append('\n')
code_lines.append('def get_ssz_type_by_name(name: str) -> SSZType:')
code_lines.append('def get_ssz_type_by_name(name: str) -> Container:')
code_lines.append(' return globals()[name]')
code_lines.append('')
return code_lines
Loading