@@ -425,8 +425,6 @@ public void ProcessBlock(Block block, ChainedHeader chainedHeader)
425425 walletUpdated = true ;
426426 }
427427
428- walletUpdated |= this . CleanTransactionsPastMaxReorg ( chainedHeader . Height ) ;
429-
430428 // Update the wallets with the last processed block height.
431429 // It's important that updating the height happens after the block processing is complete,
432430 // as if the node is stopped, on re-opening it will start updating from the previous height.
@@ -539,26 +537,27 @@ public bool ProcessTransaction(Transaction transaction, int? blockHeight = null,
539537 }
540538 }
541539
542- private bool CleanTransactionsPastMaxReorg ( int height )
540+ /// <inheritdoc />
541+ public bool CleanTransactionsPastMaxReorg ( int crossChainTransferStoreTip )
543542 {
544543 bool walletUpdated = false ;
545544
546545 if ( this . network . Consensus . MaxReorgLength == 0 || this . Wallet . MultiSigAddress . Transactions . Count <= MinimumRetainedTransactions )
547546 return walletUpdated ;
548547
549- int finalisedHeight = height - ( int ) this . network . Consensus . MaxReorgLength ;
550- var pastMaxReorg = new List < TransactionData > ( ) ;
548+ int heightToCleanFrom = crossChainTransferStoreTip - ( int ) this . network . Consensus . MaxReorgLength ;
549+ var transactionsPastMaxReorg = new List < TransactionData > ( ) ;
551550
552- foreach ( ( _ , List < TransactionData > txList ) in this . Wallet . MultiSigAddress . Transactions . SpentTransactionsBeforeHeight ( finalisedHeight ) )
551+ // Only want to remove transactions that are spent, and the spend must have passed max reorg too
552+ foreach ( ( _ , List < TransactionData > txList ) in this . Wallet . MultiSigAddress . Transactions . SpentTransactionsBeforeHeight ( heightToCleanFrom ) )
553553 {
554554 foreach ( TransactionData transactionData in txList )
555555 {
556- // Only want to remove transactions that are spent, and the spend must have passed max reorg too
557- pastMaxReorg . Add ( transactionData ) ;
556+ transactionsPastMaxReorg . Add ( transactionData ) ;
558557 }
559558 }
560559
561- foreach ( TransactionData transactionData in pastMaxReorg )
560+ foreach ( TransactionData transactionData in transactionsPastMaxReorg )
562561 {
563562 this . Wallet . MultiSigAddress . Transactions . Remove ( transactionData ) ;
564563 walletUpdated = true ;
@@ -567,6 +566,8 @@ private bool CleanTransactionsPastMaxReorg(int height)
567566 break ;
568567 }
569568
569+ this . logger . Debug ( "Cleaned {0} transactions older than the CCTS tip less max reorg of {1}." , transactionsPastMaxReorg . Count , crossChainTransferStoreTip ) ;
570+
570571 return walletUpdated ;
571572 }
572573
0 commit comments