Integrates shard-data-chains
This commit is contained in:
parent
f6ce817f24
commit
a7dbbafc92
2
Makefile
2
Makefile
|
@ -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 $@
|
||||
|
||||
$(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}
|
||||
|
||||
|
|
|
@ -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()])
|
||||
functions_spec = '\n\n'.join(functions.values())
|
||||
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
|
||||
|
||||
|
||||
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):
|
||||
functions, constants, ssz_objects, _ = function_puller.get_spec(sourcefile)
|
||||
spec = objects_to_spec(functions, constants, ssz_objects, PHASE0_IMPORTS)
|
||||
functions, constants, ssz_objects, inserts = function_puller.get_spec(sourcefile)
|
||||
spec = objects_to_spec(functions, constants, ssz_objects, inserts, PHASE0_IMPORTS)
|
||||
if outfile is not None:
|
||||
with open(outfile, 'w') as out:
|
||||
out.write(spec)
|
||||
|
@ -184,14 +194,14 @@ def build_phase0_spec(sourcefile, outfile=None):
|
|||
return spec
|
||||
|
||||
|
||||
def build_phase1_spec(phase0_sourcefile, phase1_sourcefile, outfile=None):
|
||||
phase0_functions, phase0_constants, phase0_ssz_objects, phase0_inserts = function_puller.get_spec(phase0_sourcefile)
|
||||
phase1_functions, phase1_constants, phase1_ssz_objects, phase1_inserts = function_puller.get_spec(phase1_sourcefile)
|
||||
functions = combine_functions(phase0_functions, phase1_functions)
|
||||
constants = combine_constants(phase0_constants, phase1_constants)
|
||||
ssz_objects = combine_ssz_objects(phase0_ssz_objects, phase1_ssz_objects)
|
||||
inserts = combine_inserts(phase0_inserts, phase1_inserts)
|
||||
spec = objects_to_spec(functions, constants, ssz_objects, PHASE1_IMPORTS, inserts)
|
||||
def build_phase1_spec(phase0_sourcefile, phase1_custody_sourcefile, phase1_shard_sourcefile, outfile=None):
|
||||
phase0_spec = function_puller.get_spec(phase0_sourcefile)
|
||||
phase1_custody = function_puller.get_spec(phase1_custody_sourcefile)
|
||||
phase1_shard_data = function_puller.get_spec(phase1_shard_sourcefile)
|
||||
spec_objects = phase0_spec
|
||||
for value in [phase1_custody, phase1_shard_data]:
|
||||
spec_objects = combine_spec_objects(spec_objects, value)
|
||||
spec = objects_to_spec(*spec_objects, PHASE1_IMPORTS)
|
||||
if outfile is not None:
|
||||
with open(outfile, 'w') as out:
|
||||
out.write(spec)
|
||||
|
@ -219,9 +229,10 @@ If building phase 1:
|
|||
if args.phase == 0:
|
||||
build_phase0_spec(*args.files)
|
||||
elif args.phase == 1:
|
||||
if len(args.files) == 3:
|
||||
print(args.files)
|
||||
if len(args.files) == 4:
|
||||
build_phase1_spec(*args.files)
|
||||
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:
|
||||
print("Invalid phase: {0}".format(args.phase))
|
||||
|
|
|
@ -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) |
|
||||
| `MAX_SHARD_ATTESTIONS` | `2**4` (= 16) |
|
||||
| `PHASE_1_GENESIS_EPOCH` | **TBD** |
|
||||
| `PHASE_1_GENESIS_SLOT` | get_epoch_start_slot(PHASE_1_GENESIS_EPOCH) |
|
||||
| `PHASE_1_GENESIS_SLOT` | **TBD** |
|
||||
|
||||
### Time parameters
|
||||
|
||||
|
@ -291,7 +291,7 @@ def is_valid_shard_block(beacon_blocks: List[BeaconBlock],
|
|||
# Check beacon block
|
||||
beacon_block = beacon_blocks[candidate.slot]
|
||||
assert candidate.beacon_block_root == signing_root(beacon_block)
|
||||
assert beacon_block.slot <= candidate.slot:
|
||||
assert beacon_block.slot <= candidate.slot
|
||||
|
||||
# Check state root
|
||||
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:
|
||||
# Check shard block
|
||||
shard_block = next(
|
||||
block for block in valid_shard_blocks if
|
||||
signing_root(block) == candidate.data.shard_block_root
|
||||
, None)
|
||||
(block for block in valid_shard_blocks if signing_root(block) == candidate.data.shard_block_root),
|
||||
None,
|
||||
)
|
||||
assert shard_block != None
|
||||
assert shard_block.slot == candidate.data.slot
|
||||
assert shard_block.shard == candidate.data.shard
|
||||
|
|
Loading…
Reference in New Issue