Skip to content

Commit b4aa281

Browse files
committed
Removed eth.beacon.config and added v1 namespace in DB schema
1 parent 2ba1d27 commit b4aa281

File tree

14 files changed

+155
-212
lines changed

14 files changed

+155
-212
lines changed

eth/beacon/config.py

Lines changed: 0 additions & 64 deletions
This file was deleted.

eth/beacon/db/schema.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,24 @@ def make_canonical_head_hash_lookup_key() -> bytes:
5353

5454
@staticmethod
5555
def make_block_slot_to_hash_lookup_key(slot: int) -> bytes:
56-
slot_to_hash_key = b'beacon:block-slot-to-hash:%d' % slot
56+
slot_to_hash_key = b'v1:beacon:block-slot-to-hash:%d' % slot
5757
return slot_to_hash_key
5858

5959
@staticmethod
6060
def make_block_hash_to_score_lookup_key(block_hash: Hash32) -> bytes:
61-
return b'beacon:block-hash-to-score:%s' % block_hash
61+
return b'v1:beacon:block-hash-to-score:%s' % block_hash
6262

6363
#
6464
# States
6565
#
6666
@staticmethod
6767
def make_slot_to_crystallized_state_lookup_key(slot: int) -> bytes:
68-
return b'beacon:slot-to-crystallized-state:%d' % slot
68+
return b'v1:beacon:slot-to-crystallized-state:%d' % slot
6969

7070
@staticmethod
7171
def make_crystallized_to_active_state_root_lookup_key(state_root: Hash32) -> bytes:
72-
return b'beacon:crystallized-root-to-active-state-root:%s' % state_root
72+
return b'v1:beacon:crystallized-root-to-active-state-root:%s' % state_root
7373

7474
@staticmethod
7575
def make_deletable_state_roots_lookup_key() -> bytes:
76-
return b'beacon:make-deletable-state-roots'
76+
return b'v1:beacon:make-deletable-state-roots'

eth/beacon/genesis_helpers.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from eth.constants import (
1111
ZERO_HASH32,
1212
)
13-
from eth.beacon.config import BeaconConfig # noqa: F401
1413
from eth.beacon.types.active_states import ActiveState
1514
from eth.beacon.types.blocks import BaseBeaconBlock
1615
from eth.beacon.types.crosslink_records import CrosslinkRecord
@@ -23,8 +22,8 @@
2322
from eth.beacon.types.validator_records import ValidatorRecord # noqa: F401
2423

2524

26-
def get_genesis_active_state(beacon_config: 'BeaconConfig') -> ActiveState:
27-
recent_block_hashes = [ZERO_HASH32] * beacon_config.cycle_length * 2
25+
def get_genesis_active_state(cycle_length: int) -> ActiveState:
26+
recent_block_hashes = [ZERO_HASH32] * cycle_length * 2
2827

2928
return ActiveState(
3029
pending_attestations=[],
@@ -35,17 +34,21 @@ def get_genesis_active_state(beacon_config: 'BeaconConfig') -> ActiveState:
3534
def get_genesis_crystallized_state(
3635
validators: List['ValidatorRecord'],
3736
init_shuffling_seed: Hash32,
38-
beacon_config: 'BeaconConfig') -> CrystallizedState:
37+
cycle_length: int,
38+
min_committee_size: int,
39+
shard_count: int) -> CrystallizedState:
3940

4041
current_dynasty = 1
4142
crosslinking_start_shard = 0
4243

4344
shard_and_committee_for_slots = get_new_shuffling(
44-
init_shuffling_seed,
45-
validators,
46-
current_dynasty,
47-
crosslinking_start_shard,
48-
beacon_config=beacon_config,
45+
seed=init_shuffling_seed,
46+
validators=validators,
47+
dynasty=current_dynasty,
48+
crosslinking_start_shard=crosslinking_start_shard,
49+
cycle_length=cycle_length,
50+
min_committee_size=min_committee_size,
51+
shard_count=shard_count,
4952
)
5053
# concatenate with itself to span 2*CYCLE_LENGTH
5154
shard_and_committee_for_slots = shard_and_committee_for_slots + shard_and_committee_for_slots
@@ -64,7 +67,7 @@ def get_genesis_crystallized_state(
6467
slot=0,
6568
hash=ZERO_HASH32,
6669
)
67-
for _ in range(beacon_config.shard_count)
70+
for _ in range(shard_count)
6871
],
6972
dynasty_seed=init_shuffling_seed,
7073
dynasty_start=0,

