Skip to content

Commit aaacf3e

Browse files
committed
1 parent 515232e commit aaacf3e

File tree

6 files changed

+63
-17
lines changed

6 files changed

+63
-17
lines changed

eth/beacon/types/blocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class BaseBeaconBlock(rlp.Serializable):
3131
('slot', uint64),
3232
# Proposer RANDAO reveal
3333
('randao_reveal', hash32),
34-
# Recent PoW chain reference (receipt root)
34+
# Recent PoW receipt root
3535
('candidate_pow_receipt_root', hash32),
3636
# Skip list of previous beacon block hashes
3737
# i'th item is the most recent ancestor whose slot is a multiple of 2**i for i = 0, ..., 31
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from eth_typing import (
2+
Hash32,
3+
)
4+
import rlp
5+
6+
from eth.rlp.sedes import (
7+
uint64,
8+
hash32,
9+
)
10+
11+
12+
class CandidatePoWReceiptRootRecord(rlp.Serializable):
13+
"""
14+
Note: using RLP until we have standardized serialization format.
15+
"""
16+
fields = [
17+
# Candidate PoW receipt root
18+
('candidate_pow_receipt_root', hash32),
19+
# Vote count
20+
('votes', uint64),
21+
]
22+
23+
def __init__(self,
24+
candidate_pow_receipt_root: Hash32,
25+
votes: int) -> None:
26+
super().__init__(
27+
candidate_pow_receipt_root=candidate_pow_receipt_root,
28+
votes=votes,
29+
)

eth/beacon/types/states.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
)
2525

2626
from .attestation_records import AttestationRecord
27+
from .candidate_pow_receipt_root_records import CandidatePoWReceiptRootRecord
2728
from .crosslink_records import CrosslinkRecord
2829
from .shard_and_committees import ShardAndCommittee
2930
from .shard_reassignment_records import ShardReassignmentRecord
@@ -64,10 +65,9 @@ class BeaconState(rlp.Serializable):
6465
('current_exit_seq', uint64),
6566
# Genesis time
6667
('genesis_time', uint64),
67-
# PoW chain reference
68-
('known_pow_receipt_root', hash32),
69-
('candidate_pow_receipt_root', hash32),
70-
('candidate_pow_receipt_root_votes', uint64),
68+
# PoW receipt root
69+
('processed_pow_receipt_root', hash32),
70+
('candidate_pow_receipt_roots', CountableList(CandidatePoWReceiptRootRecord)),
7171
# Parameters relevant to hard forks / versioning.
7272
# Should be updated only by hard forks.
7373
('pre_fork_version', uint64),
@@ -91,9 +91,7 @@ def __init__(self,
9191
validator_set_delta_hash_chain: Hash32,
9292
current_exit_seq: int,
9393
genesis_time: int,
94-
known_pow_receipt_root: Hash32,
95-
candidate_pow_receipt_root: Hash32,
96-
candidate_pow_receipt_root_votes: int,
94+
processed_pow_receipt_root: Hash32,
9795
pre_fork_version: int,
9896
post_fork_version: int,
9997
fork_slot_number: int,
@@ -104,6 +102,7 @@ def __init__(self,
104102
persistent_committees: Sequence[Sequence[int]]=None,
105103
persistent_committee_reassignments: Sequence[ShardReassignmentRecord]=None,
106104
deposits_penalized_in_period: Sequence[int]=None,
105+
candidate_pow_receipt_roots: Sequence[CandidatePoWReceiptRootRecord]=None,
107106
pending_attestations: Sequence[AttestationRecord]=None,
108107
recent_block_hashes: Sequence[Hash32]=None
109108
) -> None:
@@ -140,9 +139,8 @@ def __init__(self,
140139
validator_set_delta_hash_chain=validator_set_delta_hash_chain,
141140
current_exit_seq=current_exit_seq,
142141
genesis_time=genesis_time,
143-
known_pow_receipt_root=known_pow_receipt_root,
144-
candidate_pow_receipt_root=candidate_pow_receipt_root,
145-
candidate_pow_receipt_root_votes=candidate_pow_receipt_root_votes,
142+
processed_pow_receipt_root=processed_pow_receipt_root,
143+
candidate_pow_receipt_roots=candidate_pow_receipt_roots,
146144
pre_fork_version=pre_fork_version,
147145
post_fork_version=post_fork_version,
148146
fork_slot_number=fork_slot_number,

tests/beacon/conftest.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,8 @@ def sample_beacon_state_params():
7878
'validator_set_delta_hash_chain': b'\x55' * 32,
7979
'current_exit_seq': 10,
8080
'genesis_time': 10,
81-
'known_pow_receipt_root': b'\x55' * 32,
82-
'candidate_pow_receipt_root': b'\x55' * 32,
83-
'candidate_pow_receipt_root_votes': 5,
81+
'processed_pow_receipt_root': b'\x55' * 32,
82+
'candidate_pow_receipt_roots': (),
8483
'pre_fork_version': 0,
8584
'post_fork_version': 1,
8685
'fork_slot_number': 10,
@@ -90,6 +89,14 @@ def sample_beacon_state_params():
9089
}
9190

9291

92+
@pytest.fixture
93+
def sample_candidate_pow_receipt_root_record_params():
94+
return {
95+
'candidate_pow_receipt_root': b'\x43' * 32,
96+
'votes': 10,
97+
}
98+
99+
93100
@pytest.fixture
94101
def sample_crosslink_record_params():
95102
return {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from eth.beacon.types.candidate_pow_receipt_root_records import (
2+
CandidatePoWReceiptRootRecord,
3+
)
4+
5+
6+
def test_defaults(sample_candidate_pow_receipt_root_record_params):
7+
candidate_pow_receipt_roots = CandidatePoWReceiptRootRecord(
8+
**sample_candidate_pow_receipt_root_record_params
9+
)
10+
assert candidate_pow_receipt_roots.candidate_pow_receipt_root == \
11+
sample_candidate_pow_receipt_root_record_params['candidate_pow_receipt_root']
12+
assert candidate_pow_receipt_roots.votes == \
13+
sample_candidate_pow_receipt_root_record_params['votes']

tests/beacon/types/test_states.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ def empty_beacon_state():
3838
validator_set_delta_hash_chain=ZERO_HASH32,
3939
current_exit_seq=00,
4040
genesis_time=00,
41-
known_pow_receipt_root=ZERO_HASH32,
42-
candidate_pow_receipt_root=ZERO_HASH32,
43-
candidate_pow_receipt_root_votes=0,
41+
processed_pow_receipt_root=ZERO_HASH32,
42+
candidate_pow_receipt_roots=(),
4443
pre_fork_version=0,
4544
post_fork_version=0,
4645
fork_slot_number=0,

0 commit comments

Comments
 (0)