Skip to content

Commit 7412023

Browse files
committed
PR feedback
1. Move `FAR_FUTURE_SLOT` to `eth.beacon.constants` 2. Rename `get_pending_validator` to `create_pending_validator` 3. Add some docstrings
1 parent 6fb899b commit 7412023

File tree

14 files changed

+62
-67
lines changed

14 files changed

+62
-67
lines changed

eth/beacon/constants.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
from eth.beacon.typing import BLSSignature
1+
from eth.beacon.typing import (
2+
BLSSignature,
3+
SlotNumber,
4+
)
5+
26

37
#
48
# shuffle function
@@ -15,3 +19,4 @@
1519

1620
EMPTY_SIGNATURE = BLSSignature((0, 0))
1721
GWEI_PER_ETH = 10**9
22+
FAR_FUTURE_SLOT = SlotNumber(2**64 - 1)

eth/beacon/deposit_helpers.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
get_domain,
2121
)
2222
from eth.beacon.typing import (
23-
SlotNumber,
2423
BLSPubkey,
2524
BLSSignature,
2625
ValidatorIndex,
@@ -81,8 +80,7 @@ def process_deposit(*,
8180
proof_of_possession: BLSSignature,
8281
withdrawal_credentials: Hash32,
8382
randao_commitment: Hash32,
84-
custody_commitment: Hash32,
85-
far_future_slot: SlotNumber) -> BeaconState:
83+
custody_commitment: Hash32) -> BeaconState:
8684
"""
8785
Process a deposit from Ethereum 1.0.
8886
"""
@@ -97,12 +95,11 @@ def process_deposit(*,
9795

9896
validator_pubkeys = tuple(v.pubkey for v in state.validator_registry)
9997
if pubkey not in validator_pubkeys:
100-
validator = ValidatorRecord.get_pending_validator(
98+
validator = ValidatorRecord.create_pending_validator(
10199
pubkey=pubkey,
102100
withdrawal_credentials=withdrawal_credentials,
103101
randao_commitment=randao_commitment,
104102
custody_commitment=custody_commitment,
105-
far_future_slot=far_future_slot,
106103
)
107104

108105
# Note: In phase 2 registry indices that has been withdrawn for a long time

eth/beacon/state_machines/configs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
# Initial values
3737
('GENESIS_FORK_VERSION', int),
3838
('GENESIS_SLOT', SlotNumber),
39-
('FAR_FUTURE_SLOT', SlotNumber),
4039
('BLS_WITHDRAWAL_PREFIX_BYTE', bytes),
4140
# Time parameters
4241
('SLOT_DURATION', Second),

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
# Initial values
3030
GENESIS_FORK_VERSION=0,
3131
GENESIS_SLOT=SlotNumber(0),
32-
FAR_FUTURE_SLOT=SlotNumber(2**64 - 1),
3332
BLS_WITHDRAWAL_PREFIX_BYTE=b'\x00',
3433
# Time parameters
3534
SLOT_DURATION=Second(6), # seconds

eth/beacon/types/states.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ def update_validator_registry(self,
201201
def update_validator_balance(self,
202202
validator_index: ValidatorIndex,
203203
balance: Gwei) -> 'BeaconState':
204+
"""
205+
Update the balance of validator of the given ``validator_index``.
206+
"""
204207
if validator_index >= self.num_validators or validator_index < 0:
205208
raise IndexError("Incorrect validator index")
206209

@@ -216,6 +219,9 @@ def update_validator(self,
216219
validator_index: ValidatorIndex,
217220
validator: ValidatorRecord,
218221
balance: Gwei) -> 'BeaconState':
222+
"""
223+
Update the ``ValidatorRecord`` and balance of validator of the given ``validator_index``.
224+
"""
219225
state = self.update_validator_registry(validator_index, validator)
220226
state = state.update_validator_balance(validator_index, balance)
221227
return state

eth/beacon/types/validator_records.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
uint384,
99
hash32,
1010
)
11+
from eth.beacon.constants import (
12+
FAR_FUTURE_SLOT,
13+
)
1114
from eth.beacon.typing import (
1215
SlotNumber,
1316
BLSPubkey,
@@ -79,18 +82,16 @@ def __init__(self,
7982

8083
def is_active(self, slot: int) -> bool:
8184
"""
82-
Return ``True`` if the validator is active.Return ``True``
83-
if the validator is active during the slot, ``slot``.
85+
Return ``True`` if the validator is active during the slot, ``slot``.
8486
"""
8587
return self.activation_slot <= slot < self.exit_slot
8688

8789
@classmethod
88-
def get_pending_validator(cls,
89-
pubkey: BLSPubkey,
90-
withdrawal_credentials: Hash32,
91-
randao_commitment: Hash32,
92-
custody_commitment: Hash32,
93-
far_future_slot: SlotNumber) -> 'ValidatorRecord':
90+
def create_pending_validator(cls,
91+
pubkey: BLSPubkey,
92+
withdrawal_credentials: Hash32,
93+
randao_commitment: Hash32,
94+
custody_commitment: Hash32) -> 'ValidatorRecord':
9495
"""
9596
Return a new pending ``ValidatorRecord`` with the given fields.
9697
"""
@@ -99,10 +100,10 @@ def get_pending_validator(cls,
99100
withdrawal_credentials=withdrawal_credentials,
100101
randao_commitment=randao_commitment,
101102
randao_layers=0,
102-
activation_slot=far_future_slot,
103-
exit_slot=far_future_slot,
104-
withdrawal_slot=far_future_slot,
105-
penalized_slot=far_future_slot,
103+
activation_slot=FAR_FUTURE_SLOT,
104+
exit_slot=FAR_FUTURE_SLOT,
105+
withdrawal_slot=FAR_FUTURE_SLOT,
106+
penalized_slot=FAR_FUTURE_SLOT,
106107
exit_count=0,
107108
status_flags=0,
108109
custody_commitment=custody_commitment,

tests/beacon/conftest.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
aggregate_votes,
1818
)
1919
from eth.beacon.constants import (
20+
FAR_FUTURE_SLOT,
2021
GWEI_PER_ETH,
2122
)
2223
from eth.beacon.enums import (
@@ -306,16 +307,16 @@ def sample_casper_slashing_params(sample_slashable_vote_data_params):
306307

307308

308309
@pytest.fixture
309-
def sample_validator_record_params(far_future_slot):
310+
def sample_validator_record_params():
310311
return {
311312
'pubkey': 123,
312313
'withdrawal_credentials': b'\x01' * 32,
313314
'randao_commitment': b'\x01' * 32,
314315
'randao_layers': 1,
315-
'activation_slot': far_future_slot,
316-
'exit_slot': far_future_slot,
317-
'withdrawal_slot': far_future_slot,
318-
'penalized_slot': far_future_slot,
316+
'activation_slot': FAR_FUTURE_SLOT,
317+
'exit_slot': FAR_FUTURE_SLOT,
318+
'withdrawal_slot': FAR_FUTURE_SLOT,
319+
'penalized_slot': FAR_FUTURE_SLOT,
319320
'exit_count': 0,
320321
'status_flags': 0,
321322
'custody_commitment': ZERO_HASH32,
@@ -371,13 +372,12 @@ def empty_beacon_state(latest_block_roots_length,
371372

372373

373374
@pytest.fixture()
374-
def ten_validators_state(empty_beacon_state, max_deposit, far_future_slot):
375+
def ten_validators_state(empty_beacon_state, max_deposit):
375376
validator_count = 10
376377
return empty_beacon_state.copy(
377378
validator_registry=tuple(
378379
mock_validator_record(
379380
pubkey=pubkey,
380-
far_future_slot=far_future_slot,
381381
is_active=True,
382382
)
383383
for pubkey in range(validator_count)
@@ -492,11 +492,6 @@ def genesis_slot():
492492
return SERENITY_CONFIG.GENESIS_SLOT
493493

494494

495-
@pytest.fixture
496-
def far_future_slot():
497-
return SERENITY_CONFIG.FAR_FUTURE_SLOT
498-
499-
500495
@pytest.fixture
501496
def bls_withdrawal_prefix_byte():
502497
return SERENITY_CONFIG.BLS_WITHDRAWAL_PREFIX_BYTE
@@ -621,15 +616,13 @@ def genesis_state(sample_beacon_state_params,
621616
@pytest.fixture
622617
def initial_validators(init_validator_pubkeys,
623618
init_randao,
624-
max_deposit,
625-
far_future_slot):
619+
max_deposit):
626620
"""
627621
Inactive
628622
"""
629623
return tuple(
630624
mock_validator_record(
631625
pubkey=pubkey,
632-
far_future_slot=far_future_slot,
633626
withdrawal_credentials=ZERO_HASH32,
634627
randao_commitment=init_randao,
635628
status_flags=0,

tests/beacon/helpers.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
)
88
from eth.beacon.constants import (
99
EMPTY_SIGNATURE,
10+
FAR_FUTURE_SLOT,
1011
)
1112
from eth.beacon.enums import (
1213
SignatureDomain,
@@ -21,7 +22,6 @@
2122

2223

2324
def mock_validator_record(pubkey,
24-
far_future_slot,
2525
withdrawal_credentials=ZERO_HASH32,
2626
randao_commitment=ZERO_HASH32,
2727
status_flags=0,
@@ -31,10 +31,10 @@ def mock_validator_record(pubkey,
3131
withdrawal_credentials=withdrawal_credentials,
3232
randao_commitment=randao_commitment,
3333
randao_layers=0,
34-
activation_slot=0 if is_active else far_future_slot,
35-
exit_slot=far_future_slot,
36-
withdrawal_slot=far_future_slot,
37-
penalized_slot=far_future_slot,
34+
activation_slot=0 if is_active else FAR_FUTURE_SLOT,
35+
exit_slot=FAR_FUTURE_SLOT,
36+
withdrawal_slot=FAR_FUTURE_SLOT,
37+
penalized_slot=FAR_FUTURE_SLOT,
3838
exit_count=0,
3939
status_flags=status_flags,
4040
custody_commitment=b'\x55' * 32,

tests/beacon/state_machines/conftest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ def config(
2323
max_deposit,
2424
genesis_fork_version,
2525
genesis_slot,
26-
far_future_slot,
2726
bls_withdrawal_prefix_byte,
2827
slot_duration,
2928
min_attestation_inclusion_delay,
@@ -58,7 +57,6 @@ def config(
5857
MAX_DEPOSIT=max_deposit,
5958
GENESIS_FORK_VERSION=genesis_fork_version,
6059
GENESIS_SLOT=genesis_slot,
61-
FAR_FUTURE_SLOT=far_future_slot,
6260
BLS_WITHDRAWAL_PREFIX_BYTE=bls_withdrawal_prefix_byte,
6361
SLOT_DURATION=slot_duration,
6462
MIN_ATTESTATION_INCLUSION_DELAY=min_attestation_inclusion_delay,

tests/beacon/state_machines/test_proposer_signature_validation.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,11 @@ def test_validate_serenity_proposer_signature(
4949
sample_shard_committee_params,
5050
beacon_chain_shard_number,
5151
epoch_length,
52-
max_deposit,
53-
far_future_slot):
52+
max_deposit):
5453

5554
state = BeaconState(**sample_beacon_state_params).copy(
5655
validator_registry=tuple(
57-
mock_validator_record(proposer_pubkey, far_future_slot)
56+
mock_validator_record(proposer_pubkey)
5857
for _ in range(10)
5958
),
6059
validator_balances=(max_deposit * GWEI_PER_ETH,) * 10,

0 commit comments

Comments
 (0)