@@ -549,44 +549,6 @@ impl JsonRpcMsgReceiver {
549
549
}
550
550
}
551
551
552
-
553
- ///
554
- /// Struct UsedAccounts
555
- /// used for verify that account is being used to execute transaction now
556
- ///
557
- struct UsedAccounts {
558
- accs : Arc < Mutex < HashMap < AccountId , u8 > > >
559
- }
560
-
561
- impl UsedAccounts {
562
- /// Create new instance of UsedAccounts
563
- pub fn new ( ) -> Self {
564
- UsedAccounts {
565
- accs : Arc :: new ( Mutex :: new ( HashMap :: new ( ) ) )
566
- }
567
- }
568
-
569
- /// Lock account ID for execute transaction
570
- pub fn lock_acc ( & self , account_id : AccountId ) {
571
- self . accs . lock ( ) . insert ( account_id, 0 ) ;
572
- }
573
-
574
- /// verify that account is being used
575
- pub fn acc_is_use ( & self , account_id : & AccountId ) -> bool {
576
- self . accs . lock ( ) . contains_key ( account_id)
577
- }
578
-
579
- /// Unlock account
580
- pub fn unlock_acc ( & self , account_id : & AccountId ) {
581
- self . accs . lock ( ) . remove ( account_id) ;
582
- }
583
-
584
- /// Unclock all
585
- pub fn clear ( & self ) {
586
- self . accs . lock ( ) . clear ( ) ;
587
- }
588
- }
589
-
590
552
/// Struct RouteMessage. Stored peedId of thew node received message
591
553
#[ derive( Clone , Debug , PartialEq , Eq ) ]
592
554
pub struct RouteMessage {
@@ -721,7 +683,7 @@ pub struct InMessagesQueue {
721
683
storage : Mutex < BTreeSet < QueuedMessage > > ,
722
684
out_storage : Mutex < VecDeque < QueuedMessage > > ,
723
685
db : Option < Arc < Box < dyn DocumentsDb > > > ,
724
- used_accs : UsedAccounts ,
686
+ used_accs : Mutex < HashSet < AccountId > > ,
725
687
capacity : usize ,
726
688
ready_to_process : AtomicBool ,
727
689
}
@@ -735,7 +697,7 @@ impl InMessagesQueue {
735
697
shard_id,
736
698
storage : Mutex :: new ( BTreeSet :: new ( ) ) ,
737
699
out_storage : Mutex :: new ( VecDeque :: new ( ) ) ,
738
- used_accs : UsedAccounts :: new ( ) ,
700
+ used_accs : Mutex :: new ( HashSet :: new ( ) ) ,
739
701
db : None ,
740
702
capacity,
741
703
ready_to_process : AtomicBool :: new ( false ) ,
@@ -747,7 +709,7 @@ impl InMessagesQueue {
747
709
shard_id,
748
710
storage : Mutex :: new ( BTreeSet :: new ( ) ) ,
749
711
out_storage : Mutex :: new ( VecDeque :: new ( ) ) ,
750
- used_accs : UsedAccounts :: new ( ) ,
712
+ used_accs : Mutex :: new ( HashSet :: new ( ) ) ,
751
713
db : Some ( db) ,
752
714
capacity,
753
715
ready_to_process : AtomicBool :: new ( false ) ,
@@ -866,19 +828,11 @@ impl InMessagesQueue {
866
828
/// Extract oldest message from queue if message account not using in executor
867
829
pub fn dequeue_first_unused ( & self ) -> Option < QueuedMessage > {
868
830
let mut storage = self . storage . lock ( ) ;
869
- let mut used_accs = HashSet :: new ( ) ;
831
+ let used_accs = self . used_accs . lock ( ) ;
870
832
// iterate from front and find unused account message
871
833
let result = storage. iter ( ) . find ( |msg| {
872
834
msg. message ( ) . int_dst_account_id ( )
873
- . map ( |acc_id| {
874
- let used = self . used_accs . acc_is_use ( & acc_id) ;
875
- !if used {
876
- used_accs. insert ( acc_id. clone ( ) ) ;
877
- used
878
- } else {
879
- used_accs. contains ( & acc_id)
880
- }
881
- } )
835
+ . map ( |acc_id| !used_accs. contains ( & acc_id) )
882
836
. unwrap_or ( false )
883
837
} ) . cloned ( ) ;
884
838
@@ -910,17 +864,17 @@ impl InMessagesQueue {
910
864
911
865
/// lock account message for dequeue
912
866
pub fn lock_account ( & self , account_id : AccountId ) {
913
- self . used_accs . lock_acc ( account_id) ;
867
+ self . used_accs . lock ( ) . insert ( account_id) ;
914
868
}
915
869
916
870
/// unlock account mesages for dequeue
917
871
pub fn unlock_account ( & self , account_id : & AccountId ) {
918
- self . used_accs . unlock_acc ( account_id) ;
872
+ self . used_accs . lock ( ) . remove ( account_id) ;
919
873
}
920
874
921
875
/// Unlock all accounts
922
876
pub fn locks_clear ( & self ) {
923
- self . used_accs . clear ( ) ;
877
+ self . used_accs . lock ( ) . clear ( ) ;
924
878
}
925
879
926
880
}
0 commit comments