Fix tests
This commit is contained in:
parent
a6e825d460
commit
5fb32fd19b
|
@ -72,7 +72,7 @@ MIN_VALIDATOR_WITHDRAWABILITY_DELAY: 256
|
|||
# 2**11 (= 2,048) epochs 9 days
|
||||
PERSISTENT_COMMITTEE_PERIOD: 2048
|
||||
# 2**6 (= 64) epochs ~7 hours
|
||||
MAX_CROSSLINK_EPOCHS: 64
|
||||
MAX_EPOCHS_PER_CROSSLINK: 64
|
||||
# 2**2 (= 4) epochs 25.6 minutes
|
||||
MIN_EPOCHS_TO_INACTIVITY_PENALTY: 4
|
||||
|
||||
|
@ -124,4 +124,4 @@ DOMAIN_RANDAO: 1
|
|||
DOMAIN_ATTESTATION: 2
|
||||
DOMAIN_DEPOSIT: 3
|
||||
DOMAIN_VOLUNTARY_EXIT: 4
|
||||
DOMAIN_TRANSFER: 5
|
||||
DOMAIN_TRANSFER: 5
|
||||
|
|
|
@ -71,7 +71,7 @@ MIN_VALIDATOR_WITHDRAWABILITY_DELAY: 256
|
|||
# 2**11 (= 2,048) epochs 9 days
|
||||
PERSISTENT_COMMITTEE_PERIOD: 2048
|
||||
# 2**6 (= 64) epochs ~7 hours
|
||||
MAX_CROSSLINK_EPOCHS: 64
|
||||
MAX_EPOCHS_PER_CROSSLINK: 64
|
||||
# 2**2 (= 4) epochs 25.6 minutes
|
||||
MIN_EPOCHS_TO_INACTIVITY_PENALTY: 4
|
||||
|
||||
|
@ -123,4 +123,4 @@ DOMAIN_RANDAO: 1
|
|||
DOMAIN_ATTESTATION: 2
|
||||
DOMAIN_DEPOSIT: 3
|
||||
DOMAIN_VOLUNTARY_EXIT: 4
|
||||
DOMAIN_TRANSFER: 5
|
||||
DOMAIN_TRANSFER: 5
|
||||
|
|
|
@ -206,10 +206,10 @@ These configurations are updated for releases, but may be out of sync during `de
|
|||
| `SLOTS_PER_HISTORICAL_ROOT` | `2**13` (= 8,192) | slots | ~13 hours |
|
||||
| `MIN_VALIDATOR_WITHDRAWABILITY_DELAY` | `2**8` (= 256) | epochs | ~27 hours |
|
||||
| `PERSISTENT_COMMITTEE_PERIOD` | `2**11` (= 2,048) | epochs | 9 days |
|
||||
| `MAX_CROSSLINK_EPOCHS` | `2**6` (= 64) | epochs | ~7 hours |
|
||||
| `MAX_EPOCHS_PER_CROSSLINK` | `2**6` (= 64) | epochs | ~7 hours |
|
||||
| `MIN_EPOCHS_TO_INACTIVITY_PENALTY` | `2**2` (= 4) | epochs | 25.6 minutes |
|
||||
|
||||
* `MAX_CROSSLINK_EPOCHS` should be a small constant times `SHARD_COUNT // SLOTS_PER_EPOCH`
|
||||
* `MAX_EPOCHS_PER_CROSSLINK` should be a small constant times `SHARD_COUNT // SLOTS_PER_EPOCH`
|
||||
|
||||
### State list lengths
|
||||
|
||||
|
@ -1715,7 +1715,7 @@ 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, previous_crosslink.epoch + MAX_CROSSLINK_EPOCHS)
|
||||
assert data.crosslink.epoch == min(data.target_epoch, previous_crosslink.epoch + MAX_EPOCHS_PER_CROSSLINK)
|
||||
assert data.crosslink.previous_crosslink_root == hash_tree_root(previous_crosslink)
|
||||
assert data.crosslink.crosslink_data_root == ZERO_HASH # [to be removed in phase 1]
|
||||
assert verify_indexed_attestation(state, convert_to_indexed(state, attestation))
|
||||
|
|
|
@ -265,7 +265,7 @@ The `empty` function accepts and SSZ type as input and returns an object of that
|
|||
def get_custody_chunk_count(attestation: Attestation) -> int:
|
||||
crosslink_start_epoch = attestation.data.latest_crosslink.epoch
|
||||
crosslink_end_epoch = slot_to_epoch(attestation.data.slot)
|
||||
crosslink_crosslink_length = min(MAX_CROSSLINK_EPOCHS, end_epoch - start_epoch)
|
||||
crosslink_crosslink_length = min(MAX_EPOCHS_PER_CROSSLINK, end_epoch - start_epoch)
|
||||
chunks_per_epoch = 2 * BYTES_PER_SHARD_BLOCK * SLOTS_PER_EPOCH // BYTES_PER_CUSTODY_CHUNK
|
||||
return crosslink_crosslink_length * chunks_per_epoch
|
||||
```
|
||||
|
@ -426,10 +426,10 @@ def process_early_derived_secret_reveal(state: BeaconState,
|
|||
# round key
|
||||
slash_validator(state, reveal.revealed_index, reveal.masker_index)
|
||||
else:
|
||||
# Only a small penalty proportional to proposer slot reward for RANDAO reveal
|
||||
# Only a small penalty proportional to proposer slot reward for RANDAO reveal
|
||||
# that does not interfere with the custody period
|
||||
# The penalty is proportional to the max proposer reward
|
||||
|
||||
# The penalty is proportional to the max proposer reward
|
||||
|
||||
# Calculate penalty
|
||||
max_proposer_slot_reward = (
|
||||
get_base_reward(state, reveal.revealed_index) *
|
||||
|
@ -448,7 +448,7 @@ def process_early_derived_secret_reveal(state: BeaconState,
|
|||
increase_balance(state, whistleblower_index, whistleblowing_reward - proposer_reward)
|
||||
decrease_balance(state, reveal.revealed_index, penalty)
|
||||
|
||||
# Mark this derived secret as exposed so validator cannot be punished repeatedly
|
||||
# Mark this derived secret as exposed so validator cannot be punished repeatedly
|
||||
state.exposed_derived_secrets[reveal.epoch % EARLY_DERIVED_SECRET_PENALTY_MAX_FUTURE_EPOCHS].append(reveal.revealed_index)
|
||||
|
||||
```
|
||||
|
@ -474,7 +474,7 @@ def process_chunk_challenge(state: BeaconState,
|
|||
# Verify the challenge is not a duplicate
|
||||
for record in state.custody_chunk_challenge_records:
|
||||
assert (
|
||||
record.crosslink_data_root != challenge.attestation.data.crosslink_data_root or
|
||||
record.crosslink_data_root != challenge.attestation.data.crosslink.crosslink_data_root or
|
||||
record.chunk_index != challenge.chunk_index
|
||||
)
|
||||
# Verify depth
|
||||
|
@ -486,7 +486,7 @@ def process_chunk_challenge(state: BeaconState,
|
|||
challenger_index=get_beacon_proposer_index(state),
|
||||
responder_index=challenge.responder_index
|
||||
deadline=get_current_epoch(state) + CUSTODY_RESPONSE_DEADLINE,
|
||||
crosslink_data_root=challenge.attestation.data.crosslink_data_root,
|
||||
crosslink_data_root=challenge.attestation.data.crosslink.crosslink_data_root,
|
||||
depth=depth,
|
||||
chunk_index=challenge.chunk_index,
|
||||
)
|
||||
|
@ -564,7 +564,7 @@ def process_bit_challenge(state: BeaconState,
|
|||
challenger_index=challenge.challenger_index,
|
||||
responder_index=challenge.responder_index,
|
||||
deadline=get_current_epoch(state) + CUSTODY_RESPONSE_DEADLINE,
|
||||
crosslink_data_root=challenge.attestation.data.crosslink_data_root,
|
||||
crosslink_data_root=challenge.attestation.data.crosslink.crosslink_data_root,
|
||||
chunk_count=chunk_count,
|
||||
chunk_bits_merkle_root=merkle_root(pad_to_power_of_2((challenge.chunk_bits))),
|
||||
responder_key=challenge.responder_key,
|
||||
|
|
|
@ -215,7 +215,7 @@ def get_shard_header(block: ShardBlock) -> ShardBlockHeader:
|
|||
def verify_shard_attestation_signature(state: BeaconState,
|
||||
attestation: ShardAttestation) -> None:
|
||||
data = attestation.data
|
||||
persistent_committee = get_persistent_committee(state, data.shard, data.slot)
|
||||
persistent_committee = get_persistent_committee(state, data.crosslink.shard, data.slot)
|
||||
assert verify_bitfield(attestation.aggregation_bitfield, len(persistent_committee))
|
||||
pubkeys = []
|
||||
for i, index in enumerate(persistent_committee):
|
||||
|
@ -225,7 +225,7 @@ def verify_shard_attestation_signature(state: BeaconState,
|
|||
pubkeys.append(validator.pubkey)
|
||||
assert bls_verify(
|
||||
pubkey=bls_aggregate_pubkeys(pubkeys),
|
||||
message_hash=data.shard_block_root,
|
||||
message_hash=data.crosslink.shard_block_root,
|
||||
signature=attestation.aggregate_signature,
|
||||
domain=get_domain(state, slot_to_epoch(data.slot), DOMAIN_SHARD_ATTESTER)
|
||||
)
|
||||
|
@ -312,7 +312,7 @@ def is_valid_shard_block(beacon_blocks: List[BeaconBlock],
|
|||
for _, attestation in enumerate(block.attestations):
|
||||
assert max(GENESIS_SHARD_SLOT, block.slot - SLOTS_PER_EPOCH) <= attestation.data.slot
|
||||
assert attestation.data.slot <= block.slot - MIN_ATTESTATION_INCLUSION_DELAY
|
||||
assert attestation.data.shard == block.shard
|
||||
assert attestation.data.crosslink.shard == block.shard
|
||||
verify_shard_attestation_signature(beacon_state, attestation)
|
||||
|
||||
# Check signature
|
||||
|
@ -343,11 +343,11 @@ def is_valid_shard_attestation(valid_shard_blocks: List[ShardBlock],
|
|||
# Check shard block
|
||||
shard_block = next(
|
||||
block for block in valid_shard_blocks if
|
||||
signing_root(block) == candidate.attestation.data.shard_block_root
|
||||
signing_root(block) == candidate.attestation.data.crosslink.shard_block_root
|
||||
, None)
|
||||
assert shard_block != None
|
||||
assert shard_block.slot == attestation.data.slot
|
||||
assert shard_block.shard == attestation.data.shard
|
||||
assert shard_block.shard == attestation.data.crosslink.shard
|
||||
|
||||
# Check signature
|
||||
verify_shard_attestation_signature(beacon_state, attestation)
|
||||
|
@ -382,18 +382,18 @@ def is_valid_beacon_attestation(shard: Shard,
|
|||
else:
|
||||
previous_attestation = next(
|
||||
attestation for attestation in valid_attestations if
|
||||
attestation.data.crosslink_data_root == candidate.data.previous_crosslink.crosslink_data_root
|
||||
attestation.data.crosslink.crosslink_data_root == candidate.data.previous_crosslink.crosslink_data_root
|
||||
, None)
|
||||
assert previous_attestation != None
|
||||
assert candidate.data.previous_attestation.epoch < slot_to_epoch(candidate.data.slot)
|
||||
|
||||
# Check crosslink data root
|
||||
start_epoch = state.latest_crosslinks[shard].epoch
|
||||
end_epoch = min(slot_to_epoch(candidate.data.slot) - CROSSLINK_LOOKBACK, start_epoch + MAX_CROSSLINK_EPOCHS)
|
||||
end_epoch = min(slot_to_epoch(candidate.data.slot) - CROSSLINK_LOOKBACK, start_epoch + MAX_EPOCHS_PER_CROSSLINK)
|
||||
blocks = []
|
||||
for slot in range(start_epoch * SLOTS_PER_EPOCH, end_epoch * SLOTS_PER_EPOCH):
|
||||
blocks.append(shard_blocks[slot])
|
||||
assert candidate.data.crosslink_data_root == compute_crosslink_data_root(blocks)
|
||||
assert candidate.data.crosslink.crosslink_data_root == compute_crosslink_data_root(blocks)
|
||||
|
||||
return True
|
||||
```
|
||||
|
|
|
@ -271,7 +271,7 @@ _Note:_ This can be looked up in the state using:
|
|||
|
||||
##### Shard
|
||||
|
||||
Set `attestation_data.shard = shard` where `shard` is the shard associated with the validator's committee defined by `get_crosslink_committees_at_slot`.
|
||||
Set `attestation_data.crosslink.shard = shard` where `shard` is the shard associated with the validator's committee defined by `get_crosslink_committees_at_slot`.
|
||||
|
||||
##### Previous crosslink root
|
||||
|
||||
|
@ -279,7 +279,7 @@ Set `attestation_data.previous_crosslink_root = hash_tree_root(head_state.curren
|
|||
|
||||
##### Crosslink data root
|
||||
|
||||
Set `attestation_data.crosslink_data_root = ZERO_HASH`.
|
||||
Set `attestation_data.crosslink.crosslink_data_root = ZERO_HASH`.
|
||||
|
||||
_Note:_ This is a stub for phase 0.
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ def test_non_zero_crosslink_data_root(state):
|
|||
attestation = get_valid_attestation(state)
|
||||
state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY
|
||||
|
||||
attestation.data.crosslink_data_root = b'\x42' * 32
|
||||
attestation.data.crosslink.crosslink_data_root = b'\x42' * 32
|
||||
|
||||
pre_state, post_state = run_attestation_processing(state, attestation, False)
|
||||
|
||||
|
@ -126,7 +126,7 @@ def test_bad_previous_crosslink(state):
|
|||
for _ in range(spec.MIN_ATTESTATION_INCLUSION_DELAY):
|
||||
next_slot(state)
|
||||
|
||||
state.current_crosslinks[attestation.data.shard].epoch += 10
|
||||
state.current_crosslinks[attestation.data.crosslink.shard].epoch += 10
|
||||
|
||||
pre_state, post_state = run_attestation_processing(state, attestation, False)
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ def test_single_crosslink_update_from_current_epoch(state):
|
|||
|
||||
pre_state, post_state = run_process_crosslinks(state)
|
||||
|
||||
shard = attestation.data.shard
|
||||
shard = attestation.data.crosslink.shard
|
||||
assert post_state.previous_crosslinks[shard] != post_state.current_crosslinks[shard]
|
||||
assert pre_state.current_crosslinks[shard] != post_state.current_crosslinks[shard]
|
||||
|
||||
|
@ -84,11 +84,11 @@ def test_single_crosslink_update_from_previous_epoch(state):
|
|||
pre_state, post_state = run_process_crosslinks(state)
|
||||
crosslink_deltas = get_crosslink_deltas(state)
|
||||
|
||||
shard = attestation.data.shard
|
||||
shard = attestation.data.crosslink.shard
|
||||
assert post_state.previous_crosslinks[shard] != post_state.current_crosslinks[shard]
|
||||
assert pre_state.current_crosslinks[shard] != post_state.current_crosslinks[shard]
|
||||
# ensure rewarded
|
||||
for index in get_crosslink_committee(state, attestation.data.target_epoch, attestation.data.shard):
|
||||
for index in get_crosslink_committee(state, attestation.data.target_epoch, attestation.data.crosslink.shard):
|
||||
assert crosslink_deltas[0][index] > 0
|
||||
assert crosslink_deltas[1][index] == 0
|
||||
|
||||
|
@ -108,7 +108,7 @@ def test_double_late_crosslink(state):
|
|||
|
||||
for slot in range(spec.SLOTS_PER_EPOCH):
|
||||
attestation_2 = get_valid_attestation(state)
|
||||
if attestation_2.data.shard == attestation_1.data.shard:
|
||||
if attestation_2.data.crosslink.shard == attestation_1.data.crosslink.shard:
|
||||
break
|
||||
next_slot(state)
|
||||
fill_aggregate_attestation(state, attestation_2)
|
||||
|
@ -124,12 +124,12 @@ def test_double_late_crosslink(state):
|
|||
pre_state, post_state = run_process_crosslinks(state)
|
||||
crosslink_deltas = get_crosslink_deltas(state)
|
||||
|
||||
shard = attestation_2.data.shard
|
||||
shard = attestation_2.data.crosslink.shard
|
||||
|
||||
# ensure that the current crosslinks were not updated by the second attestation
|
||||
assert post_state.previous_crosslinks[shard] == post_state.current_crosslinks[shard]
|
||||
# ensure no reward, only penalties for the failed crosslink
|
||||
for index in get_crosslink_committee(state, attestation_2.data.target_epoch, attestation_2.data.shard):
|
||||
for index in get_crosslink_committee(state, attestation_2.data.target_epoch, attestation_2.data.crosslink.shard):
|
||||
assert crosslink_deltas[0][index] == 0
|
||||
assert crosslink_deltas[1][index] > 0
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ from eth2spec.utils.minimal_ssz import signing_root
|
|||
from eth2spec.phase0.spec import (
|
||||
# constants
|
||||
ZERO_HASH,
|
||||
MAX_EPOCHS_PER_CROSSLINK,
|
||||
# SSZ
|
||||
Attestation,
|
||||
AttestationData,
|
||||
|
@ -17,6 +18,7 @@ from eth2spec.phase0.spec import (
|
|||
AttesterSlashing,
|
||||
BeaconBlock,
|
||||
BeaconBlockHeader,
|
||||
Crosslink,
|
||||
Deposit,
|
||||
DepositData,
|
||||
Eth1Data,
|
||||
|
@ -174,14 +176,17 @@ def build_attestation_data(state, slot, shard):
|
|||
|
||||
crosslinks = state.current_crosslinks if slot_to_epoch(slot) == get_current_epoch(state) else state.previous_crosslinks
|
||||
return AttestationData(
|
||||
shard=shard,
|
||||
beacon_block_root=block_root,
|
||||
source_epoch=justified_epoch,
|
||||
source_root=justified_block_root,
|
||||
target_epoch=slot_to_epoch(slot),
|
||||
target_root=epoch_boundary_root,
|
||||
crosslink_data_root=spec.ZERO_HASH,
|
||||
previous_crosslink_root=hash_tree_root(crosslinks[shard]),
|
||||
crosslink=Crosslink(
|
||||
shard=shard,
|
||||
epoch=min(slot_to_epoch(slot), crosslinks[shard].epoch + MAX_EPOCHS_PER_CROSSLINK),
|
||||
crosslink_data_root=spec.ZERO_HASH,
|
||||
previous_crosslink_root=hash_tree_root(crosslinks[shard]),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
@ -288,7 +293,7 @@ def get_valid_attestation(state, slot=None):
|
|||
|
||||
attestation_data = build_attestation_data(state, slot, shard)
|
||||
|
||||
crosslink_committee = get_crosslink_committee(state, attestation_data.target_epoch, attestation_data.shard)
|
||||
crosslink_committee = get_crosslink_committee(state, attestation_data.target_epoch, attestation_data.crosslink.shard)
|
||||
|
||||
committee_size = len(crosslink_committee)
|
||||
bitfield_length = (committee_size + 7) // 8
|
||||
|
@ -381,7 +386,7 @@ def get_attestation_signature(state, attestation_data, privkey, custody_bit=0b0)
|
|||
|
||||
|
||||
def fill_aggregate_attestation(state, attestation):
|
||||
crosslink_committee = get_crosslink_committee(state, attestation.data.target_epoch, attestation.data.shard)
|
||||
crosslink_committee = get_crosslink_committee(state, attestation.data.target_epoch, attestation.data.crosslink.shard)
|
||||
for i in range(len(crosslink_committee)):
|
||||
attestation.aggregation_bitfield = set_bitfield_bit(attestation.aggregation_bitfield, i)
|
||||
|
||||
|
|
Loading…
Reference in New Issue