Skip to content

Commit

Permalink
sweep: remove dead code and add better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
yyforyongyu committed Feb 7, 2025
1 parent 24ebae2 commit bce9814
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion chainntnfs/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (m *MempoolNotifier) findRelevantInputs(tx *btcutil.Tx) (inputsWithTx,

// If found, save it to watchedInputs to notify the
// subscriber later.
Log.Infof("Found input %s, spent in %s", op, txid)
Log.Debugf("Found input %s, spent in %s", op, txid)

// Construct the spend details.
details := &SpendDetail{
Expand Down
24 changes: 9 additions & 15 deletions sweep/fee_bumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,6 @@ func (t *TxPublisher) processRecords() {
// For records that are confirmed, we'll notify the caller about this
// result.
for _, r := range confirmedRecords {
log.Debugf("Tx=%v is confirmed", r.tx.TxHash())
t.wg.Add(1)
go t.handleTxConfirmed(r)
}
Expand All @@ -982,16 +981,13 @@ func (t *TxPublisher) processRecords() {

// For records that are not confirmed, we perform a fee bump if needed.
for _, r := range feeBumpRecords {
log.Debugf("Attempting to fee bump Tx=%v", r.tx.TxHash())
t.wg.Add(1)
go t.handleFeeBumpTx(r, currentHeight)
}

// For records that are failed, we'll notify the caller about this
// result.
for _, r := range failedRecords {
log.Debugf("Tx=%v has inputs been spent by a third party, "+
"failing it now", r.tx.TxHash())
t.wg.Add(1)
go t.handleThirdPartySpent(r)
}
Expand All @@ -1004,6 +1000,8 @@ func (t *TxPublisher) processRecords() {
func (t *TxPublisher) handleTxConfirmed(r *monitorRecord) {
defer t.wg.Done()

log.Debugf("Record %v is spent in tx=%v", r.requestID, r.tx.TxHash())

// Create a result that will be sent to the resultChan which is
// listened by the caller.
result := &BumpResult{
Expand Down Expand Up @@ -1113,6 +1111,9 @@ func (t *TxPublisher) handleInitialBroadcast(r *monitorRecord) {
func (t *TxPublisher) handleFeeBumpTx(r *monitorRecord, currentHeight int32) {
defer t.wg.Done()

log.Debugf("Attempting to fee bump tx=%v in record %v", r.tx.TxHash(),
r.requestID)

oldTxid := r.tx.TxHash()

// Get the current conf target for this record.
Expand Down Expand Up @@ -1158,6 +1159,10 @@ func (t *TxPublisher) handleFeeBumpTx(r *monitorRecord, currentHeight int32) {
func (t *TxPublisher) handleThirdPartySpent(r *monitorRecord) {
defer t.wg.Done()

log.Debugf("Record %v has inputs spent by a tx unknown to the fee "+
"bumper, failing it now:\n%v", r.requestID,
inputTypeSummary(r.req.Inputs))

// Create a result that will be sent to the resultChan which is
// listened by the caller.
result := &BumpResult{
Expand Down Expand Up @@ -1272,17 +1277,6 @@ func (t *TxPublisher) createAndPublishTx(
return fn.Some(*result)
}

// isConfirmed checks the btcwallet to see whether the tx is confirmed.
func (t *TxPublisher) isConfirmed(txid chainhash.Hash) bool {
details, err := t.cfg.Wallet.GetTransactionDetails(&txid)
if err != nil {
log.Warnf("Failed to get tx details for %v: %v", txid, err)
return false
}

return details.NumConfirmations > 0
}

// isThirdPartySpent checks whether the inputs of the tx has already been spent
// by a third party. When a tx is not confirmed, yet its inputs has been spent,
// then it must be spent by a different tx other than the sweeping tx here.
Expand Down

0 comments on commit bce9814

Please sign in to comment.