46
46
from eth .beacon .typing import (
47
47
ShardNumber ,
48
48
BLSPubkey ,
49
+ SlotNumber ,
50
+ ValidatorIndex ,
51
+ Bitfield ,
52
+ Gwei ,
53
+ Ether ,
49
54
)
50
55
51
56
if TYPE_CHECKING :
59
64
60
65
def _get_element_from_recent_list (
61
66
target_list : Sequence [Any ],
62
- target_slot : int ,
63
- slot_relative_position : int ) -> Any :
67
+ target_slot : SlotNumber ,
68
+ slot_relative_position : SlotNumber ) -> Any :
64
69
"""
65
70
Return the element from ``target_list`` by the ``target_slot`` number,
66
71
where the the element should be at ``target_slot - slot_relative_position``th
@@ -88,12 +93,12 @@ def _get_element_from_recent_list(
88
93
#
89
94
def get_block_root (
90
95
latest_block_roots : Sequence [Hash32 ],
91
- current_slot : int ,
92
- slot : int ) -> Hash32 :
96
+ current_slot : SlotNumber ,
97
+ slot : SlotNumber ) -> Hash32 :
93
98
"""
94
99
Returns the block root at a recent ``slot``.
95
100
"""
96
- slot_relative_position = current_slot - len (latest_block_roots )
101
+ slot_relative_position = SlotNumber ( current_slot - len (latest_block_roots ) )
97
102
return _get_element_from_recent_list (
98
103
latest_block_roots ,
99
104
slot ,
@@ -106,9 +111,9 @@ def get_block_root(
106
111
#
107
112
@to_tuple
108
113
def _get_shard_committees_at_slot (
109
- state_slot : int ,
114
+ state_slot : SlotNumber ,
110
115
shard_committees_at_slots : Sequence [Sequence [ShardCommittee ]],
111
- slot : int ,
116
+ slot : SlotNumber ,
112
117
epoch_length : int ) -> Iterable [ShardCommittee ]:
113
118
if len (shard_committees_at_slots ) != epoch_length * 2 :
114
119
raise ValueError (
@@ -118,7 +123,7 @@ def _get_shard_committees_at_slot(
118
123
)
119
124
)
120
125
121
- slot_relative_position = state_slot - epoch_length
126
+ slot_relative_position = SlotNumber ( state_slot - epoch_length )
122
127
123
128
yield from _get_element_from_recent_list (
124
129
shard_committees_at_slots ,
@@ -128,7 +133,7 @@ def _get_shard_committees_at_slot(
128
133
129
134
130
135
def get_shard_committees_at_slot (state : 'BeaconState' ,
131
- slot : int ,
136
+ slot : SlotNumber ,
132
137
epoch_length : int ) -> Tuple [ShardCommittee ]:
133
138
"""
134
139
Return the ``ShardCommittee`` for the ``slot``.
@@ -141,12 +146,13 @@ def get_shard_committees_at_slot(state: 'BeaconState',
141
146
)
142
147
143
148
144
- def get_active_validator_indices (validators : Sequence ['ValidatorRecord' ]) -> Tuple [int , ...]:
149
+ def get_active_validator_indices (
150
+ validators : Sequence ['ValidatorRecord' ]) -> Tuple [ValidatorIndex , ...]:
145
151
"""
146
152
Get indices of active validators from ``validators``.
147
153
"""
148
154
return tuple (
149
- i for i , v in enumerate (validators )
155
+ ValidatorIndex ( i ) for i , v in enumerate (validators )
150
156
if v .is_active
151
157
)
152
158
@@ -156,8 +162,8 @@ def get_active_validator_indices(validators: Sequence['ValidatorRecord']) -> Tup
156
162
#
157
163
@to_tuple
158
164
def _get_shards_committees_for_shard_indices (
159
- shard_indices : Sequence [Sequence [int ]],
160
- start_shard : int ,
165
+ shard_indices : Sequence [Sequence [ShardNumber ]],
166
+ start_shard : ShardNumber ,
161
167
total_validator_count : int ,
162
168
shard_count : int ) -> Iterable [ShardCommittee ]:
163
169
"""
@@ -175,7 +181,7 @@ def _get_shards_committees_for_shard_indices(
175
181
def get_new_shuffling (* ,
176
182
seed : Hash32 ,
177
183
validators : Sequence ['ValidatorRecord' ],
178
- crosslinking_start_shard : int ,
184
+ crosslinking_start_shard : ShardNumber ,
179
185
epoch_length : int ,
180
186
target_committee_size : int ,
181
187
shard_count : int ) -> Iterable [Iterable [ShardCommittee ]]:
@@ -288,7 +294,7 @@ def get_block_committees_info(parent_block: 'BaseBeaconBlock',
288
294
289
295
290
296
def get_beacon_proposer_index (state : 'BeaconState' ,
291
- slot : int ,
297
+ slot : SlotNumber ,
292
298
epoch_length : int ) -> int :
293
299
"""
294
300
Return the beacon proposer index for the ``slot``.
@@ -318,10 +324,10 @@ def get_beacon_proposer_index(state: 'BeaconState',
318
324
#
319
325
@to_tuple
320
326
def get_attestation_participants (state : 'BeaconState' ,
321
- slot : int ,
322
- shard : int ,
323
- participation_bitfield : bytes ,
324
- epoch_length : int ) -> Iterable [int ]:
327
+ slot : SlotNumber ,
328
+ shard : ShardNumber ,
329
+ participation_bitfield : Bitfield ,
330
+ epoch_length : int ) -> Iterable [ValidatorIndex ]:
325
331
"""
326
332
Return the participants' indices at the ``slot`` of shard ``shard``
327
333
from ``participation_bitfield``.
@@ -365,7 +371,10 @@ def get_attestation_participants(state: 'BeaconState',
365
371
#
366
372
# Misc
367
373
#
368
- def get_effective_balance (validator_balances : Sequence [int ], index : int , max_deposit : int ) -> int :
374
+ def get_effective_balance (
375
+ validator_balances : Sequence [Gwei ],
376
+ index : ValidatorIndex ,
377
+ max_deposit : Ether ) -> Gwei :
369
378
"""
370
379
Return the effective balance (also known as "balance at stake") for a
371
380
``validator`` with the given ``index``.
@@ -374,7 +383,7 @@ def get_effective_balance(validator_balances: Sequence[int], index: int, max_dep
374
383
375
384
376
385
def get_new_validator_registry_delta_chain_tip (current_validator_registry_delta_chain_tip : Hash32 ,
377
- validator_index : int ,
386
+ validator_index : ValidatorIndex ,
378
387
pubkey : BLSPubkey ,
379
388
flag : int ) -> Hash32 :
380
389
"""
@@ -390,7 +399,7 @@ def get_new_validator_registry_delta_chain_tip(current_validator_registry_delta_
390
399
391
400
392
401
def get_fork_version (fork_data : 'ForkData' ,
393
- slot : int ) -> int :
402
+ slot : SlotNumber ) -> int :
394
403
"""
395
404
Return the current ``fork_version`` from the given ``fork_data`` and ``slot``.
396
405
"""
@@ -401,7 +410,7 @@ def get_fork_version(fork_data: 'ForkData',
401
410
402
411
403
412
def get_domain (fork_data : 'ForkData' ,
404
- slot : int ,
413
+ slot : SlotNumber ,
405
414
domain_type : SignatureDomain ) -> int :
406
415
"""
407
416
Return the domain number of the current fork and ``domain_type``.
@@ -415,14 +424,14 @@ def get_domain(fork_data: 'ForkData',
415
424
416
425
@to_tuple
417
426
def get_pubkey_for_indices (validators : Sequence ['ValidatorRecord' ],
418
- indices : Sequence [int ]) -> Iterable [int ]:
427
+ indices : Sequence [ValidatorIndex ]) -> Iterable [BLSPubkey ]:
419
428
for index in indices :
420
429
yield validators [index ].pubkey
421
430
422
431
423
432
@to_tuple
424
433
def generate_aggregate_pubkeys (validators : Sequence ['ValidatorRecord' ],
425
- vote_data : 'SlashableVoteData' ) -> Iterable [int ]:
434
+ vote_data : 'SlashableVoteData' ) -> Iterable [BLSPubkey ]:
426
435
"""
427
436
Compute the aggregate pubkey we expect based on
428
437
the proof-of-custody indices found in the ``vote_data``.
0 commit comments