@@ -260,7 +260,6 @@ def import_block(
260
260
self .active_state ,
261
261
block ,
262
262
self .chaindb ,
263
- self .config ,
264
263
is_validating_signatures = True ,
265
264
)
266
265
@@ -278,49 +277,53 @@ def import_block(
278
277
279
278
return self .block , self .crystallized_state , self .active_state
280
279
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
+
281
286
#
282
287
# Process block APIs
283
288
#
289
+ @classmethod
284
290
def process_block (
285
- self ,
291
+ cls ,
286
292
crystallized_state : CrystallizedState ,
287
293
active_state : ActiveState ,
288
294
block : BaseBeaconBlock ,
289
295
chaindb : BaseBeaconChainDB ,
290
- config : BeaconConfig ,
291
296
is_validating_signatures : bool = True
292
297
) -> Tuple [BaseBeaconBlock , CrystallizedState , ActiveState ]:
293
298
"""
294
299
Process ``block`` and return the new crystallized state and active state.
295
300
"""
296
301
# Process per block state changes (ActiveState)
297
- processing_active_state = self .compute_per_block_transition (
302
+ processing_active_state = cls .compute_per_block_transition (
298
303
crystallized_state ,
299
304
active_state ,
300
305
block ,
301
306
chaindb ,
302
- config .CYCLE_LENGTH ,
303
307
is_validating_signatures = is_validating_signatures ,
304
308
)
305
309
306
310
# 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 (
308
312
crystallized_state ,
309
313
processing_active_state ,
310
314
block ,
311
- config ,
312
315
)
313
316
314
317
# Return the copy
315
318
result_block = block .copy ()
316
319
return result_block , processed_crystallized_state , processed_active_state
317
320
318
- def compute_per_block_transition (self ,
321
+ @classmethod
322
+ def compute_per_block_transition (cls ,
319
323
crystallized_state : CrystallizedState ,
320
324
active_state : ActiveState ,
321
325
block : BaseBeaconBlock ,
322
326
chaindb : BaseBeaconChainDB ,
323
- cycle_length : int ,
324
327
is_validating_signatures : bool = True ) -> ActiveState :
325
328
"""
326
329
Process ``block`` and return the new ActiveState.
@@ -341,11 +344,11 @@ def compute_per_block_transition(self,
341
344
crystallized_state ,
342
345
block ,
343
346
parent_block ,
344
- cycle_length ,
347
+ cls . config . CYCLE_LENGTH ,
345
348
)
346
349
347
350
# TODO: to implement the RANDAO reveal validation.
348
- self .validate_randao_reveal ()
351
+ cls .validate_randao_reveal ()
349
352
350
353
for attestation in block .attestations :
351
354
validate_attestation (
@@ -355,7 +358,7 @@ def compute_per_block_transition(self,
355
358
recent_block_hashes ,
356
359
attestation ,
357
360
chaindb ,
358
- cycle_length ,
361
+ cls . config . CYCLE_LENGTH ,
359
362
is_validating_signatures = is_validating_signatures ,
360
363
)
361
364
@@ -366,38 +369,36 @@ def compute_per_block_transition(self,
366
369
),
367
370
)
368
371
372
+ @classmethod
369
373
def compute_cycle_transitions (
370
- self ,
374
+ cls ,
371
375
crystallized_state : CrystallizedState ,
372
376
active_state : ActiveState ,
373
- block : BaseBeaconBlock ,
374
- config : BeaconConfig ) -> Tuple [CrystallizedState , ActiveState ]:
377
+ block : BaseBeaconBlock ) -> Tuple [CrystallizedState , ActiveState ]:
375
378
"""
376
379
Compute the cycle transitions and return processed CrystallizedState and ActiveState.
377
380
"""
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 (
380
383
crystallized_state ,
381
384
active_state ,
382
385
block ,
383
- config ,
384
386
)
385
387
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 (
388
390
crystallized_state ,
389
391
block ,
390
- config
391
392
)
392
393
393
394
return crystallized_state , active_state
394
395
396
+ @classmethod
395
397
def compute_per_cycle_transition (
396
- self ,
398
+ cls ,
397
399
crystallized_state : CrystallizedState ,
398
400
active_state : ActiveState ,
399
- block : BaseBeaconBlock ,
400
- config : BeaconConfig ) -> Tuple [CrystallizedState , ActiveState ]:
401
+ block : BaseBeaconBlock ) -> Tuple [CrystallizedState , ActiveState ]:
401
402
"""
402
403
Initialize a new cycle.
403
404
"""
@@ -407,22 +408,22 @@ def compute_per_cycle_transition(
407
408
#
408
409
# Crosslinks
409
410
#
410
- def compute_crosslinks (self ,
411
+ @classmethod
412
+ def compute_crosslinks (cls ,
411
413
crystallized_state : CrystallizedState ,
412
414
active_state : ActiveState ,
413
- block : BaseBeaconBlock ,
414
- config : BeaconConfig ) -> Tuple ['CrosslinkRecord' , ...]:
415
+ block : BaseBeaconBlock ) -> Tuple ['CrosslinkRecord' , ...]:
415
416
# TODO
416
417
return ()
417
418
418
419
#
419
420
# Rewards and penalties
420
421
#
421
- def apply_rewards_and_penalties (self ,
422
+ @classmethod
423
+ def apply_rewards_and_penalties (cls ,
422
424
crystallized_state : CrystallizedState ,
423
425
active_state : ActiveState ,
424
- block : BaseBeaconBlock ,
425
- config : BeaconConfig ) -> Tuple ['ValidatorRecord' , ...]:
426
+ block : BaseBeaconBlock ) -> Tuple ['ValidatorRecord' , ...]:
426
427
"""
427
428
Apply the rewards and penalties to the validators and return the updated ValidatorRecords.
428
429
"""
@@ -432,20 +433,20 @@ def apply_rewards_and_penalties(self,
432
433
#
433
434
# Dynasty
434
435
#
435
- def ready_for_dynasty_transition (self ,
436
+ @classmethod
437
+ def ready_for_dynasty_transition (cls ,
436
438
crystallized_state : CrystallizedState ,
437
- block : BaseBeaconBlock ,
438
- config : BeaconConfig ) -> bool :
439
+ block : BaseBeaconBlock ) -> bool :
439
440
"""
440
441
Check if it's ready for dynasty transition.
441
442
"""
442
443
# TODO
443
444
return False
444
445
445
- def compute_dynasty_transition (self ,
446
+ @classmethod
447
+ def compute_dynasty_transition (cls ,
446
448
crystallized_state : CrystallizedState ,
447
- block : BaseBeaconBlock ,
448
- config : BeaconConfig ) -> CrystallizedState :
449
+ block : BaseBeaconBlock ) -> CrystallizedState :
449
450
"""
450
451
Compute the dynasty transition.
451
452
"""
@@ -457,24 +458,23 @@ def compute_dynasty_transition(self,
457
458
# Proposer APIs
458
459
#
459
460
#
461
+ @classmethod
460
462
def propose_block (
461
- self ,
463
+ cls ,
462
464
crystallized_state : CrystallizedState ,
463
465
active_state : ActiveState ,
464
466
block_proposal : 'BlockProposal' ,
465
467
chaindb : BaseBeaconChainDB ,
466
- config : BeaconConfig ,
467
468
private_key : int
468
469
) -> Tuple [BaseBeaconBlock , CrystallizedState , ActiveState , 'AttestationRecord' ]:
469
470
"""
470
471
Propose the given block.
471
472
"""
472
- block , post_crystallized_state , post_active_state = self .process_block (
473
+ block , post_crystallized_state , post_active_state = cls .process_block (
473
474
crystallized_state ,
474
475
active_state ,
475
476
block_proposal .block ,
476
477
chaindb ,
477
- config ,
478
478
is_validating_signatures = False ,
479
479
)
480
480
@@ -489,28 +489,21 @@ def propose_block(
489
489
shard_block_hash = block_proposal .shard_block_hash ,
490
490
)
491
491
492
- proposer_attestation = self .attest_proposed_block (
492
+ proposer_attestation = cls .attest_proposed_block (
493
493
post_crystallized_state ,
494
494
post_active_state ,
495
495
filled_block_proposal ,
496
496
chaindb ,
497
- config .CYCLE_LENGTH ,
498
497
private_key ,
499
498
)
500
499
return post_block , post_crystallized_state , post_active_state , proposer_attestation
501
500
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 ,
509
503
post_crystallized_state : CrystallizedState ,
510
504
post_active_state : ActiveState ,
511
505
block_proposal : 'BlockProposal' ,
512
506
chaindb : BaseBeaconChainDB ,
513
- cycle_length : int ,
514
507
private_key : int ) -> 'AttestationRecord' :
515
508
"""
516
509
Return the initial attestation by the block proposer.
@@ -520,7 +513,7 @@ def attest_proposed_block(self,
520
513
block_committees_info = get_block_committees_info (
521
514
block_proposal .block ,
522
515
post_crystallized_state ,
523
- cycle_length ,
516
+ cls . config . CYCLE_LENGTH ,
524
517
)
525
518
# Vote
526
519
attester_bitfield = set_voted (
@@ -536,7 +529,7 @@ def attest_proposed_block(self,
536
529
parent_hashes = get_hashes_to_sign (
537
530
post_active_state .recent_block_hashes ,
538
531
block_proposal .block ,
539
- cycle_length ,
532
+ cls . config . CYCLE_LENGTH ,
540
533
)
541
534
542
535
message = create_signing_message (
@@ -551,7 +544,7 @@ def attest_proposed_block(self,
551
544
private_key ,
552
545
)
553
546
554
- return self .get_attestation_record_class ()(
547
+ return cls .get_attestation_record_class ()(
555
548
slot = block_proposal .block .slot_number ,
556
549
shard_id = block_proposal .shard_id ,
557
550
oblique_parent_hashes = (),
0 commit comments