mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-07 19:30:46 +02:00
lnd: define additional rebroadcaster function.
The MapCustomBroadcastError of the rebroadcaster is defined. This let's us use the Rebroadcaster of the neutrino package (pushtx) with other backends and guarantee a consistent behaviour. Prior to this change the rebroadcaster would stop rebroadcasting transactions because they did not meet the neutrino specific broadcastErr type.
This commit is contained in:
@@ -3,6 +3,7 @@ package lnd
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
@@ -719,6 +720,10 @@ func (d *DefaultWalletImpl) BuildChainControl(
|
|||||||
partialChainControl.ChainNotifier,
|
partialChainControl.ChainNotifier,
|
||||||
),
|
),
|
||||||
RebroadcastInterval: pushtx.DefaultRebroadcastInterval,
|
RebroadcastInterval: pushtx.DefaultRebroadcastInterval,
|
||||||
|
// In case the backend is different from neutrino we
|
||||||
|
// make sure that broadcast backend errors are mapped
|
||||||
|
// to the neutrino broadcastErr.
|
||||||
|
MapCustomBroadcastError: broadcastErrorMapper,
|
||||||
}
|
}
|
||||||
|
|
||||||
lnWalletConfig.Rebroadcaster = newWalletReBroadcaster(
|
lnWalletConfig.Rebroadcaster = newWalletReBroadcaster(
|
||||||
@@ -1420,3 +1425,50 @@ func parseHeaderStateAssertion(state string) (*headerfs.FilterHeader, error) {
|
|||||||
FilterHash: *hash,
|
FilterHash: *hash,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// broadcastErrorMapper maps errors from bitcoin backends other than neutrino to
|
||||||
|
// 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 := wallet.MapBroadcastBackendError(err)
|
||||||
|
|
||||||
|
// We only filter for specific backend errors which are relevant for the
|
||||||
|
// Rebroadcaster.
|
||||||
|
var errAlreadyConfirmed *wallet.ErrAlreadyConfirmed
|
||||||
|
var errInMempool *wallet.ErrInMempool
|
||||||
|
var errMempoolFee *wallet.ErrMempoolFee
|
||||||
|
|
||||||
|
switch {
|
||||||
|
// This makes sure the tx is removed from the rebroadcaster once it is
|
||||||
|
// confirmed.
|
||||||
|
case errors.As(returnErr, &errAlreadyConfirmed):
|
||||||
|
returnErr = &pushtx.BroadcastError{
|
||||||
|
Code: pushtx.Confirmed,
|
||||||
|
Reason: returnErr.Error(),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transactions which are still in mempool but might fall out because
|
||||||
|
// of low fees are rebroadcasted despite of their backend error.
|
||||||
|
case errors.As(returnErr, &errInMempool):
|
||||||
|
returnErr = &pushtx.BroadcastError{
|
||||||
|
Code: pushtx.Mempool,
|
||||||
|
Reason: returnErr.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.As(returnErr, &errMempoolFee):
|
||||||
|
ltndLog.Warnf("Error while broadcasting transaction: %v",
|
||||||
|
returnErr)
|
||||||
|
|
||||||
|
returnErr = &pushtx.BroadcastError{
|
||||||
|
Code: pushtx.Mempool,
|
||||||
|
Reason: returnErr.Error(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnErr
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user