Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions sweep/fee_bumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ var (
// ErrInputMissing is returned when a given input no longer exists,
// e.g., spending from an orphan tx.
ErrInputMissing = errors.New("input no longer exists")

// ErrMempoolAcceptance is returned when a transaction fails
// testmempoolaccept for a reason that doesn't have a more specific
// sweeper error type.
ErrMempoolAcceptance = errors.New("mempool acceptance check failed")
)

var (
Expand Down Expand Up @@ -673,8 +678,8 @@ func (t *TxPublisher) createAndCheckTx(r *monitorRecord) (*sweepTxCtx, error) {
return sweepCtx, ErrInputMissing
}

return sweepCtx, fmt.Errorf("tx=%v failed mempool check: %w",
sweepCtx.tx.TxHash(), err)
return sweepCtx, fmt.Errorf("%w: tx=%v: %w",
ErrMempoolAcceptance, sweepCtx.tx.TxHash(), err)
}

// handleMissingInputs handles the case when the chain backend reports back a
Expand Down Expand Up @@ -1142,6 +1147,21 @@ func (t *TxPublisher) handleInitialTxError(r *monitorRecord, err error) {
case errors.Is(err, ErrInputMissing):
result = t.handleMissingInputs(r)

// If testmempoolaccept rejects the initial sweep tx for a
// non-fee-related reason, don't terminally fail the entire input set.
// The failure may be caused by a single bad witness in a larger batch,
// so let the sweeper retry and re-cluster the inputs instead.
case errors.Is(err, ErrMempoolAcceptance):
result.Event = TxFailed

feeRate, err := t.calculateRetryFeeRate(r)
if err != nil {
result.Event = TxFatal
result.Err = err
}

result.FeeRate = feeRate

// Otherwise this is not a fee-related error and the tx cannot be
// retried. In that case we will fail ALL the inputs in this tx, which
// means they will be removed from the sweeper and never be tried
Expand Down
6 changes: 4 additions & 2 deletions sweep/fee_bumper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1944,8 +1944,10 @@ func TestHandleInitialBroadcastFail(t *testing.T) {
t.Fatal("timeout waiting for subscriber to receive result")

case result := <-resultChan:
// We expect the first result to be TxFatal.
require.Equal(t, TxFatal, result.Event)
// A non-fee-related testmempoolaccept failure should be
// retried by the sweeper instead of terminally failing all
// inputs in the initial batch.
require.Equal(t, TxFailed, result.Event)
}

// Validate the record was NOT stored.
Expand Down
Loading