diff --git a/eth2/beacon/epoch_processing_helpers.py b/eth2/beacon/epoch_processing_helpers.py index 984b2a31a6..58be9ac50f 100644 --- a/eth2/beacon/epoch_processing_helpers.py +++ b/eth2/beacon/epoch_processing_helpers.py @@ -104,19 +104,19 @@ def get_winning_root( committee_config: CommitteeConfig) -> Tuple[Hash32, Gwei]: winning_root = None winning_root_balance: Gwei = Gwei(0) - shard_block_roots = set( + crosslink_data_roots = set( [ - a.data.shard_block_root for a in attestations + a.data.crosslink_data_root for a in attestations if a.data.shard == shard ] ) - for shard_block_root in shard_block_roots: + for crosslink_data_root in crosslink_data_roots: attesting_validator_indices = get_attester_indices_from_attesttion( state=state, attestations=[ a for a in attestations - if a.data.shard == shard and a.data.shard_block_root == shard_block_root + if a.data.shard == shard and a.data.crosslink_data_root == crosslink_data_root ], committee_config=committee_config, ) @@ -126,11 +126,11 @@ def get_winning_root( max_deposit_amount, ) if total_attesting_balance > winning_root_balance: - winning_root = shard_block_root + winning_root = crosslink_data_root winning_root_balance = total_attesting_balance elif total_attesting_balance == winning_root_balance and winning_root_balance > 0: - if shard_block_root < winning_root: - winning_root = shard_block_root + if crosslink_data_root < winning_root: + winning_root = crosslink_data_root if winning_root is None: raise NoWinningRootError diff --git a/eth2/beacon/on_genesis.py b/eth2/beacon/on_genesis.py index 960bb9b9eb..0479e644d8 100644 --- a/eth2/beacon/on_genesis.py +++ b/eth2/beacon/on_genesis.py @@ -108,7 +108,7 @@ def get_genesis_beacon_state(*, # Recent state latest_crosslinks=( - (CrosslinkRecord(epoch=genesis_epoch, shard_block_root=ZERO_HASH32),) * shard_count + (CrosslinkRecord(epoch=genesis_epoch, crosslink_data_root=ZERO_HASH32),) * shard_count ), latest_block_roots=(ZERO_HASH32,) * latest_block_roots_length, latest_active_index_roots=(ZERO_HASH32,) * latest_active_index_roots_length, diff --git a/eth2/beacon/state_machines/forks/serenity/block_validation.py b/eth2/beacon/state_machines/forks/serenity/block_validation.py index 0cfb0835c1..405fc237c1 100644 --- a/eth2/beacon/state_machines/forks/serenity/block_validation.py +++ b/eth2/beacon/state_machines/forks/serenity/block_validation.py @@ -262,10 +262,10 @@ def validate_attestation(state: BeaconState, validate_attestation_latest_crosslink_root( attestation.data, - latest_crosslink_root=state.latest_crosslinks[attestation.data.shard].shard_block_root, + latest_crosslink_root=state.latest_crosslinks[attestation.data.shard].crosslink_data_root, ) - validate_attestation_shard_block_root(attestation.data) + validate_attestation_crosslink_data_root(attestation.data) validate_attestation_aggregate_signature( state, @@ -360,41 +360,41 @@ def validate_attestation_justified_block_root(attestation_data: AttestationData, def validate_attestation_latest_crosslink_root(attestation_data: AttestationData, latest_crosslink_root: Hash32) -> None: """ - Validate that either the attestation ``latest_crosslink_root`` or ``shard_block_root`` + Validate that either the attestation ``latest_crosslink_root`` or ``crosslink_data_root`` field of ``attestation_data`` is the provided ``latest_crosslink_root``. Raise ``ValidationError`` if it's invalid. """ - acceptable_shard_block_roots = { + acceptable_crosslink_data_roots = { attestation_data.latest_crosslink_root, - attestation_data.shard_block_root, + attestation_data.crosslink_data_root, } - if latest_crosslink_root not in acceptable_shard_block_roots: + if latest_crosslink_root not in acceptable_crosslink_data_roots: raise ValidationError( "Neither the attestation ``latest_crosslink_root`` nor the attestation " - "``shard_block_root`` are equal to the ``latest_crosslink_root``.\n" + "``crosslink_data_root`` are equal to the ``latest_crosslink_root``.\n" "\tFound: %s and %s, Expected %s" % ( attestation_data.latest_crosslink_root, - attestation_data.shard_block_root, + attestation_data.crosslink_data_root, latest_crosslink_root, ) ) -def validate_attestation_shard_block_root(attestation_data: AttestationData) -> None: +def validate_attestation_crosslink_data_root(attestation_data: AttestationData) -> None: """ - Validate ``shard_block_root`` field of `attestation_data`. + Validate ``crosslink_data_root`` field of `attestation_data`. Raise ``ValidationError`` if it's invalid. - Note: This is the Phase 0 version of ``shard_block_root`` validation. + Note: This is the Phase 0 version of ``crosslink_data_root`` validation. This is a built-in stub and will be changed in phase 1. """ - if attestation_data.shard_block_root != ZERO_HASH32: + if attestation_data.crosslink_data_root != ZERO_HASH32: raise ValidationError( - "Attestation ``shard_block_root`` is not ZERO_HASH32.\n" + "Attestation ``crosslink_data_root`` is not ZERO_HASH32.\n" "\tFound: %s, Expected %s" % ( - attestation_data.shard_block_root, + attestation_data.crosslink_data_root, ZERO_HASH32, ) ) diff --git a/eth2/beacon/state_machines/forks/serenity/epoch_processing.py b/eth2/beacon/state_machines/forks/serenity/epoch_processing.py index 3b43dd0828..f7a2f317cd 100644 --- a/eth2/beacon/state_machines/forks/serenity/epoch_processing.py +++ b/eth2/beacon/state_machines/forks/serenity/epoch_processing.py @@ -276,7 +276,7 @@ def process_crosslinks(state: BeaconState, config: BeaconConfig) -> BeaconState: shard, CrosslinkRecord( epoch=state.current_epoch(config.SLOTS_PER_EPOCH), - shard_block_root=winning_root, + crosslink_data_root=winning_root, ), ) else: @@ -663,7 +663,7 @@ def _process_rewards_and_penalties_for_crosslinks( attestations=( a for a in filtered_attestations - if a.data.shard == shard and a.data.shard_block_root == winning_root + if a.data.shard == shard and a.data.crosslink_data_root == winning_root ), committee_config=CommitteeConfig(config), ) diff --git a/eth2/beacon/tools/builder/validator.py b/eth2/beacon/tools/builder/validator.py index 3596c7a77c..c930e6b38f 100644 --- a/eth2/beacon/tools/builder/validator.py +++ b/eth2/beacon/tools/builder/validator.py @@ -347,14 +347,14 @@ def create_mock_signed_attestations_at_slot( committee, shard = crosslink_committee num_voted_attesters = int(len(committee) * voted_attesters_ratio) - latest_crosslink_root = state.latest_crosslinks[shard].shard_block_root + latest_crosslink_root = state.latest_crosslinks[shard].crosslink_data_root attestation_data = AttestationData( slot=attestation_slot, shard=shard, beacon_block_root=beacon_block_root, epoch_boundary_root=epoch_boundary_root, - shard_block_root=ZERO_HASH32, + crosslink_data_root=ZERO_HASH32, latest_crosslink_root=latest_crosslink_root, justified_epoch=state.justified_epoch, justified_block_root=justified_block_root, diff --git a/eth2/beacon/types/attestation_data.py b/eth2/beacon/types/attestation_data.py index 3fb2eea12e..4bd86d8e18 100644 --- a/eth2/beacon/types/attestation_data.py +++ b/eth2/beacon/types/attestation_data.py @@ -27,7 +27,7 @@ class AttestationData(ssz.Serializable): # Hash of the ancestor at the epoch boundary ('epoch_boundary_root', bytes32), # Shard block root being attested to - ('shard_block_root', bytes32), + ('crosslink_data_root', bytes32), # Last crosslink hash ('latest_crosslink_root', bytes32), # epoch of the last justified beacon block @@ -41,7 +41,7 @@ def __init__(self, shard: Shard, beacon_block_root: Hash32, epoch_boundary_root: Hash32, - shard_block_root: Hash32, + crosslink_data_root: Hash32, latest_crosslink_root: Hash32, justified_epoch: Epoch, justified_block_root: Hash32) -> None: @@ -50,7 +50,7 @@ def __init__(self, shard, beacon_block_root, epoch_boundary_root, - shard_block_root, + crosslink_data_root, latest_crosslink_root, justified_epoch, justified_block_root, diff --git a/eth2/beacon/types/crosslink_records.py b/eth2/beacon/types/crosslink_records.py index 75cf947e42..de4cbe862f 100644 --- a/eth2/beacon/types/crosslink_records.py +++ b/eth2/beacon/types/crosslink_records.py @@ -17,14 +17,14 @@ class CrosslinkRecord(ssz.Serializable): # Epoch during which crosslink was added ('epoch', uint64), # Shard chain block root - ('shard_block_root', bytes32), + ('crosslink_data_root', bytes32), ] def __init__(self, epoch: Epoch, - shard_block_root: Hash32) -> None: + crosslink_data_root: Hash32) -> None: super().__init__( epoch=epoch, - shard_block_root=shard_block_root, + crosslink_data_root=crosslink_data_root, ) diff --git a/eth2/beacon/types/states.py b/eth2/beacon/types/states.py index 75b8309998..7f910337fc 100644 --- a/eth2/beacon/types/states.py +++ b/eth2/beacon/types/states.py @@ -232,7 +232,12 @@ def create_filled_state(cls, # Recent state latest_crosslinks=( - (CrosslinkRecord(epoch=genesis_epoch, shard_block_root=ZERO_HASH32),) * shard_count + ( + CrosslinkRecord( + epoch=genesis_epoch, + crosslink_data_root=ZERO_HASH32, + ), + ) * shard_count ), latest_block_roots=(ZERO_HASH32,) * latest_block_roots_length, latest_active_index_roots=(ZERO_HASH32,) * latest_active_index_roots_length, diff --git a/tests/core/p2p-proto/bcc/test_commands.py b/tests/core/p2p-proto/bcc/test_commands.py index c97362e36e..ca2d611248 100644 --- a/tests/core/p2p-proto/bcc/test_commands.py +++ b/tests/core/p2p-proto/bcc/test_commands.py @@ -166,7 +166,7 @@ async def test_send_single_attestation(request, event_loop): shard=1, beacon_block_root=ZERO_HASH32, epoch_boundary_root=ZERO_HASH32, - shard_block_root=ZERO_HASH32, + crosslink_data_root=ZERO_HASH32, latest_crosslink_root=ZERO_HASH32, justified_epoch=SERENITY_CONFIG.GENESIS_EPOCH, justified_block_root=ZERO_HASH32, @@ -193,7 +193,7 @@ async def test_send_multiple_attestations(request, event_loop): shard=shard, beacon_block_root=ZERO_HASH32, epoch_boundary_root=ZERO_HASH32, - shard_block_root=ZERO_HASH32, + crosslink_data_root=ZERO_HASH32, latest_crosslink_root=ZERO_HASH32, justified_epoch=SERENITY_CONFIG.GENESIS_EPOCH, justified_block_root=ZERO_HASH32, diff --git a/tests/eth2/beacon/conftest.py b/tests/eth2/beacon/conftest.py index bd3db42566..86d70ed6b0 100644 --- a/tests/eth2/beacon/conftest.py +++ b/tests/eth2/beacon/conftest.py @@ -106,7 +106,7 @@ def sample_attestation_data_params(): 'shard': 12, 'beacon_block_root': b'\x11' * 32, 'epoch_boundary_root': b'\x22' * 32, - 'shard_block_root': b'\x33' * 32, + 'crosslink_data_root': b'\x33' * 32, 'latest_crosslink_root': b'\x44' * 32, 'justified_epoch': 0, 'justified_block_root': b'\x55' * 32, @@ -198,7 +198,7 @@ def sample_eth1_data_vote_params(sample_eth1_data_params): def sample_crosslink_record_params(): return { 'epoch': 0, - 'shard_block_root': b'\x43' * 32, + 'crosslink_data_root': b'\x43' * 32, } @@ -586,7 +586,7 @@ def genesis_state(filled_beacon_state, latest_crosslinks=tuple( CrosslinkRecord( epoch=genesis_epoch, - shard_block_root=ZERO_HASH32, + crosslink_data_root=ZERO_HASH32, ) for _ in range(shard_count) ), diff --git a/tests/eth2/beacon/state_machines/forks/test_serenity_block_attestation_validation.py b/tests/eth2/beacon/state_machines/forks/test_serenity_block_attestation_validation.py index 0d2b5a3d21..0b62235c6c 100644 --- a/tests/eth2/beacon/state_machines/forks/test_serenity_block_attestation_validation.py +++ b/tests/eth2/beacon/state_machines/forks/test_serenity_block_attestation_validation.py @@ -20,7 +20,7 @@ validate_attestation_latest_crosslink_root, validate_attestation_justified_block_root, validate_attestation_justified_epoch, - validate_attestation_shard_block_root, + validate_attestation_crosslink_data_root, validate_attestation_slot, ) from eth2.beacon.tools.builder.validator import ( @@ -166,7 +166,7 @@ def test_validate_attestation_justified_block_root(sample_attestation_data_param @pytest.mark.parametrize( ( 'attestation_latest_crosslink_root,' - 'attestation_shard_block_root,' + 'attestation_crosslink_data_root,' 'latest_crosslink_root,' 'is_valid,' ), @@ -180,14 +180,14 @@ def test_validate_attestation_justified_block_root(sample_attestation_data_param ) def test_validate_attestation_latest_crosslink_root(sample_attestation_data_params, attestation_latest_crosslink_root, - attestation_shard_block_root, + attestation_crosslink_data_root, latest_crosslink_root, is_valid): sample_attestation_data_params['latest_crosslink_root'] = attestation_latest_crosslink_root - sample_attestation_data_params['shard_block_root'] = attestation_shard_block_root + sample_attestation_data_params['crosslink_data_root'] = attestation_crosslink_data_root attestation_data = AttestationData(**sample_attestation_data_params).copy( latest_crosslink_root=attestation_latest_crosslink_root, - shard_block_root=attestation_shard_block_root, + crosslink_data_root=attestation_crosslink_data_root, ) if is_valid: @@ -205,7 +205,7 @@ def test_validate_attestation_latest_crosslink_root(sample_attestation_data_para @pytest.mark.parametrize( ( - 'attestation_shard_block_root,' + 'attestation_crosslink_data_root,' 'is_valid,' ), [ @@ -214,20 +214,20 @@ def test_validate_attestation_latest_crosslink_root(sample_attestation_data_para (b'\x66' * 32, False), ] ) -def test_validate_attestation_shard_block_root(sample_attestation_data_params, - attestation_shard_block_root, - is_valid): +def test_validate_attestation_crosslink_data_root(sample_attestation_data_params, + attestation_crosslink_data_root, + is_valid): attestation_data = AttestationData(**sample_attestation_data_params).copy( - shard_block_root=attestation_shard_block_root, + crosslink_data_root=attestation_crosslink_data_root, ) if is_valid: - validate_attestation_shard_block_root( + validate_attestation_crosslink_data_root( attestation_data, ) else: with pytest.raises(ValidationError): - validate_attestation_shard_block_root( + validate_attestation_crosslink_data_root( attestation_data, ) diff --git a/tests/eth2/beacon/state_machines/forks/test_serenity_epoch_processing.py b/tests/eth2/beacon/state_machines/forks/test_serenity_epoch_processing.py index 92be4708cb..3568d67c25 100644 --- a/tests/eth2/beacon/state_machines/forks/test_serenity_epoch_processing.py +++ b/tests/eth2/beacon/state_machines/forks/test_serenity_epoch_processing.py @@ -293,11 +293,11 @@ def test_process_crosslinks( sample_attestation_data_params, sample_attestation_params): shard = 1 - shard_block_root = hash_eth2(b'shard_block_root') + crosslink_data_root = hash_eth2(b'crosslink_data_root') current_slot = config.SLOTS_PER_EPOCH * 2 - 1 genesis_crosslinks = tuple([ - CrosslinkRecord(epoch=config.GENESIS_EPOCH, shard_block_root=ZERO_HASH32) + CrosslinkRecord(epoch=config.GENESIS_EPOCH, crosslink_data_root=ZERO_HASH32) for _ in range(shard_count) ]) state = n_validators_state.copy( @@ -334,7 +334,7 @@ def test_process_crosslinks( data=AttestationData(**sample_attestation_data_params).copy( slot=slot_in_cur_epoch, shard=shard, - shard_block_root=shard_block_root, + crosslink_data_root=crosslink_data_root, ), aggregation_bitfield=aggregation_bitfield, ) @@ -344,18 +344,18 @@ def test_process_crosslinks( latest_attestations=cur_epoch_attestations, ) assert (state.latest_crosslinks[shard].epoch == config.GENESIS_EPOCH and - state.latest_crosslinks[shard].shard_block_root == ZERO_HASH32) + state.latest_crosslinks[shard].crosslink_data_root == ZERO_HASH32) new_state = process_crosslinks(state, config) crosslink_record = new_state.latest_crosslinks[shard] if success_crosslink_in_cur_epoch: attestation = cur_epoch_attestations[0] assert (crosslink_record.epoch == slot_to_epoch(current_slot, slots_per_epoch) and - crosslink_record.shard_block_root == attestation.data.shard_block_root and - attestation.data.shard_block_root == shard_block_root) + crosslink_record.crosslink_data_root == attestation.data.crosslink_data_root and + attestation.data.crosslink_data_root == crosslink_data_root) else: assert (crosslink_record.epoch == config.GENESIS_EPOCH and - crosslink_record.shard_block_root == ZERO_HASH32) + crosslink_record.crosslink_data_root == ZERO_HASH32) # @@ -739,13 +739,13 @@ def test_process_rewards_and_penalties_for_crosslinks( committee, shard = prev_epoch_crosslink_committees[i] # Randomly sample `num_attesting_validators` validators # from the committee to attest in this slot. - shard_block_root_attesting_validators = random.sample( + crosslink_data_root_attesting_validators = random.sample( committee, num_attesting_validators, ) - each_slot_attestion_validators_list.append(shard_block_root_attesting_validators) + each_slot_attestion_validators_list.append(crosslink_data_root_attesting_validators) participants_bitfield = get_empty_bitfield(target_committee_size) - for index in shard_block_root_attesting_validators: + for index in crosslink_data_root_attesting_validators: participants_bitfield = set_voted(participants_bitfield, committee.index(index)) data_slot = i + previous_epoch * slots_per_epoch previous_epoch_attestations.append( @@ -885,7 +885,7 @@ def test_check_if_update_validator_registry(genesis_state, if has_crosslink: crosslink = CrosslinkRecord( epoch=crosslink_epoch, - shard_block_root=ZERO_HASH32, + crosslink_data_root=ZERO_HASH32, ) latest_crosslinks = state.latest_crosslinks for shard in range(config.SHARD_COUNT): diff --git a/tests/eth2/beacon/test_epoch_processing_helpers.py b/tests/eth2/beacon/test_epoch_processing_helpers.py index 016b004a20..1f96b96d8e 100644 --- a/tests/eth2/beacon/test_epoch_processing_helpers.py +++ b/tests/eth2/beacon/test_epoch_processing_helpers.py @@ -275,19 +275,19 @@ def mock_get_crosslink_committees_at_slot(state, ) # `attestions` contains attestation to different block root by different set of participants attestations = ( - # Attestation to `shard_block_root_1` by `attestation_participants_1` + # Attestation to `crosslink_data_root_1` by `attestation_participants_1` Attestation(**sample_attestation_params).copy( data=AttestationData(**sample_attestation_data_params).copy( shard=shard, - shard_block_root=competing_block_roots[0], + crosslink_data_root=competing_block_roots[0], ), aggregation_bitfield=root_1_participants_bitfield ), - # Attestation to `shard_block_root_2` by `attestation_participants_2` + # Attestation to `crosslink_data_root_2` by `attestation_participants_2` Attestation(**sample_attestation_params).copy( data=AttestationData(**sample_attestation_data_params).copy( shard=shard, - shard_block_root=competing_block_roots[1], + crosslink_data_root=competing_block_roots[1], ), aggregation_bitfield=root_2_participants_bitfield ), @@ -306,7 +306,7 @@ def mock_get_crosslink_committees_at_slot(state, attestations=( a for a in attestations - if a.data.shard == shard and a.data.shard_block_root == winning_root + if a.data.shard == shard and a.data.crosslink_data_root == winning_root ), committee_config=committee_config, ) diff --git a/tests/eth2/beacon/test_on_genesis.py b/tests/eth2/beacon/test_on_genesis.py index 74f4ed08b7..c52e177497 100644 --- a/tests/eth2/beacon/test_on_genesis.py +++ b/tests/eth2/beacon/test_on_genesis.py @@ -155,7 +155,7 @@ def test_get_genesis_beacon_state( assert len(state.latest_crosslinks) == shard_count assert state.latest_crosslinks[0] == CrosslinkRecord( epoch=genesis_epoch, - shard_block_root=ZERO_HASH32, + crosslink_data_root=ZERO_HASH32, ) assert len(state.latest_block_roots) == latest_block_roots_length assert state.latest_block_roots[0] == ZERO_HASH32 diff --git a/tests/eth2/beacon/types/test_crosslink_record.py b/tests/eth2/beacon/types/test_crosslink_record.py index 70ab3a807d..42bfb42d57 100644 --- a/tests/eth2/beacon/types/test_crosslink_record.py +++ b/tests/eth2/beacon/types/test_crosslink_record.py @@ -6,4 +6,4 @@ def test_defaults(sample_crosslink_record_params): crosslink = CrosslinkRecord(**sample_crosslink_record_params) assert crosslink.epoch == sample_crosslink_record_params['epoch'] - assert crosslink.shard_block_root == sample_crosslink_record_params['shard_block_root'] + assert crosslink.crosslink_data_root == sample_crosslink_record_params['crosslink_data_root']