@@ -260,7 +260,6 @@ def import_block(
260260 self .active_state ,
261261 block ,
262262 self .chaindb ,
263- self .config ,
264263 is_validating_signatures = True ,
265264 )
266265
@@ -278,49 +277,53 @@ def import_block(
278277
279278 return self .block , self .crystallized_state , self .active_state
280279
280+ def _update_the_states (self ,
281+ crystallized_state : CrystallizedState ,
282+ active_state : ActiveState ) -> None :
283+ self ._crytallized_state = crystallized_state
284+ self ._active_state = active_state
285+
281286 #
282287 # Process block APIs
283288 #
289+ @classmethod
284290 def process_block (
285- self ,
291+ cls ,
286292 crystallized_state : CrystallizedState ,
287293 active_state : ActiveState ,
288294 block : BaseBeaconBlock ,
289295 chaindb : BaseBeaconChainDB ,
290- config : BeaconConfig ,
291296 is_validating_signatures : bool = True
292297 ) -> Tuple [BaseBeaconBlock , CrystallizedState , ActiveState ]:
293298 """
294299 Process ``block`` and return the new crystallized state and active state.
295300 """
296301 # Process per block state changes (ActiveState)
297- processing_active_state = self .compute_per_block_transition (
302+ processing_active_state = cls .compute_per_block_transition (
298303 crystallized_state ,
299304 active_state ,
300305 block ,
301306 chaindb ,
302- config .CYCLE_LENGTH ,
303307 is_validating_signatures = is_validating_signatures ,
304308 )
305309
306310 # Process per cycle state changes (CrystallizedState and ActiveState)
307- processed_crystallized_state , processed_active_state = self .compute_cycle_transitions (
311+ processed_crystallized_state , processed_active_state = cls .compute_cycle_transitions (
308312 crystallized_state ,
309313 processing_active_state ,
310314 block ,
311- config ,
312315 )
313316
314317 # Return the copy
315318 result_block = block .copy ()
316319 return result_block , processed_crystallized_state , processed_active_state
317320
318- def compute_per_block_transition (self ,
321+ @classmethod
322+ def compute_per_block_transition (cls ,
319323 crystallized_state : CrystallizedState ,
320324 active_state : ActiveState ,
321325 block : BaseBeaconBlock ,
322326 chaindb : BaseBeaconChainDB ,
323- cycle_length : int ,
324327 is_validating_signatures : bool = True ) -> ActiveState :
325328 """
326329 Process ``block`` and return the new ActiveState.
@@ -341,11 +344,11 @@ def compute_per_block_transition(self,
341344 crystallized_state ,
342345 block ,
343346 parent_block ,
344- cycle_length ,
347+ cls . config . CYCLE_LENGTH ,
345348 )
346349
347350 # TODO: to implement the RANDAO reveal validation.
348- self .validate_randao_reveal ()
351+ cls .validate_randao_reveal ()
349352
350353 for attestation in block .attestations :
351354 validate_attestation (
@@ -355,7 +358,7 @@ def compute_per_block_transition(self,
355358 recent_block_hashes ,
356359 attestation ,
357360 chaindb ,
358- cycle_length ,
361+ cls . config . CYCLE_LENGTH ,
359362 is_validating_signatures = is_validating_signatures ,
360363 )
361364
@@ -366,38 +369,36 @@ def compute_per_block_transition(self,
366369 ),
367370 )
368371
372+ @classmethod
369373 def compute_cycle_transitions (
370- self ,
374+ cls ,
371375 crystallized_state : CrystallizedState ,
372376 active_state : ActiveState ,
373- block : BaseBeaconBlock ,
374- config : BeaconConfig ) -> Tuple [CrystallizedState , ActiveState ]:
377+ block : BaseBeaconBlock ) -> Tuple [CrystallizedState , ActiveState ]:
375378 """
376379 Compute the cycle transitions and return processed CrystallizedState and ActiveState.
377380 """
378- while block .slot_number >= crystallized_state .last_state_recalc + config .CYCLE_LENGTH :
379- crystallized_state , active_state = self .compute_per_cycle_transition (
381+ while block .slot_number >= crystallized_state .last_state_recalc + cls . config .CYCLE_LENGTH :
382+ crystallized_state , active_state = cls .compute_per_cycle_transition (
380383 crystallized_state ,
381384 active_state ,
382385 block ,
383- config ,
384386 )
385387
386- if self .ready_for_dynasty_transition (crystallized_state , block , config ):
387- crystallized_state = self .compute_dynasty_transition (
388+ if cls .ready_for_dynasty_transition (crystallized_state , block ):
389+ crystallized_state = cls .compute_dynasty_transition (
388390 crystallized_state ,
389391 block ,
390- config
391392 )
392393
393394 return crystallized_state , active_state
394395
396+ @classmethod
395397 def compute_per_cycle_transition (
396- self ,
398+ cls ,
397399 crystallized_state : CrystallizedState ,
398400 active_state : ActiveState ,
399- block : BaseBeaconBlock ,
400- config : BeaconConfig ) -> Tuple [CrystallizedState , ActiveState ]:
401+ block : BaseBeaconBlock ) -> Tuple [CrystallizedState , ActiveState ]:
401402 """
402403 Initialize a new cycle.
403404 """
@@ -407,22 +408,22 @@ def compute_per_cycle_transition(
407408 #
408409 # Crosslinks
409410 #
410- def compute_crosslinks (self ,
411+ @classmethod
412+ def compute_crosslinks (cls ,
411413 crystallized_state : CrystallizedState ,
412414 active_state : ActiveState ,
413- block : BaseBeaconBlock ,
414- config : BeaconConfig ) -> Tuple ['CrosslinkRecord' , ...]:
415+ block : BaseBeaconBlock ) -> Tuple ['CrosslinkRecord' , ...]:
415416 # TODO
416417 return ()
417418
418419 #
419420 # Rewards and penalties
420421 #
421- def apply_rewards_and_penalties (self ,
422+ @classmethod
423+ def apply_rewards_and_penalties (cls ,
422424 crystallized_state : CrystallizedState ,
423425 active_state : ActiveState ,
424- block : BaseBeaconBlock ,
425- config : BeaconConfig ) -> Tuple ['ValidatorRecord' , ...]:
426+ block : BaseBeaconBlock ) -> Tuple ['ValidatorRecord' , ...]:
426427 """
427428 Apply the rewards and penalties to the validators and return the updated ValidatorRecords.
428429 """
@@ -432,20 +433,20 @@ def apply_rewards_and_penalties(self,
432433 #
433434 # Dynasty
434435 #
435- def ready_for_dynasty_transition (self ,
436+ @classmethod
437+ def ready_for_dynasty_transition (cls ,
436438 crystallized_state : CrystallizedState ,
437- block : BaseBeaconBlock ,
438- config : BeaconConfig ) -> bool :
439+ block : BaseBeaconBlock ) -> bool :
439440 """
440441 Check if it's ready for dynasty transition.
441442 """
442443 # TODO
443444 return False
444445
445- def compute_dynasty_transition (self ,
446+ @classmethod
447+ def compute_dynasty_transition (cls ,
446448 crystallized_state : CrystallizedState ,
447- block : BaseBeaconBlock ,
448- config : BeaconConfig ) -> CrystallizedState :
449+ block : BaseBeaconBlock ) -> CrystallizedState :
449450 """
450451 Compute the dynasty transition.
451452 """
@@ -457,24 +458,23 @@ def compute_dynasty_transition(self,
457458 # Proposer APIs
458459 #
459460 #
461+ @classmethod
460462 def propose_block (
461- self ,
463+ cls ,
462464 crystallized_state : CrystallizedState ,
463465 active_state : ActiveState ,
464466 block_proposal : 'BlockProposal' ,
465467 chaindb : BaseBeaconChainDB ,
466- config : BeaconConfig ,
467468 private_key : int
468469 ) -> Tuple [BaseBeaconBlock , CrystallizedState , ActiveState , 'AttestationRecord' ]:
469470 """
470471 Propose the given block.
471472 """
472- block , post_crystallized_state , post_active_state = self .process_block (
473+ block , post_crystallized_state , post_active_state = cls .process_block (
473474 crystallized_state ,
474475 active_state ,
475476 block_proposal .block ,
476477 chaindb ,
477- config ,
478478 is_validating_signatures = False ,
479479 )
480480
@@ -489,28 +489,21 @@ def propose_block(
489489 shard_block_hash = block_proposal .shard_block_hash ,
490490 )
491491
492- proposer_attestation = self .attest_proposed_block (
492+ proposer_attestation = cls .attest_proposed_block (
493493 post_crystallized_state ,
494494 post_active_state ,
495495 filled_block_proposal ,
496496 chaindb ,
497- config .CYCLE_LENGTH ,
498497 private_key ,
499498 )
500499 return post_block , post_crystallized_state , post_active_state , proposer_attestation
501500
502- def _update_the_states (self ,
503- crystallized_state : CrystallizedState ,
504- active_state : ActiveState ) -> None :
505- self ._crytallized_state = crystallized_state
506- self ._active_state = active_state
507-
508- def attest_proposed_block (self ,
501+ @classmethod
502+ def attest_proposed_block (cls ,
509503 post_crystallized_state : CrystallizedState ,
510504 post_active_state : ActiveState ,
511505 block_proposal : 'BlockProposal' ,
512506 chaindb : BaseBeaconChainDB ,
513- cycle_length : int ,
514507 private_key : int ) -> 'AttestationRecord' :
515508 """
516509 Return the initial attestation by the block proposer.
@@ -520,7 +513,7 @@ def attest_proposed_block(self,
520513 block_committees_info = get_block_committees_info (
521514 block_proposal .block ,
522515 post_crystallized_state ,
523- cycle_length ,
516+ cls . config . CYCLE_LENGTH ,
524517 )
525518 # Vote
526519 attester_bitfield = set_voted (
@@ -536,7 +529,7 @@ def attest_proposed_block(self,
536529 parent_hashes = get_hashes_to_sign (
537530 post_active_state .recent_block_hashes ,
538531 block_proposal .block ,
539- cycle_length ,
532+ cls . config . CYCLE_LENGTH ,
540533 )
541534
542535 message = create_signing_message (
@@ -551,7 +544,7 @@ def attest_proposed_block(self,
551544 private_key ,
552545 )
553546
554- return self .get_attestation_record_class ()(
547+ return cls .get_attestation_record_class ()(
555548 slot = block_proposal .block .slot_number ,
556549 shard_id = block_proposal .shard_id ,
557550 oblique_parent_hashes = (),
0 commit comments