Skip to content

Commit c96a781

Browse files
committed
Sync with the spec again
1. ethereum/consensus-specs#172 updates 2. ethereum/consensus-specs#165 updates 3. Add `BLSDomain` enum 4. Add `AttestationSignedData`
1 parent 8b3a58b commit c96a781

File tree

9 files changed

+111
-22
lines changed

9 files changed

+111
-22
lines changed

eth/beacon/enums/bls_domain.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from enum import IntEnum
2+
3+
4+
class BLSDomain(IntEnum):
5+
DOMAIN_DEPOSIT = 0
6+
DOMAIN_ATTESTATION = 1
7+
DOMAIN_PROPOSAL = 2
8+
DOMAIN_LOGOUT = 3

eth/beacon/state_machines/configs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
('MIN_VALIDATOR_SET_CHANGE_INTERVAL', int), # slots
2121
('SHARD_PERSISTENT_COMMITTEE_CHANGE_PERIOD', int), # slots
2222
('MIN_ATTESTATION_INCLUSION_DELAY', int), # slots
23-
('RANDAO_SLOTS_PER_LAYER', int), # slots
2423
('SQRT_E_DROP_TIME', int), # slots
2524
('WITHDRAWALS_PER_CYCLE', int), # validators
2625
('MIN_WITHDRAWAL_PERIOD', int), # slots
@@ -31,7 +30,7 @@
3130
('BASE_REWARD_QUOTIENT', int),
3231
('MAX_VALIDATOR_CHURN_QUOTIENT', int),
3332
('POW_CONTRACT_MERKLE_TREE_DEPTH', int),
34-
('LOGOUT_MESSAGE', str),
33+
('MAX_ATTESTATION_COUNT', int),
3534
('INITIAL_FORK_VERSION', int),
3635
)
3736
)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
MIN_VALIDATOR_SET_CHANGE_INTERVAL=2**8, # = 256 slots
1616
SHARD_PERSISTENT_COMMITTEE_CHANGE_PERIOD=2**17, # = 131,072 slots
1717
MIN_ATTESTATION_INCLUSION_DELAY=2**2, # = 4 slots
18-
RANDAO_SLOTS_PER_LAYER=2**12, # = 4,096 slots
1918
SQRT_E_DROP_TIME=2**18, # = 262,144 slots
2019
WITHDRAWALS_PER_CYCLE=2**2, # = 4 validators
2120
MIN_WITHDRAWAL_PERIOD=2**13, # = 8,192 slots
@@ -26,6 +25,6 @@
2625
BASE_REWARD_QUOTIENT=2**15, # = 32,768
2726
MAX_VALIDATOR_CHURN_QUOTIENT=2**5, # = 32
2827
POW_CONTRACT_MERKLE_TREE_DEPTH=2**5, # =32
29-
LOGOUT_MESSAGE="LOGOUT",
28+
MAX_ATTESTATION_COUNT=2**7, # 128
3029
INITIAL_FORK_VERSION=0,
3130
)

eth/beacon/types/attestation_records.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from typing import (
2-
Iterable,
3-
Tuple,
2+
Sequence,
43
)
54

65
from eth_typing import (
@@ -55,12 +54,12 @@ def __init__(self,
5554
attester_bitfield: bytes,
5655
justified_slot: int,
5756
justified_block_hash: Hash32,
58-
parent_hashes: Tuple[Hash32, ...]=None,
59-
aggregate_sig: Iterable[int]=None) -> None:
57+
parent_hashes: Sequence[Hash32]=None,
58+
aggregate_sig: Sequence[int]=None) -> None:
6059
if parent_hashes is None:
6160
parent_hashes = ()
6261
if aggregate_sig is None:
63-
aggregate_sig = [0, 0]
62+
aggregate_sig = (0, 0)
6463

6564
super().__init__(
6665
slot=slot,
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
CountableList,
11+
)
12+
13+
from eth.rlp.sedes import (
14+
uint64,
15+
hash32,
16+
)
17+
18+
19+
class AttestationSignedData(rlp.Serializable):
20+
"""
21+
Note: using RLP until we have standardized serialization format.
22+
"""
23+
fields = [
24+
# Slot number
25+
('slot', uint64),
26+
# Shard number
27+
('shard', uint64),
28+
# CYCLE_LENGTH parent hashes
29+
('parent_hashes', CountableList(hash32)),
30+
# Shard block hash being attested to
31+
('shard_block_hash', hash32),
32+
# Last crosslink hash
33+
('last_crosslink_hash', hash32),
34+
# Root of data between last hash and this one
35+
('shard_block_combined_data_root', hash32),
36+
# Hash of last justified beacon block
37+
('justified_slot', uint64),
38+
]
39+
40+
def __init__(self,
41+
slot: int,
42+
shard: int,
43+
shard_block_hash: Hash32,
44+
last_crosslink_hash: Hash32,
45+
shard_block_combined_data_root: Hash32,
46+
justified_slot: int,
47+
parent_hashes: Sequence[Hash32]=None) -> None:
48+
if parent_hashes is None:
49+
parent_hashes = ()
50+
51+
super().__init__(
52+
slot=slot,
53+
shard=shard,
54+
parent_hashes=parent_hashes,
55+
shard_block_hash=shard_block_hash,
56+
last_crosslink_hash=last_crosslink_hash,
57+
shard_block_combined_data_root=shard_block_combined_data_root,
58+
justified_slot=justified_slot
59+
)

