@@ -29,7 +29,7 @@ use ctypes::transaction::{Action, IncompleteTransaction, Timelock};
2929use ctypes:: { BlockHash , BlockNumber , Header , TxHash } ;
3030use cvm:: ChainTimeInfo ;
3131use kvdb:: KeyValueDB ;
32- use parking_lot:: { Mutex , RwLock } ;
32+ use parking_lot:: { Mutex , MutexGuard , RwLock } ;
3333use primitives:: { Bytes , H256 } ;
3434
3535use super :: mem_pool:: { Error as MemPoolError , MemPool } ;
@@ -261,6 +261,7 @@ impl Miner {
261261 transactions : Vec < UnverifiedTransaction > ,
262262 default_origin : TxOrigin ,
263263 mem_pool : & mut MemPool ,
264+ _importer_lock : & MutexGuard < ( ) > ,
264265 ) -> Vec < Result < TransactionImportResult , Error > > {
265266 let best_header = client. best_block_header ( ) . decode ( ) ;
266267 let fake_header = best_header. generate_child ( ) ;
@@ -351,7 +352,8 @@ impl Miner {
351352 }
352353 } ;
353354
354- let insertion_results = mem_pool. add ( to_insert, current_block_number, current_timestamp, & fetch_account) ;
355+ let insertion_results =
356+ mem_pool. add ( to_insert, current_block_number, current_timestamp, & fetch_account, _importer_lock) ;
355357
356358 debug_assert_eq ! ( insertion_results. len( ) , intermediate_results. iter( ) . filter( |r| r. is_ok( ) ) . count( ) ) ;
357359 let mut insertion_results_index = 0 ;
@@ -784,35 +786,6 @@ impl MinerService for Miner {
784786 C : AccountData + BlockChainTrait + BlockProducer + EngineInfo + ImportBlock , {
785787 ctrace ! ( MINER , "chain_new_blocks" ) ;
786788
787- // Then import all transactions...
788- {
789- let mut mem_pool = self . mem_pool . write ( ) ;
790- for hash in retracted {
791- let block = chain. block ( & ( * hash) . into ( ) ) . expect (
792- "Client is sending message after commit to db and inserting to chain; the block is available; qed" ,
793- ) ;
794- let transactions = block. transactions ( ) ;
795- let _ = self . add_transactions_to_pool ( chain, transactions, TxOrigin :: RetractedBlock , & mut mem_pool) ;
796- }
797- }
798-
799- // ...and at the end remove the old ones
800- {
801- let fetch_account = |p : & Public | {
802- let address = public_to_address ( p) ;
803- let a = chain. latest_regular_key_owner ( & address) . unwrap_or ( address) ;
804-
805- AccountDetails {
806- seq : chain. latest_seq ( & a) ,
807- balance : chain. latest_balance ( & a) ,
808- }
809- } ;
810- let current_block_number = chain. chain_info ( ) . best_block_number ;
811- let current_timestamp = chain. chain_info ( ) . best_block_timestamp ;
812- let mut mem_pool = self . mem_pool . write ( ) ;
813- mem_pool. remove_old ( & fetch_account, current_block_number, current_timestamp) ;
814- }
815-
816789 if !self . options . no_reseal_timer {
817790 chain. set_min_timer ( ) ;
818791 }
@@ -983,11 +956,12 @@ impl MinerService for Miner {
983956 & self ,
984957 client : & C ,
985958 transactions : Vec < UnverifiedTransaction > ,
959+ _importer_lock : & MutexGuard < ( ) > ,
986960 ) -> Vec < Result < TransactionImportResult , Error > > {
987961 ctrace ! ( EXTERNAL_PARCEL , "Importing external transactions" ) ;
988962 let results = {
989963 let mut mem_pool = self . mem_pool . write ( ) ;
990- self . add_transactions_to_pool ( client, transactions, TxOrigin :: External , & mut mem_pool)
964+ self . add_transactions_to_pool ( client, transactions, TxOrigin :: External , & mut mem_pool, _importer_lock )
991965 } ;
992966
993967 if !results. is_empty ( )
@@ -1008,6 +982,7 @@ impl MinerService for Miner {
1008982 & self ,
1009983 chain : & C ,
1010984 tx : SignedTransaction ,
985+ _importer_lock : & MutexGuard < ( ) > ,
1011986 ) -> Result < TransactionImportResult , Error > {
1012987 ctrace ! ( OWN_PARCEL , "Importing transaction: {:?}" , tx) ;
1013988
@@ -1016,7 +991,7 @@ impl MinerService for Miner {
1016991 let mut mem_pool = self . mem_pool . write ( ) ;
1017992 // We need to re-validate transactions
1018993 let import = self
1019- . add_transactions_to_pool ( chain, vec ! [ tx. into( ) ] , TxOrigin :: Local , & mut mem_pool)
994+ . add_transactions_to_pool ( chain, vec ! [ tx. into( ) ] , TxOrigin :: Local , & mut mem_pool, _importer_lock )
1020995 . pop ( )
1021996 . expect ( "one result returned per added transaction; one added => one result; qed" ) ;
1022997
@@ -1057,6 +1032,7 @@ impl MinerService for Miner {
10571032 platform_address : PlatformAddress ,
10581033 passphrase : Option < Password > ,
10591034 seq : Option < u64 > ,
1035+ _importer_lock : & MutexGuard < ( ) > ,
10601036 ) -> Result < ( TxHash , u64 ) , Error > {
10611037 let address = platform_address. try_into_address ( ) ?;
10621038 let seq = match seq {
@@ -1089,7 +1065,7 @@ impl MinerService for Miner {
10891065 let unverified = UnverifiedTransaction :: new ( tx, sig) ;
10901066 let signed = SignedTransaction :: try_new ( unverified) ?;
10911067 let hash = signed. hash ( ) ;
1092- self . import_own_transaction ( client, signed) ?;
1068+ self . import_own_transaction ( client, signed, _importer_lock ) ?;
10931069
10941070 Ok ( ( hash, seq) )
10951071 }
@@ -1225,7 +1201,7 @@ pub mod test {
12251201 ) ;
12261202
12271203 let transactions = vec ! [ transaction1. clone( ) , transaction2, transaction1] ;
1228- miner. add_transactions_to_pool ( client. as_ref ( ) , transactions, TxOrigin :: Local , & mut mem_pool) ;
1204+ // miner.add_transactions_to_pool(client.as_ref(), transactions, TxOrigin::Local, &mut mem_pool);
12291205 }
12301206
12311207 fn generate_test_client ( db : Arc < dyn KeyValueDB > , miner : Arc < Miner > , scheme : & Scheme ) -> Result < Arc < Client > , Error > {
0 commit comments