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

Phase 1 rebase #1504

Merged
merged 118 commits into from
Jan 23, 2020
Merged
Show file tree
Hide file tree
Changes from 94 commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
b4b5cc9
Merge branch 'v09x' into dev
djrtwo Dec 5, 2019
88aeba0
Added new shards
vbuterin Oct 12, 2019
f6be6b2
Added a few things
vbuterin Oct 12, 2019
25db268
Added a few more things
vbuterin Oct 13, 2019
26df98b
MAX_CATCHUP -> MAX_CATCHUP_RATIO
vbuterin Oct 13, 2019
fe60b4d
Variable max attestation length
vbuterin Oct 13, 2019
b792fe6
formatting
vbuterin Oct 13, 2019
9abfc62
Cleaned up state transition and honest committee member
vbuterin Oct 14, 2019
e5544d0
Made trace a commitment separate from state roots
vbuterin Oct 14, 2019
7fc2830
Some updates
vbuterin Oct 27, 2019
bb2835e
Shard slots to 128 bytes
vbuterin Oct 27, 2019
539c681
Updates to add new proposals
vbuterin Oct 29, 2019
0ff5985
Fix markdown and ToC
hwwhww Oct 28, 2019
08fc024
Changed fraud proof details
vbuterin Oct 29, 2019
bf0a2b7
Renaming
vbuterin Oct 29, 2019
bf886d6
Small edits
vbuterin Oct 29, 2019
b36820a
Changes to make Danny happy
vbuterin Nov 1, 2019
6b1bc1e
Reformed attestations
vbuterin Nov 3, 2019
3934369
Restructured shard blocks
vbuterin Nov 3, 2019
d723431
Fixed pending attestation handling and added empty transition check
vbuterin Nov 3, 2019
03ab1d5
A few cleanups
vbuterin Nov 4, 2019
1fdd033
Update ToC
hwwhww Nov 5, 2019
462d05d
Update specs/core/1_new_shards.md
vbuterin Nov 5, 2019
213032e
Update specs/core/1_new_shards.md
vbuterin Nov 5, 2019
d3f9bfe
Update specs/core/1_new_shards.md
vbuterin Nov 5, 2019
d59e87f
Update specs/core/1_new_shards.md
vbuterin Nov 5, 2019
bcd06d8
Update specs/core/1_new_shards.md
vbuterin Nov 5, 2019
9d3a230
Update specs/core/1_new_shards.md
vbuterin Nov 5, 2019
9810a3d
Update specs/core/1_new_shards.md
vbuterin Nov 5, 2019
4d1e9e1
Update specs/core/1_new_shards.md
vbuterin Nov 5, 2019
8a6bd20
Update specs/core/1_new_shards.md
vbuterin Nov 5, 2019
41be60e
Update specs/core/1_new_shards.md
vbuterin Nov 5, 2019
793c861
Update specs/core/1_new_shards.md
vbuterin Nov 5, 2019
bf13757
Update specs/core/1_new_shards.md
vbuterin Nov 5, 2019
0ddc0ba
Update specs/core/1_new_shards.md
vbuterin Nov 5, 2019
822cead
Update specs/core/1_new_shards.md
vbuterin Nov 5, 2019
a749dd9
Update specs/core/1_new_shards.md
vbuterin Nov 5, 2019
c9cc110
Update specs/core/1_new_shards.md
vbuterin Nov 5, 2019
2ea8eb9
Update specs/core/1_new_shards.md
vbuterin Nov 5, 2019
ff3bd72
Update specs/core/1_new_shards.md
vbuterin Nov 6, 2019
8cb404d
Update specs/core/1_new_shards.md
vbuterin Nov 6, 2019
e66b4e0
Update specs/core/1_new_shards.md
vbuterin Nov 6, 2019
b6680d2
Update specs/core/1_new_shards.md
vbuterin Nov 6, 2019
8f34a07
Some initial changes
vbuterin Nov 6, 2019
7b4a6e8
Simplified gasprice update
vbuterin Nov 7, 2019
4d6dcd1
Some fixes
vbuterin Nov 12, 2019
ef936b9
Added get_shard_proposer_index
vbuterin Nov 12, 2019
a33e01d
Start making phase1 work in pyspec again
protolambda Nov 15, 2019
7d2341b
Note: is_valid_indexed_attestation is overriden
protolambda Nov 15, 2019
edef2fd
more refactoring: more immediate custody game, general phase1 beacon …
protolambda Nov 15, 2019
465f6cb
update readme spec links
protolambda Nov 15, 2019
589d5a4
Add notes on custody game spec funcs
protolambda Nov 15, 2019
74d6021
PR comment fixes
protolambda Nov 16, 2019
cc0aac3
typo
protolambda Nov 16, 2019
36503f9
placeholder: rudimentary phase 0 to phase 1 fork process
protolambda Nov 16, 2019
4c9e5b8
add link to phase1 upgrade doc
protolambda Nov 16, 2019
03e956f
validator init adjustments
protolambda Nov 16, 2019
79be034
fix call to process_attestation
djrtwo Nov 18, 2019
82c9adc
fix phase 1 make build (not lint or tests)
djrtwo Nov 18, 2019
9f80a7f
phase1 lint (1)
djrtwo Nov 18, 2019
d6bfe5d
lint phase 1 (2)
djrtwo Nov 18, 2019
e73316c
change configs to be loaded in time; reload specs module to make new …
protolambda Nov 19, 2019
1a1c377
implement custody game revamp for new shard proposal: simplifications…
protolambda Nov 20, 2019
41be2ed
bugfix custody bit index lookup + lint fixes
protolambda Nov 20, 2019
1623d40
fix: check malefactor custody key
protolambda Nov 20, 2019
72a9dfc
fix lint problems
protolambda Nov 20, 2019
ddd7cd2
divide new and old containers out in phase 1
djrtwo Nov 22, 2019
a1ac0d5
fix get_shard_committee
djrtwo Nov 22, 2019
f533fef
add missing attestation validations; cleanup process_attestations and…
djrtwo Nov 23, 2019
4bf5eb8
fix issues using indexed attestation and custody bit wrapper
djrtwo Nov 23, 2019
a32b010
rebase fixes
djrtwo Dec 5, 2019
e31f17f
modify phase 1 to use new signature (no signing_root) pattern
djrtwo Dec 5, 2019
595d2f6
Merge branch 'dev' into phase1rebase
djrtwo Dec 5, 2019
ce40666
version pyspec module and test on one attesterslashing test
djrtwo Dec 5, 2019
0a3cc8a
malefactor_key -> malefactor_secret
djrtwo Jan 3, 2020
c9f52d0
Merge branch 'dev' into phase1rebase
djrtwo Jan 3, 2020
a5faabb
Merge branch 'version-pyspec-module' into phase1rebase
protolambda Jan 4, 2020
13cdfa8
apply configs in tests properly
protolambda Jan 4, 2020
018927d
generalize previous-slot function
protolambda Jan 5, 2020
a8276f6
don't hardcode shard count, bad example, need upgradeability
protolambda Jan 5, 2020
11011f2
test context can handle multiple phases better now
protolambda Jan 5, 2020
2e6090f
bugfixes for experimental phase0 -> phase1 fork py code
protolambda Jan 5, 2020
3995bd6
coerce container types, since classes do not match between phases
protolambda Jan 5, 2020
752eeec
old challenge based custody game tests are not relevant anymore
protolambda Jan 5, 2020
bf86a71
force-add in phase0 in test context, since state creation is not inde…
protolambda Jan 5, 2020
2f3919c
bugfix: pass block body to sub processing functions
protolambda Jan 5, 2020
0cf866e
fix bug, test should run properly, forward generator in return
protolambda Jan 5, 2020
6b872da
light client bitfield is vector now, small size anyway, better separa…
protolambda Jan 5, 2020
ce84ddd
initial update of phase1 section of configs
protolambda Jan 5, 2020
9c07e26
length assert not applicable anymore
protolambda Jan 5, 2020
68d93f9
online countdown fixes
protolambda Jan 5, 2020
ba10046
minor lint fixes
protolambda Jan 5, 2020
cd7a214
fix genesis tests: only run on single phase, ignore phases extra data
protolambda Jan 5, 2020
9dd8d1d
add two missing decorators
protolambda Jan 6, 2020
140129e
Merge dev into phase1 refactor, update BLS phase1
protolambda Jan 9, 2020
f810e6b
update to python v3.8
protolambda Jan 9, 2020
68ff136
warn about broken attestation validation, fix most attester slashings…
protolambda Jan 9, 2020
4732c7b
merge in dev (v0.10) and fix reorg/lint issues
protolambda Jan 13, 2020
507a9af
apply custody bit fix suggestion from Dankrad
protolambda Jan 13, 2020
419b6a3
config change, need more space for worst-case reveals
protolambda Jan 13, 2020
702b253
update configs for phase1
protolambda Jan 13, 2020
46be6ae
fix config loader to support list inputs
protolambda Jan 13, 2020
6c74468
forkchoice store on top of any state now
protolambda Jan 14, 2020
fee3baa
fix attesting indices error
protolambda Jan 14, 2020
e8654bf
merkle proofs out, moving to ssz spec
protolambda Jan 14, 2020
f6f8bd5
no custody bits fallback
protolambda Jan 14, 2020
f04a686
doctoc
protolambda Jan 14, 2020
d98c50a
update ci caches
protolambda Jan 14, 2020
5785b4f
custody bits temporary solution
protolambda Jan 14, 2020
f16d74d
fix custody key reveal tests not running due to decorator order problem
protolambda Jan 14, 2020
0d8a2ef
fix broken fork choice tests; compute anchor root for state, not just…
protolambda Jan 14, 2020
e6f98eb
minor config style fixes
protolambda Jan 14, 2020
90bc1f5
Fix config loading problem
protolambda Jan 14, 2020
8d0e1bd
downgrade deposit contract back to python 3.6, vyper syntax parsing i…
protolambda Jan 14, 2020
3c07b2c
Make phase 0 fork choice more modular to more easily adopt for slight…
djrtwo Jan 15, 2020
c0b69e5
cycle through committee indexes instead of through active shards when…
djrtwo Jan 16, 2020
7a41253
remove test_shard_blocks (outdated) and reduce PERSISTENT_COMMITTEE_P…
djrtwo Jan 16, 2020
86b699b
Merge branch 'dev' into phase1rebase
protolambda Jan 23, 2020
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ $(PY_SPEC_PHASE_0_TARGETS): $(PY_SPEC_PHASE_0_DEPS)
python3 $(SCRIPT_DIR)/build_spec.py -p0 $(SPEC_DIR)/core/0_beacon-chain.md $(SPEC_DIR)/core/0_fork-choice.md $(SPEC_DIR)/validator/0_beacon-chain-validator.md $@