eth/beacon/helpers.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from eth.utils.blake import (
2121
blake,
2222
)
23-
from eth.beacon.config import BeaconConfig # noqa: F401
2423
from eth.beacon.types.shard_and_committees import (
2524
ShardAndCommittee,
2625
)
@@ -268,11 +267,14 @@ def _get_shards_and_committees_for_shard_indices(
268267

269268

270269
@to_tuple
271-
def get_new_shuffling(seed: Hash32,
270+
def get_new_shuffling(*,
271+
seed: Hash32,
272272
validators: Sequence['ValidatorRecord'],
273273
dynasty: int,
274274
crosslinking_start_shard: int,
275-
beacon_config: BeaconConfig) -> Iterable[Iterable[ShardAndCommittee]]:
275+
cycle_length: int,
276+
min_committee_size: int,
277+
shard_count: int) -> Iterable[Iterable[ShardAndCommittee]]:
276278
"""
277279
Returns shuffled ``shard_and_committee_for_slots`` (``[[ShardAndCommittee]]``) of
278280
the given active ``validators``.
@@ -317,10 +319,6 @@ def get_new_shuffling(seed: Hash32,
317319
318320
NOTE: The spec might be updated to output an array rather than an array of arrays.
319321
"""
320-
cycle_length = beacon_config.cycle_length
321-
min_committee_size = beacon_config.min_committee_size
322-
shard_count = beacon_config.shard_count
323-
324322
active_validators = get_active_validator_indices(dynasty, validators)
325323
active_validators_size = len(active_validators)
326324

@@ -353,11 +351,11 @@ def get_new_shuffling(seed: Hash32,
353351
#
354352
def get_proposer_position(parent_block: 'BaseBeaconBlock',
355353
crystallized_state: 'CrystallizedState',
356-
beacon_config: BeaconConfig) -> Tuple[int, int]:
354+
cycle_length: int) -> Tuple[int, int]:
357355
shards_and_committees = get_shards_and_committees_for_slot(
358356
crystallized_state,
359357
parent_block.slot_number,
360-
beacon_config.cycle_length,
358+
cycle_length,
361359
)
362360
"""
363361
Returns the proposer index in committee and the ``shard_id``.

eth/beacon/state_machines/base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,9 @@ def active_state(self) -> ActiveState:
165165
)
166166
blocks = blocks[::-1]
167167

168-
self._active_state = self.get_active_state_class().from_old_active_and_blocks(
168+
self._active_state = self.get_active_state_class().from_old_active_state_and_blocks(
169169
old_active_state,
170170
blocks,
171-
self.config.CYCLE_LENGTH * 2,
172171
)
173172

174173
return self._active_state

eth/beacon/state_machines/configs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
('DEFAULT_END_DYNASTY', int),
1010
('DEPOSIT_SIZE', int),
1111
('CYCLE_LENGTH', int),
12-
('MAX_VALIDATOR_COUNT', int),
1312
('MIN_COMMITTEE_SIZE', int),
1413
('MIN_DYNASTY_LENGTH', int),
1514
('SHARD_COUNT', int),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from .active_states import SerenityActiveState
1111
from .blocks import SerenityBeaconBlock
1212
from .crystallized_states import SerenityCrystallizedState
13-
from .configs import SENERITY_CONFIG
13+
from .configs import SERENITY_CONFIG
1414

1515

1616
class SerenityBeaconStateMachine(BeaconStateMachine):
@@ -21,4 +21,4 @@ class SerenityBeaconStateMachine(BeaconStateMachine):
2121
block_class = SerenityBeaconBlock # type: Type[BaseBeaconBlock]
2222
crystallized_state_class = SerenityCrystallizedState # type: Type[CrystallizedState]
2323
active_state_class = SerenityActiveState # type: Type[ActiveState]
24-
config = SENERITY_CONFIG
24+
config = SERENITY_CONFIG

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1+
2+
from typing import (
3+
Sequence,
4+
TYPE_CHECKING,
5+
)
6+
17
from eth.beacon.types.active_states import ActiveState
28
from eth.beacon.helpers import (
39
get_new_recent_block_hashes,
410
)
511

12+
if TYPE_CHECKING:
13+
from eth.beacon.types.blocks import BaseBeaconBlock
14+
615

716
class SerenityActiveState(ActiveState):
817
@classmethod
9-
def from_old_active_and_blocks(cls, old_active_state, blocks, recent_block_hashes_length):
18+
def from_old_active_state_and_blocks(cls,
19+
old_active_state: ActiveState,
20+
blocks: Sequence['BaseBlock']):
1021
recent_block_hashes = old_active_state.recent_block_hashes
1122
pending_attestations = old_active_state.pending_attestations
1223

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
from eth.beacon.state_machines.configs import BeaconConfig
44

55

6-
SENERITY_CONFIG = BeaconConfig(
6+
SERENITY_CONFIG = BeaconConfig(
77
BASE_REWARD_QUOTIENT=2**15,
88
DEFAULT_END_DYNASTY=9999999999999999999,
99
DEPOSIT_SIZE=32 * denoms.ether, # WEI
1010
CYCLE_LENGTH=64, # slots
11-
MAX_VALIDATOR_COUNT=2**22, # validators
1211
MIN_COMMITTEE_SIZE=128, # validators
1312
MIN_DYNASTY_LENGTH=256, # slots
1413
SHARD_COUNT=1024, # shards

0 commit comments

Comments
 (0)