Skip to content

Commit 8b3a58b

Browse files
committed
PR feedback
1 parent ac69ffb commit 8b3a58b

File tree

9 files changed

+42
-33
lines changed

9 files changed

+42
-33
lines changed

eth/beacon/db/chain.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,25 +278,25 @@ def _persist_block_chain(
278278
return tuple(), tuple()
279279
else:
280280
for parent, child in sliding_window(2, blocks):
281-
if parent.hash != child.ancestor_hashes[0]:
281+
if parent.hash != child.parent_hash:
282282
raise ValidationError(
283283
"Non-contiguous chain. Expected {} to have {} as parent but was {}".format(
284284
encode_hex(child.hash),
285285
encode_hex(parent.hash),
286-
encode_hex(child.ancestor_hashes[0]),
286+
encode_hex(child.parent_hash),
287287
)
288288
)
289289

290-
is_genesis = first_block.ancestor_hashes[0] == GENESIS_PARENT_HASH
291-
if not is_genesis and not cls._block_exists(db, first_block.ancestor_hashes[0]):
290+
is_genesis = first_block.parent_hash == GENESIS_PARENT_HASH
291+
if not is_genesis and not cls._block_exists(db, first_block.parent_hash):
292292
raise ParentNotFound(
293293
"Cannot persist block ({}) with unknown parent ({})".format(
294-
encode_hex(first_block.hash), encode_hex(first_block.ancestor_hashes[0])))
294+
encode_hex(first_block.hash), encode_hex(first_block.parent_hash)))
295295

296296
if is_genesis:
297297
score = 0
298298
else:
299-
score = cls._get_score(db, first_block.ancestor_hashes[0])
299+
score = cls._get_score(db, first_block.parent_hash)
300300

