Integrates shard-data-chains

This commit is contained in:
Carl Beekhuizen 2019-05-26 14:14:48 +02:00
parent f6ce817f24
commit a7dbbafc92
No known key found for this signature in database
GPG Key ID: D05CA176D0020646
3 changed files with 30 additions and 19 deletions

View File

@ -72,7 +72,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 $@ python3 $(SCRIPT_DIR)/build_spec.py -p0 $(SPEC_DIR)/core/0_beacon-chain.md $@
$(PY_SPEC_DIR)/eth2spec/phase1/spec.py: $(PY_SPEC_PHASE_1_DEPS) $(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/1_custody-game.md $@ python3 $(SCRIPT_DIR)/build_spec.py -p1 $(SPEC_DIR)/core/0_beacon-chain.md $(SPEC_DIR)/core/1_custody-game.md $(SPEC_DIR)/core/1_shard-data-chains.md $@
CURRENT_DIR = ${CURDIR} CURRENT_DIR = ${CURDIR}

View File

@ -107,7 +107,7 @@ def apply_constants_preset(preset: Dict[str, Any]):
''' '''
def objects_to_spec(functions, constants, ssz_objects, imports, inserts={}): def objects_to_spec(functions, constants, ssz_objects, inserts, imports):
new_type_definitions = '\n'.join(['''%s = NewType('%s', %s)''' % (key, key, value) for key, value in NEW_TYPES.items()]) new_type_definitions = '\n'.join(['''%s = NewType('%s', %s)''' % (key, key, value) for key, value in NEW_TYPES.items()])
functions_spec = '\n\n'.join(functions.values()) functions_spec = '\n\n'.join(functions.values())
constants_spec = '\n'.join(map(lambda x: '%s = %s' % (x, constants[x]),constants)) constants_spec = '\n'.join(map(lambda x: '%s = %s' % (x, constants[x]),constants))
@ -174,9 +174,19 @@ def combine_ssz_objects(old_objects, new_objects):
combine_inserts = combine_functions combine_inserts = combine_functions
def combine_spec_objects(spec0, spec1):
functions0, constants0, ssz_objects0, inserts0 = spec0
functions1, constants1, ssz_objects1, inserts1 = spec1
functions = combine_functions(functions0, functions1)
constants = combine_constants(constants0, constants1)
ssz_objects = combine_ssz_objects(ssz_objects0, ssz_objects1)
inserts = combine_inserts(inserts0, inserts1)
return functions, constants, ssz_objects, inserts
def build_phase0_spec(sourcefile, outfile=None): def build_phase0_spec(sourcefile, outfile=None):
functions, constants, ssz_objects, _ = function_puller.get_spec(sourcefile) functions, constants, ssz_objects, inserts = function_puller.get_spec(sourcefile)
spec = objects_to_spec(functions, constants, ssz_objects, PHASE0_IMPORTS) spec = objects_to_spec(functions, constants, ssz_objects, inserts, PHASE0_IMPORTS)
if outfile is not None: if outfile is not None:
with open(outfile, 'w') as out: with open(outfile, 'w') as out:
out.write(spec) out.write(spec)
@ -184,14 +194,14 @@ def build_phase0_spec(sourcefile, outfile=None):
return spec return spec
def build_phase1_spec(phase0_sourcefile, phase1_sourcefile, outfile=None): def build_phase1_spec(phase0_sourcefile, phase1_custody_sourcefile, phase1_shard_sourcefile, outfile=None):
phase0_functions, phase0_constants, phase0_ssz_objects, phase0_inserts = function_puller.get_spec(phase0_sourcefile) phase0_spec = function_puller.get_spec(phase0_sourcefile)
phase1_functions, phase1_constants, phase1_ssz_objects, phase1_inserts = function_puller.get_spec(phase1_sourcefile) phase1_custody = function_puller.get_spec(phase1_custody_sourcefile)
functions = combine_functions(phase0_functions, phase1_functions) phase1_shard_data = function_puller.get_spec(phase1_shard_sourcefile)
constants = combine_constants(phase0_constants, phase1_constants) spec_objects = phase0_spec
ssz_objects = combine_ssz_objects(phase0_ssz_objects, phase1_ssz_objects) for value in [phase1_custody, phase1_shard_data]:
inserts = combine_inserts(phase0_inserts, phase1_inserts) spec_objects = combine_spec_objects(spec_objects, value)
spec = objects_to_spec(functions, constants, ssz_objects, PHASE1_IMPORTS, inserts) spec = objects_to_spec(*spec_objects, PHASE1_IMPORTS)
if outfile is not None: if outfile is not None:
with open(outfile, 'w') as out: with open(outfile, 'w') as out:
out.write(spec) out.write(spec)
@ -219,9 +229,10 @@ If building phase 1:
if args.phase == 0: if args.phase == 0:
build_phase0_spec(*args.files) build_phase0_spec(*args.files)
elif args.phase == 1: elif args.phase == 1:
if len(args.files) == 3: print(args.files)
if len(args.files) == 4:
build_phase1_spec(*args.files) build_phase1_spec(*args.files)
else: else:
print(" Phase 1 requires an output as well as 2 input files (phase0.md and phase1.md)") print(" Phase 1 requires an output as well as 3 input files (phase0.md and phase1.md, phase1.md)")
else: else:
print("Invalid phase: {0}".format(args.phase)) print("Invalid phase: {0}".format(args.phase))

View File

@ -47,7 +47,7 @@ This document describes the shard data layer and the shard fork choice rule in P
| `BYTES_PER_SHARD_BLOCK_BODY` | `2**14` (= 16,384) | | `BYTES_PER_SHARD_BLOCK_BODY` | `2**14` (= 16,384) |
| `MAX_SHARD_ATTESTIONS` | `2**4` (= 16) | | `MAX_SHARD_ATTESTIONS` | `2**4` (= 16) |
| `PHASE_1_GENESIS_EPOCH` | **TBD** | | `PHASE_1_GENESIS_EPOCH` | **TBD** |
| `PHASE_1_GENESIS_SLOT` | get_epoch_start_slot(PHASE_1_GENESIS_EPOCH) | | `PHASE_1_GENESIS_SLOT` | **TBD** |
### Time parameters ### Time parameters
@ -291,7 +291,7 @@ def is_valid_shard_block(beacon_blocks: List[BeaconBlock],
# Check beacon block # Check beacon block
beacon_block = beacon_blocks[candidate.slot] beacon_block = beacon_blocks[candidate.slot]
assert candidate.beacon_block_root == signing_root(beacon_block) assert candidate.beacon_block_root == signing_root(beacon_block)
assert beacon_block.slot <= candidate.slot: assert beacon_block.slot <= candidate.slot
# Check state root # Check state root
assert candidate.state_root == ZERO_HASH # [to be removed in phase 2] assert candidate.state_root == ZERO_HASH # [to be removed in phase 2]
@ -344,9 +344,9 @@ def is_valid_shard_attestation(valid_shard_blocks: List[ShardBlock],
candidate: ShardAttestation) -> bool: candidate: ShardAttestation) -> bool:
# Check shard block # Check shard block
shard_block = next( shard_block = next(
block for block in valid_shard_blocks if (block for block in valid_shard_blocks if signing_root(block) == candidate.data.shard_block_root),
signing_root(block) == candidate.data.shard_block_root None,
, None) )
assert shard_block != None assert shard_block != None
assert shard_block.slot == candidate.data.slot assert shard_block.slot == candidate.data.slot
assert shard_block.shard == candidate.data.shard assert shard_block.shard == candidate.data.shard