eth/beacon/types/proposal_signed_data.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class ProposalSignedData(rlp.Serializable):
1414
Note: using RLP until we have standardized serialization format.
1515
"""
1616
fields = [
17-
# Fork version
1817
# Slot number
1918
('slot', uint64),
2019
# Shard number (or `2**64 - 1` for beacon chain)

eth/beacon/types/validator_records.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class ValidatorRecord(rlp.Serializable):
2121
('withdrawal_credentials', hash32),
2222
# RANDAO commitment
2323
('randao_commitment', hash32),
24-
# Slot the RANDAO commitment was last changed
25-
('randao_last_change', uint64),
24+
# Slot the proposer has skipped (ie. layers of RANDAO expected)
25+
('randao_skips', uint64),
2626
# Balance in Gwei
2727
('balance', uint64),
2828
# Status code
@@ -37,7 +37,7 @@ def __init__(self,
3737
pubkey: int,
3838
withdrawal_credentials: Hash32,
3939
randao_commitment: Hash32,
40-
randao_last_change: int,
40+
randao_skips: int,
4141
balance: int,
4242
status: int,
4343
last_status_change_slot: int,
@@ -46,7 +46,7 @@ def __init__(self,
4646
pubkey=pubkey,
4747
withdrawal_credentials=withdrawal_credentials,
4848
randao_commitment=randao_commitment,
49-
randao_last_change=randao_last_change,
49+
randao_skips=randao_skips,
5050
balance=balance,
5151
status=status,
5252
last_status_change_slot=last_status_change_slot,

tests/beacon/conftest.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ def sample_attestation_record_params():
4646
}
4747

4848

49+
@pytest.fixture
50+
def sample_attestation_signed_data_params():
51+
return {
52+
'slot': 10,
53+
'shard': 12,
54+
'parent_hashes': [b'\x11' * 32],
55+
'shard_block_hash': b'\x22' * 32,
56+
'last_crosslink_hash': b'\x33' * 32,
57+
'shard_block_combined_data_root': b'\x44' * 32,
58+
'justified_slot': 5,
59+
}
60+
61+
4962
@pytest.fixture
5063
def sample_beacon_block_params():
5164
return {
@@ -154,7 +167,7 @@ def sample_validator_record_params():
154167
'pubkey': 123,
155168
'withdrawal_credentials': b'\x01' * 32,
156169
'randao_commitment': b'\x01' * 32,
157-
'randao_last_change': 1,
170+
'randao_skips': 1,
158171
'balance': 100,
159172
'status': 1,
160173
'last_status_change_slot': 0,
@@ -243,11 +256,6 @@ def min_attestation_inclusion_delay():
243256
return SERENITY_CONFIG.MIN_ATTESTATION_INCLUSION_DELAY
244257

245258

246-
@pytest.fixture
247-
def randao_slots_per_layer():
248-
return SERENITY_CONFIG.RANDAO_SLOTS_PER_LAYER
249-
250-
251259
@pytest.fixture
252260
def sqrt_e_drop_time():
253261
return SERENITY_CONFIG.SQRT_E_DROP_TIME
@@ -299,8 +307,8 @@ def pow_contract_merkle_tree_depth():
299307

300308

301309
@pytest.fixture
302-
def logout_message():
303-
return SERENITY_CONFIG.LOGOUT_MESSAGE
310+
def max_attestation_count():
311+
return SERENITY_CONFIG.MAX_ATTESTATION_COUNT
304312

305313

306314
@pytest.fixture
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import pytest
2+
3+
from eth.beacon.types.attestation_signed_data import (
4+
AttestationSignedData,
5+
)
6+
7+
8+
@pytest.mark.parametrize(
9+
'param,default_value',
10+
[
11+
('parent_hashes', ()),
12+
]
13+
)
14+
def test_defaults(param, default_value, sample_attestation_signed_data_params):
15+
del sample_attestation_signed_data_params[param]
16+
attestation_signed_data = AttestationSignedData(**sample_attestation_signed_data_params)
17+
18+
assert getattr(attestation_signed_data, param) == default_value

0 commit comments

Comments
 (0)