@@ -62,79 +62,82 @@ class BaseBeaconChainDB(ABC):
62
62
@abstractmethod
63
63
def persist_block (self ,
64
64
block : BaseBeaconBlock ) -> Tuple [Tuple [bytes , ...], Tuple [bytes , ...]]:
65
- raise NotImplementedError ( "BeaconChainDB classes must implement this method" )
65
+ pass
66
66
67
67
@abstractmethod
68
68
def get_canonical_block_hash (self , slot : int ) -> Hash32 :
69
- raise NotImplementedError ( "BeaconChainDB classes must implement this method" )
69
+ pass
70
70
71
71
@abstractmethod
72
72
def get_canonical_block_by_slot (self , slot : int ) -> BaseBeaconBlock :
73
- raise NotImplementedError ( "BeaconChainDB classes must implement this method" )
73
+ pass
74
74
75
75
@abstractmethod
76
76
def get_canonical_head (self ) -> BaseBeaconBlock :
77
- raise NotImplementedError ( "BeaconChainDB classes must implement this method" )
77
+ pass
78
78
79
79
@abstractmethod
80
80
def get_block_by_hash (self , block_hash : Hash32 ) -> BaseBeaconBlock :
81
- raise NotImplementedError ( "BeaconChainDB classes must implement this method" )
81
+ pass
82
82
83
83
@abstractmethod
84
84
def get_score (self , block_hash : Hash32 ) -> int :
85
- raise NotImplementedError ( "BeaconChainDB classes must implement this method" )
85
+ pass
86
86
87
87
@abstractmethod
88
88
def block_exists (self , block_hash : Hash32 ) -> bool :
89
- raise NotImplementedError ( "BeaconChainDB classes must implement this method" )
89
+ pass
90
90
91
91
@abstractmethod
92
92
def persist_block_chain (
93
93
self ,
94
94
blocks : Iterable [BaseBeaconBlock ]
95
95
) -> Tuple [Tuple [BaseBeaconBlock , ...], Tuple [BaseBeaconBlock , ...]]:
96
- raise NotImplementedError ( "BeaconChainDB classes must implement this method" )
96
+ pass
97
97
98
98
#
99
99
# Crystallized State
100
100
#
101
101
@abstractmethod
102
102
def get_crystallized_state_by_root (self , state_root : Hash32 ) -> CrystallizedState :
103
- raise NotImplementedError ( "BeaconChainDB classes must implement this method" )
103
+ pass
104
104
105
105
@abstractmethod
106
106
def get_canonical_crystallized_state_root (self , slot : int ) -> Hash32 :
107
- raise NotImplementedError ( "BeaconChainDB classes must implement this method" )
107
+ pass
108
108
109
109
@abstractmethod
110
110
def persist_crystallized_state (self ,
111
111
crystallized_state : CrystallizedState ) -> None :
112
- raise NotImplementedError ( "BeaconChainDB classes must implement this method" )
112
+ pass
113
113
114
114
#
115
115
# Active State
116
116
#
117
+ @abstractmethod
117
118
def get_active_state_by_root (self , state_root : Hash32 ) -> ActiveState :
118
- raise NotImplementedError ( "BeaconChainDB classes must implement this method" )
119
+ pass
119
120
121
+ @abstractmethod
120
122
def get_active_state_root_by_crystallized (self , crystallized_state_root : Hash32 ) -> Hash32 :
121
- raise NotImplementedError ( "BeaconChainDB classes must implement this method" )
123
+ pass
122
124
125
+ @abstractmethod
123
126
def persist_active_state (self ,
124
127
active_state : ActiveState ,
125
128
crystallized_state_root : Hash32 ) -> None :
126
- raise NotImplementedError ( "BeaconChainDB classes must implement this method" )
129
+ pass
127
130
128
131
#
129
132
# Raw Database API
130
133
#
131
134
@abstractmethod
132
135
def exists (self , key : bytes ) -> bool :
133
- raise NotImplementedError ( "BeaconChainDB classes must implement this method" )
136
+ pass
134
137
135
138
@abstractmethod
136
139
def get (self , key : bytes ) -> bytes :
137
- raise NotImplementedError ( "BeaconChainDB classes must implement this method" )
140
+ pass
138
141
139
142
140
143
class BeaconChainDB (BaseBeaconChainDB ):
@@ -170,9 +173,9 @@ def _persist_block(
170
173
#
171
174
def get_canonical_block_hash (self , slot : int ) -> Hash32 :
172
175
"""
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.
174
177
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
176
179
canonical chain.
177
180
"""
178
181
return self ._get_canonical_block_hash (self .db , slot )
@@ -192,9 +195,9 @@ def _get_canonical_block_hash(db: BaseDB, slot: int) -> Hash32:
192
195
193
196
def get_canonical_block_by_slot (self , slot : int ) -> BaseBeaconBlock :
194
197
"""
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.
196
199
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
198
201
canonical chain.
199
202
"""
200
203
return self ._get_canonical_block_by_slot (self .db , slot )
@@ -210,7 +213,7 @@ def _get_canonical_block_by_slot(
210
213
211
214
def get_canonical_head (self ) -> BaseBeaconBlock :
212
215
"""
213
- Returns the current block at the head of the chain.
216
+ Return the current block at the head of the chain.
214
217
"""
215
218
return self ._get_canonical_head (self .db )
216
219
@@ -228,9 +231,9 @@ def get_block_by_hash(self, block_hash: Hash32) -> BaseBeaconBlock:
228
231
@staticmethod
229
232
def _get_block_by_hash (db : BaseDB , block_hash : Hash32 ) -> BaseBeaconBlock :
230
233
"""
231
- Returns the requested block header as specified by block hash.
234
+ Return the requested block header as specified by block hash.
232
235
233
- Raises BlockNotFound if it is not present in the db.
236
+ Raise BlockNotFound if it is not present in the db.
234
237
"""
235
238
validate_word (block_hash , title = "Block Hash" )
236
239
try :
@@ -333,7 +336,7 @@ def _set_as_canonical_chain_head(
333
336
cls , db : BaseDB ,
334
337
block_hash : Hash32 ) -> Tuple [Tuple [BaseBeaconBlock , ...], Tuple [BaseBeaconBlock , ...]]:
335
338
"""
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
337
340
given block hash.
338
341
339
342
: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(
370
373
@to_tuple
371
374
def _find_new_ancestors (cls , db : BaseDB , block : BaseBeaconBlock ) -> Iterable [BaseBeaconBlock ]:
372
375
"""
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)
374
377
the first ancestor it has in common with our canonical chain.
375
378
376
379
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
402
405
@staticmethod
403
406
def _add_block_slot_to_hash_lookup (db : BaseDB , block : BaseBeaconBlock ) -> None :
404
407
"""
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
406
409
block slot.
407
410
"""
408
411
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
422
425
@staticmethod
423
426
def _get_crystallized_state_by_root (db : BaseDB , state_root : Hash32 ) -> CrystallizedState :
424
427
"""
425
- Returns the requested crystallized state as specified by state hash.
428
+ Return the requested crystallized state as specified by state hash.
426
429
427
430
Raises StateRootNotFound if it is not present in the db.
428
431
"""
@@ -436,7 +439,7 @@ def _get_crystallized_state_by_root(db: BaseDB, state_root: Hash32) -> Crystalli
436
439
437
440
def get_canonical_crystallized_state_root (self , slot : int ) -> Hash32 :
438
441
"""
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.
440
443
441
444
Raises StateRootNotFound if there's no state with the given slot in the
442
445
canonical chain.
@@ -478,7 +481,7 @@ def _add_slot_to_crystallized_state_lookup(cls,
478
481
db : BaseDB ,
479
482
crystallized_state : CrystallizedState ) -> None :
480
483
"""
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
482
485
last state recalculation slot.
483
486
484
487
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,
501
504
@staticmethod
502
505
def _get_deletable_state_roots (db : BaseDB ) -> Tuple [Hash32 ]:
503
506
"""
504
- Returns deletable_state_roots.
507
+ Return deletable_state_roots.
505
508
"""
506
509
lookup_key = SchemaV1 .make_deletable_state_roots_lookup_key ()
507
510
if not db .exists (lookup_key ):
@@ -516,7 +519,7 @@ def _get_deletable_state_roots(db: BaseDB) -> Tuple[Hash32]:
516
519
@staticmethod
517
520
def _set_deletatable_state (db : BaseDB , deletable_state_roots : Iterable [Hash32 ]) -> None :
518
521
"""
519
- Sets deletable_state_roots.
522
+ Set deletable_state_roots.
520
523
"""
521
524
lookup_key = SchemaV1 .make_deletable_state_roots_lookup_key ()
522
525
db .set (
@@ -533,7 +536,7 @@ def get_active_state_by_root(self, state_root: Hash32) -> ActiveState:
533
536
@staticmethod
534
537
def _get_active_state_by_root (db : BaseDB , state_root : Hash32 ) -> ActiveState :
535
538
"""
536
- Returns the requested crystallized state as specified by state hash.
539
+ Return the requested crystallized state as specified by state hash.
537
540
538
541
Raises StateRootNotFound if it is not present in the db.
539
542
"""
@@ -547,7 +550,7 @@ def _get_active_state_by_root(db: BaseDB, state_root: Hash32) -> ActiveState:
547
550
548
551
def get_active_state_root_by_crystallized (self , crystallized_state_root : Hash32 ) -> Hash32 :
549
552
"""
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.
551
554
552
555
Raises StateRootNotFound if there's no state with the given slot in the
553
556
canonical chain.
@@ -598,7 +601,7 @@ def _add_crystallized_to_active_state_lookup(cls,
598
601
active_state : ActiveState ,
599
602
crystallized_state_root : Hash32 ) -> None :
600
603
"""
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
602
605
last state recalculation slot.
603
606
"""
604
607
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,
614
617
#
615
618
def exists (self , key : bytes ) -> bool :
616
619
"""
617
- Returns True if the given key exists in the database.
620
+ Return True if the given key exists in the database.
618
621
"""
619
622
return self .db .exists (key )
620
623
0 commit comments