Rename some `shard_blocks` to `shard_block_dict`

This commit is contained in:
Hsiao-Wei Wang 2020-06-19 18:11:28 +08:00
parent 520ad97c3e
commit ea59193157
No known key found for this signature in database
GPG Key ID: 95B070122902DEA4
4 changed files with 16 additions and 12 deletions

View File

@ -72,7 +72,7 @@ def apply_shard_and_beacon(spec, state, store, shard_store, shard_blocks_buffer)
shard_transitions = get_shard_transitions(
spec,
state,
shard_blocks={shard: shard_blocks_buffer},
shard_block_dict={shard: shard_blocks_buffer},
)
shard_transition = shard_transitions[shard]
attestation = get_valid_on_time_attestation(

View File

@ -30,7 +30,7 @@ def build_shard_block(spec,
slot = shard_parent_state.slot + 1
if body is None:
body = b'\x56' * 128
body = get_sample_shard_block_body()
beacon_state, beacon_parent_root = get_state_and_beacon_parent_root_at_slot(spec, beacon_state, slot)
proposer_index = spec.get_shard_proposer_index(beacon_state, slot, shard)
@ -52,10 +52,10 @@ def build_shard_block(spec,
return signed_block
def get_shard_transitions(spec, parent_beacon_state, shard_blocks):
def get_shard_transitions(spec, parent_beacon_state, shard_block_dict):
shard_transitions = [spec.ShardTransition()] * spec.MAX_SHARDS
on_time_slot = parent_beacon_state.slot + 1
for shard, blocks in shard_blocks.items():
for shard, blocks in shard_block_dict.items():
shard_transition = spec.get_shard_transition(parent_beacon_state, shard, blocks)
offset_slots = spec.compute_offset_slots(
spec.get_latest_slot_for_shard(parent_beacon_state, shard),
@ -81,3 +81,7 @@ def get_committee_index_of_shard(spec, state, slot, shard): # Optional[Committe
if (start_shard + committee_index) % active_shard_count == shard:
return committee_index
return None
def get_sample_shard_block_body():
return b'\x56' * 128

View File

@ -16,7 +16,7 @@ def run_basic_crosslink_tests(spec, state, target_len_offset_slot, valid=True):
state = transition_to_valid_shard_slot(spec, state)
committee_index = spec.CommitteeIndex(0)
init_slot = state.slot
shard_slot = state.slot + target_len_offset_slot - 1
shard_slot = init_slot + target_len_offset_slot - 1
shard = spec.compute_shard_from_committee_index(state, committee_index, shard_slot)
assert state.shard_states[shard].slot == init_slot - 1
@ -31,7 +31,7 @@ def run_basic_crosslink_tests(spec, state, target_len_offset_slot, valid=True):
shard_transitions = get_shard_transitions(
spec,
state,
shard_blocks={shard: shard_blocks},
shard_block_dict={shard: shard_blocks},
)
shard_transition = shard_transitions[shard]
attestation = get_valid_on_time_attestation(

View File

@ -19,9 +19,9 @@ def run_beacon_block_with_shard_blocks(spec, state, target_len_offset_slot, comm
body = b'\x56' * spec.MAX_SHARD_BLOCK_SIZE
shard_block = build_shard_block(spec, state, shard, body=body, slot=state.slot, signed=True)
shard_blocks: Dict[spec.Shard, Sequence[spec.SignedShardBlock]] = {shard: [shard_block]}
shard_block_dict: Dict[spec.Shard, Sequence[spec.SignedShardBlock]] = {shard: [shard_block]}
shard_transitions = get_shard_transitions(spec, state, shard_blocks)
shard_transitions = get_shard_transitions(spec, state, shard_block_dict)
attestations = [
get_valid_on_time_attestation(
spec,
@ -30,7 +30,7 @@ def run_beacon_block_with_shard_blocks(spec, state, target_len_offset_slot, comm
shard_transition=shard_transitions[shard],
signed=True,
)
for shard in shard_blocks.keys()
for shard in shard_block_dict.keys()
]
beacon_block = build_empty_block(spec, state, slot=state.slot + 1)
@ -50,16 +50,16 @@ def run_beacon_block_with_shard_blocks(spec, state, target_len_offset_slot, comm
for shard in range(spec.get_active_shard_count(state)):
post_shard_state = state.shard_states[shard]
if shard in shard_blocks:
if shard in shard_block_dict:
# Shard state has been changed to state_transition result
assert post_shard_state == shard_transitions[shard].shard_states[
len(shard_transitions[shard].shard_states) - 1
]
assert post_shard_state.slot == state.slot - 1
if len(shard_blocks[shard]) == 0:
if len((shard_block_dict[shard])) == 0:
# `latest_block_root` is the same
assert post_shard_state.latest_block_root == pre_shard_states[shard].latest_block_root
if target_len_offset_slot == 1 and len(shard_blocks) > 0:
if target_len_offset_slot == 1 and len(shard_block_dict[shard]) > 0:
assert post_shard_state.gasprice > pre_gasprice