Skip to content

Commit e792570

Browse files
committed
1 parent 673b565 commit e792570

File tree

11 files changed

+135
-103
lines changed

11 files changed

+135
-103
lines changed

eth/beacon/state_machines/configs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
('POW_RECEIPT_ROOT_VOTING_PERIOD', int), # slots
2929
('SLASHING_WHISTLEBLOWER_REWARD_DENOMINATOR', int),
3030
('BASE_REWARD_QUOTIENT', int),
31+
('INCLUDER_REWARD_SHARE_QUOTIENT', int),
3132
('MAX_VALIDATOR_CHURN_QUOTIENT', int),
3233
('POW_CONTRACT_MERKLE_TREE_DEPTH', int),
3334
('MAX_ATTESTATION_COUNT', int),

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
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-
SQRT_E_DROP_TIME=2**18, # = 262,144 slots
18+
SQRT_E_DROP_TIME=2**11, # = 2,048 cycles
1919
WITHDRAWALS_PER_CYCLE=2**2, # = 4 validators
2020
MIN_WITHDRAWAL_PERIOD=2**13, # = 8,192 slots
2121
DELETION_PERIOD=2**22, # = 4,194,304 slots
2222
COLLECTIVE_PENALTY_CALCULATION_PERIOD=2**20, # = 1,048,576 slots
2323
POW_RECEIPT_ROOT_VOTING_PERIOD=2**10, # = 1024
2424
SLASHING_WHISTLEBLOWER_REWARD_DENOMINATOR=2**9, # = 512
25-
BASE_REWARD_QUOTIENT=2**15, # = 32,768
25+
BASE_REWARD_QUOTIENT=2**11, # = 2,048
26+
INCLUDER_REWARD_SHARE_QUOTIENT=2**3, # = 8
2627
MAX_VALIDATOR_CHURN_QUOTIENT=2**5, # = 32
2728
POW_CONTRACT_MERKLE_TREE_DEPTH=2**5, # =32
2829
MAX_ATTESTATION_COUNT=2**7, # 128

eth/beacon/types/attestation_records.py

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
Sequence,
33
)
44

5-
from eth_typing import (
6-
Hash32,
7-
)
85
import rlp
96
from rlp.sedes import (
107
binary,
118
CountableList,
129
)
1310

1411
from eth.rlp.sedes import (
15-
uint64,
1612
uint256,
17-
hash32,
13+
)
14+
15+
16+
from .attestation_signed_data import (
17+
AttestationSignedData,
1818
)
1919

2020

