Skip to content

Commit 340f0af

Browse files
committed
PR feedback - mostly enhance docstring and rename some parameters
1 parent 1733d53 commit 340f0af

File tree

5 files changed

+74
-64
lines changed

5 files changed

+74
-64
lines changed

eth/beacon/db/chain.py

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -62,79 +62,82 @@ class BaseBeaconChainDB(ABC):
6262
@abstractmethod
6363
def persist_block(self,
6464
block: BaseBeaconBlock) -> Tuple[Tuple[bytes, ...], Tuple[bytes, ...]]:
65-
raise NotImplementedError("BeaconChainDB classes must implement this method")
65+
pass
6666

6767
@abstractmethod
6868
def get_canonical_block_hash(self, slot: int) -> Hash32:
69-
raise NotImplementedError("BeaconChainDB classes must implement this method")
69+
pass
7070

7171
@abstractmethod
7272
def get_canonical_block_by_slot(self, slot: int) -> BaseBeaconBlock:
73-
raise NotImplementedError("BeaconChainDB classes must implement this method")
73+
pass
7474

7575
@abstractmethod
7676
def get_canonical_head(self) -> BaseBeaconBlock:
77-
raise NotImplementedError("BeaconChainDB classes must implement this method")
77+
pass
7878

7979
@abstractmethod
8080
def get_block_by_hash(self, block_hash: Hash32) -> BaseBeaconBlock:
81-
raise NotImplementedError("BeaconChainDB classes must implement this method")
81+
pass
8282

8383
@abstractmethod
8484
def get_score(self, block_hash: Hash32) -> int:
85-
raise NotImplementedError("BeaconChainDB classes must implement this method")
85+
pass
8686

8787
@abstractmethod
8888
def block_exists(self, block_hash: Hash32) -> bool:
89-
raise NotImplementedError("BeaconChainDB classes must implement this method")
89+
pass
9090

9191
@abstractmethod
9292
def persist_block_chain(
9393
self,
9494
blocks: Iterable[BaseBeaconBlock]
9595
) -> Tuple[Tuple[BaseBeaconBlock, ...], Tuple[BaseBeaconBlock, ...]]:
96-
raise NotImplementedError("BeaconChainDB classes must implement this method")
96+
pass
9797

9898
#
9999
# Crystallized State
100100
#
101101
@abstractmethod
102102
def get_crystallized_state_by_root(self, state_root: Hash32) -> CrystallizedState:
103-
raise NotImplementedError("BeaconChainDB classes must implement this method")
103+
pass
104104

105105
@abstractmethod
106106
def get_canonical_crystallized_state_root(self, slot: int) -> Hash32:
107-
raise NotImplementedError("BeaconChainDB classes must implement this method")
107+
pass
108108

109109
@abstractmethod
110110
def persist_crystallized_state(self,
111111
crystallized_state: CrystallizedState) -> None:
112-
raise NotImplementedError("BeaconChainDB classes must implement this method")
112+
pass
113113

114114
#
115115
# Active State
116116
#
117+
@abstractmethod
117118
def get_active_state_by_root(self, state_root: Hash32) -> ActiveState:
118-
raise NotImplementedError("BeaconChainDB classes must implement this method")
119+
pass
119120

121+
@abstractmethod
120122
def get_active_state_root_by_crystallized(self, crystallized_state_root: Hash32) -> Hash32:
121-
raise NotImplementedError("BeaconChainDB classes must implement this method")
123+
pass
122124

125+
@abstractmethod
123126
def persist_active_state(self,
124127
active_state: ActiveState,
125128
crystallized_state_root: Hash32) -> None:
126-
raise NotImplementedError("BeaconChainDB classes must implement this method")
129+
pass
127130

128131
#
129132
# Raw Database API
130133
#
131134
@abstractmethod
132135
def exists(self, key: bytes) -> bool:
133-
raise NotImplementedError("BeaconChainDB classes must implement this method")
136+
pass
134137

135138
@abstractmethod
136139
def get(self, key: bytes) -> bytes:
137-
raise NotImplementedError("BeaconChainDB classes must implement this method")
140+
pass
138141

139142

