Merge pull request #11472 from yyforyongyu/task-sweep-rejections
What changed, and why it matters
This commit fixes a bug in LND's transaction sweeping logic. Previously, if the Bitcoin backend rejected a sweep transaction for a temporary or unknown reason (for example, the mempool was full, a network error occurred, or the rejection reason was unclear), LND would treat the inputs as permanently failed and stop trying to spend them. The fix makes LND retry these inputs later while preserving the intended fee increase schedule, so funds are not left stuck. It also updates the required Go version to 1.27.3 across the project.
Reviewers should verify that the new retry cases do not accidentally retry permanently invalid transactions (e.g., double spends or consensus-invalid inputs) and that the fee cap is respected in all retry paths. Operators should upgrade to a release containing this commit to avoid stuck sweep transactions during mempool congestion or transient backend errors.
Security signals we found
Funds-availability / liveness fix: temporary or unknown mempool rejections could leave sweep inputs unspent.
Error-handling reclassification: previously fatal errors now retryable.
Retry metadata preservation: next fee rate and fee cap kept across attempts.
Go toolchain bump to 1.27.3 (build requirement, not a runtime vulnerability fix).
Dependency normalization: btcwallet pseudo-version replaced with tagged v0.18.1.
Evidence from the diff
The change is in sweep/fee_bumper.go. It reclassifies several backend/mempool errors as retryable (TxFailed) rather than terminal (TxFatal). Specifically, chain.ErrUndefined, chain.ErrMempoolFull, chain.ErrMempoolChainTooLong, chain.ErrTooManyReplacements, chain.ErrReplacementAddsUnconfirmed, and chain.ErrMempoolConflict now keep inputs available for retry. createAndCheckTx wraps non-RPC, non-undefined errors in chain.ErrUndefined so unknown backend failures are retried. Already-in-mempool/known/confirmed errors are treated as success paths so idempotent publication and tracking continue. The retry fee rate is preserved even when the fee function is at its ceiling. Tests are added/updated to cover these cases. The rest of the diff is a Go 1.27.3 version bump and dependency tidying.
Changed components
sweep/fee_bumper.gosweep/fee_bumper_test.godocs/release-notes/unreleased/11472.mdgo.mod and submodule go.mod files (Go version bump)Inspect captured patch +290 / −97
### actor/go.mod
@@ -1,6 +1,6 @@
module github.com/lightningnetwork/lnd/actor
-go 1.26.10
+go 1.27.3
require (
github.com/btcsuite/btclog/v2 v2.0.1-0.20250602222548-9967d19bb084
### cert/go.mod
@@ -1,6 +1,6 @@
module github.com/lightningnetwork/lnd/cert
-go 1.26.10
+go 1.27.3
require github.com/stretchr/testify v1.8.2
### clock/go.mod
@@ -1,6 +1,6 @@
module github.com/lightningnetwork/lnd/clock
-go 1.26.10
+go 1.27.3
require github.com/stretchr/testify v1.8.2
### docs/INSTALL.md
@@ -93,23 +93,23 @@ following build dependencies are required:
### Installing Go
-`lnd` is written in Go, with a minimum version of `1.26.10` (or, in case this
+`lnd` is written in Go, with a minimum version of `1.27.3` (or, in case this
document gets out of date, whatever the Go version in the main `go.mod` file
requires). To install, run one of the following commands for your OS:
<details>
<summary>Linux (x86-64)</summary>
```
- wget https://dl.google.com/go/go1.26.10.linux-amd64.tar.gz
- echo "ccfe7ae822d2c2f41f4fe7c956199967a4dac22d0ee0d2b2bfdb440aab3b20c5 go1.26.10.linux-amd64.tar.gz" | sha256sum --check
+ wget https://dl.google.com/go/go1.27.3.linux-amd64.tar.gz
+ echo "65efbc80fdc1fa2cd2631cad5b481777a68e8725f34e89f50fc6ac714e379b40 go1.27.3.linux-amd64.tar.gz" | sha256sum --check
```
- The command above should output `go1.26.10.linux-amd64.tar.gz: OK`. If it
+ The command above should output `go1.27.3.linux-amd64.tar.gz: OK`. If it
doesn't, then the target REPO HAS BEEN MODIFIED, and you shouldn't install
this version of Go. If it matches, then proceed to install Go:
```
- sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.26.10.linux-amd64.tar.gz
+ sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.27.3.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
```
</details>
@@ -118,15 +118,15 @@ requires). To install, run one of the following commands for your OS:
<summary>Linux (ARMv6)</summary>
```
- wget https://dl.google.com/go/go1.26.10.linux-armv6l.tar.gz
- echo "7d89fd32259eb0ff647381e8c3465dc32ccfc7f71cb7b9bcd95604c3481f5109 go1.26.10.linux-armv6l.tar.gz" | sha256sum --check
+ wget https://dl.google.com/go/go1.27.3.linux-armv6l.tar.gz
+ echo "d6f4e11dd7157030d7ac11c51c8f73201a2db932d593c3106b1da11cc32bfdf8 go1.27.3.linux-armv6l.tar.gz" | sha256sum --check
```
- The command above should output `go1.26.10.linux-armv6l.tar.gz: OK`. If it
+ The command above should output `go1.27.3.linux-armv6l.tar.gz: OK`. If it
isn't, then the target REPO HAS BEEN MODIFIED, and you shouldn't install
this version of Go. If it matches, then proceed to install Go:
```
- sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.26.10.linux-armv6l.tar.gz
+ sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.27.3.linux-armv6l.tar.gz
export PATH=$PATH:/usr/local/go/bin
```
### docs/release-notes/unreleased/11472.md
@@ -0,0 +1,12 @@
+# Bug Fixes
+
+* Sweep inputs [remain available for retry after unknown or transient mempool
+ acceptance failures](https://github.com/lightningnetwork/lnd/pull/11472),
+ preserving the existing fee cap. Already accepted initial transactions
+ continue through normal publication and tracking.
+
+# Improvements
+
+## Breaking Changes
+
+* Building `lnd` now [requires Go 1.27.3](https://github.com/lightningnetwork/lnd/pull/11472).
### fn/go.mod
@@ -1,6 +1,6 @@
module github.com/lightningnetwork/lnd/fn/v2
-go 1.26.10
+go 1.27.3
require (
github.com/stretchr/testify v1.8.1
### go.mod
@@ -16,7 +16,7 @@ require (
github.com/btcsuite/btcd/wire/v2 v2.0.0
github.com/btcsuite/btclog v1.0.0
github.com/btcsuite/btclog/v2 v2.0.1-0.20250728225537-6090e87c6c5b
- github.com/btcsuite/btcwallet v0.18.1-0.20261020132555-16cfb4483d1f
+ github.com/btcsuite/btcwallet v0.18.1
github.com/btcsuite/btcwallet/wallet/txauthor v1.4.0
github.com/btcsuite/btcwallet/wallet/txrules v1.3.0
github.com/btcsuite/btcwallet/walletdb v1.6.0
@@ -35,6 +35,7 @@ require (
github.com/jessevdk/go-flags v1.6.1
github.com/jrick/logrotate v1.1.2
github.com/kkdai/bstream v1.0.0
+ github.com/klauspost/compress v1.18.0
github.com/lightninglabs/neutrino v0.18.0
github.com/lightninglabs/neutrino/cache v1.1.4
github.com/lightningnetwork/lightning-onion v1.4.0
@@ -51,6 +52,7 @@ require (
github.com/lightningnetwork/lnd/tor v1.2.0
github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796
github.com/miekg/dns v1.1.43
+ github.com/pmezard/go-difflib v1.0.0
github.com/prometheus/client_golang v1.23.2
github.com/stretchr/testify v1.11.1
github.com/tv42/zbase32 v0.0.0-20160707012821-501572607d02
@@ -62,6 +64,7 @@ require (
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028
golang.org/x/sync v0.22.0
golang.org/x/term v0.45.0
+ golang.org/x/text v0.40.0
golang.org/x/time v0.3.0
google.golang.org/grpc v1.83.1
google.golang.org/protobuf v1.36.11
@@ -70,11 +73,6 @@ require (
pgregory.net/rapid v1.2.0
)
-require (
- github.com/felixge/httpsnoop v1.1.0 // indirect
- github.com/kcalvinalvin/anet v0.0.0-20251112173137-d8ddc1f6dbee // indirect
-)
-
require (
dario.cat/mergo v1.0.1 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
@@ -102,6 +100,7 @@ require (
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
+ github.com/felixge/httpsnoop v1.1.0 // indirect
github.com/fergusstrange/embedded-postgres v1.25.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-logr/logr v1.4.3 // indirect
@@ -126,7 +125,7 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/juju/loggo v0.0.0-20210728185423-eebad3a902c4 // indirect
github.com/juju/testing v0.0.0-20220203020004-a0ff61f03494 // indirect
- github.com/klauspost/compress v1.18.0
+ github.com/kcalvinalvin/anet v0.0.0-20251112173137-d8ddc1f6dbee // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf // indirect
github.com/mattn/go-isatty v0.0.24 // indirect
@@ -145,7 +144,6 @@ require (
github.com/opencontainers/runc v1.2.8 // indirect
github.com/ory/dockertest/v3 v3.10.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
- github.com/pmezard/go-difflib v1.0.0
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.66.1 // indirect
github.com/prometheus/procfs v0.16.1 // indirect
@@ -187,7 +185,6 @@ require (
golang.org/x/mod v0.38.0 // indirect
golang.org/x/net v0.57.0 // indirect
golang.org/x/sys v0.47.0 // indirect
- golang.org/x/text v0.40.0
golang.org/x/tools v0.48.0 // indirect
google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa // indirect
@@ -213,7 +210,7 @@ replace google.golang.org/protobuf => github.com/lightninglabs/protobuf-go-hex-d
// If you change this please also update docs/INSTALL.md and all other go.mod
// files. The release build toolchain version is tracked separately by
// GO_VERSION in Makefile.
-go 1.26.10
+go 1.27.3
godebug multipathtcp=0
### go.sum
@@ -57,8 +57,8 @@ github.com/btcsuite/btclog v1.0.0 h1:sEkpKJMmfGiyZjADwEIgB1NSwMyfdD1FB8v6+w1T0Ns
github.com/btcsuite/btclog v1.0.0/go.mod h1:w7xnGOhwT3lmrS4H3b/D1XAXxvh+tbhUm8xeHN2y3TQ=
github.com/btcsuite/btclog/v2 v2.0.1-0.20250728225537-6090e87c6c5b h1:MQ+Q6sDy37V1wP1Yu79A5KqJutolqUGwA99UZWQDWZM=
github.com/btcsuite/btclog/v2 v2.0.1-0.20250728225537-6090e87c6c5b/go.mod h1:XItGUfVOxotJL8kkuk2Hj3EVow5KCugXl3wWfQ6K0AE=
-github.com/btcsuite/btcwallet v0.18.1-0.20261020132555-16cfb4483d1f h1:eOaOMpYKDUjcGUI2lQrTSGZa1dy1uS3UrySruwLofhU=
-github.com/btcsuite/btcwallet v0.18.1-0.20261020132555-16cfb4483d1f/go.mod h1:IQrr6b13s0ZTaj9RlM/LhQ+Xvmo/gK86L9oGu2upIeQ=
+github.com/btcsuite/btcwallet v0.18.1 h1:0MdBr89n7XpwqR8sfxL0sjlZwOVkeWW9T+vLDN3KzOM=
+github.com/btcsuite/btcwallet v0.18.1/go.mod h1:PLqcx9tFoT7L2b/cf/aY/lMq4sJaoQYXTS9BmroVy7I=
github.com/btcsuite/btcwallet/wallet/txauthor v1.4.0 h1:oIkGj32YK1CvWaJGlVwZA1f+y/KVHkfrd2PoST0ZpQs=
github.com/btcsuite/btcwallet/wallet/txauthor v1.4.0/go.mod h1:sGrBjcqQ8UPexuRajFs72+o544CJn3Pavv/5H0VAWVk=
github.com/btcsuite/btcwallet/wallet/txrules v1.3.0 h1:D5aGMwWIxdqek3xEJs4eOdMoh6iga2EI2xSlaXCdnNo=
### healthcheck/go.mod
@@ -23,4 +23,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)
-go 1.26.10
+go 1.27.3
### kvdb/go.mod
@@ -139,4 +139,4 @@ require (
sigs.k8s.io/yaml v1.2.0 // indirect
)
-go 1.26.10
+go 1.27.3
### queue/go.mod
@@ -1,6 +1,6 @@
module github.com/lightningnetwork/lnd/queue
-go 1.26.10
+go 1.27.3
require (
github.com/lightningnetwork/lnd/fn/v2 v2.0.8
### sqldb/go.mod
@@ -67,4 +67,4 @@ require (
modernc.org/memory v1.12.1 // indirect
)
-go 1.26.10
+go 1.27.3
### sqldb/v2/go.mod
@@ -70,4 +70,4 @@ require (
// did not yet make it into the upstream repository.
replace github.com/golang-migrate/migrate/v4 => github.com/lightninglabs/migrate/v4 v4.18.2-9023d66a-fork-pr-2.0.20251211093704-71c1eef09789
-go 1.26.10
+go 1.27.3
### sweep/fee_bumper.go
@@ -80,10 +80,11 @@ const (
// TxPublished is sent when the broadcast attempt is finished.
TxPublished BumpEvent = iota
- // TxFailed is sent when the tx has encountered a fee-related error
- // during its creation or broadcast, or an internal error from the fee
- // bumper. In either case the inputs in this tx should be retried with
- // either a different grouping strategy or an increased budget.
+ // TxFailed is sent when creation or broadcast fails but its inputs can
+ // be retried, including fee constraints and transient mempool failures.
+ // Retry can regroup inputs or adjust fees within the budget. A supplied
+ // retry fee rate applies to the next attempt. Initialization can still
+ // reject a zero rate delta and trigger re-estimation.
//
// TODO(yy): Remove the above usage once we remove sweeping non-CPFP
// anchors.
@@ -106,9 +107,9 @@ const (
// broadcast and confirmed.
TxUnknownSpend
- // TxFatal is sent when the inputs in this tx cannot be retried. Txns
- // will end up in this state if they have encountered a non-fee related
- // error, which means they cannot be retried with increased budget.
+ // TxFatal is sent when an error prevents retrying the inputs, such as a
+ // known non-retryable rejection or a local initialization failure.
+ // Unknown and transient mempool acceptance errors use TxFailed.
TxFatal
// sentinelEvent is used to check if an event is unknown.
@@ -551,7 +552,13 @@ func (t *TxPublisher) createRBFCompliantTx(
sweepCtx, err := t.createAndCheckTx(r)
switch {
- case err == nil:
+ // An accepted initial tx still needs idempotent publication to
+ // register rebroadcasting and confirmation tracking.
+ case err == nil,
+ errors.Is(err, chain.ErrTxAlreadyInMempool),
+ errors.Is(err, chain.ErrTxAlreadyKnown),
+ errors.Is(err, chain.ErrTxAlreadyConfirmed):
+
// The tx is valid, store it.
record := t.updateRecord(r, sweepCtx)
@@ -615,6 +622,7 @@ func (t *TxPublisher) createRBFCompliantTx(
// script, and the fee rate. In addition, it validates the tx's mempool
// acceptance before returning a tx that can be published directly, along with
// its fee.
+// Unknown backend failures retain their causes under chain.ErrUndefined.
func (t *TxPublisher) createAndCheckTx(r *monitorRecord) (*sweepTxCtx, error) {
req := r.req
f := r.feeFunction
@@ -673,6 +681,14 @@ func (t *TxPublisher) createAndCheckTx(r *monitorRecord) (*sweepTxCtx, error) {
return sweepCtx, ErrInputMissing
}
+ // Unknown backend errors, including transport failures, do not prove an
+ // input invalid. Reuse ErrUndefined while retaining the original cause;
+ // mapped script and policy errors keep their existing classification.
+ var rpcErr chain.RPCErr
+ if !errors.As(err, &rpcErr) && !errors.Is(err, chain.ErrUndefined) {
+ err = fmt.Errorf("%w: %w", chain.ErrUndefined, err)
+ }
+
return sweepCtx, fmt.Errorf("tx=%v failed mempool check: %w",
sweepCtx.tx.TxHash(), err)
}
@@ -803,9 +819,9 @@ func (t *TxPublisher) notifyResult(result *BumpResult) {
}
}
-// removeResult removes the tracking of the result if the result contains a
-// non-nil error, or the tx is confirmed, the record will be removed from the
-// maps.
+// removeResult releases tracking for a completed publisher attempt. TxFailed
+// leaves the sweeper responsible for retaining and retrying its inputs under
+// a new request.
func (t *TxPublisher) removeResult(result *BumpResult) {
id := result.requestID
@@ -814,15 +830,11 @@ func (t *TxPublisher) removeResult(result *BumpResult) {
txid = result.Tx.TxHash()
}
- // Remove the record from the maps if there's an error or the tx is
- // confirmed. When there's an error, it means this tx has failed its
- // broadcast and cannot be retried. There are two cases it may fail,
- // - when the budget cannot cover the increased fee calculated by the
- // fee function, hence the budget is used up.
- // - when a non-fee related error returned from PublishTransaction.
+ // Finished attempts must release their publisher records. TxFailed
+ // keeps the inputs retryable in the sweeper under a fresh request.
switch result.Event {
case TxFailed:
- log.Errorf("Removing monitor record=%v, tx=%v, due to err: %v",
+ log.Warnf("Removing monitor record=%v, tx=%v, due to err: %v",
id, txid, result.Err)
case TxConfirmed:
@@ -1090,8 +1102,8 @@ func (t *TxPublisher) handleTxConfirmed(r *monitorRecord) {
t.handleResult(result)
}
-// handleInitialTxError takes the error from `initializeTx` and decides the
-// bump event. It will construct a BumpResult and handles it.
+// handleInitialTxError maps initialization failures to retry or terminal
+// results. Backend uncertainty retains inputs and the next retry fee.
func (t *TxPublisher) handleInitialTxError(r *monitorRecord, err error) {
// Create a bump result to be sent to the sweeper.
result := &BumpResult{
@@ -1118,11 +1130,17 @@ func (t *TxPublisher) handleInitialTxError(r *monitorRecord, err error) {
case errors.Is(err, ErrMaxPosition):
fallthrough
- // If the tx doesn't not have enough budget, or if the inputs amounts
- // are not sufficient to cover the budget, we will return a TxFailed
- // event so the sweeper can handle it by re-clustering the utxos.
+ // Budget constraints and reversible or unknown backend failures leave
+ // inputs available for a later block. Preserve their fee trajectory so
+ // re-clustering does not restart at the same insufficient rate.
case errors.Is(err, ErrNotEnoughInputs),
- errors.Is(err, ErrNotEnoughBudget):
+ errors.Is(err, ErrNotEnoughBudget),
+ errors.Is(err, chain.ErrUndefined),
+ errors.Is(err, chain.ErrMempoolFull),
+ errors.Is(err, chain.ErrMempoolChainTooLong),
+ errors.Is(err, chain.ErrTooManyReplacements),
+ errors.Is(err, chain.ErrReplacementAddsUnconfirmed),
+ errors.Is(err, chain.ErrMempoolConflict):
result.Event = TxFailed
@@ -1142,10 +1160,9 @@ func (t *TxPublisher) handleInitialTxError(r *monitorRecord, err error) {
case errors.Is(err, ErrInputMissing):
result = t.handleMissingInputs(r)
- // 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
- // again.
+ // Known non-retryable rejections and local construction errors retain
+ // terminal handling. Only acceptance errors normalized above can enter
+ // the unknown-backend retry case.
//
// TODO(yy): Find out which input is causing the failure and fail that
// one only.
@@ -1175,7 +1192,7 @@ func (t *TxPublisher) handleInitialBroadcast(r *monitorRecord) {
// Create the initial tx to be broadcasted.
record, err := t.initializeTx(r)
if err != nil {
- log.Errorf("Initial broadcast failed: %v", err)
+ log.Warnf("Initial broadcast failed: %v", err)
// We now handle the initialization error and exit.
t.handleInitialTxError(r, err)
@@ -1942,9 +1959,9 @@ func (t *TxPublisher) calculateRetryFeeRate(
// inputs.
_, err := feeFunc.Increment()
if err != nil {
- // The fee function has reached its max position - nothing we
- // can do here other than letting the user increase the budget.
- log.Errorf("Failed to calculate the next fee rate for "+
+ // At its ceiling the existing rate remains usable for retry,
+ // for example after a temporary mempool restriction clears.
+ log.Warnf("Failed to calculate the next fee rate for "+
"Record(%v): %v", r.requestID, err)
}
### sweep/fee_bumper_test.go
@@ -2,6 +2,7 @@ package sweep
import (
"fmt"
+ "io"
"sync/atomic"
"testing"
"time"
@@ -1071,13 +1072,13 @@ func TestBroadcast(t *testing.T) {
require.Equal(t, req, record.req)
}
-// TestBroadcastImmediate checks the public `Broadcast` method can successfully
-// register a broadcast request and publish the tx when `Immediate` flag is
-// set.
+// TestBroadcastImmediate checks immediate requests initialize synchronously
+// and preserve fatal errors that occur before mempool acceptance.
func TestBroadcastImmediate(t *testing.T) {
t.Parallel()
- // Create a publisher using the mocks.
+ // Arrange an immediate request whose estimator fails before a candidate
+ // reaches the backend, separating local failure from RPC uncertainty.
tp, m := createTestPublisher(t)
// Create a test feerate.
@@ -1096,26 +1097,190 @@ func TestBroadcastImmediate(t *testing.T) {
Immediate: true,
}
- // Mock the fee estimator to return an error.
- //
- // NOTE: We are not testing `handleInitialBroadcast` here, but only
- // interested in checking that this method is indeed called when
- // `Immediate` is true. Thus we mock the method to return an error to
- // quickly abort. As long as this mocked method is called, we know the
- // `Immediate` flag works.
+ // Estimation is the first initialization step; no backend call is
+ // expected when it fails, and fixture cleanup verifies the sole call.
m.estimator.On("EstimateFeePerKW", mock.Anything).Return(
chainfee.SatPerKWeight(0), errDummy).Once()
- // Send the req and expect no error.
+ // Act through the public interface without starting block processing;
+ // the immediate flag must deliver the initialization outcome now.
resultChan := tp.Broadcast(req)
require.NotNil(t, resultChan)
- // Validate the record was removed due to an error returned in initial
- // broadcast.
+ // Assert that local initialization failure stays fatal and removes its
+ // request rather than entering the backend-error retry path. Bound the
+ // receive so missing delivery fails before the suite timeout.
+ var result *BumpResult
+ select {
+ case result = <-resultChan:
+
+ case <-time.After(time.Second):
+ t.Fatal("timeout waiting for initial broadcast result")
+ }
+
+ require.Equal(t, TxFatal, result.Event)
+ require.ErrorIs(t, result.Err, errDummy)
require.Empty(t, tp.records.Len())
require.Empty(t, tp.subscriberChans.Len())
}
+// TestBroadcastRetryMempoolErrors checks backend uncertainty and transient
+// policy rejections return retry metadata even at the fee ceiling.
+func TestBroadcastRetryMempoolErrors(t *testing.T) {
+ t.Parallel()
+
+ // Arrange an unknown reason and recognized reversible policy
+ // failures; only the final case varies the available fee headroom.
+ unknownErr := fmt.Errorf("%w: unknown rejection", chain.ErrUndefined)
+ testCases := []struct {
+ name string
+ err error
+ atCeiling bool
+ }{
+ {
+ name: "unknown rejection",
+ err: unknownErr,
+ },
+ {
+ name: "RPC transport failure",
+ err: io.EOF,
+ },
+ {
+ name: "mempool full",
+ err: chain.ErrMempoolFull,
+ },
+ {
+ name: "mempool chain limit",
+ err: chain.ErrMempoolChainTooLong,
+ },
+ {
+ name: "replacement count limit",
+ err: chain.ErrTooManyReplacements,
+ },
+ {
+ name: "replacement unconfirmed input",
+ err: chain.ErrReplacementAddsUnconfirmed,
+ },
+ {
+ name: "unconfirmed conflicting spend",
+ err: chain.ErrMempoolConflict,
+ },
+ {
+ name: "unknown rejection at fee ceiling",
+ err: unknownErr,
+ atCeiling: true,
+ },
+ }
+
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ // Arrange one funded singleton and an explicit starting
+ // rate so the fee function needs no estimator calls.
+ tp, m := createTestPublisher(t)
+ inp := createTestInput(100_000, input.WitnessKeyHash)
+ feeRate := chainfee.SatPerKWeight(1000)
+ maxFeeRate := feeRate * 10
+ deadline := int32(10)
+
+ // A one-block deadline initializes directly at the cap.
+ // This checks retry metadata. A distant capped start
+ // still takes the zero-delta path, which permits
+ // re-estimation on the next block.
+ if tc.atCeiling {
+ deadline = 1
+ }
+ req := &BumpRequest{
+ DeliveryAddress: changePkScript,
+ Inputs: []input.Input{&inp},
+ Budget: btcutil.Amount(10_000),
+ MaxFeeRate: maxFeeRate,
+ StartingFeeRate: fn.Some(feeRate),
+ DeadlineHeight: deadline,
+ Immediate: true,
+ }
+ m.signer.On(
+ "ComputeInputScript",
+ mock.Anything, mock.Anything,
+ ).Return(&input.Script{}, nil).Once()
+ m.wallet.On(
+ "CheckMempoolAcceptance", mock.Anything,
+ ).Return(tc.err).Once()
+
+ // Act with one public broadcast; the failed acceptance
+ // must return without trying to publish the candidate.
+ resultChan := tp.Broadcast(req)
+
+ // Assert retry preserves cause and next fee, keeping
+ // the cap when no further increase is possible. Bound
+ // missing delivery so a regression fails promptly.
+ var result *BumpResult
+ select {
+ case result = <-resultChan:
+
+ case <-time.After(time.Second):
+ t.Fatal("timeout waiting for retry result")
+ }
+
+ require.Equal(t, TxFailed, result.Event)
+ require.ErrorIs(t, result.Err, tc.err)
+ if tc.atCeiling {
+ require.Equal(t, maxFeeRate, result.FeeRate)
+ } else {
+ require.Greater(t, result.FeeRate, feeRate)
+ }
+ })
+ }
+}
+
+// TestBroadcastAlreadyInMempool checks an accepted initial transaction reaches
+// publication so the existing tracking path can continue managing its inputs.
+func TestBroadcastAlreadyInMempool(t *testing.T) {
+ t.Parallel()
+
+ // Arrange a funded immediate request with an explicit rate, isolating
+ // acceptance handling from estimation. The wallet wraps its sentinel,
+ // as the acceptance adapter does before returning to the publisher.
+ tp, m := createTestPublisher(t)
+ inp := createTestInput(100_000, input.WitnessKeyHash)
+ feeRate := chainfee.SatPerKWeight(1000)
+ req := &BumpRequest{
+ DeliveryAddress: changePkScript,
+ Inputs: []input.Input{&inp},
+ Budget: btcutil.Amount(10_000),
+ MaxFeeRate: feeRate * 10,
+ StartingFeeRate: fn.Some(feeRate),
+ DeadlineHeight: 10,
+ Immediate: true,
+ }
+ acceptanceErr := fmt.Errorf("check: %w", chain.ErrTxAlreadyInMempool)
+ m.signer.On(
+ "ComputeInputScript", mock.Anything, mock.Anything,
+ ).Return(&input.Script{}, nil).Once()
+ m.wallet.On(
+ "CheckMempoolAcceptance", mock.Anything,
+ ).Return(acceptanceErr).Once()
+ m.wallet.On(
+ "PublishTransaction", mock.Anything, mock.Anything,
+ ).Return(nil).Once()
+
+ // Act through the public immediate interface; an already accepted
+ // candidate must still reach idempotent publication and registration.
+ resultChan := tp.Broadcast(req)
+
+ // Assert the public result keeps the transaction managed instead of
+ // reporting a fatal rejection. Fixture cleanup verifies publication was
+ // called once; bounded delivery exposes notification regressions.
+ select {
+ case result := <-resultChan:
+ require.Equal(t, TxPublished, result.Event)
+ require.NoError(t, result.Err)
+ require.NotNil(t, result.Tx)
+
+ case <-time.After(time.Second):
+ t.Fatal("timeout waiting for already accepted broadcast result")
+ }
+}
+
// TestCreateAndPublishFail checks all the error cases are handled properly in
// the method createAndPublishTx.
func TestCreateAndPublishFail(t *testing.T) {
@@ -1882,7 +2047,8 @@ func TestHandleInitialBroadcastSuccess(t *testing.T) {
func TestHandleInitialBroadcastFail(t *testing.T) {
t.Parallel()
- // Create a publisher using the mocks.
+ // Arrange a permanent script rejection followed by a publication
+ // failure, keeping their different terminal/retry outcomes explicit.
tp, m := createTestPublisher(t)
// Create a test feerate.
@@ -1915,13 +2081,18 @@ func TestHandleInitialBroadcastFail(t *testing.T) {
// Signer check and always assume the tx has a valid sig.
script := &input.Script{}
m.signer.On("ComputeInputScript", mock.Anything,
- mock.Anything).Return(script, nil)
+ mock.Anything).Return(script, nil).Twice()
- // Mock the testmempoolaccept to return an error.
+ // Both attempts reach acceptance, but only the second can publish.
+ // Fixture cleanup verifies each required call exactly once.
m.wallet.On("CheckMempoolAcceptance",
- mock.Anything).Return(errDummy).Once()
+ mock.Anything).Return(chain.ErrScriptVerifyFlag).Once()
+ m.wallet.On("CheckMempoolAcceptance", mock.Anything).Return(nil).Once()
+ m.wallet.On("PublishTransaction",
+ mock.Anything, mock.Anything).Return(errDummy).Once()
- // Register the testing record use `Broadcast`.
+ // Act by registering a deferred request and driving its first attempt
+ // directly, so no background block processing is needed.
resultChan := tp.Broadcast(req)
// Grab the monitor record from the map.
@@ -1933,28 +2104,23 @@ func TestHandleInitialBroadcastFail(t *testing.T) {
tp.wg.Add(1)
tp.handleInitialBroadcast(rec)
- // Check the result is sent back.
+ // Assert recognized script failure remains fatal rather than being
+ // normalized as backend uncertainty, and its record is removed.
select {
case <-time.After(time.Second):
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)
+ require.ErrorIs(t, result.Err, chain.ErrScriptVerifyFlag)
}
// Validate the record was NOT stored.
require.Equal(t, 0, tp.records.Len())
require.Equal(t, 0, tp.subscriberChans.Len())
- // Mock the testmempoolaccept again, this time it passes.
- m.wallet.On("CheckMempoolAcceptance", mock.Anything).Return(nil).Once()
-
- // Mock the wallet to fail on publish.
- m.wallet.On("PublishTransaction",
- mock.Anything, mock.Anything).Return(errDummy).Once()
-
- // Register the testing record use `Broadcast`.
+ // Act with the separately arranged accepted candidate whose publication
+ // fails, exercising the existing retry contract after acceptance.
resultChan = tp.Broadcast(req)
// Grab the monitor record from the map.
@@ -1966,7 +2132,8 @@ func TestHandleInitialBroadcastFail(t *testing.T) {
tp.wg.Add(1)
tp.handleInitialBroadcast(rec)
- // Check the result is sent back.
+ // Assert publication still returns the original retryable error and
+ // releases this attempt's monitoring records for later re-offering.
select {
case <-time.After(time.Second):
t.Fatal("timeout waiting for subscriber to receive result")
### ticker/go.mod
@@ -1,3 +1,3 @@
module github.com/lightningnetwork/lnd/ticker
-go 1.26.10
+go 1.27.3
### tlv/go.mod
@@ -22,4 +22,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)
-go 1.26.10
+go 1.27.3
### tools/go.mod
@@ -1,6 +1,6 @@
module github.com/lightningnetwork/lnd/tools
-go 1.26.10
+go 1.27.3
require (
4d63.com/gocheckcompilerdirectives v1.4.0 // indirect
### tools/linters/go.mod
@@ -1,6 +1,6 @@
module github.com/lightningnetwork/lnd/tools/linters
-go 1.26.10
+go 1.27.3
require (
github.com/golangci/plugin-module-register v0.1.1
### tor/go.mod
@@ -25,4 +25,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)
-go 1.26.10
+go 1.27.3Why this scored 44/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.