@@ -23,53 +23,26 @@ class AttestationRecord(rlp.Serializable):
2323
Note: using RLP until we have standardized serialization format.
2424
"""
2525
fields = [
26-
# Slot number
27-
('slot', uint64),
28-
# Shard number
29-
('shard', uint64),
30-
# Beacon block hashes not part of the current chain, oldest to newest
31-
('parent_hashes', CountableList(hash32)),
32-
# Shard block hash being attested to
33-
('shard_block_hash', hash32),
34-
# Last crosslink hash
35-
('last_crosslink_hash', hash32),
36-
# Root of data between last hash and this one
37-
('shard_block_combined_data_root', hash32),
38-
# Attester participation bitfield (1 bit per attester)
26+
('data', AttestationSignedData),
27+
# Attester participation bitfield
3928
('attester_bitfield', binary),
40-
# Hash of last justified beacon block
41-
('justified_slot', uint64),
42-
# Slot of last justified beacon block
43-
('justified_block_hash', hash32),
29+
# Proof of custody bitfield
30+
('poc_bitfield', binary),
4431
# BLS aggregate signature
4532
('aggregate_sig', CountableList(uint256)),
4633
]
4734

4835
def __init__(self,
49-
slot: int,
50-
shard: int,
51-
shard_block_hash: Hash32,
52-
last_crosslink_hash: Hash32,
53-
shard_block_combined_data_root: Hash32,
36+
data: AttestationSignedData,
5437
attester_bitfield: bytes,
55-
justified_slot: int,
56-
justified_block_hash: Hash32,
57-
parent_hashes: Sequence[Hash32]=None,
38+
poc_bitfield: bytes,
5839
aggregate_sig: Sequence[int]=None) -> None:
59-
if parent_hashes is None:
60-
parent_hashes = ()
6140
if aggregate_sig is None:
6241
aggregate_sig = (0, 0)
6342

6443
super().__init__(
65-
slot=slot,
66-
shard=shard,
67-
parent_hashes=parent_hashes,
68-
shard_block_hash=shard_block_hash,
69-
last_crosslink_hash=last_crosslink_hash,
70-
shard_block_combined_data_root=shard_block_combined_data_root,
44+
data=data,
7145
attester_bitfield=attester_bitfield,
72-
justified_slot=justified_slot,
73-
justified_block_hash=justified_block_hash,
46+
poc_bitfield=poc_bitfield,
7447
aggregate_sig=aggregate_sig,
7548
)
Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
from typing import (
2-
Sequence,
3-
)
4-
51
from eth_typing import (
62
Hash32,
73
)
84
import rlp
9-
from rlp.sedes import (
10-
CountableList,
11-
)
125

136
from eth.rlp.sedes import (
147
uint64,
@@ -25,35 +18,36 @@ class AttestationSignedData(rlp.Serializable):
2518
('slot', uint64),
2619
# Shard number
2720
('shard', uint64),
28-
# CYCLE_LENGTH parent hashes
29-
('parent_hashes', CountableList(hash32)),
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),
3025
# Shard block hash being attested to
3126
('shard_block_hash', hash32),
3227
# Last crosslink hash
3328
('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
29+
# Slot of last justified beacon block
3730
('justified_slot', uint64),
31+
# Hash of last justified beacon block
32+
('justified_block_hash', hash32),
3833
]
3934

4035
def __init__(self,
4136
slot: int,
4237
shard: int,
38+
block_hash: Hash32,
39+
cycle_boundary_hash: Hash32,
4340
shard_block_hash: Hash32,
4441
last_crosslink_hash: Hash32,
45-
shard_block_combined_data_root: Hash32,
4642
justified_slot: int,
47-
parent_hashes: Sequence[Hash32]=None) -> None:
48-
if parent_hashes is None:
49-
parent_hashes = ()
50-
43+
justified_block_hash: Hash32) -> None:
5144
super().__init__(
5245
slot=slot,
5346
shard=shard,
54-
parent_hashes=parent_hashes,
47+
block_hash=block_hash,
48+
cycle_boundary_hash=cycle_boundary_hash,
5549
shard_block_hash=shard_block_hash,
5650
last_crosslink_hash=last_crosslink_hash,
57-
shard_block_combined_data_root=shard_block_combined_data_root,
58-
justified_slot=justified_slot
51+
justified_slot=justified_slot,
52+
justified_block_hash=justified_block_hash,
5953
)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import rlp
2+
from rlp.sedes import (
3+
binary,
4+
)
5+
6+
from eth.rlp.sedes import (
7+
uint64,
8+
)
9+
10+
11+
from .attestation_signed_data import (
12+
AttestationSignedData,
13+
)
14+
15+
16+
class ProcessedAttestation(rlp.Serializable):
17+
"""
18+
Note: using RLP until we have standardized serialization format.
19+
"""
20+
fields = [
21+
# Signed data
22+
('data', AttestationSignedData),
23+
# Attester participation bitfield
24+
('attester_bitfield', binary),
25+
# Proof of custody bitfield
26+
('poc_bitfield', binary),
27+
# Slot in which it was included
28+
('slot_included', uint64),
29+
]
30+
31+
def __init__(self,
32+
data: AttestationSignedData,
33+
attester_bitfield: bytes,
34+
poc_bitfield: bytes,
35+
slot_included: int) -> None:
36+
super().__init__(
37+
data=data,
38+
attester_bitfield=attester_bitfield,
39+
poc_bitfield=poc_bitfield,
40+
slot_included=slot_included,
41+
)

eth/beacon/types/states.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
blake,
2424
)
2525

26-
from .attestation_records import AttestationRecord
26+
from .processed_attestation import ProcessedAttestation
2727
from .candidate_pow_receipt_root_records import CandidatePoWReceiptRootRecord
2828
from .crosslink_records import CrosslinkRecord
2929
from .shard_and_committees import ShardAndCommittee
@@ -46,10 +46,11 @@ class BeaconState(rlp.Serializable):
4646
('last_state_recalculation_slot', uint64),
4747
# Last finalized slot
4848
('last_finalized_slot', uint64),
49-
# Last justified slot
50-
('last_justified_slot', uint64),
51-
# Number of consecutive justified slots
52-
('justified_streak', uint64),
49+
# Justification source
50+
('justification_source', uint64),
51+
('prev_cycle_justification_source', uint64),
52+
# Recent justified slot bitmask
53+
('justified_slot_bitfield', uint64),
5354
# Committee members and their assigned shard, per slot
5455
('shard_and_committee_for_slots', CountableList(CountableList(ShardAndCommittee))),
5556
# Persistent shard committees
@@ -74,7 +75,7 @@ class BeaconState(rlp.Serializable):
7475
('post_fork_version', uint64),
7576
('fork_slot_number', uint64),
7677
# Attestations not yet processed
77-
('pending_attestations', CountableList(AttestationRecord)),
78+
('pending_attestations', CountableList(ProcessedAttestation)),
7879
# recent beacon block hashes needed to process attestations, older to newer
7980
('recent_block_hashes', CountableList(hash32)),
8081
# RANDAO state
@@ -85,8 +86,9 @@ def __init__(self,
8586
validator_set_change_slot: int,
8687
last_state_recalculation_slot: int,
8788
last_finalized_slot: int,
88-
last_justified_slot: int,
89-
justified_streak: int,
89+
justification_source: int,
90+
prev_cycle_justification_source: int,
91+
justified_slot_bitfield: int,
9092
next_shuffling_seed: Hash32,
9193
validator_set_delta_hash_chain: Hash32,
9294
current_exit_seq: int,
@@ -103,7 +105,7 @@ def __init__(self,
103105
persistent_committee_reassignments: Sequence[ShardReassignmentRecord]=None,
104106
deposits_penalized_in_period: Sequence[int]=None,
105107
candidate_pow_receipt_roots: Sequence[CandidatePoWReceiptRootRecord]=None,
106-
pending_attestations: Sequence[AttestationRecord]=None,
108+
pending_attestations: Sequence[ProcessedAttestation]=None,
107109
recent_block_hashes: Sequence[Hash32]=None
108110
) -> None:
109111
if validators is None:
@@ -129,8 +131,9 @@ def __init__(self,
129131
crosslinks=crosslinks,
130132
last_state_recalculation_slot=last_state_recalculation_slot,
131133
last_finalized_slot=last_finalized_slot,
132-
last_justified_slot=last_justified_slot,
133-
justified_streak=justified_streak,
134+
justification_source=justification_source,
135+
prev_cycle_justification_source=prev_cycle_justification_source,
136+
justified_slot_bitfield=justified_slot_bitfield,
134137
shard_and_committee_for_slots=shard_and_committee_for_slots,
135138
persistent_committees=persistent_committees,
136139
persistent_committee_reassignments=persistent_committee_reassignments,

tests/beacon/conftest.py

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
from eth.beacon.state_machines.forks.serenity.configs import SERENITY_CONFIG
77

8+
from eth.beacon.types.attestation_signed_data import (
9+
AttestationSignedData,
10+
)
11+
12+
813
DEFAULT_SHUFFLING_SEED = b'\00' * 32
914
DEFAULT_RANDAO = b'\45' * 32
1015
DEFAULT_NUM_VALIDATORS = 40
@@ -31,17 +36,11 @@ def pubkeys(keymap):
3136

3237

3338
@pytest.fixture
34-
def sample_attestation_record_params():
39+
def sample_attestation_record_params(sample_attestation_signed_data_params):
3540
return {
36-
'slot': 10,
37-
'shard': 12,
38-
'parent_hashes': [b'\x11' * 32],
39-
'shard_block_hash': b'\x22' * 32,
40-
'last_crosslink_hash': b'\x33' * 32,
41-
'shard_block_combined_data_root': b'\x44' * 32,
42-
'attester_bitfield': b'\x33\x1F',
43-
'justified_slot': 5,
44-
'justified_block_hash': b'\x33' * 32,
41+
'data': AttestationSignedData(**sample_attestation_signed_data_params),
42+
'attester_bitfield': b'\12' * 16,
43+
'poc_bitfield': b'\34' * 16,
4544
'aggregate_sig': [0, 0],
4645
}
4746

@@ -51,11 +50,12 @@ def sample_attestation_signed_data_params():
5150
return {
5251
'slot': 10,
5352
'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,
53+
'block_hash': b'\x11' * 32,
54+
'cycle_boundary_hash': b'\x22' * 32,
55+
'shard_block_hash': b'\x33' * 32,
56+
'last_crosslink_hash': b'\x44' * 32,
5857
'justified_slot': 5,
58+
'justified_block_hash': b'\x55' * 32,
5959
}
6060

6161

@@ -81,8 +81,9 @@ def sample_beacon_state_params():
8181
'crosslinks': (),
8282
'last_state_recalculation_slot': 1,
8383
'last_finalized_slot': 2,
84-
'last_justified_slot': 2,
85-
'justified_streak': 2,
84+
'prev_cycle_justification_source': 2,
85+
'justification_source': 2,
86+
'justified_slot_bitfield': 2,
8687
'shard_and_committee_for_slots': (),
8788
'persistent_committees': (),
8889
'persistent_committee_reassignments': (),
@@ -127,6 +128,16 @@ def sample_fork_data_params():
127128
}
128129

129130

131+
@pytest.fixture
132+
def sample_processed_attestation_params(sample_attestation_signed_data_params):
133+
return {
134+
'data': AttestationSignedData(**sample_attestation_signed_data_params),
135+
'attester_bitfield': b'\12' * 16,
136+
'poc_bitfield': b'\34' * 16,
137+
'slot_included': 0,
138+
}
139+
140+
130141
@pytest.fixture
131142
def sample_proposal_signed_data_params():
132143
return {
@@ -270,6 +281,11 @@ def sqrt_e_drop_time():
270281
return SERENITY_CONFIG.SQRT_E_DROP_TIME
271282

272283

284+
@pytest.fixture
285+
def includer_reward_share_quotient():
286+
return SERENITY_CONFIG.INCLUDER_REWARD_SHARE_QUOTIENT
287+
288+
273289
@pytest.fixture
274290
def withdrawals_per_cycle():
275291
return SERENITY_CONFIG.WITHDRAWALS_PER_CYCLE
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from eth.beacon.types.processed_attestation import (
2+
ProcessedAttestation,
3+
)
4+
5+
6+
def test_defaults(sample_processed_attestation_params):
7+
attestation_record = ProcessedAttestation(**sample_processed_attestation_params)
8+
9+
assert attestation_record.data == sample_processed_attestation_params['data']
10+
assert attestation_record.attester_bitfield == sample_processed_attestation_params['attester_bitfield'] # noqa: E501
11+
assert attestation_record.poc_bitfield == sample_processed_attestation_params['poc_bitfield']
12+
assert attestation_record.slot_included == sample_processed_attestation_params['slot_included']

tests/beacon/types/test_attestation_record.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
@pytest.mark.parametrize(
99
'param,default_value',
1010
[
11-
('parent_hashes', ()),
1211
('aggregate_sig', (0, 0)),
1312
]
1413
)

0 commit comments

Comments
 (0)