@@ -689,9 +689,6 @@ impl OutputCache {
689
689
confirmed_tx : & Transaction ,
690
690
block_id : Id < GenBlock > ,
691
691
) -> WalletResult < Vec < Id < Transaction > > > {
692
- // Collect all conflicting txs
693
- let mut conflicting_txs = vec ! [ ] ;
694
-
695
692
let mut frozen_token_id: Option < TokenId > = None ;
696
693
let mut confirmed_account_nonce: Option < ( AccountType , AccountNonce ) > = None ;
697
694
@@ -722,14 +719,15 @@ impl OutputCache {
722
719
}
723
720
}
724
721
725
- if frozen_token_id. is_some ( ) | confirmed_account_nonce. is_some ( ) {
722
+ // Collect all conflicting txs
723
+ let mut conflicting_txs = vec ! [ ] ;
724
+
725
+ if frozen_token_id. is_some ( ) || confirmed_account_nonce. is_some ( ) {
726
726
for unconfirmed in self . unconfirmed_descendants . keys ( ) {
727
727
if let Some ( frozen_token_id) = frozen_token_id {
728
728
let unconfirmed_tx = self . txs . get ( unconfirmed) . expect ( "must be present" ) ;
729
729
if self . uses_token ( unconfirmed_tx, & frozen_token_id) {
730
- let unconfirmed_tx =
731
- self . txs . get_mut ( unconfirmed) . expect ( "must be present" ) ;
732
- if let WalletTx :: Tx ( ref mut tx) = unconfirmed_tx {
730
+ if let WalletTx :: Tx ( tx) = unconfirmed_tx {
733
731
conflicting_txs. push ( tx. get_transaction ( ) . get_id ( ) ) ;
734
732
}
735
733
}
@@ -743,9 +741,7 @@ impl OutputCache {
743
741
confirmed_account,
744
742
confirmed_account_nonce,
745
743
) {
746
- let unconfirmed_tx =
747
- self . txs . get_mut ( unconfirmed) . expect ( "must be present" ) ;
748
- if let WalletTx :: Tx ( ref mut tx) = unconfirmed_tx {
744
+ if let WalletTx :: Tx ( tx) = unconfirmed_tx {
749
745
conflicting_txs. push ( tx. get_transaction ( ) . get_id ( ) ) ;
750
746
}
751
747
}
@@ -755,11 +751,16 @@ impl OutputCache {
755
751
756
752
// Remove all descendants of conflicting txs
757
753
let mut conflicting_txs_with_descendants = vec ! [ ] ;
754
+
758
755
for conflicting_tx in conflicting_txs {
759
- let descendants =
760
- self . remove_descendants_and_mark_as ( conflicting_tx, TxState :: Conflicted ( block_id) ) ?;
756
+ if conflicting_tx != confirmed_tx. get_id ( ) {
757
+ let descendants = self . remove_descendants_and_mark_as (
758
+ conflicting_tx,
759
+ TxState :: Conflicted ( block_id) ,
760
+ ) ?;
761
761
762
- conflicting_txs_with_descendants. extend ( descendants. into_iter ( ) ) ;
762
+ conflicting_txs_with_descendants. extend ( descendants. into_iter ( ) ) ;
763
+ }
763
764
}
764
765
765
766
Ok ( conflicting_txs_with_descendants)
@@ -828,8 +829,11 @@ impl OutputCache {
828
829
| TxState :: Abandoned => true ,
829
830
TxState :: Confirmed ( _, _, _) => false ,
830
831
} ;
832
+
831
833
if is_unconfirmed && !already_present {
832
834
self . unconfirmed_descendants . insert ( tx_id. clone ( ) , BTreeSet :: new ( ) ) ;
835
+ } else {
836
+ self . unconfirmed_descendants . remove ( & tx_id) ;
833
837
}
834
838
835
839
self . update_inputs ( & tx, is_unconfirmed, & tx_id, already_present) ?;
@@ -944,13 +948,14 @@ impl OutputCache {
944
948
match input {
945
949
TxInput :: Utxo ( outpoint) => {
946
950
self . consumed . insert ( outpoint. clone ( ) , tx. state ( ) ) ;
947
- if is_unconfirmed {
948
- self . unconfirmed_descendants
949
- . get_mut ( & outpoint. source_id ( ) )
950
- . as_mut ( )
951
- . map ( |descendants| descendants. insert ( tx_id. clone ( ) ) ) ;
952
- } else {
953
- self . unconfirmed_descendants . remove ( tx_id) ;
951
+ if let Some ( descendants) =
952
+ self . unconfirmed_descendants . get_mut ( & outpoint. source_id ( ) )
953
+ {
954
+ if is_unconfirmed {
955
+ descendants. insert ( tx_id. clone ( ) ) ;
956
+ } else {
957
+ descendants. remove ( tx_id) ;
958
+ }
954
959
}
955
960
}
956
961
TxInput :: Account ( outpoint) => match outpoint. account ( ) {
@@ -1753,8 +1758,8 @@ fn uses_conflicting_nonce(
1753
1758
confirmed_account_type : AccountType ,
1754
1759
confirmed_nonce : AccountNonce ,
1755
1760
) -> bool {
1756
- unconfirmed_tx. inputs ( ) . iter ( ) . all ( |inp| match inp {
1757
- TxInput :: Utxo ( _) => true ,
1761
+ unconfirmed_tx. inputs ( ) . iter ( ) . any ( |inp| match inp {
1762
+ TxInput :: Utxo ( _) => false ,
1758
1763
TxInput :: AccountCommand ( nonce, cmd) => {
1759
1764
confirmed_account_type == cmd. into ( ) && * nonce <= confirmed_nonce
1760
1765
}
0 commit comments