Skip to content

Commit 691e390

Browse files
committed
Sync data structure
1 parent 5ef07d9 commit 691e390

22 files changed

+322
-283
lines changed

eth/beacon/block_committees_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
)
66

77
if TYPE_CHECKING:
8-
from eth.beacon.types.shard_and_committees import ShardAndCommittee # noqa: F401
8+
from eth.beacon.types.shard_committees import ShardCommittee # noqa: F401
99

1010

1111
BlockCommitteesInfo = NamedTuple(
@@ -15,6 +15,6 @@
1515
('proposer_index_in_committee', int),
1616
('proposer_shard_id', int),
1717
('proposer_committee_size', int),
18-
('shards_and_committees', Tuple['ShardAndCommittee'])
18+
('shards_and_committees', Tuple['ShardCommittee'])
1919
)
2020
)

eth/beacon/helpers.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
from eth.beacon.enums.validator_status_codes import (
2727
ValidatorStatusCode,
2828
)
29-
from eth.beacon.types.shard_and_committees import (
30-
ShardAndCommittee,
29+
from eth.beacon.types.shard_committees import (
30+
ShardCommittee,
3131
)
3232
from eth.beacon.utils.random import (
3333
shuffle,
@@ -173,22 +173,22 @@ def get_new_recent_block_hashes(old_block_hashes: Sequence[Hash32],
173173
def get_shards_and_committees_for_slot(
174174
crystallized_state: 'CrystallizedState',
175175
slot: int,
176-
cycle_length: int) -> Iterable[ShardAndCommittee]:
176+
cycle_length: int) -> Iterable[ShardCommittee]:
177177
"""
178178
FIXME
179179
"""
180-
if len(crystallized_state.shard_and_committee_for_slots) != cycle_length * 2:
180+
if len(crystallized_state.shard_committee_for_slots) != cycle_length * 2:
181181
raise ValueError(
182-
"Length of shard_and_committee_for_slots != cycle_length * 2"
182+
"Length of shard_committee_for_slots != cycle_length * 2"
183183
"\texpected: %s, found: %s" % (
184-
cycle_length * 2, len(crystallized_state.shard_and_committee_for_slots)
184+
cycle_length * 2, len(crystallized_state.shard_committee_for_slots)
185185
)
186186
)
187187

188188
slot_relative_position = crystallized_state.last_state_recalc - cycle_length
189189

190190
yield from _get_element_from_recent_list(
191-
crystallized_state.shard_and_committee_for_slots,
191+
crystallized_state.shard_committee_for_slots,
192192
slot,
193193
slot_relative_position,
194194
)
@@ -210,9 +210,9 @@ def get_attestation_indices(crystallized_state: 'CrystallizedState',
210210
cycle_length,
211211
)
212212

213-
for shard_and_committee in shards_and_committees_for_slot:
214-
if shard_and_committee.shard_id == shard_id:
215-
yield from shard_and_committee.committee
213+
for shard_committee in shards_and_committees_for_slot:
214+
if shard_committee.shard_id == shard_id:
215+
yield from shard_committee.committee
216216

217217

218218
def get_active_validator_indices(validators: Sequence['ValidatorRecord']) -> Tuple[int, ...]:
@@ -232,12 +232,12 @@ def get_active_validator_indices(validators: Sequence['ValidatorRecord']) -> Tup
232232
def _get_shards_and_committees_for_shard_indices(
233233
shard_indices: Sequence[Sequence[int]],
234234
start_shard: int,
235-
shard_count: int) -> Iterable[ShardAndCommittee]:
235+
shard_count: int) -> Iterable[ShardCommittee]:
236236
"""
237-
Returns filled [ShardAndCommittee] tuple.
237+
Returns filled [ShardCommittee] tuple.
238238
"""
239239
for index, indices in enumerate(shard_indices):
240-
yield ShardAndCommittee(
240+
yield ShardCommittee(
241241
shard=(start_shard + index) % shard_count,
242242
committee=indices
243243
)
@@ -250,16 +250,16 @@ def get_new_shuffling(*,
250250
crosslinking_start_shard: int,
251251
cycle_length: int,
252252
target_committee_size: int,
253-
shard_count: int) -> Iterable[Iterable[ShardAndCommittee]]:
253+
shard_count: int) -> Iterable[Iterable[ShardCommittee]]:
254254
"""
255-
Return shuffled ``shard_and_committee_for_slots`` (``[[ShardAndCommittee]]``) of
255+
Return shuffled ``shard_committee_for_slots`` (``[[ShardCommittee]]``) of
256256
the given active ``validators`` using ``seed`` as entropy.
257257
258258
Two-dimensional:
259259
The first layer is ``slot`` number
260-
``shard_and_committee_for_slots[slot] -> [ShardAndCommittee]``
260+
``shard_committee_for_slots[slot] -> [ShardCommittee]``
261261
The second layer is ``shard_indices`` number
262-
``shard_and_committee_for_slots[slot][shard_indices] -> ShardAndCommittee``
262+
``shard_committee_for_slots[slot][shard_indices] -> ShardCommittee``
263263
264264
Example:
265265
validators:
@@ -278,18 +278,18 @@ def get_new_shuffling(*,
278278
[
279279
# slot 0
280280
[
281-
ShardAndCommittee(shard_id=0, committee=[6, 0]),
282-
ShardAndCommittee(shard_id=1, committee=[2, 12, 14]),
281+
ShardCommittee(shard_id=0, committee=[6, 0]),
282+
ShardCommittee(shard_id=1, committee=[2, 12, 14]),
283283
],
284284
# slot 1
285285
[
286-
ShardAndCommittee(shard_id=2, committee=[8, 10]),
287-
ShardAndCommittee(shard_id=3, committee=[4, 9, 1]),
286+
ShardCommittee(shard_id=2, committee=[8, 10]),
287+
ShardCommittee(shard_id=3, committee=[4, 9, 1]),
288288
],
289289
# slot 2
290290
[
291-
ShardAndCommittee(shard_id=4, committee=[5, 13, 15]),
292-
ShardAndCommittee(shard_id=5, committee=[7, 3, 11]),
291+
ShardCommittee(shard_id=4, committee=[5, 13, 15]),
292+
ShardCommittee(shard_id=5, committee=[7, 3, 11]),
293293
],
294294
]
295295
"""
@@ -331,14 +331,14 @@ def get_block_committees_info(parent_block: 'BaseBeaconBlock',
331331
FIXME
332332
Return the block committees and proposer info with BlockCommitteesInfo pack.
333333
"""
334-
# `proposer_index_in_committee` th attester in `shard_and_committee`
334+
# `proposer_index_in_committee` th attester in `shard_committee`
335335
# is the proposer of the parent block.
336336
try:
337-
shard_and_committee = shards_and_committees[0]
337+
shard_committee = shards_and_committees[0]
338338
except IndexError:
339339
raise ValueError("shards_and_committees should not be empty.")
340340

341-
proposer_committee_size = len(shard_and_committee.committee)
341+
proposer_committee_size = len(shard_committee.committee)
342342
if proposer_committee_size <= 0:
343343
raise ValueError(
344344
"The first committee should not be empty"
@@ -350,12 +350,12 @@ def get_block_committees_info(parent_block: 'BaseBeaconBlock',
350350
)
351351

352352
# The index in CrystallizedState.validators
353-
proposer_index = shard_and_committee.committee[proposer_index_in_committee]
353+
proposer_index = shard_committee.committee[proposer_index_in_committee]
354354

355355
return BlockCommitteesInfo(
356356
proposer_index=proposer_index,
357357
proposer_index_in_committee=proposer_index_in_committee,
358-
proposer_shard_id=shard_and_committee.shard_id,
358+
proposer_shard_id=shard_committee.shard_id,
359359
proposer_committee_size=proposer_committee_size,
360360
shards_and_committees=shards_and_committees,
361361
)

eth/beacon/types/attestation_signed_data.py renamed to eth/beacon/types/attestation_data.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
)
1010

1111

12-
class AttestationSignedData(rlp.Serializable):
12+
class AttestationData(rlp.Serializable):
1313
"""
1414
Note: using RLP until we have standardized serialization format.
1515
"""
@@ -18,36 +18,36 @@ class AttestationSignedData(rlp.Serializable):
1818
('slot', uint64),
1919
# Shard number
2020
('shard', uint64),
21-
# Hash of the block we're signing
22-
('block_hash', hash32),
23-
# Hash of the ancestor at the cycle boundary
24-
('cycle_boundary_hash', hash32),
21+
# Hash of the signed beacon block
22+
('beacon_block_hash', hash32),
23+
# Hash of the ancestor at the epoch boundary
24+
('epoch_boundary_hash', hash32),
2525
# Shard block hash being attested to
2626
('shard_block_hash', hash32),
2727
# Last crosslink hash
28-
('last_crosslink_hash', hash32),
29-
# Slot of last justified beacon block
28+
('latest_crosslink_hash', hash32),
29+
# Slot of the last justified beacon block
3030
('justified_slot', uint64),
31-
# Hash of last justified beacon block
31+
# Hash of the last justified beacon block
3232
('justified_block_hash', hash32),
3333
]
3434

3535
def __init__(self,
3636
slot: int,
3737
shard: int,
38-
block_hash: Hash32,
39-
cycle_boundary_hash: Hash32,
38+
beacon_block_hash: Hash32,
39+
epoch_boundary_hash: Hash32,
4040
shard_block_hash: Hash32,
41-
last_crosslink_hash: Hash32,
41+
latest_crosslink_hash: Hash32,
4242
justified_slot: int,
4343
justified_block_hash: Hash32) -> None:
4444
super().__init__(
4545
slot=slot,
4646
shard=shard,
47-
block_hash=block_hash,
48-
cycle_boundary_hash=cycle_boundary_hash,
47+
beacon_block_hash=beacon_block_hash,
48+
epoch_boundary_hash=epoch_boundary_hash,
4949
shard_block_hash=shard_block_hash,
50-
last_crosslink_hash=last_crosslink_hash,
50+
latest_crosslink_hash=latest_crosslink_hash,
5151
justified_slot=justified_slot,
5252
justified_block_hash=justified_block_hash,
5353
)

eth/beacon/types/attestation_records.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
)
1414

1515

16-
from .attestation_signed_data import (
17-
AttestationSignedData,
16+
from .attestation_data import (
17+
AttestationData,
1818
)
1919

2020

@@ -23,7 +23,7 @@ class AttestationRecord(rlp.Serializable):
2323
Note: using RLP until we have standardized serialization format.
2424
"""
2525
fields = [
26-
('data', AttestationSignedData),
26+
('data', AttestationData),
2727
# Attester participation bitfield
2828
('attester_bitfield', binary),
2929
# Proof of custody bitfield
@@ -33,7 +33,7 @@ class AttestationRecord(rlp.Serializable):
3333
]
3434

3535
def __init__(self,
36-
data: AttestationSignedData,
36+
data: AttestationData,
3737
attester_bitfield: bytes,
3838
poc_bitfield: bytes,
3939
aggregate_sig: Sequence[int]=None) -> None:
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from typing import (
2+
Sequence,
3+
)
4+
5+
from eth_typing import (
6+
Hash32,
7+
)
8+
import rlp
9+
from rlp.sedes import (
10+
binary,
11+
CountableList,
12+
)
13+
14+
from eth.rlp.sedes import (
15+
hash32,
16+
uint256,
17+
)
18+
19+
20+
class DepositParametersRecord(rlp.Serializable):
21+
"""
22+
Note: using RLP until we have standardized serialization format.
23+
"""
24+
fields = [
25+
# BLS pubkey
26+
('pubkey', uint256),
27+
# BLS proof of possession (a BLS signature)
28+
('proof_of_possession', CountableList(uint256)),
29+
# Withdrawal credentials
30+
('withdrawal_credentials', hash32),
31+
# Initial RANDAO commitment
32+
('randao_commitment', hash32),
33+
]
34+
35+
def __init__(self,
36+
pubkey: int,
37+
withdrawal_credentials: Hash32,
38+
randao_commitment: Hash32,
39+
proof_of_possession: Sequence[int]=None) -> None:
40+
if proof_of_possession is None:
41+
proof_of_possession = (0, 0)
42+
43+
super().__init__(
44+
pubkey=pubkey,
45+
proof_of_possession=proof_of_possession,
46+
withdrawal_credentials=withdrawal_credentials,
47+
randao_commitment=randao_commitment,
48+
)

eth/beacon/types/fork_data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ class ForkData(rlp.Serializable):
1515
# Post fork version
1616
('post_fork_version', uint64),
1717
# Fork slot number
18-
('fork_slot_number', uint64)
18+
('fork_slot', uint64)
1919
]
2020

2121
def __init__(self,
2222
pre_fork_version: int,
2323
post_fork_version: int,
24-
fork_slot_number: int) -> None:
24+
fork_slot: int) -> None:
2525
super().__init__(
2626
pre_fork_version=pre_fork_version,
2727
post_fork_version=post_fork_version,
28-
fork_slot_number=fork_slot_number,
28+
fork_slot=fork_slot,
2929
)

