@@ -39,7 +39,7 @@ use super::{MinerService, MinerStatus, TransactionImportResult};
3939use crate :: account_provider:: { AccountProvider , Error as AccountProviderError } ;
4040use crate :: block:: { Block , ClosedBlock , IsBlock } ;
4141use crate :: client:: {
42- AccountData , BlockChainTrait , BlockProducer , Client , EngineInfo , ImportBlock , MiningBlockChainClient ,
42+ AccountData , BlockChainTrait , BlockProducer , Client , EngineInfo , ImportBlock , MiningBlockChainClient , TermInfo ,
4343} ;
4444use crate :: codechain_machine:: CodeChainMachine ;
4545use crate :: consensus:: { CodeChainEngine , EngineType } ;
@@ -445,7 +445,7 @@ impl Miner {
445445
446446 /// Prepares new block for sealing including top transactions from queue.
447447 fn prepare_block <
448- C : AccountData + BlockChainTrait + BlockProducer + ChainTimeInfo + EngineInfo + FindActionHandler ,
448+ C : AccountData + BlockChainTrait + BlockProducer + ChainTimeInfo + EngineInfo + FindActionHandler + TermInfo ,
449449 > (
450450 & self ,
451451 parent_block_id : BlockId ,
@@ -532,7 +532,17 @@ impl Miner {
532532 ( parent_header. decode ( ) , parent_hash)
533533 } ;
534534 let parent_common_params = chain. common_params ( parent_hash. into ( ) ) . unwrap ( ) ;
535- let block = open_block. close ( & parent_header, & parent_common_params) ?;
535+ let term_common_params = {
536+ let block_number = chain
537+ . last_term_finished_block_num ( parent_hash. into ( ) )
538+ . expect ( "The block of the parent hash should exist" ) ;
539+ if block_number == 0 {
540+ None
541+ } else {
542+ Some ( chain. common_params ( ( block_number) . into ( ) ) . expect ( "Common params should exist" ) )
543+ }
544+ } ;
545+ let block = open_block. close ( & parent_header, & parent_common_params, term_common_params. as_ref ( ) ) ?;
536546
537547 let fetch_seq = |p : & Public | {
538548 let address = public_to_address ( p) ;
@@ -751,7 +761,7 @@ impl MinerService for Miner {
751761 }
752762
753763 fn prepare_work_sealing <
754- C : AccountData + BlockChainTrait + BlockProducer + ChainTimeInfo + EngineInfo + FindActionHandler ,
764+ C : AccountData + BlockChainTrait + BlockProducer + ChainTimeInfo + EngineInfo + FindActionHandler + TermInfo ,
755765 > (
756766 & self ,
757767 client : & C ,
@@ -800,8 +810,14 @@ impl MinerService for Miner {
800810
801811 fn update_sealing < C > ( & self , chain : & C , parent_block : BlockId , allow_empty_block : bool )
802812 where
803- C : AccountData + BlockChainTrait + BlockProducer + EngineInfo + ImportBlock + ChainTimeInfo + FindActionHandler ,
804- {
813+ C : AccountData
814+ + BlockChainTrait
815+ + BlockProducer
816+ + EngineInfo
817+ + ImportBlock
818+ + ChainTimeInfo
819+ + FindActionHandler
820+ + TermInfo , {
805821 ctrace ! ( MINER , "update_sealing: preparing a block" ) ;
806822
807823 let parent_block_number = chain. block_header ( & parent_block) . expect ( "Parent is always exist" ) . number ( ) ;
@@ -879,7 +895,7 @@ impl MinerService for Miner {
879895
880896 fn map_sealing_work < C , F , T > ( & self , client : & C , f : F ) -> Option < T >
881897 where
882- C : AccountData + BlockChainTrait + BlockProducer + ChainTimeInfo + EngineInfo + FindActionHandler ,
898+ C : AccountData + BlockChainTrait + BlockProducer + ChainTimeInfo + EngineInfo + FindActionHandler + TermInfo ,
883899 F : FnOnce ( & ClosedBlock ) -> T , {
884900 ctrace ! ( MINER , "map_sealing_work: entering" ) ;
885901 self . prepare_work_sealing ( client) ;
@@ -890,7 +906,7 @@ impl MinerService for Miner {
890906 ret. map ( f)
891907 }
892908
893- fn import_external_transactions < C : MiningBlockChainClient + EngineInfo > (
909+ fn import_external_transactions < C : MiningBlockChainClient + EngineInfo + TermInfo > (
894910 & self ,
895911 client : & C ,
896912 transactions : Vec < UnverifiedTransaction > ,
@@ -915,7 +931,7 @@ impl MinerService for Miner {
915931 results
916932 }
917933
918- fn import_own_transaction < C : MiningBlockChainClient + EngineInfo > (
934+ fn import_own_transaction < C : MiningBlockChainClient + EngineInfo + TermInfo > (
919935 & self ,
920936 chain : & C ,
921937 tx : SignedTransaction ,
@@ -960,7 +976,7 @@ impl MinerService for Miner {
960976 imported
961977 }
962978
963- fn import_incomplete_transaction < C : MiningBlockChainClient + AccountData + EngineInfo > (
979+ fn import_incomplete_transaction < C : MiningBlockChainClient + AccountData + EngineInfo + TermInfo > (
964980 & self ,
965981 client : & C ,
966982 account_provider : & AccountProvider ,
@@ -1020,7 +1036,7 @@ impl MinerService for Miner {
10201036 self . mem_pool . read ( ) . future_transactions ( )
10211037 }
10221038
1023- fn start_sealing < C : MiningBlockChainClient + EngineInfo > ( & self , client : & C ) {
1039+ fn start_sealing < C : MiningBlockChainClient + EngineInfo + TermInfo > ( & self , client : & C ) {
10241040 cdebug ! ( MINER , "Start sealing" ) ;
10251041 self . sealing_enabled . store ( true , Ordering :: Relaxed ) ;
10261042 // ------------------------------------------------------------------
0 commit comments