Skip to content

Commit 6fb899b

Browse files
committed
PR feedback
1 parent 30e6cea commit 6fb899b

File tree

11 files changed

+55
-54
lines changed

11 files changed

+55
-54
lines changed

eth/beacon/deposit_helpers.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
from typing import (
2-
Tuple,
3-
)
4-
51
from eth_typing import (
62
Hash32,
73
)
@@ -66,19 +62,16 @@ def validate_proof_of_possession(state: BeaconState,
6662

6763
def add_pending_validator(state: BeaconState,
6864
validator: ValidatorRecord,
69-
amount: Gwei) -> Tuple[BeaconState, int]:
65+
amount: Gwei) -> BeaconState:
7066
"""
7167
Add a validator to ``state``.
7268
"""
73-
validator_registry = state.validator_registry + (validator,)
7469
state = state.copy(
75-
validator_registry=validator_registry,
76-
validator_balances=state.validator_balances + (amount, )
70+
validator_registry=state.validator_registry + (validator,),
71+
validator_balances=state.validator_balances + (amount, ),
7772
)
7873

79-
index = len(state.validator_registry) - 1
80-
81-
return state, index
74+
return state
8275

8376

8477
def process_deposit(*,
@@ -114,7 +107,7 @@ def process_deposit(*,
114107

115108
# Note: In phase 2 registry indices that has been withdrawn for a long time
116109
# will be recycled.
117-
state, index = add_pending_validator(
110+
state = add_pending_validator(
118111
state,
119112
validator,
120113
amount,

eth/beacon/helpers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,13 @@ def get_shard_committees_at_slot(state: 'BeaconState',
155155

156156

157157
def get_active_validator_indices(validators: Sequence['ValidatorRecord'],
158-
slot: SlotNumber) -> Tuple[int, ...]:
158+
slot: SlotNumber) -> Tuple[ValidatorIndex, ...]:
159159
"""
160160
Get indices of active validators from ``validators``.
161161
"""
162162
return tuple(
163-
i for i, v in enumerate(validators)
164-
if v.is_active(slot)
163+
ValidatorIndex(index) for index, validator in enumerate(validators)
164+
if validator.is_active(slot)
165165
)
166166

167167

eth/beacon/state_machines/configs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
('SLOT_DURATION', Second),
4343
('MIN_ATTESTATION_INCLUSION_DELAY', int),
4444
('EPOCH_LENGTH', int),
45-
('MIN_VALIDATOR_REGISTRY_CHANGE_INTERVAL', int),
4645
('SEED_LOOKAHEAD', int),
4746
('ENTRY_EXIT_DELAY', int),
4847
('POW_RECEIPT_ROOT_VOTING_PERIOD', int),

eth/beacon/state_machines/forks/serenity/configs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@
2929
# Initial values
3030
GENESIS_FORK_VERSION=0,
3131
GENESIS_SLOT=SlotNumber(0),
32-
FAR_FUTURE_SLOT=SlotNumber(2**63),
32+
FAR_FUTURE_SLOT=SlotNumber(2**64 - 1),
3333
BLS_WITHDRAWAL_PREFIX_BYTE=b'\x00',
3434
# Time parameters
3535
SLOT_DURATION=Second(6), # seconds
3636
MIN_ATTESTATION_INCLUSION_DELAY=2**2, # (= 4) slots
3737
EPOCH_LENGTH=2**6, # (= 64) slots
38-
MIN_VALIDATOR_REGISTRY_CHANGE_INTERVAL=2**8, # (= 256) slots
3938
SEED_LOOKAHEAD=2**6, # (= 64) slots
4039
ENTRY_EXIT_DELAY=2**8, # (= 256) slots
4140
POW_RECEIPT_ROOT_VOTING_PERIOD=2**10, # (= 1,024) slots

eth/beacon/types/states.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ def num_crosslinks(self) -> int:
184184
def update_validator_registry(self,
185185
validator_index: ValidatorIndex,
186186
validator: ValidatorRecord) -> 'BeaconState':
187+
"""
188+
Replace ``self.validator_registry[validator_index]`` with ``validator``.
189+
"""
187190
if validator_index >= self.num_validators or validator_index < 0:
188191
raise IndexError("Incorrect validator index")
189192

eth/beacon/types/validator_records.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ def __init__(self,
7979

8080
def is_active(self, slot: int) -> bool:
8181
"""
82-
Return ``True`` if the validator is active.
82+
Return ``True`` if the validator is active.Return ``True``
83+
if the validator is active during the slot, ``slot``.
8384
"""
8485
return self.activation_slot <= slot < self.exit_slot
8586

tests/beacon/conftest.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
from eth.constants import (
55
ZERO_HASH32,
66
)
7+
from eth_utils import (
8+
to_tuple,
9+
)
710

811
import eth._utils.bls as bls
912
from eth.beacon._utils.hash import hash_eth2
@@ -514,11 +517,6 @@ def epoch_length():
514517
return SERENITY_CONFIG.EPOCH_LENGTH
515518

516519

517-
@pytest.fixture
518-
def min_validator_registry_change_interval():
519-
return SERENITY_CONFIG.MIN_VALIDATOR_REGISTRY_CHANGE_INTERVAL
520-
521-
522520
@pytest.fixture
523521
def seed_lookahead():
524522
return SERENITY_CONFIG.SEED_LOOKAHEAD
@@ -641,15 +639,14 @@ def initial_validators(init_validator_pubkeys,
641639
)
642640

643641

642+
@to_tuple
644643
@pytest.fixture
645644
def activated_genesis_validators(initial_validators, genesis_slot):
646645
"""
647646
Active
648647
"""
649-
validators = tuple()
650648
for validator in initial_validators:
651-
validators += (validator.copy(activation_slot=genesis_slot),)
652-
return validators
649+
yield validator.copy(activation_slot=genesis_slot)
653650

654651

655652
@pytest.fixture

tests/beacon/helpers.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
from eth.beacon.constants import (
99
EMPTY_SIGNATURE,
1010
)
11+
from eth.beacon.enums import (
12+
SignatureDomain,
13+
)
14+
from eth.beacon.helpers import (
15+
get_domain,
16+
)
1117
from eth.beacon.types.deposit_input import DepositInput
1218
from eth.beacon.types.validator_records import (
1319
ValidatorRecord,
@@ -52,7 +58,12 @@ def get_pseudo_chain(length, genesis_block):
5258
yield block
5359

5460

55-
def sign_proof_of_possession(deposit_input, privkey, domain):
61+
def sign_proof_of_possession(deposit_input, privkey, fork_data, slot):
62+
domain = get_domain(
63+
fork_data,
64+
slot,
65+
SignatureDomain.DOMAIN_DEPOSIT,
66+
)
5667
return bls.sign(deposit_input.root, privkey, domain)
5768

5869

tests/beacon/state_machines/conftest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def config(
2828
slot_duration,
2929
min_attestation_inclusion_delay,
3030
epoch_length,
31-
min_validator_registry_change_interval,
3231
seed_lookahead,
3332
entry_exit_delay,
3433
pow_receipt_root_voting_period,
@@ -64,7 +63,6 @@ def config(
6463
SLOT_DURATION=slot_duration,
6564
MIN_ATTESTATION_INCLUSION_DELAY=min_attestation_inclusion_delay,
6665
EPOCH_LENGTH=epoch_length,
67-
MIN_VALIDATOR_REGISTRY_CHANGE_INTERVAL=min_validator_registry_change_interval,
6866
SEED_LOOKAHEAD=seed_lookahead,
6967
ENTRY_EXIT_DELAY=entry_exit_delay,
7068
POW_RECEIPT_ROOT_VOTING_PERIOD=pow_receipt_root_voting_period,

tests/beacon/test_deposit_helpers.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@
1212
process_deposit,
1313
validate_proof_of_possession,
1414
)
15-
from eth.beacon.enums import (
16-
SignatureDomain,
17-
)
18-
from eth.beacon.helpers import (
19-
get_domain,
20-
)
2115
from eth.beacon.types.states import BeaconState
2216
from eth.beacon.types.validator_records import ValidatorRecord
2317

@@ -40,13 +34,13 @@ def test_add_pending_validator(sample_beacon_state_params,
4034
)
4135
validator = ValidatorRecord(**sample_validator_record_params)
4236
amount = 5566
43-
state, index = add_pending_validator(
37+
state = add_pending_validator(
4438
state,
4539
validator,
4640
amount,
4741
)
48-
assert index == validator_registry_len
49-
assert state.validator_registry[index] == validator
42+
43+
assert state.validator_registry[-1] == validator
5044

5145

5246
@pytest.mark.parametrize(
@@ -64,11 +58,6 @@ def test_validate_proof_of_possession(sample_beacon_state_params, pubkeys, privk
6458
withdrawal_credentials = b'\x34' * 32
6559
custody_commitment = b'\x12' * 32
6660
randao_commitment = b'\x56' * 32
67-
domain = get_domain(
68-
state.fork_data,
69-
state.slot,
70-
SignatureDomain.DOMAIN_DEPOSIT,
71-
)
7261

7362
deposit_input = make_deposit_input(
7463
pubkey=pubkey,
@@ -77,7 +66,12 @@ def test_validate_proof_of_possession(sample_beacon_state_params, pubkeys, privk
7766
custody_commitment=custody_commitment,
7867
)
7968
if expected is True:
80-
proof_of_possession = sign_proof_of_possession(deposit_input, privkey, domain)
69+
proof_of_possession = sign_proof_of_possession(
70+
deposit_input,
71+
privkey,
72+
state.fork_data,
73+
state.slot,
74+
)
8175

8276
validate_proof_of_possession(
8377
state=state,
@@ -116,19 +110,20 @@ def test_process_deposit(sample_beacon_state_params,
116110
withdrawal_credentials = b'\x34' * 32
117111
custody_commitment = b'\x11' * 32
118112
randao_commitment = b'\x56' * 32
119-
domain = get_domain(
120-
state.fork_data,
121-
state.slot,
122-
SignatureDomain.DOMAIN_DEPOSIT,
123-
)
124113

125114
deposit_input = make_deposit_input(
126115
pubkey=pubkey_1,
127116
withdrawal_credentials=withdrawal_credentials,
128117
randao_commitment=randao_commitment,
129118
custody_commitment=custody_commitment,
130119
)
131-
proof_of_possession = sign_proof_of_possession(deposit_input, privkey_1, domain)
120+
proof_of_possession = sign_proof_of_possession(
121+
deposit_input,
122+
privkey_1,
123+
state.fork_data,
124+
state.slot,
125+
)
126+
132127
# Add the first validator
133128
result_state = process_deposit(
134129
state=state,
@@ -159,7 +154,12 @@ def test_process_deposit(sample_beacon_state_params,
159154
randao_commitment=randao_commitment,
160155
custody_commitment=custody_commitment,
161156
)
162-
proof_of_possession = sign_proof_of_possession(deposit_input, privkey_2, domain)
157+
proof_of_possession = sign_proof_of_possession(
158+
deposit_input,
159+
privkey_2,
160+
state.fork_data,
161+
state.slot,
162+
)
163163
result_state = process_deposit(
164164
state=result_state,
165165
pubkey=pubkey_2,

0 commit comments

Comments
 (0)