$(PY_SPEC_DIR)/eth2spec/phase1/spec.py: $(PY_SPEC_PHASE_1_DEPS)
python3 $(SCRIPT_DIR)/build_spec.py -p1 $(SPEC_DIR)/core/0_beacon-chain.md $(SPEC_DIR)/core/0_fork-choice.md $(SPEC_DIR)/light_client/merkle_proofs.md $(SPEC_DIR)/core/1_custody-game.md $(SPEC_DIR)/core/1_shard-data-chains.md $(SPEC_DIR)/core/1_beacon-chain-misc.md $@
python3 $(SCRIPT_DIR)/build_spec.py -p1 $(SPEC_DIR)/core/0_beacon-chain.md $(SPEC_DIR)/core/0_fork-choice.md $(SPEC_DIR)/light_client/merkle_proofs.md $(SPEC_DIR)/core/1_custody-game.md $(SPEC_DIR)/core/1_beacon-chain.md $(SPEC_DIR)/core/1_fraud-proofs.md $(SPEC_DIR)/core/1_phase1-fork.md $@

CURRENT_DIR = ${CURDIR}

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ Core specifications for Eth2 client validation can be found in [specs/core](spec
* [Honest Validator](specs/validator/0_beacon-chain-validator.md)

### Phase 1
* [From Phase 0 to Phase 1](specs/core/1_phase1_fork.md)
* [The Beacon Chain for Shards](specs/core/1_beacon-chain.md)
* [Custody Game](specs/core/1_custody-game.md)
* [Shard Data Chains](specs/core/1_shard-data-chains.md)
* [Misc beacon chain updates](specs/core/1_beacon-chain-misc.md)
* [Shard Transition and Fraud Proofs](specs/core/1_fraud_proofs.md)

### Phase 2

Expand Down
12 changes: 9 additions & 3 deletions configs/mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ DOMAIN_BEACON_ATTESTER: 0x01000000
DOMAIN_RANDAO: 0x02000000
DOMAIN_DEPOSIT: 0x03000000
DOMAIN_VOLUNTARY_EXIT: 0x04000000
DOMAIN_CUSTODY_BIT_CHALLENGE: 0x06000000
DOMAIN_SHARD_PROPOSER: 0x80000000
DOMAIN_SHARD_ATTESTER: 0x81000000
DOMAIN_SHARD_PROPOSAL: 0x80000000
DOMAIN_SHARD_COMMITTEE: 0x81000000
DOMAIN_LIGHT_CLIENT: 0x82000000
DOMAIN_CUSTODY_BIT_SLASHING: 0x83000000


# Phase 1
# ---------------------------------------------------------------
INITIAL_ACTIVE_SHARDS: 64
15 changes: 6 additions & 9 deletions configs/minimal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,13 @@ DOMAIN_BEACON_ATTESTER: 0x01000000
DOMAIN_RANDAO: 0x02000000
DOMAIN_DEPOSIT: 0x03000000
DOMAIN_VOLUNTARY_EXIT: 0x04000000
DOMAIN_CUSTODY_BIT_CHALLENGE: 0x06000000
DOMAIN_SHARD_PROPOSER: 0x80000000
DOMAIN_SHARD_ATTESTER: 0x81000000
DOMAIN_SHARD_PROPOSAL: 0x80000000
DOMAIN_SHARD_COMMITTEE: 0x81000000
DOMAIN_LIGHT_CLIENT: 0x82000000
DOMAIN_CUSTODY_BIT_SLASHING: 0x83000000


# Phase 1
# ---------------------------------------------------------------
SHARD_SLOTS_PER_BEACON_SLOT: 2
EPOCHS_PER_SHARD_PERIOD: 4
# PHASE_1_FORK_EPOCH >= EPOCHS_PER_SHARD_PERIOD * 2
PHASE_1_FORK_EPOCH: 8
# PHASE_1_FORK_SLOT = PHASE_1_FORK_EPOCH * SLOTS_PER_EPOCH
PHASE_1_FORK_SLOT: 64
# [customized] reduced for testing
INITIAL_ACTIVE_SHARDS: 4
133 changes: 44 additions & 89 deletions scripts/build_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
Optional,
)

