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

Crosslinks store start and end epoch #1097

Merged
merged 5 commits into from
May 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 5 additions & 3 deletions specs/core/0_beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,9 @@ The types are defined topologically to aid in facilitating an executable version
{
# Shard number
'shard': 'uint64',
# Epoch number
'epoch': 'uint64',
# Crosslinking data from epochs [start....end-1]
'start_epoch': 'uint64',
'end_epoch': 'uint64',
# Root of the previous crosslink
'parent_root': 'bytes32',
# Root of the crosslinked shard data since the previous crosslink
Expand Down Expand Up @@ -1728,7 +1729,8 @@ def process_attestation(state: BeaconState, attestation: Attestation) -> None:

# Check FFG data, crosslink data, and signature
assert ffg_data == (data.source_epoch, data.source_root, data.target_epoch)
assert data.crosslink.epoch == min(data.target_epoch, parent_crosslink.epoch + MAX_EPOCHS_PER_CROSSLINK)
assert data.crosslink.start_epoch == parent_crosslink.end_epoch
assert data.crosslink.end_epoch == min(data.target_epoch, parent_crosslink.end_epoch + MAX_EPOCHS_PER_CROSSLINK)
assert data.crosslink.parent_root == hash_tree_root(parent_crosslink)
assert data.crosslink.data_root == ZERO_HASH # [to be removed in phase 1]
validate_indexed_attestation(state, convert_to_indexed(state, attestation))
Expand Down
6 changes: 4 additions & 2 deletions specs/validator/0_beacon-chain-validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,12 @@ Set `attestation_data.beacon_block_root = signing_root(head_block)`.

##### Crosslink vote

Construct `attestation_data.crosslink` via the following
Construct `attestation_data.crosslink` via the following.

* Set `attestation_data.crosslink.shard = shard` where `shard` is the shard associated with the validator's committee.
* Set `attestation_data.crosslink.epoch = min(attestation_data.target_epoch, head_state.current_crosslinks[shard].epoch + MAX_EPOCHS_PER_CROSSLINK)`.
* Let `parent_crosslink = head_state.current_crosslinks[shard]`.
* Set `attestation_data.crosslink.start_epoch = parent_crosslink.end_epoch`.
* Set `attestation_data.crosslink.end_epoch = min(attestation_data.target_epoch, parent_crosslink.end_epoch + MAX_EPOCHS_PER_CROSSLINK)`.
* Set `attestation_data.crosslink.parent_root = hash_tree_root(head_state.current_crosslinks[shard])`.
* Set `attestation_data.crosslink.data_root = ZERO_HASH`. *Note*: This is a stub for Phase 0.

Expand Down
2 changes: 1 addition & 1 deletion test_libs/pyspec/eth2spec/utils/bls_stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ def bls_verify_multiple(pubkeys, message_hashes, signature, domain):


def bls_aggregate_pubkeys(pubkeys):
return b'\x42' * 96
return b'\x42' * 48
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ def test_success_prevous_epoch(state):
return pre_state, attestation, post_state


def test_success_since_max_epochs_per_crosslink(state):
for _ in range(spec.MAX_EPOCHS_PER_CROSSLINK + 2):
next_epoch(state)

attestation = get_valid_attestation(state)
data = attestation.data
assert data.crosslink.end_epoch - data.crosslink.start_epoch == spec.MAX_EPOCHS_PER_CROSSLINK

for _ in range(spec.MIN_ATTESTATION_INCLUSION_DELAY):
next_slot(state)

pre_state, post_state = run_attestation_processing(state, attestation)

return pre_state, attestation, post_state


def test_before_inclusion_delay(state):
attestation = get_valid_attestation(state)
# do not increment slot to allow for inclusion delay
Expand Down Expand Up @@ -124,7 +140,33 @@ def test_bad_previous_crosslink(state):
for _ in range(spec.MIN_ATTESTATION_INCLUSION_DELAY):
next_slot(state)

state.current_crosslinks[attestation.data.crosslink.shard].epoch += 10
attestation.data.crosslink.parent_root = b'\x27' * 32

pre_state, post_state = run_attestation_processing(state, attestation, False)

return pre_state, attestation, post_state


def test_bad_crosslink_start_epoch(state):
next_epoch(state)
attestation = get_valid_attestation(state)
for _ in range(spec.MIN_ATTESTATION_INCLUSION_DELAY):
next_slot(state)

attestation.data.crosslink.start_epoch += 1

pre_state, post_state = run_attestation_processing(state, attestation, False)

return pre_state, attestation, post_state


def test_bad_crosslink_end_epoch(state):
next_epoch(state)
attestation = get_valid_attestation(state)
for _ in range(spec.MIN_ATTESTATION_INCLUSION_DELAY):
next_slot(state)

attestation.data.crosslink.end_epoch += 1

pre_state, post_state = run_attestation_processing(state, attestation, False)

Expand Down
6 changes: 4 additions & 2 deletions test_libs/pyspec/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def build_attestation_data(state, slot, shard):
justified_block_root = state.current_justified_root

crosslinks = state.current_crosslinks if slot_to_epoch(slot) == get_current_epoch(state) else state.previous_crosslinks
parent_crosslink = crosslinks[shard]
return AttestationData(
beacon_block_root=block_root,
source_epoch=justified_epoch,
Expand All @@ -185,9 +186,10 @@ def build_attestation_data(state, slot, shard):
target_root=epoch_boundary_root,
crosslink=Crosslink(
shard=shard,
epoch=min(slot_to_epoch(slot), crosslinks[shard].epoch + MAX_EPOCHS_PER_CROSSLINK),
start_epoch=parent_crosslink.end_epoch,
end_epoch=min(slot_to_epoch(slot), parent_crosslink.end_epoch + MAX_EPOCHS_PER_CROSSLINK),
data_root=spec.ZERO_HASH,
parent_root=hash_tree_root(crosslinks[shard]),
parent_root=hash_tree_root(parent_crosslink),
),
)

Expand Down