4444 AtomicDatabaseAPI ,
4545 BlockHeaderAPI ,
4646 BlockImportResult ,
47+ BlockPersistResult ,
4748 ChainAPI ,
4849 ChainDatabaseAPI ,
4950 ConsensusContextAPI ,
@@ -481,17 +482,27 @@ def import_block(self,
481482 except ValidationError :
482483 self .logger .warning ("Proposed %s doesn't follow EVM rules, rejecting..." , block )
483484 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 )
485496
486497 (
487498 new_canonical_hashes ,
488499 old_canonical_hashes ,
489- ) = self .chaindb .persist_block (imported_block )
500+ ) = self .chaindb .persist_block (block )
490501
491502 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 ),
495506 )
496507
497508 new_canonical_blocks = tuple (
@@ -505,11 +516,10 @@ def import_block(self,
505516 in old_canonical_hashes
506517 )
507518
508- return BlockImportResult (
509- imported_block = imported_block ,
519+ return BlockPersistResult (
520+ imported_block = block ,
510521 new_canonical_blocks = new_canonical_blocks ,
511522 old_canonical_blocks = old_canonical_blocks ,
512- meta_witness = block_result .meta_witness ,
513523 )
514524
515525 #
@@ -667,11 +677,43 @@ def import_block(self,
667677 self .header = self .ensure_header ()
668678 return result
669679
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+
670707 def mine_block (self , * args : Any , ** kwargs : Any ) -> BlockAPI :
708+ """
709+ Mine whatever transactions have been incrementally applied so far.
710+ """
671711 return self .mine_block_extended (* args , ** kwargs ).block
672712
673713 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 )
675717 mined_block = mine_result .block
676718
677719 self .validate_block (mined_block )
0 commit comments