CONFIG_LOADER = '''
apply_constants_preset(globals())
'''

PHASE0_IMPORTS = '''from typing import (
Any, Dict, Set, Sequence, Tuple, Optional
PHASE0_IMPORTS = '''from eth2spec.config.apply_config import apply_constants_preset
from typing import (
Any, Callable, Dict, Set, Sequence, Tuple, Optional
)

from dataclasses import (
Expand All @@ -33,8 +37,10 @@

from eth2spec.utils.hash_function import hash
'''
PHASE1_IMPORTS = '''from typing import (
Any, Dict, Set, Sequence, MutableSequence, NewType, Tuple, Union,
PHASE1_IMPORTS = '''from eth2spec.phase0 import spec as phase0
from eth2spec.config.apply_config import apply_constants_preset
from typing import (
Any, Callable, Dict, Set, Sequence, NewType, Tuple, Union,
)
from math import (
log2,
Expand All @@ -45,15 +51,12 @@
field,
)

from eth2spec.utils.ssz.ssz_impl import (
hash_tree_root,
is_zero,
)
from eth2spec.utils.ssz.ssz_impl import hash_tree_root
from eth2spec.utils.ssz.ssz_typing import (
BasicValue, Elements, BaseBytes, BaseList, SSZType,
Container, List, Vector, ByteList, ByteVector, Bitlist, Bitvector, Bits,
Bytes1, Bytes4, Bytes8, Bytes32, Bytes48, Bytes96,
uint64, bit, boolean, byte,
uint64, uint8, bit, boolean,
)
from eth2spec.utils.bls import (
bls_aggregate_pubkeys,
Expand Down Expand Up @@ -101,51 +104,15 @@ def compute_committee(indices: Sequence[ValidatorIndex], # type: ignore

if param_hash not in committee_cache:
committee_cache[param_hash] = _compute_committee(indices, seed, index, count)
return committee_cache[param_hash]


# Access to overwrite spec constants based on configuration
def apply_constants_preset(preset: Dict[str, Any]) -> None:
global_vars = globals()
for k, v in preset.items():
if k.startswith('DOMAIN_'):
global_vars[k] = DomainType(v) # domain types are defined as bytes in the configs
else:
global_vars[k] = v

# Deal with derived constants
global_vars['GENESIS_EPOCH'] = compute_epoch_at_slot(GENESIS_SLOT)

# Initialize SSZ types again, to account for changed lengths
init_SSZ_types()
'''


def remove_for_phase1(functions: Dict[str, str]):
for key, value in functions.items():
lines = value.split("\n")
lines = filter(lambda s: "[to be removed in phase 1]" not in s, lines)
functions[key] = "\n".join(lines)


def strip_comments(raw: str) -> str:
comment_line_regex = re.compile(r'^\s+# ')
lines = raw.split('\n')
out = []
for line in lines:
if not comment_line_regex.match(line):
if ' #' in line:
line = line[:line.index(' #')]
out.append(line)
return '\n'.join(out)
return committee_cache[param_hash]'''


def objects_to_spec(functions: Dict[str, str],
custom_types: Dict[str, str],
constants: Dict[str, str],
ssz_objects: Dict[str, str],
inserts: Dict[str, str],
imports: Dict[str, str],
version: str,
) -> str:
"""
Given all the objects that constitute a spec, combine them into a single pyfile.
Expand All @@ -167,27 +134,18 @@ def objects_to_spec(functions: Dict[str, str],
constants[k] += " # noqa: E501"
constants_spec = '\n'.join(map(lambda x: '%s = %s' % (x, constants[x]), constants))
ssz_objects_instantiation_spec = '\n\n'.join(ssz_objects.values())
ssz_objects_reinitialization_spec = (
'def init_SSZ_types() -> None:\n global_vars = globals()\n\n '
+ '\n\n '.join([strip_comments(re.sub(r'(?!\n\n)\n', r'\n ', value[:-1]))
for value in ssz_objects.values()])
+ '\n\n'
+ '\n'.join(map(lambda x: ' global_vars[\'%s\'] = %s' % (x, x), ssz_objects.keys()))
)
spec = (
imports
+ '\n\n' + f"version = \'{version}\'\n"
+ '\n\n' + new_type_definitions
+ '\n' + SUNDRY_CONSTANTS_FUNCTIONS
+ '\n\n' + constants_spec
+ '\n\n\n' + ssz_objects_instantiation_spec
+ '\n\n' + CONFIG_LOADER
+ '\n\n' + ssz_objects_instantiation_spec
+ '\n\n' + functions_spec
+ '\n' + SUNDRY_FUNCTIONS
+ '\n\n' + ssz_objects_reinitialization_spec
+ '\n'
)
# Handle @inserts
for key, value in inserts.items():
spec = re.sub('[ ]*# %s\\n' % key, value, spec)
return spec


Expand All @@ -204,10 +162,10 @@ def combine_constants(old_constants: Dict[str, str], new_constants: Dict[str, st


ignored_dependencies = [
'bit', 'boolean', 'Vector', 'List', 'Container', 'Hash', 'BLSPubkey', 'BLSSignature', 'ByteList', 'ByteVector'
'bit', 'boolean', 'Vector', 'List', 'Container', 'BLSPubkey', 'BLSSignature',
'Bytes1', 'Bytes4', 'Bytes32', 'Bytes48', 'Bytes96', 'Bitlist', 'Bitvector',
'uint8', 'uint16', 'uint32', 'uint64', 'uint128', 'uint256',
'bytes', 'byte', 'ByteVector' # to be removed after updating spec doc
'bytes', 'byte', 'ByteList', 'ByteVector'
]


Expand Down Expand Up @@ -240,32 +198,26 @@ def combine_ssz_objects(old_objects: Dict[str, str], new_objects: Dict[str, str]
and returns the newer versions of the objects in dependency order.
"""
for key, value in new_objects.items():
if key in old_objects:
# remove trailing newline
old_objects[key] = old_objects[key]
# remove leading variable name
value = re.sub(r'^class [\w]*\(Container\):\n', '', value)
old_objects[key] = old_objects.get(key, '') + value
dependency_order_ssz_objects(old_objects, custom_types)
old_objects[key] = value
return old_objects


# inserts are handled the same way as functions
combine_inserts = combine_functions


def combine_spec_objects(spec0: SpecObject, spec1: SpecObject) -> SpecObject:
"""
Takes in two spec variants (as tuples of their objects) and combines them using the appropriate combiner function.
"""
functions0, custom_types0, constants0, ssz_objects0, inserts0 = spec0
functions1, custom_types1, constants1, ssz_objects1, inserts1 = spec1
functions0, custom_types0, constants0, ssz_objects0 = spec0
functions1, custom_types1, constants1, ssz_objects1 = spec1
functions = combine_functions(functions0, functions1)
custom_types = combine_constants(custom_types0, custom_types1)
constants = combine_constants(constants0, constants1)
ssz_objects = combine_ssz_objects(ssz_objects0, ssz_objects1, custom_types)
inserts = combine_inserts(inserts0, inserts1)
return functions, custom_types, constants, ssz_objects, inserts
return functions, custom_types, constants, ssz_objects


def dependency_order_spec(objs: SpecObject):
functions, custom_types, constants, ssz_objects = objs
dependency_order_ssz_objects(ssz_objects, custom_types)


def build_phase0_spec(phase0_sourcefile: str, fork_choice_sourcefile: str,
Expand All @@ -276,7 +228,8 @@ def build_phase0_spec(phase0_sourcefile: str, fork_choice_sourcefile: str,
spec_objects = phase0_spec
for value in [fork_choice_spec, v_guide]:
spec_objects = combine_spec_objects(spec_objects, value)
spec = objects_to_spec(*spec_objects, PHASE0_IMPORTS)
dependency_order_spec(spec_objects)
spec = objects_to_spec(*spec_objects, PHASE0_IMPORTS, 'phase0')
if outfile is not None:
with open(outfile, 'w') as out:
out.write(spec)
Expand All @@ -287,24 +240,25 @@ def build_phase1_spec(phase0_beacon_sourcefile: str,
phase0_fork_choice_sourcefile: str,
merkle_proofs_sourcefile: str,
phase1_custody_sourcefile: str,
phase1_shard_sourcefile: str,
phase1_beacon_misc_sourcefile: str,
phase1_beacon_sourcefile: str,
phase1_fraud_sourcefile: str,
phase1_fork_sourcefile: str,
outfile: str=None) -> Optional[str]:
all_sourcefiles = (
phase0_beacon_sourcefile,
phase0_fork_choice_sourcefile,
merkle_proofs_sourcefile,
phase1_custody_sourcefile,
phase1_shard_sourcefile,
phase1_beacon_misc_sourcefile,
phase1_beacon_sourcefile,
phase1_fraud_sourcefile,
phase1_fork_sourcefile,
)
all_spescs = [get_spec(spec) for spec in all_sourcefiles]
for spec in all_spescs:
remove_for_phase1(spec[0])
spec_objects = all_spescs[0]
for value in all_spescs[1:]:
spec_objects = combine_spec_objects(spec_objects, value)
spec = objects_to_spec(*spec_objects, PHASE1_IMPORTS)
dependency_order_spec(spec_objects)
spec = objects_to_spec(*spec_objects, PHASE1_IMPORTS, 'phase1')
if outfile is not None:
with open(outfile, 'w') as out:
out.write(spec)
Expand All @@ -325,9 +279,10 @@ def build_phase1_spec(phase0_beacon_sourcefile: str,
2nd argument is input /core/0_fork-choice.md
3rd argument is input /light_client/merkle_proofs.md
4th argument is input /core/1_custody-game.md
5th argument is input /core/1_shard-data-chains.md
6th argument is input /core/1_beacon-chain-misc.md
7th argument is output spec.py
5th argument is input /core/1_beacon-chain.md
6th argument is input /core/1_fraud-proofs.md
7th argument is input /core/1_phase1-fork.md
8th argument is output spec.py
'''
parser = ArgumentParser(description=description)
parser.add_argument("-p", "--phase", dest="phase", type=int, default=0, help="Build for phase #")
Expand All @@ -340,14 +295,14 @@ def build_phase1_spec(phase0_beacon_sourcefile: str,
else:
print(" Phase 0 requires spec, forkchoice, and v-guide inputs as well as an output file.")
elif args.phase == 1:
if len(args.files) == 7:
if len(args.files) == 8:
build_phase1_spec(*args.files)
else:
print(
" Phase 1 requires input files as well as an output file:\n"
"\t core/phase_0: (0_beacon-chain.md, 0_fork-choice.md)\n"
"\t light_client: (merkle_proofs.md)\n"
"\t core/phase_1: (1_custody-game.md, 1_shard-data-chains.md, 1_beacon-chain-misc.md)\n"
"\t core/phase_1: (1_custody-game.md, 1_beacon-chain.md, 1_fraud-proofs.md, 1_phase1-fork.md)\n"
"\t and output.py"
)
else:
Expand Down
25 changes: 5 additions & 20 deletions scripts/function_puller.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@


FUNCTION_REGEX = r'^def [\w_]*'
BEGIN_INSERT_REGEX = r'# begin insert '
END_INSERT_REGEX = r'# end insert'

SpecObject = NewType('SpecObjects', Tuple[Dict[str, str], Dict[str, str], Dict[str, str], Dict[str, str]])

Expand All @@ -15,22 +13,18 @@ def get_spec(file_name: str) -> SpecObject:
functions = {function_name: function_code}
constants= {constant_name: constant_code}
ssz_objects= {object_name: object}
inserts= {insert_tag: code to be inserted}

Note: This function makes heavy use of the inherent ordering of dicts,
if this is not supported by your python version, it will not work.
"""
pulling_from = None # line number of start of latest object
current_name = None # most recent section title
insert_name = None # stores the label of the current insert object
functions = {}
constants = {}
ssz_objects = {}
inserts = {}
functions: Dict[str, str] = {}
constants: Dict[str, str] = {}
ssz_objects: Dict[str, str] = {}
function_matcher = re.compile(FUNCTION_REGEX)
inserts_matcher = re.compile(BEGIN_INSERT_REGEX)
is_ssz = False
custom_types = {}
custom_types: Dict[str, str] = {}
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] == '`':
Expand All @@ -40,15 +34,6 @@ def get_spec(file_name: str) -> SpecObject:
pulling_from = linenum + 1
elif line[:3] == '```':
pulling_from = None
elif inserts_matcher.match(line) is not None:
# Find @insert names
insert_name = re.search(r'@[\w]*', line).group(0)
elif insert_name is not None:
# In insert mode, either the next line is more code, or the end of the insert
if re.match(END_INSERT_REGEX, line) is not None:
insert_name = None
else:
inserts[insert_name] = inserts.get(insert_name, '') + line + '\n'
else:
# Handle function definitions & ssz_objects
if pulling_from is not None:
Expand Down Expand Up @@ -84,4 +69,4 @@ def get_spec(file_name: str) -> SpecObject:
constants[row[0]] = row[1].replace('**TBD**', '2**32')
elif row[1].startswith('uint') or row[1].startswith('Bytes'):
custom_types[row[0]] = row[1]
return functions, custom_types, constants, ssz_objects, inserts
return SpecObject((functions, custom_types, constants, ssz_objects))
Loading