44
44
AtomicDatabaseAPI ,
45
45
BlockHeaderAPI ,
46
46
BlockImportResult ,
47
+ BlockPersistResult ,
47
48
ChainAPI ,
48
49
ChainDatabaseAPI ,
49
50
ConsensusContextAPI ,
@@ -481,17 +482,27 @@ def import_block(self,
481
482
except ValidationError :
482
483
self .logger .warning ("Proposed %s doesn't follow EVM rules, rejecting..." , block )
483
484
raise
484
- self .validate_block (imported_block )
485
+
486
+ persist_result = self .persist_block (imported_block , perform_validation )
487
+ return BlockImportResult (* persist_result , block_result .meta_witness )
488
+
489
+ def persist_block (
490
+ self ,
491
+ block : BlockAPI ,
492
+ perform_validation : bool = True ) -> BlockPersistResult :
493
+
494
+ if perform_validation :
495
+ self .validate_block (block )
485
496
486
497
(
487
498
new_canonical_hashes ,
488
499
old_canonical_hashes ,
489
- ) = self .chaindb .persist_block (imported_block )
500
+ ) = self .chaindb .persist_block (block )
490
501
491
502
self .logger .debug (
492
- 'IMPORTED_BLOCK : number %s | hash %s' ,
493
- imported_block .number ,
494
- encode_hex (imported_block .hash ),
503
+ 'Persisted block : number %s | hash %s' ,
504
+ block .number ,
505
+ encode_hex (block .hash ),
495
506
)
496
507
497
508
new_canonical_blocks = tuple (
@@ -505,11 +516,10 @@ def import_block(self,
505
516
in old_canonical_hashes
506
517
)
507
518
508
- return BlockImportResult (
509
- imported_block = imported_block ,
519
+ return BlockPersistResult (
520
+ imported_block = block ,
510
521
new_canonical_blocks = new_canonical_blocks ,
511
522
old_canonical_blocks = old_canonical_blocks ,
512
- meta_witness = block_result .meta_witness ,
513
523
)
514
524
515
525
#
@@ -667,11 +677,43 @@ def import_block(self,
667
677
self .header = self .ensure_header ()
668
678
return result
669
679
680
+ def mine_all (
681
+ self ,
682
+ transactions : Sequence [SignedTransactionAPI ],
683
+ * args : Any ,
684
+ parent_header : BlockHeaderAPI = None ,
685
+ ** kwargs : Any ,
686
+ ) -> Tuple [BlockImportResult , Tuple [ReceiptAPI , ...], Tuple [ComputationAPI , ...]]:
687
+
688
+ if parent_header is None :
689
+ base_header = self .header
690
+ else :
691
+ base_header = self .create_header_from_parent (parent_header )
692
+
693
+ vm = self .get_vm (base_header )
694
+
695
+ new_header , receipts , computations = vm .apply_all_transactions (transactions , base_header )
696
+ filled_block = vm .set_block_transactions (vm .get_block (), new_header , transactions , receipts )
697
+
698
+ block_result = vm .mine_block (filled_block , * args , ** kwargs )
699
+ imported_block = block_result .block
700
+
701
+ block_persist_result = self .persist_block (imported_block )
702
+ block_import_result = BlockImportResult (* block_persist_result , block_result .meta_witness )
703
+
704
+ self .header = self .create_header_from_parent (imported_block .header )
705
+ return (block_import_result , receipts , computations )
706
+
670
707
def mine_block (self , * args : Any , ** kwargs : Any ) -> BlockAPI :
708
+ """
709
+ Mine whatever transactions have been incrementally applied so far.
710
+ """
671
711
return self .mine_block_extended (* args , ** kwargs ).block
672
712
673
713
def mine_block_extended (self , * args : Any , ** kwargs : Any ) -> BlockAndMetaWitness :
674
- mine_result = self .get_vm (self .header ).mine_block (* args , ** kwargs )
714
+ vm = self .get_vm (self .header )
715
+ current_block = vm .get_block ()
716
+ mine_result = vm .mine_block (current_block , * args , ** kwargs )
675
717
mined_block = mine_result .block
676
718
677
719
self .validate_block (mined_block )
0 commit comments