140143
class BeaconChainDB(BaseBeaconChainDB):
@@ -170,9 +173,9 @@ def _persist_block(
170173
#
171174
def get_canonical_block_hash(self, slot: int) -> Hash32:
172175
"""
173-
Returns the block hash for the canonical block at the given number.
176+
Return the block hash for the canonical block at the given number.
174177
175-
Raises BlockNotFound if there's no block with the given number in the
178+
Raise BlockNotFound if there's no block with the given number in the
176179
canonical chain.
177180
"""
178181
return self._get_canonical_block_hash(self.db, slot)
@@ -192,9 +195,9 @@ def _get_canonical_block_hash(db: BaseDB, slot: int) -> Hash32:
192195

193196
def get_canonical_block_by_slot(self, slot: int) -> BaseBeaconBlock:
194197
"""
195-
Returns the block header with the given slot in the canonical chain.
198+
Return the block header with the given slot in the canonical chain.
196199
197-
Raises BlockNotFound if there's no block with the given slot in the
200+
Raise BlockNotFound if there's no block with the given slot in the
198201
canonical chain.
199202
"""
200203
return self._get_canonical_block_by_slot(self.db, slot)
@@ -210,7 +213,7 @@ def _get_canonical_block_by_slot(
210213

211214
def get_canonical_head(self) -> BaseBeaconBlock:
212215
"""
213-
Returns the current block at the head of the chain.
216+
Return the current block at the head of the chain.
214217
"""
215218
return self._get_canonical_head(self.db)
216219

@@ -228,9 +231,9 @@ def get_block_by_hash(self, block_hash: Hash32) -> BaseBeaconBlock:
228231
@staticmethod
229232
def _get_block_by_hash(db: BaseDB, block_hash: Hash32) -> BaseBeaconBlock:
230233
"""
231-
Returns the requested block header as specified by block hash.
234+
Return the requested block header as specified by block hash.
232235
233-
Raises BlockNotFound if it is not present in the db.
236+
Raise BlockNotFound if it is not present in the db.
234237
"""
235238
validate_word(block_hash, title="Block Hash")
236239
try:
@@ -333,7 +336,7 @@ def _set_as_canonical_chain_head(
333336
cls, db: BaseDB,
334337
block_hash: Hash32) -> Tuple[Tuple[BaseBeaconBlock, ...], Tuple[BaseBeaconBlock, ...]]:
335338
"""
336-
Sets the canonical chain HEAD to the block as specified by the
339+
Set the canonical chain HEAD to the block as specified by the
337340
given block hash.
338341
339342
:return: a tuple of the blocks that are newly in the canonical chain, and the blocks that
@@ -370,7 +373,7 @@ def _set_as_canonical_chain_head(
370373
@to_tuple
371374
def _find_new_ancestors(cls, db: BaseDB, block: BaseBeaconBlock) -> Iterable[BaseBeaconBlock]:
372375
"""
373-
Returns the chain leading up from the given block until (but not including)
376+
Return the chain leading up from the given block until (but not including)
374377
the first ancestor it has in common with our canonical chain.
375378
376379
If D is the canonical head in the following chain, and F is the new block,
@@ -402,7 +405,7 @@ def _find_new_ancestors(cls, db: BaseDB, block: BaseBeaconBlock) -> Iterable[Bas
402405
@staticmethod
403406
def _add_block_slot_to_hash_lookup(db: BaseDB, block: BaseBeaconBlock) -> None:
404407
"""
405-
Sets a record in the database to allow looking up this block by its
408+
Set a record in the database to allow looking up this block by its
406409
block slot.
407410
"""
408411
block_slot_to_hash_key = SchemaV1.make_block_slot_to_hash_lookup_key(
@@ -422,7 +425,7 @@ def get_crystallized_state_by_root(self, state_root: Hash32) -> CrystallizedStat
422425
@staticmethod
423426
def _get_crystallized_state_by_root(db: BaseDB, state_root: Hash32) -> CrystallizedState:
424427
"""
425-
Returns the requested crystallized state as specified by state hash.
428+
Return the requested crystallized state as specified by state hash.
426429
427430
Raises StateRootNotFound if it is not present in the db.
428431
"""
@@ -436,7 +439,7 @@ def _get_crystallized_state_by_root(db: BaseDB, state_root: Hash32) -> Crystalli
436439

437440
def get_canonical_crystallized_state_root(self, slot: int) -> Hash32:
438441
"""
439-
Returns the state hash for the canonical state at the given slot.
442+
Return the state hash for the canonical state at the given slot.
440443
441444
Raises StateRootNotFound if there's no state with the given slot in the
442445
canonical chain.
@@ -478,7 +481,7 @@ def _add_slot_to_crystallized_state_lookup(cls,
478481
db: BaseDB,
479482
crystallized_state: CrystallizedState) -> None:
480483
"""
481-
Sets a record in the database to allow looking up this block by its
484+
Set a record in the database to allow looking up this block by its
482485
last state recalculation slot.
483486
484487
If it's a fork, store the old state root in `deletable_state_roots`.
@@ -501,7 +504,7 @@ def _add_slot_to_crystallized_state_lookup(cls,
501504
@staticmethod
502505
def _get_deletable_state_roots(db: BaseDB) -> Tuple[Hash32]:
503506
"""
504-
Returns deletable_state_roots.
507+
Return deletable_state_roots.
505508
"""
506509
lookup_key = SchemaV1.make_deletable_state_roots_lookup_key()
507510
if not db.exists(lookup_key):
@@ -516,7 +519,7 @@ def _get_deletable_state_roots(db: BaseDB) -> Tuple[Hash32]:
516519
@staticmethod
517520
def _set_deletatable_state(db: BaseDB, deletable_state_roots: Iterable[Hash32]) -> None:
518521
"""
519-
Sets deletable_state_roots.
522+
Set deletable_state_roots.
520523
"""
521524
lookup_key = SchemaV1.make_deletable_state_roots_lookup_key()
522525
db.set(
@@ -533,7 +536,7 @@ def get_active_state_by_root(self, state_root: Hash32) -> ActiveState:
533536
@staticmethod
534537
def _get_active_state_by_root(db: BaseDB, state_root: Hash32) -> ActiveState:
535538
"""
536-
Returns the requested crystallized state as specified by state hash.
539+
Return the requested crystallized state as specified by state hash.
537540
538541
Raises StateRootNotFound if it is not present in the db.
539542
"""
@@ -547,7 +550,7 @@ def _get_active_state_by_root(db: BaseDB, state_root: Hash32) -> ActiveState:
547550

548551
def get_active_state_root_by_crystallized(self, crystallized_state_root: Hash32) -> Hash32:
549552
"""
550-
Returns the state hash for the canonical state at the given crystallized_state_root.
553+
Return the state hash for the canonical state at the given crystallized_state_root.
551554
552555
Raises StateRootNotFound if there's no state with the given slot in the
553556
canonical chain.
@@ -598,7 +601,7 @@ def _add_crystallized_to_active_state_lookup(cls,
598601
active_state: ActiveState,
599602
crystallized_state_root: Hash32) -> None:
600603
"""
601-
Sets a record in the database to allow looking up this block by its
604+
Set a record in the database to allow looking up this block by its
602605
last state recalculation slot.
603606
"""
604607
slot_to_hash_key = SchemaV1.make_crystallized_to_active_state_root_lookup_key(
@@ -614,7 +617,7 @@ def _add_crystallized_to_active_state_lookup(cls,
614617
#
615618
def exists(self, key: bytes) -> bool:
616619
"""
617-
Returns True if the given key exists in the database.
620+
Return True if the given key exists in the database.
618621
"""
619622
return self.db.exists(key)
620623

eth/beacon/db/schema.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,35 @@ class BaseSchema(ABC):
1212
@staticmethod
1313
@abstractmethod
1414
def make_canonical_head_hash_lookup_key() -> bytes:
15-
raise NotImplementedError('Must be implemented by subclasses')
15+
pass
1616

1717
@staticmethod
1818
@abstractmethod
1919
def make_block_slot_to_hash_lookup_key(slot: int) -> bytes:
20-
raise NotImplementedError('Must be implemented by subclasses')
20+
pass
2121

2222
@staticmethod
2323
@abstractmethod
2424
def make_block_hash_to_score_lookup_key(block_hash: Hash32) -> bytes:
25-
raise NotImplementedError('Must be implemented by subclasses')
25+
pass
2626

2727
#
2828
# States
2929
#
3030
@staticmethod
3131
@abstractmethod
3232
def make_slot_to_crystallized_state_lookup_key(slot: int) -> bytes:
33-
raise NotImplementedError('Must be implemented by subclasses')
33+
pass
3434

3535
@staticmethod
3636
@abstractmethod
3737
def make_crystallized_to_active_state_root_lookup_key(state_root: Hash32) -> bytes:
38-
raise NotImplementedError('Must be implemented by subclasses')
38+
pass
3939

4040
@staticmethod
4141
@abstractmethod
4242
def make_deletable_state_roots_lookup_key() -> bytes:
43-
raise NotImplementedError('Must be implemented by subclasses')
43+
pass
4444

4545

4646
class SchemaV1(BaseSchema):

eth/beacon/genesis_helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import (
2-
List,
2+
Sequence,
33
TYPE_CHECKING,
44
)
55

@@ -32,7 +32,7 @@ def get_genesis_active_state(cycle_length: int) -> ActiveState:
3232

3333

3434
def get_genesis_crystallized_state(
35-
validators: List['ValidatorRecord'],
35+
validators: Sequence['ValidatorRecord'],
3636
init_shuffling_seed: Hash32,
3737
cycle_length: int,
3838
min_committee_size: int,

0 commit comments

Comments
 (0)