@@ -897,8 +897,6 @@ func (t *TxPublisher) processRecords() {
897
897
898
898
// failedRecords stores a map of records which has inputs being spent
899
899
// by a third party.
900
- //
901
- // NOTE: this is only used for neutrino backend.
902
900
failedRecords := make (map [uint64 ]* monitorRecord )
903
901
904
902
// initialRecords stores a map of records which are being created and
@@ -908,32 +906,55 @@ func (t *TxPublisher) processRecords() {
908
906
// visitor is a helper closure that visits each record and divides them
909
907
// into two groups.
910
908
visitor := func (requestID uint64 , r * monitorRecord ) error {
911
- if r .tx == nil {
912
- initialRecords [requestID ] = r
913
- return nil
914
- }
909
+ log .Tracef ("Checking monitor recordID=%v" , requestID )
910
+
911
+ // Check whether the inputs have already been spent.
912
+ spends := t .getSpentInputs (r )
913
+
914
+ // If the any of the inputs has been spent, the record will be
915
+ // marked as failed or confirmed.
916
+ if len (spends ) != 0 {
917
+ // When tx is nil, it means we haven't tried the initial
918
+ // broadcast yet the input is already spent. This could
919
+ // happen when the node shuts down, a previous sweeping
920
+ // tx confirmed, then the node comes back online and
921
+ // reoffers the inputs. Another case is the remote node
922
+ // spends the input quickly before we even attempt the
923
+ // sweep. In either case we will fail the record and let
924
+ // the sweeper handles it.
925
+ if r .tx == nil {
926
+ failedRecords [requestID ] = r
927
+ return nil
928
+ }
915
929
916
- log .Tracef ("Checking monitor recordID=%v for tx=%v" , requestID ,
917
- r .tx .TxHash ())
930
+ // Check whether the inputs has been spent by a unknown
931
+ // tx.
932
+ if t .isThirdPartySpent (r , spends ) {
933
+ failedRecords [requestID ] = r
934
+
935
+ // Move to the next record.
936
+ return nil
937
+ }
918
938
919
- // If the tx is already confirmed , we can stop monitoring it.
920
- if t . isConfirmed ( r . tx . TxHash ()) {
939
+ // The tx is ours , we can move it to the confirmed queue
940
+ // and stop monitoring it.
921
941
confirmedRecords [requestID ] = r
922
942
923
943
// Move to the next record.
924
944
return nil
925
945
}
926
946
927
- // Check whether the inputs has been spent by a third party.
928
- //
929
- // NOTE: this check is only done for neutrino backend.
930
- if t .isThirdPartySpent (r ) {
931
- failedRecords [requestID ] = r
947
+ // This is the first time we see this record, so we put it in
948
+ // the initial queue.
949
+ if r .tx == nil {
950
+ initialRecords [requestID ] = r
932
951
933
- // Move to the next record.
934
952
return nil
935
953
}
936
954
955
+ // We can only get here when the inputs are not spent and a
956
+ // previous sweeping tx has been attempted. In this case we will
957
+ // perform an RBF on it in the current block.
937
958
feeBumpRecords [requestID ] = r
938
959
939
960
// Return nil to move to the next record.
@@ -1265,17 +1286,10 @@ func (t *TxPublisher) isConfirmed(txid chainhash.Hash) bool {
1265
1286
// isThirdPartySpent checks whether the inputs of the tx has already been spent
1266
1287
// by a third party. When a tx is not confirmed, yet its inputs has been spent,
1267
1288
// then it must be spent by a different tx other than the sweeping tx here.
1268
- //
1269
- // NOTE: this check is only performed for neutrino backend as it has no
1270
- // reliable way to tell a tx has been replaced.
1271
- func (t * TxPublisher ) isThirdPartySpent (r * monitorRecord ) bool {
1272
- // Skip this check for if this is not neutrino backend.
1273
- if ! t .isNeutrinoBackend () {
1274
- return false
1275
- }
1289
+ func (t * TxPublisher ) isThirdPartySpent (r * monitorRecord ,
1290
+ spends map [wire.OutPoint ]* wire.MsgTx ) bool {
1276
1291
1277
1292
txid := r .tx .TxHash ()
1278
- spends := t .getSpentInputs (r )
1279
1293
1280
1294
// Iterate all the spending txns and check if they match the sweeping
1281
1295
// tx.
0 commit comments