301301
for block in blocks:
302302
db.set(
@@ -389,10 +389,10 @@ def _find_new_ancestors(cls, db: BaseDB, block: BaseBeaconBlock) -> Iterable[Bas
389389
# Found a new ancestor
390390
yield block
391391

392-
if block.ancestor_hashes[0] == GENESIS_PARENT_HASH:
392+
if block.parent_hash == GENESIS_PARENT_HASH:
393393
break
394394
else:
395-
block = cls._get_block_by_hash(db, block.ancestor_hashes[0])
395+
block = cls._get_block_by_hash(db, block.parent_hash)
396396

397397
@staticmethod
398398
def _add_block_slot_to_hash_lookup(db: BaseDB, block: BaseBeaconBlock) -> None:

eth/beacon/types/blocks.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ def __init__(self,
5454
state_root: Hash32,
5555
attestations: Sequence[AttestationRecord],
5656
specials: Sequence[SpecialRecord],
57-
proposer_signature: Sequence[int]) -> None:
57+
proposer_signature: Sequence[int]=None) -> None:
58+
if proposer_signature is None:
59+
proposer_signature = (0, 0)
5860
super().__init__(
5961
slot=slot,
6062
randao_reveal=randao_reveal,
@@ -83,3 +85,10 @@ def hash(self) -> Hash32:
8385
@property
8486
def num_attestations(self) -> int:
8587
return len(self.attestations)
88+
89+
@property
90+
def parent_hash(self) -> Hash32:
91+
if not self.ancestor_hashes:
92+
return None
93+
else:
94+
return self.ancestor_hashes[0]

eth/beacon/types/validator_records.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
from eth_typing import (
2-
Address,
32
Hash32,
43
)
54
import rlp
65

76
from eth.rlp.sedes import (
8-
address,
9-
uint8,
10-
uint16,
117
uint64,
128
uint256,
139
hash32,
@@ -21,18 +17,16 @@ class ValidatorRecord(rlp.Serializable):
2117
fields = [
2218
# BLS public key
2319
('pubkey', uint256),
24-
# Withdrawal shard number
25-
('withdrawal_shard', uint16),
26-
# Withdrawal address
27-
('withdrawal_address', address),
20+
# Withdrawal credentials
21+
('withdrawal_credentials', hash32),
2822
# RANDAO commitment
2923
('randao_commitment', hash32),
3024
# Slot the RANDAO commitment was last changed
3125
('randao_last_change', uint64),
3226
# Balance in Gwei
3327
('balance', uint64),
3428
# Status code
35-
('status', uint8),
29+
('status', uint64),
3630
# Slot when validator last changed status (or 0)
3731
('last_status_change_slot', uint64),
3832
# Sequence number when validator exited (or 0)
@@ -41,8 +35,7 @@ class ValidatorRecord(rlp.Serializable):
4135

4236
def __init__(self,
4337
pubkey: int,
44-
withdrawal_shard: int,
45-
withdrawal_address: Address,
38+
withdrawal_credentials: Hash32,
4639
randao_commitment: Hash32,
4740
randao_last_change: int,
4841
balance: int,
@@ -51,8 +44,7 @@ def __init__(self,
5144
exit_seq: int) -> None:
5245
super().__init__(
5346
pubkey=pubkey,
54-
withdrawal_shard=withdrawal_shard,
55-
withdrawal_address=withdrawal_address,
47+
withdrawal_credentials=withdrawal_credentials,
5648
randao_commitment=randao_commitment,
5749
randao_last_change=randao_last_change,
5850
balance=balance,

eth/rlp/sedes.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@
1111
address = Binary.fixed_length(20, allow_empty=True)
1212
collation_body = Binary.fixed_length(COLLATION_SIZE)
1313
hash32 = Binary.fixed_length(32)
14-
uint8 = BigEndianInt(8)
15-
uint16 = BigEndianInt(16)
1614
uint24 = BigEndianInt(24)
1715
uint32 = BigEndianInt(32)
1816
uint64 = BigEndianInt(64)
19-
uint128 = BigEndianInt(128)
2017
uint256 = BigEndianInt(256)
2118
trie_root = Binary.fixed_length(32, allow_empty=True)

tests/beacon/conftest.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def sample_beacon_block_params():
5656
'state_root': b'\x55' * 32,
5757
'attestations': (),
5858
'specials': (),
59-
'proposer_signature': (),
59+
'proposer_signature': (0, 0),
6060
}
6161

6262

@@ -108,7 +108,6 @@ def sample_crosslink_record_params():
108108
@pytest.fixture
109109
def sample_proposal_signed_data_params():
110110
return {
111-
'fork_version': 9,
112111
'slot': 10,
113112
'shard': 12,
114113
'block_hash': b'\x43' * 32,
@@ -153,8 +152,7 @@ def sample_special_params():
153152
def sample_validator_record_params():
154153
return {
155154
'pubkey': 123,
156-
'withdrawal_shard': 10,
157-
'withdrawal_address': b'\x01' * 20,
155+
'withdrawal_credentials': b'\x01' * 32,
158156
'randao_commitment': b'\x01' * 32,
159157
'randao_last_change': 1,
160158
'balance': 100,

tests/beacon/helpers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
def mock_validator_record(pubkey, deposit_size, default_end_dynasty, start_dynasty=0):
1010
return ValidatorRecord(
1111
pubkey=pubkey,
12-
withdrawal_shard=0,
13-
withdrawal_address=pubkey.to_bytes(32, 'big')[-20:],
12+
withdrawal_credentials=b'\x44' * 32,
1413
randao_commitment=b'\x55' * 32,
1514
balance=deposit_size,
1615
start_dynasty=start_dynasty,

tests/beacon/types/test_block.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,17 @@ def test_update_attestations(sample_attestation_record_params, sample_beacon_blo
3030
def test_hash(sample_beacon_block_params):
3131
block = BaseBeaconBlock(**sample_beacon_block_params)
3232
assert block.hash == blake(rlp.encode(block))
33+
34+
35+
def test_parent_hash(sample_beacon_block_params):
36+
block = BaseBeaconBlock(**sample_beacon_block_params)
37+
block = block.copy(
38+
ancestor_hashes=(),
39+
)
40+
assert block.parent_hash is None
41+
42+
sample_parent_hash = b'\x01' * 32
43+
block = block.copy(
44+
ancestor_hashes=(sample_parent_hash,),
45+
)
46+
assert block.parent_hash == sample_parent_hash

tests/beacon/types/test_proposal_signed_data.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
def test_defaults(sample_proposal_signed_data_params):
77
proposal_signed_data = ProposalSignedData(**sample_proposal_signed_data_params)
8-
assert proposal_signed_data.fork_version == sample_proposal_signed_data_params['fork_version']
98
assert proposal_signed_data.slot == sample_proposal_signed_data_params['slot']
109
assert proposal_signed_data.shard == sample_proposal_signed_data_params['shard']
1110
assert proposal_signed_data.block_hash == sample_proposal_signed_data_params['block_hash']

tests/beacon/types/test_validator_record.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
def test_defaults(sample_validator_record_params):
77
validator = ValidatorRecord(**sample_validator_record_params)
88
assert validator.pubkey == sample_validator_record_params['pubkey']
9-
assert validator.withdrawal_shard == sample_validator_record_params['withdrawal_shard']
9+
assert validator.withdrawal_credentials == \
10+
sample_validator_record_params['withdrawal_credentials']

0 commit comments

Comments
 (0)