Skip to content

Commit

Permalink
Merge pull request #8887 from yyforyongyu/fix-err-match
Browse files Browse the repository at this point in the history
multi: fix `lnwallet.ErrDoubleSpend`
  • Loading branch information
yyforyongyu authored Jul 8, 2024
2 parents d7e0f69 + e27a656 commit 3526f82
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 99 deletions.
4 changes: 4 additions & 0 deletions chainreg/no_chain_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,8 @@ func (n *NoChainSource) TestMempoolAccept([]*wire.MsgTx,
return nil, nil
}

func (n *NoChainSource) MapRPCErr(err error) error {
return err
}

var _ chain.Interface = (*NoChainSource)(nil)
28 changes: 15 additions & 13 deletions config_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (

"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/rpcclient"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btclog"
"github.com/btcsuite/btcwallet/chain"
"github.com/btcsuite/btcwallet/waddrmgr"
"github.com/btcsuite/btcwallet/wallet"
"github.com/btcsuite/btcwallet/walletdb"
Expand Down Expand Up @@ -708,9 +708,9 @@ func (d *DefaultWalletImpl) BuildChainControl(
// The broadcast is already always active for neutrino nodes, so we
// don't want to create a rebroadcast loop.
if partialChainControl.Cfg.NeutrinoCS == nil {
cs := partialChainControl.ChainSource
broadcastCfg := pushtx.Config{
Broadcast: func(tx *wire.MsgTx) error {
cs := partialChainControl.ChainSource
_, err := cs.SendRawTransaction(
tx, true,
)
Expand All @@ -724,7 +724,10 @@ func (d *DefaultWalletImpl) BuildChainControl(
// In case the backend is different from neutrino we
// make sure that broadcast backend errors are mapped
// to the neutrino broadcastErr.
MapCustomBroadcastError: broadcastErrorMapper,
MapCustomBroadcastError: func(err error) error {
rpcErr := cs.MapRPCErr(err)
return broadcastErrorMapper(rpcErr)
},
}

lnWalletConfig.Rebroadcaster = newWalletReBroadcaster(
Expand Down Expand Up @@ -1475,41 +1478,40 @@ func parseHeaderStateAssertion(state string) (*headerfs.FilterHeader, error) {
// the neutrino BroadcastError which allows the Rebroadcaster which currently
// resides in the neutrino package to use all of its functionalities.
func broadcastErrorMapper(err error) error {
returnErr := rpcclient.MapRPCErr(err)
var returnErr error

// We only filter for specific backend errors which are relevant for the
// Rebroadcaster.
switch {
// This makes sure the tx is removed from the rebroadcaster once it is
// confirmed.
case errors.Is(returnErr, rpcclient.ErrTxAlreadyKnown),
errors.Is(err, rpcclient.ErrTxAlreadyConfirmed):
case errors.Is(err, chain.ErrTxAlreadyKnown),
errors.Is(err, chain.ErrTxAlreadyConfirmed):

returnErr = &pushtx.BroadcastError{
Code: pushtx.Confirmed,
Reason: returnErr.Error(),
Reason: err.Error(),
}

// Transactions which are still in mempool but might fall out because
// of low fees are rebroadcasted despite of their backend error.
case errors.Is(returnErr, rpcclient.ErrTxAlreadyInMempool):
case errors.Is(err, chain.ErrTxAlreadyInMempool):
returnErr = &pushtx.BroadcastError{
Code: pushtx.Mempool,
Reason: returnErr.Error(),
Reason: err.Error(),
}

// Transactions which are not accepted into mempool because of low fees
// in the first place are rebroadcasted despite of their backend error.
// Mempool conditions change over time so it makes sense to retry
// publishing the transaction. Moreover we log the detailed error so the
// user can intervene and increase the size of his mempool.
case errors.Is(err, rpcclient.ErrMempoolMinFeeNotMet):
ltndLog.Warnf("Error while broadcasting transaction: %v",
returnErr)
case errors.Is(err, chain.ErrMempoolMinFeeNotMet):
ltndLog.Warnf("Error while broadcasting transaction: %v", err)

returnErr = &pushtx.BroadcastError{
Code: pushtx.Mempool,
Reason: returnErr.Error(),
Reason: err.Error(),
}
}

Expand Down
64 changes: 4 additions & 60 deletions docs/release-notes/release-notes-0.18.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,76 +19,25 @@

# Bug Fixes

* `closedchannels` now [successfully reports](https://github.com/lightningnetwork/lnd/pull/8800)
settled balances even if the delivery address is set to an address that
LND does not control.

* [SendPaymentV2](https://github.com/lightningnetwork/lnd/pull/8734) now cancels
the background payment loop if the user cancels the stream context.

* [Fixed a bug](https://github.com/lightningnetwork/lnd/pull/8822) that caused
LND to read the config only partially and continued with the startup.
* [Fixed a bug](https://github.com/lightningnetwork/lnd/pull/8887) in error
matching from publishing already confirmed transactions that can cause lnd
fail to startup if `btcd` with an older version (pre-`v0.24.2`) is used.

# New Features
## Functional Enhancements
## RPC Additions

* The [SendPaymentRequest](https://github.com/lightningnetwork/lnd/pull/8734)
message receives a new flag `cancelable` which indicates if the payment loop
is cancelable. The cancellation can either occur manually by cancelling the
send payment stream context, or automatically at the end of the timeout period
if the user provided `timeout_seconds`.

## lncli Additions

* [Added](https://github.com/lightningnetwork/lnd/pull/8491) the `cltv_expiry`
argument to `addinvoice` and `addholdinvoice`, allowing users to set the
`min_final_cltv_expiry_delta`.

* The [`lncli wallet estimatefeerate`](https://github.com/lightningnetwork/lnd/pull/8730)
command returns the fee rate estimate for on-chain transactions in sat/kw and
sat/vb to achieve a given confirmation target.

# Improvements
## Functional Updates
## RPC Updates

* [`xImportMissionControl`](https://github.com/lightningnetwork/lnd/pull/8779)
now accepts `0` failure amounts.

* [`ChanInfoRequest`](https://github.com/lightningnetwork/lnd/pull/8813)
adds support for channel points.

## lncli Updates

* [`importmc`](https://github.com/lightningnetwork/lnd/pull/8779) now accepts
`0` failure amounts.

* [`getchaninfo`](https://github.com/lightningnetwork/lnd/pull/8813) now accepts
a channel outpoint besides a channel id.

* [Fixed](https://github.com/lightningnetwork/lnd/pull/8823) how we parse the
`--amp` flag when sending a payment specifying the payment request.

## Code Health
## Breaking Changes
## Performance Improvements

* Mission Control Store [improved performance during DB
flushing](https://github.com/lightningnetwork/lnd/pull/8549) stage.

# Technical and Architectural Updates
## BOLT Spec Updates

* Start assuming that all hops used during path-finding and route construction
[support the TLV onion
format](https://github.com/lightningnetwork/lnd/pull/8791).

* Allow channel fundee to send a [minimum confirmation depth of
0](https://github.com/lightningnetwork/lnd/pull/8796) for a non-zero-conf
channel. We will still wait for the channel to have at least one confirmation
and so the main change here is that we don't error out for such a case.

## Testing
## Database

Expand All @@ -100,9 +49,4 @@

# Contributors (Alphabetical Order)

* Andras Banki-Horvath
* Bufo
* Elle Mouton
* Matheus Degiovani
* Oliver Gugger
* Slyghtning
* Yong Yu
105 changes: 105 additions & 0 deletions docs/release-notes/release-notes-0.18.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Release Notes
- [Bug Fixes](#bug-fixes)
- [New Features](#new-features)
- [Functional Enhancements](#functional-enhancements)
- [RPC Additions](#rpc-additions)
- [lncli Additions](#lncli-additions)
- [Improvements](#improvements)
- [Functional Updates](#functional-updates)
- [RPC Updates](#rpc-updates)
- [lncli Updates](#lncli-updates)
- [Breaking Changes](#breaking-changes)
- [Performance Improvements](#performance-improvements)
- [Technical and Architectural Updates](#technical-and-architectural-updates)
- [BOLT Spec Updates](#bolt-spec-updates)
- [Testing](#testing)
- [Database](#database)
- [Code Health](#code-health)
- [Tooling and Documentation](#tooling-and-documentation)

# Bug Fixes

* `closedchannels` now [successfully reports](https://github.com/lightningnetwork/lnd/pull/8800)
settled balances even if the delivery address is set to an address that
LND does not control.

* [SendPaymentV2](https://github.com/lightningnetwork/lnd/pull/8734) now cancels
the background payment loop if the user cancels the stream context.

* [Fixed a bug](https://github.com/lightningnetwork/lnd/pull/8822) that caused
LND to read the config only partially and continued with the startup.

# New Features
## Functional Enhancements
## RPC Additions

* The [SendPaymentRequest](https://github.com/lightningnetwork/lnd/pull/8734)
message receives a new flag `cancelable` which indicates if the payment loop
is cancelable. The cancellation can either occur manually by cancelling the
send payment stream context, or automatically at the end of the timeout period
if the user provided `timeout_seconds`.

## lncli Additions

* [Added](https://github.com/lightningnetwork/lnd/pull/8491) the `cltv_expiry`
argument to `addinvoice` and `addholdinvoice`, allowing users to set the
`min_final_cltv_expiry_delta`.

* The [`lncli wallet estimatefeerate`](https://github.com/lightningnetwork/lnd/pull/8730)
command returns the fee rate estimate for on-chain transactions in sat/kw and
sat/vb to achieve a given confirmation target.

# Improvements
## Functional Updates
## RPC Updates

* [`xImportMissionControl`](https://github.com/lightningnetwork/lnd/pull/8779)
now accepts `0` failure amounts.

* [`ChanInfoRequest`](https://github.com/lightningnetwork/lnd/pull/8813)
adds support for channel points.

## lncli Updates

* [`importmc`](https://github.com/lightningnetwork/lnd/pull/8779) now accepts
`0` failure amounts.

* [`getchaninfo`](https://github.com/lightningnetwork/lnd/pull/8813) now accepts
a channel outpoint besides a channel id.

* [Fixed](https://github.com/lightningnetwork/lnd/pull/8823) how we parse the
`--amp` flag when sending a payment specifying the payment request.

## Code Health
## Breaking Changes
## Performance Improvements

* Mission Control Store [improved performance during DB
flushing](https://github.com/lightningnetwork/lnd/pull/8549) stage.

# Technical and Architectural Updates
## BOLT Spec Updates

* Start assuming that all hops used during path-finding and route construction
[support the TLV onion
format](https://github.com/lightningnetwork/lnd/pull/8791).

* Allow channel fundee to send a [minimum confirmation depth of
0](https://github.com/lightningnetwork/lnd/pull/8796) for a non-zero-conf
channel. We will still wait for the channel to have at least one confirmation
and so the main change here is that we don't error out for such a case.

## Testing
## Database
## Code Health
## Tooling and Documentation

# Contributors (Alphabetical Order)

* Andras Banki-Horvath
* Bufo
* Elle Mouton
* Matheus Degiovani
* Oliver Gugger
* Slyghtning
* Yong Yu
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/btcsuite/btcd/btcutil/psbt v1.1.8
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
github.com/btcsuite/btcwallet v0.16.10-0.20240625163855-b42ed59f0528
github.com/btcsuite/btcwallet v0.16.10-0.20240706055350-e391a1c31df2
github.com/btcsuite/btcwallet/wallet/txauthor v1.3.4
github.com/btcsuite/btcwallet/wallet/txrules v1.2.1
github.com/btcsuite/btcwallet/walletdb v1.4.2
Expand Down Expand Up @@ -54,7 +54,7 @@ require (
golang.org/x/crypto v0.22.0
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028
golang.org/x/net v0.22.0
golang.org/x/net v0.24.0
golang.org/x/sync v0.6.0
golang.org/x/term v0.19.0
golang.org/x/time v0.3.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0/go.mod h1:7SFka0XMvUgj3hfZtyd
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
github.com/btcsuite/btcwallet v0.16.10-0.20240625163855-b42ed59f0528 h1:DZRmr47CdPnNglwEVACPnJnGrfb/GBGyoGs5oqvLFg4=
github.com/btcsuite/btcwallet v0.16.10-0.20240625163855-b42ed59f0528/go.mod h1:SLFUSQbP8ON/wxholYMfVLvGPJyk7boczOW/ob+nww4=
github.com/btcsuite/btcwallet v0.16.10-0.20240706055350-e391a1c31df2 h1:mJquwdcEA4hZip4XKbRPAM9rOrus6wlNEcWzMz5CHsI=
github.com/btcsuite/btcwallet v0.16.10-0.20240706055350-e391a1c31df2/go.mod h1:SLFUSQbP8ON/wxholYMfVLvGPJyk7boczOW/ob+nww4=
github.com/btcsuite/btcwallet/wallet/txauthor v1.3.4 h1:poyHFf7+5+RdxNp5r2T6IBRD7RyraUsYARYbp/7t4D8=
github.com/btcsuite/btcwallet/wallet/txauthor v1.3.4/go.mod h1:GETGDQuyq+VFfH1S/+/7slLM/9aNa4l7P4ejX6dJfb0=
github.com/btcsuite/btcwallet/wallet/txrules v1.2.1 h1:UZo7YRzdHbwhK7Rhv3PO9bXgTxiOH45edK5qdsdiatk=
Expand Down Expand Up @@ -759,8 +759,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down
6 changes: 6 additions & 0 deletions lnmock/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,9 @@ func (m *MockChain) TestMempoolAccept(txns []*wire.MsgTx, maxFeeRate float64) (

return args.Get(0).([]*btcjson.TestMempoolAcceptResult), args.Error(1)
}

func (m *MockChain) MapRPCErr(err error) error {
args := m.Called(err)

return args.Error(0)
}
Loading

0 comments on commit 3526f82

Please sign in to comment.