eth/beacon/types/processed_attestation.py renamed to eth/beacon/types/pending_attestation_records.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,34 @@
88
)
99

1010

11-
from .attestation_signed_data import (
12-
AttestationSignedData,
11+
from .attestation_data import (
12+
AttestationData,
1313
)
1414

1515

16-
class ProcessedAttestation(rlp.Serializable):
16+
class PendingAttestationRecord(rlp.Serializable):
1717
"""
1818
Note: using RLP until we have standardized serialization format.
1919
"""
2020
fields = [
2121
# Signed data
22-
('data', AttestationSignedData),
22+
('data', AttestationData),
2323
# Attester participation bitfield
24-
('attester_bitfield', binary),
24+
('participation_bitfield', binary),
2525
# Proof of custody bitfield
26-
('poc_bitfield', binary),
26+
('custody_bitfield', binary),
2727
# Slot in which it was included
2828
('slot_included', uint64),
2929
]
3030

3131
def __init__(self,
32-
data: AttestationSignedData,
33-
attester_bitfield: bytes,
34-
poc_bitfield: bytes,
32+
data: AttestationData,
33+
participation_bitfield: bytes,
34+
custody_bitfield: bytes,
3535
slot_included: int) -> None:
3636
super().__init__(
3737
data=data,
38-
attester_bitfield=attester_bitfield,
39-
poc_bitfield=poc_bitfield,
38+
participation_bitfield=participation_bitfield,
39+
custody_bitfield=custody_bitfield,
4040
slot_included=slot_included,
4141
)

eth/beacon/types/shard_and_committees.py renamed to eth/beacon/types/shard_committees.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
)
1414

1515

16-
class ShardAndCommittee(rlp.Serializable):
16+
class ShardCommittee(rlp.Serializable):
1717
"""
1818
Note: using RLP until we have standardized serialization format.
1919
"""

0 commit comments

Comments
 (0)